簡體   English   中英

Spring security - 拒絕授權用戶訪問

[英]Spring security - Access denied to authorised user

我正在使用 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

如您所見,日志顯示用戶已通過身份驗證並具有“管理員”訪問權限,並且應該能夠查看 /welcome 頁面,但這並沒有發生。

任何幫助在這里將不勝感激。

Spring 版本 - 4.2.6 Spring Security - 4.1.0 Java - 1.8

你沒有提到“/welcome”的授權

前任:

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

原來是一個“/”在逃學。

<intercept-url pattern="/welcome*" access="hasRole('ADMIN')" />更改為<intercept-url pattern="/welcome/*" access="hasRole('ADMIN')" />

我看過模式為“/abc/**”的教程 誰能告訴我單 * 和雙之間的區別? 謝謝

暫無
暫無

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

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