1

以下是我的安全配置:

    <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 我收到错误登录密码的错误消息..并且重置密码或忘记密码链接也有效并重定向。但是,不是欢迎页面

此时它失败了,当我调试时,主体具有 role_admin 权限,并且密码具有正确的值。但是,在这个调用newAuth之后有空值!UsernamePasswordAuthenticationToken

Authentication newAuth = new UsernamePasswordAuthenticationToken(principal, password);

编辑:它试图通过身份验证管理器,因为在我的配置中,我正在使用 authentication-manager并且UsernamePasswordAuthenticationToken方法需要 3 个参数。

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

这将解决问题!

4

2 回答 2

1

UsernamePasswordAuthenticationTokenAuthentication Manager由于配置的原因,试图通过,UsernamePasswordAuthenticationToken方法需要 3 个参数。

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

通过传递第三个参数authorities经理感到满意:)并让用户通过!

于 2013-02-21T16:54:08.270 回答
0

我猜发生的情况是,在成功登录后,浏览器实际上被重定向到/welcome.do,但经过身份验证的用户无权查看该页面,因此它被发送回登录页面。仔细检查(例如,通过启用调试级别日志记录)用户是否确实拥有下列权限之一:

        <security:intercept-url pattern="/welcome.do" access="ROLE_ADMIN,ROLE_HD,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR,ROLE_USER,ROLE_SCANNER"/>
于 2013-02-21T16:08:15.447 回答