簡體   English   中英

春季安全性3.1:登錄后,不重定向到歡迎頁面

[英]spring secruity 3.1: after login, not redirecting to welcome page

以下是我的安全配置:

    <security:http pattern="/login.*" security="none"/>
      <security:http realm="myrealm">
            <security:intercept-url pattern="/" access="ROLE_USER,ROLE_ADMIN,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR"/>
            <security:intercept-url pattern="/*jsp" access="ROLE_USER,ROLE_ADMIN,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR"/>
            <security:intercept-url pattern="/welcome.do" access="ROLE_ADMIN,ROLE_HD,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR,ROLE_USER,ROLE_SCANNER"/>
            <security:intercept-url pattern="/*do"   access="ROLE_ADMIN,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR,ROLE_USER"/>
            <security:form-login login-page="/login.do" 
                 default-target-url="/welcome.do" 
                 always-use-default-target="true"
                 authentication-failure-url="/login.do?login_error=1"/>
            <security:logout logout-success-url="/login.do" />
            <security:http-basic/>
            <security:anonymous />
     </security:http>

    <bean id="authProvider" class="AuthenticationProvider">
    </bean>     
    <security:authentication-manager alias="authenticationManager">  
        <security:authentication-provider ref="authProvider"/>
    </security:authentication-manager>

在輸入憑據並提交后,我可以看到登錄頁面,它沒有重定向並刷新了相同的登錄頁面。 在調試模式下,我可以看到: Authenticated SCOTT on local database我在錯誤的登錄密碼上收到錯誤消息。並且重置密碼或忘記密碼的鏈接也可以正常工作並重定向。 但是,不是歡迎頁面

這是失敗的,當我調試時,principal具有role_admin權限,而password具有正確的值。 但是,在此UsernamePasswordAuthenticationToken調用之后, newAuth值為空!

Authentication newAuth = new UsernamePasswordAuthenticationToken(principal, password);

編輯:它正試圖通過身份驗證管理器,因為在我的配置中,我使用的是authentication-managerUsernamePasswordAuthenticationToken方法需要3個參數。

UsernamePasswordAuthenticationToken(object principal, object credentials, collection authorities);

這將解決問題!

UsernamePasswordAuthenticationToken試圖去througth的Authentication Manager ,因為CONFIGS的, UsernamePasswordAuthenticationToken方法需要3個參數。

UsernamePasswordAuthenticationToken(object principal, object credentials, collection authorities);

通過粘貼第三個參數authorities管理器,可以滿足:)並讓用戶通過!!!

我猜發生了什么事,成功登錄后,瀏覽器實際上被重定向到/welcome.do ,但是未授權經過身份驗證的用戶查看該頁面,因此將其發送回登錄頁面。 仔細檢查(例如,通過啟用調試級別日志記錄)用戶是否確實擁有以下所列權限之一:

        <security:intercept-url pattern="/welcome.do" access="ROLE_ADMIN,ROLE_HD,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR,ROLE_USER,ROLE_SCANNER"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM