View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }