1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.kim.client.acegi;
17  
18  import org.acegisecurity.GrantedAuthority;
19  import org.acegisecurity.ldap.LdapUserSearch;
20  import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator;
21  import org.acegisecurity.userdetails.User;
22  import org.acegisecurity.userdetails.UserDetails;
23  import org.acegisecurity.userdetails.UserDetailsService;
24  import org.acegisecurity.userdetails.ldap.LdapUserDetails;
25  import org.springframework.beans.factory.InitializingBean;
26  import org.springframework.util.Assert;
27  
28  public class LdapUserDetailsService implements UserDetailsService, InitializingBean
29  {
30      LdapUserSearch           ldapUserSearch;
31      LdapAuthoritiesPopulator ldapAuthoritiesPopulator;
32  
33      public void afterPropertiesSet() throws Exception
34      {
35          Assert.notNull(this.ldapUserSearch, "An LDAP search object must be set");
36          Assert.notNull(this.ldapAuthoritiesPopulator, "An LDAP authorities populator must be set");
37      }
38  
39      public UserDetails loadUserByUsername(String username)
40      {
41          LdapUserDetails ldapUserDetails = ldapUserSearch.searchForUser(username);
42          GrantedAuthority[] authorities = ldapAuthoritiesPopulator.getGrantedAuthorities(ldapUserDetails);
43  
44          return new User(username, "empty_password", true, true, true, true, authorities);
45      }
46  
47      public LdapAuthoritiesPopulator getLdapAuthoritiesPopulator()
48      {
49          return ldapAuthoritiesPopulator;
50      }
51  
52      public void setLdapAuthoritiesPopulator(LdapAuthoritiesPopulator ldapAuthoritiesPopulator)
53      {
54          this.ldapAuthoritiesPopulator = ldapAuthoritiesPopulator;
55      }
56  
57      public LdapUserSearch getLdapUserSearch()
58      {
59          return ldapUserSearch;
60      }
61  
62      public void setLdapUserSearch(LdapUserSearch ldapUserSearch)
63      {
64          this.ldapUserSearch = ldapUserSearch;
65      }
66  }