Bonjour à tous,
J'utilise spring security 3.1 dans mon appli. Mes utilisateurs doivent être dans le LDAP. Les rôles sont chargés depuis la base. Ca marche bien.
Par contre, ce que je n'arrive pas à faire, c'est récupérer les info perso (prénom, email, etc.) et les mapper directement vers un bean.
mon security-app-context.xml :
Mon populator :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 <beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"> <beans:constructor-arg index="0" value="ldap://clusterldap.masociete.com:389/dc=corp,dc=masociete,dc=com" /> <beans:property name="userDn" value="cn=readldap,dc=masociete,dc=com" /> <beans:property name="password" value="lecture" /> </beans:bean> <beans:bean id="ldapUserSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"> <beans:constructor-arg index="0" value="ou=people" /> <!-- Branche principale à partir de laquelle faire la recherche --> <beans:constructor-arg index="1" value="(uid={0})" /> <!-- Critère de recherche LDAP, ici le login de l'utilisateur correspond à l'uid de l'entrée LDAP --> <beans:constructor-arg index="2" ref="contextSource" /> <beans:property name="searchSubtree" value="true" /> <!-- Recherche dans les sous-branches --> </beans:bean> <beans:bean id="myAuthoritiesPopulator" class="com.masociete.monprojet.web.MyAuthoritiesPopulator" /> <beans:bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"> <beans:constructor-arg index="0"> <beans:bean class="org.springframework.security.ldap.authentication.BindAuthenticator"> <beans:constructor-arg index="0" ref="contextSource" /> <beans:property name="userSearch" ref="ldapUserSearch" /> </beans:bean> </beans:constructor-arg> <beans:constructor-arg index="1" ref="myAuthoritiesPopulator" /> </beans:bean> <authentication-manager alias="authenticationManager"> <authentication-provider ref="ldapAuthProvider" /> </authentication-manager> <!-- reste de la conf a faire pour mapper directement -->
Quant à mon UserLdap, je voudrais qu'il ressemble à ça :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public class MyAuthoritiesPopulator implements LdapAuthoritiesPopulator { public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) { final List<GrantedAuthority> authorities = newArrayList(); final MonUserDB user = monCredentialsService.searchUser(username); // token final List<GrantedAuthority> grantedAuthorities = getAuthorities(user.getRoles()); authorities.addAll(grantedAuthorities); return authorities; }
Au debuger, je vois bien que mon DirContextOperations userData contient les champs suivants dans originalAttrs :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 class UserLdap { string prenom; string email; ... }
Mais je voudrais bien que spring me remplisse tout seul les infos qui viennent du ldap.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3givenname=givenName: Thierry mail=mail: thierry_leriche@masociete.com
Merci d'avance.
Partager