私は本当に春のセキュリティに新しいですので、気をつけてください。誰かが私を導くことができるなら、この質問をより具体的にするための提案に私は開いています。Spring SecurityのインターセプトURLがカスタムUserDetailsオブジェクトと連携していません
私の問題は、春のセキュリティではインターセプトURL設定があるが、ユーザーが必要な役割を果たす場合でも常にアクセス拒否ページにリダイレクトされることです。これは私の春のセキュリティの設定です:
私の研究を通して<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.1.xsd">
<!-- enable use-expressions -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
<!-- access denied page -->
<access-denied-handler error-page="/403" />
<session-management invalid-session-url="/login"
session-fixation-protection="newSession">
<concurrency-control max-sessions="1"
error-if-maximum-exceeded="true" />
</session-management>
<form-login login-page="/login" authentication-failure-url="/login?error"
username-parameter="emailId" password-parameter="pwd" />
<logout logout-success-url="/login?logout" delete-cookies="JSESSIONID" />
<csrf token-repository-ref="tokenRepository" />
</http>
<authentication-manager>
<authentication-provider ref="customAuthenticationProvider" />
</authentication-manager>
</beans:beans>
私は何も間違っては、上記の構成ではなかったことを感じましたが、それが原因で私が使用していたカスタムUserDetailsオブジェクトの問題である可能性があります。
public class CustomUser implements UserDetails {
private static final long serialVersionUID = 1L;
private String userID;
private String emailId;
private String password;
private boolean enabled = true;
private boolean accountNonExpired = true;
private boolean credentialsNonExpired = true;
private boolean accountNonLocked = true;
private List<Role> authorities;
@Override
public List<Role> getAuthorities() {
return authorities;
}
//other setters and getters
}
役割クラス::私もCustomUser POJOを移入するカスタムUserDAOクラスを持っていると私は値の設定には問題がないことを確認した
public class Role implements GrantedAuthority {
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthority() {
return this.name;
}
}
これはPOJOです。
これが私の原則(ログに書かれた通り)である:ページが常に拒否された理由かもしれない何
Principal: CustomUser [userID=user1, [email protected], password=pwd, enabled=true, accountNonExpired=true, credentialsNonExpired=true, authorities=[Role [name=ADMIN]]];
?この全体の記事を読むために時間を割いて
感謝:)
"ROLE_は" 事前に定義されていますプレフィックスはSpringセキュリティがすべてのロールAFAIKに追加するプレフィックスです。しかし、私はあなたの提案を試みましたが、それは助けになりませんでした。問題は依然として続きます。 – javaGirl243
これをチェックしてください:[Spring Securityは接頭辞を追加します](http://stackoverflow.com/a/33206127/6345100) – javaGirl243
私の編集した答えをチェックしてください。 –