java - Spring Security Authentification with LDAP -
my problem is, create user in ldap role, don't role in java. need role, because users have role 'assistent' allowed call method.
my applicationclass:
@configuration @componentscan({ "my.package.project" }) @enableautoconfiguration public class application extends springbootservletinitializer { public static void main(string[] args) { springapplication.run(application.class, args); } @override protected springapplicationbuilder configure(springapplicationbuilder builder) { return builder.sources(application.class); } @configuration @enablewebsecurity public class securityconfiguration extends websecurityconfigureradapter { @override protected void configure(httpsecurity http) throws exception { http.authorizerequests().anyrequest().authenticated().and().formlogin().permitall().and().logout() .permitall().and().csrf().disable(); } @autowired protected void configure(authenticationmanagerbuilder auth) throws exception { auth.ldapauthentication().usersearchfilter("uid={0}").contextsource() .url("ldap://localhost:10389/dc=example,dc=com"); } } }
ldap configuration:
group:
user:
controller:
@requestmapping(method = requestmethod.get) public listwrapper<experienceentity> getexperiences(authentication a, httpservletrequest auth, principal principal) { log.error(""+a); log.error("" + auth.isuserinrole("assistent")); log.error("" + auth); }
log:
2017-08-15 10:33:41.246 error 7308 --- [http-nio-8080-exec-11] experiencecontroller : org.springframework.security.authentication.usernamepasswordauthenticationtoken@89cda41: principal: org.springframework.security.ldap.userdetails.ldapuserdetailsimpl@f7632585: dn: cn=admin user,dc=example,dc=com; username: adminuser; password: [protected]; enabled: true; accountnonexpired: true; credentialsnonexpired: true; accountnonlocked: true; not granted authorities; credentials: [protected]; authenticated: true; details: org.springframework.security.web.authentication.webauthenticationdetails@0: remoteipaddress: 10.12.25.196; sessionid: 8ca0a30b56f1c9707b77ab7322a6cf9d; not granted authorities 2017-08-15 10:33:41.246 error 7308 --- [http-nio-8080-exec-11] experiencecontroller : false 2017-08-15 10:33:41.246 error 7308 --- [http-nio-8080-exec-11] experiencecontroller : securitycontextholderawarerequestwrapper[ org.springframework.security.web.context.httpsessionsecuritycontextrepository$servlet3savetosessionrequestwrapper@7053d575]
Comments
Post a Comment