001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kim.client.acegi; 017 018import org.acegisecurity.GrantedAuthority; 019import org.acegisecurity.ldap.LdapUserSearch; 020import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator; 021import org.acegisecurity.userdetails.User; 022import org.acegisecurity.userdetails.UserDetails; 023import org.acegisecurity.userdetails.UserDetailsService; 024import org.acegisecurity.userdetails.ldap.LdapUserDetails; 025import org.springframework.beans.factory.InitializingBean; 026import org.springframework.util.Assert; 027 028public class LdapUserDetailsService implements UserDetailsService, InitializingBean 029{ 030 LdapUserSearch ldapUserSearch; 031 LdapAuthoritiesPopulator ldapAuthoritiesPopulator; 032 033 public void afterPropertiesSet() throws Exception 034 { 035 Assert.notNull(this.ldapUserSearch, "An LDAP search object must be set"); 036 Assert.notNull(this.ldapAuthoritiesPopulator, "An LDAP authorities populator must be set"); 037 } 038 039 public UserDetails loadUserByUsername(String username) 040 { 041 LdapUserDetails ldapUserDetails = ldapUserSearch.searchForUser(username); 042 GrantedAuthority[] authorities = ldapAuthoritiesPopulator.getGrantedAuthorities(ldapUserDetails); 043 044 return new User(username, "empty_password", true, true, true, true, authorities); 045 } 046 047 public LdapAuthoritiesPopulator getLdapAuthoritiesPopulator() 048 { 049 return ldapAuthoritiesPopulator; 050 } 051 052 public void setLdapAuthoritiesPopulator(LdapAuthoritiesPopulator ldapAuthoritiesPopulator) 053 { 054 this.ldapAuthoritiesPopulator = ldapAuthoritiesPopulator; 055 } 056 057 public LdapUserSearch getLdapUserSearch() 058 { 059 return ldapUserSearch; 060 } 061 062 public void setLdapUserSearch(LdapUserSearch ldapUserSearch) 063 { 064 this.ldapUserSearch = ldapUserSearch; 065 } 066}