java - Spring Security intercept URL not working with custom UserDetails object -


i'm new spring security please please patient. open suggestions make question more specific if guide me.

my problem have intercept-url configuration in spring security redirecting access denied page when user has requisite role. spring security config:

<?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> 

through research felt there nothing wrong in above configuration problem because of custom userdetails object using. pojo:

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 , getters } 

role class:

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;     } } 

i have custom userdao class populates customuser pojo , have verified there no issue in setting of values.

this principle(as written in logs):

principal: customuser [userid=user1, emailid=test@test.com, password=pwd, enabled=true, accountnonexpired=true, credentialsnonexpired=true, authorities=[role [name=admin]]]; 

what reason pages denied?

thanks taking time read whole post :)

changed

<intercept-url pattern="/admin/**" access="hasrole('role_admin')" /> 

to

<intercept-url pattern="/admin/**" access="hasrole('admin')" /> 

edit

if previous solution didn't work try way.

see in role returns "admin" , expect "role_admin"

change role name table

"admin" "role_admin"


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -