java - sec:authorize doesn't work for newly added users -


i have done spring security databbases tutorial mkyong. working fine, when i'm adding new user users , user_roles table , logining on these accounts sec:authorize access="hasrole('role_user')" doesn't work , data in sec:authorize tag isn't displayed.

there spring-security settings

<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-3.2.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" />          <form-login              login-page="/login"              default-target-url="/welcome"              authentication-failure-url="/login?error"              username-parameter="username"             password-parameter="password" />         <logout logout-success-url="/login?logout"  />         <!-- enable csrf protection -->         <csrf/>     </http>      <!-- select users , user_roles database -->     <authentication-manager>       <authentication-provider>         <jdbc-user-service data-source-ref="datasource"           users-by-username-query=             "select username,password, enabled users username=?"           authorities-by-username-query=             "select username, role user_roles username =?  " />       </authentication-provider>     </authentication-manager>  </beans:beans> 

and there mentioned code sec:authorize block

<sec:authorize access="hasrole('role_user')">         <!-- login user -->         <c:url value="/j_spring_security_logout" var="logouturl" />         <form action="${logouturl}" method="post" id="logoutform">             <input type="hidden" name="${_csrf.parametername}"                 value="${_csrf.token}" />         </form>         <script>             function formsubmit() {                 document.getelementbyid("logoutform").submit();             }         </script>          <c:if test="${pagecontext.request.userprincipal.name != null}">             <h2>                 user : ${pagecontext.request.userprincipal.name} | <a                     href="javascript:formsubmit()"> logout</a>             </h2>         </c:if>       </sec:authorize> 

i can check if user logged in in controller, sec:authorize doesn't work in session in newly created user logged in:

//this works if (!(auth instanceof anonymousauthenticationtoken)) {             userdetails userdetail = (userdetails) auth.getprincipal();             model.addobject("username", userdetail.getusername());         } 

problem solved.

as @holmis83 suggested, have added

<sec:authentication property="principal.authorities"/> 

to check content of role column in user_roles table in db. turned out saving roles 'user_role' , should 'role_user'. have updated users roles proper values , works well.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -