【问题标题】:Spring security - Access denied to authorised userSpring security - 拒绝授权用户访问
【发布时间】: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

【问题讨论】:

标签: java spring spring-mvc spring-security


【解决方案1】:

原来是一个“/”在逃学。

已更改 &lt;intercept-url pattern="/welcome*" access="hasRole('ADMIN')" /&gt; &lt;intercept-url pattern="/welcome/*" access="hasRole('ADMIN')" /&gt;

我看过模式是“/abc/**”的教程,谁能告诉我单*和双精度的区别?谢谢

【讨论】:

  • 要提出新问题,请使用页面顶部的“”按钮。如果它有助于提供上下文,您可以链接到这个问题。
【解决方案2】:

你没有提到“/welcome”的授权

例如:

<intercept-url pattern="/welcome" access="isAuthenticated()" />

【讨论】:

  • 我已经添加了这个(实际上编辑了错字)但问题仍然存在。
猜你喜欢
  • 2020-04-26
  • 2018-04-27
  • 2021-10-10
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
  • 2015-11-13
  • 2022-01-06
  • 2020-04-05
相关资源
最近更新 更多