【发布时间】:2016-09-29 02:47:45
【问题描述】:
我正在使用 Spring Security 来验证和验证我的用户。身份验证工作得很好,但是当用户被重定向到需要特定访问权限的登录页面时,它会转到拒绝访问页面(用户具有所需的访问权限)
这是我的 Spring 安全配置:
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/welcome*" access="hasRole('ADMIN')" />
<!-- access denied page -->
<access-denied-handler error-page="/403" />
<form-login login-page="/login"
default-target-url="/welcome"
authentication-failure-url="/login?error"
username-parameter="emailId"
password-parameter="pwd" />
<logout logout-success-url="/login?logout" />
</http>
这是控制台日志的最后一部分:
2016-05-31 12:37:39 DEBUG FilterSecurityInterceptor:348 - Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@2586e756: Principal: org.springframework.security.core.userdetails.User@4361438: Username: test@test.com; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted **Authorities: ADMIN**,USER-EX; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffd3270: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: EF69C8E091A4AFEA8B043CC29AF29AE0; Granted Authorities: ADMIN, USER-EX
2016-05-31 12:37:39 DEBUG AffirmativeBased:66 - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@6eb2a0ec, returned: -1
2016-05-31 12:37:39 DEBUG ExceptionTranslationFilter:186 - Access is denied (user is not anonymous); delegating to AccessDeniedHandler
org.springframework.security.access.AccessDeniedException: Access is denied
如您所见,日志显示用户已通过身份验证并具有“ADMIN”访问权限,并且应该能够查看 /welcome 页面,但这并没有发生。
我们将不胜感激。
春季版 - 4.2.6 弹簧安全 - 4.1.0 Java - 1.8
【问题讨论】:
-
-
你使用的是spring 4所以使用java配置youtube.com/watch?v=gTDNgD1Iz6c
-
@LynAs 纠正了我的错字。但问题仍然存在。
标签: java spring spring-mvc spring-security