I'm trying to implement spring security 3.1.0.M1 and I'm unable to get my application to set the Authentication.getPrincipal to my custom UserDetails implementation. It always returns a principal of "guest" when I try to get the logged in user. See getLoggedInUser method below.
In Users.java (UserDetails impl) the getAuthorities method never gets called and maybe that's why the user_role doesn't get assigned.
to Maybe I've misconfigured something...I've attached an outline of my implementation hoping someone can spot my error. Thanks for the assistance!
security context file:
UserDetails Implementation (Users.java):Code:<global-method-security secured-annotations="enabled"> </global-method-security> <http security="none" pattern="/services/rest-api/1.0/**" /> <http security="none" pattern="/preregistered/**" /> <http access-denied-page="/auth/denied.html"> <intercept-url pattern="/**/*.xhtml" access="ROLE_NONE_GETS_ACCESS" /> <intercept-url pattern="/auth/**" access="ROLE_ANONYMOUS,ROLE_USER" /> <intercept-url pattern="/auth/*" access="ROLE_ANONYMOUS" /> <intercept-url pattern="/**" access="ROLE_USER" /> <form-login login-processing-url="/j_spring_security_check.html" login-page="/auth/login.html" default-target-url="/registered/home.html" authentication-failure-url="/auth/login.html?_dc=45" /> <logout logout-url="/auth/logout.html" logout-success-url="/" /> <anonymous username="guest" granted-authority="ROLE_ANONYMOUS"/> <remember-me user-service-ref="userManager" key="valid key here"/> </http> <!-- Configure the authentication provider --> <authentication-manager> <authentication-provider user-service-ref="userManager"> <password-encoder ref="passwordEncoder" /> </authentication-provider> </authentication-manager>
user-service-ref="userManager" (UserManagerImpl.java):Code:public class Users implements Serializable, UserDetails { //user db fields here.... public Collection<GrantedAuthority> getAuthorities() { List<GrantedAuthority> auth = new ArrayList<GrantedAuthority>(); auth.add(new GrantedAuthorityImpl("ROLE_USER")); return auth; }
Code:public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { Users user = null; try { user = userDAO.findByUsername(username); } catch (DataAccessException ex) { throw new UsernameNotFoundException("Invalid login", ex); } if (user == null) { throw new UsernameNotFoundException("User not found."); } return user; }


Reply With Quote
