01: package ru.emdev.EmForge.security.ldap;
02:
03: import org.acegisecurity.GrantedAuthority;
04: import org.acegisecurity.providers.ldap.LdapAuthenticationProvider;
05: import org.acegisecurity.providers.ldap.LdapAuthenticator;
06: import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator;
07: import org.acegisecurity.userdetails.UserDetails;
08: import org.acegisecurity.userdetails.UserDetailsService;
09: import org.acegisecurity.userdetails.ldap.LdapUserDetails;
10:
11: /** LDAP Based User-Details Service Implementation */
12: public class LdapAuthenticationServiceImpl extends
13: LdapAuthenticationProvider {
14: /** UserDetailsService is used for passing into EmForgeUser and getting manager information */
15: private UserDetailsService m_userDetailsService;
16:
17: public LdapAuthenticationServiceImpl(
18: LdapAuthenticator authenticator,
19: LdapAuthoritiesPopulator authoritiesPopulator) {
20: super (authenticator, authoritiesPopulator);
21: }
22:
23: public void setUserDetailsService(
24: UserDetailsService i_userDetailsService) {
25: m_userDetailsService = i_userDetailsService;
26: }
27:
28: /** Override this method to create own, EmForge-Specific User Details
29: *
30: */
31: @Override
32: protected UserDetails createUserDetails(LdapUserDetails ldapUser,
33: String username, String password) {
34: EmForgeUserLdap.Essence user = new EmForgeUserLdap.Essence(
35: ldapUser);
36: user.setUsername(username);
37: user.setPassword(password);
38: user.setUserDetailsService(m_userDetailsService);
39:
40: GrantedAuthority[] extraAuthorities = getAuthoritiesPopulator()
41: .getGrantedAuthorities(ldapUser);
42:
43: for (int i = 0; i < extraAuthorities.length; i++) {
44: user.addAuthority(extraAuthorities[i]);
45: }
46:
47: return user.createUserDetails();
48: }
49:
50: }
|