以下是我的安全配置:
<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);
这将解决问题!