1 18 package org.apache.roller.ui.core.security; 19 20 import java.util.List ; 21 22 import org.acegisecurity.GrantedAuthority; 23 import org.acegisecurity.GrantedAuthorityImpl; 24 import org.acegisecurity.ldap.LdapDataAccessException; 25 import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator; 26 import org.acegisecurity.userdetails.UsernameNotFoundException; 27 import org.acegisecurity.userdetails.jdbc.JdbcDaoImpl; 28 import org.acegisecurity.userdetails.ldap.LdapUserDetails; 29 import org.springframework.util.Assert; 30 31 35 public class AuthoritiesPopulator extends JdbcDaoImpl implements LdapAuthoritiesPopulator { 36 37 38 39 private GrantedAuthority defaultRole = null; 40 41 44 public GrantedAuthority[] getGrantedAuthorities(LdapUserDetails userDetails) throws LdapDataAccessException { 45 46 List dbAuths = authoritiesByUsernameMapping.execute(userDetails.getUsername()); 47 48 addCustomAuthorities(userDetails.getUsername(), dbAuths); 49 50 if (defaultRole != null) { 51 dbAuths.add(defaultRole); 52 } 53 54 if (dbAuths.size() == 0) { 55 throw new UsernameNotFoundException("User has no GrantedAuthority"); 56 } 57 58 return (GrantedAuthority[]) dbAuths.toArray(new GrantedAuthority[dbAuths.size()]); 59 } 60 61 66 public void setDefaultRole(String defaultRole) { 67 Assert.notNull(defaultRole, "The defaultRole property cannot be set to null"); 68 this.defaultRole = new GrantedAuthorityImpl(defaultRole); 69 } 70 71 } 72 | Popular Tags |