Added accessors for setting several important properties. Updated JNDI code for looking up roles in user context. Clarified some variable names.

This commit is contained in:
Robert Sanders 2005-06-26 15:23:57 +00:00
parent a312fede74
commit b6657a18d1
1 changed files with 44 additions and 5 deletions

View File

@ -45,7 +45,7 @@ public class LdapPassword2AuthenticationDao implements PasswordAuthenticationDao
/** Array of LdapSearchBean which will be used to search the context. /** Array of LdapSearchBean which will be used to search the context.
*/ */
private UserSearchBean[] ldapSearchBeans; private UserSearchBean[] userSearchBeans;
private String defaultRole; private String defaultRole;
@ -99,9 +99,9 @@ public class LdapPassword2AuthenticationDao implements PasswordAuthenticationDao
InitialDirContext ctx = ldapSupport.getInitialContext(); InitialDirContext ctx = ldapSupport.getInitialContext();
UserSearchResults userSearchResults = null; UserSearchResults userSearchResults = null;
try { try {
for (int i = 0; (i < ldapSearchBeans.length) && (null == userSearchResults); i++) { for (int i = 0; (i < userSearchBeans.length) && (null == userSearchResults); i++) {
try { try {
userSearchResults = ldapSearchBeans[i].searchForUser(ctx, username); userSearchResults = userSearchBeans[i].searchForUser(ctx, username);
} catch (NamingException nx) { } catch (NamingException nx) {
logger.warn(nx); logger.warn(nx);
} }
@ -131,7 +131,7 @@ public class LdapPassword2AuthenticationDao implements PasswordAuthenticationDao
protected GrantedAuthority[] getUserRolesLdap(DirContext ctx, String[] roleAttrs) { protected GrantedAuthority[] getUserRolesLdap(DirContext ctx, String[] roleAttrs) {
try { try {
NamingEnumeration enm = ctx.search((Name)null, null, roleAttrs, null); NamingEnumeration enm = ctx.search("", null, roleAttrs);
if (!enm.hasMore()) { if (!enm.hasMore()) {
return null; return null;
} }
@ -140,7 +140,6 @@ public class LdapPassword2AuthenticationDao implements PasswordAuthenticationDao
SearchResult searchResult = (SearchResult)enm.next(); SearchResult searchResult = (SearchResult)enm.next();
Attributes attrs = searchResult.getAttributes(); Attributes attrs = searchResult.getAttributes();
ArrayList roleList = new ArrayList(attrs.size()); ArrayList roleList = new ArrayList(attrs.size());
NamingEnumeration attrEnm = attrs.getAll(); NamingEnumeration attrEnm = attrs.getAll();
while (attrEnm.hasMore()) { while (attrEnm.hasMore()) {
@ -173,5 +172,45 @@ public class LdapPassword2AuthenticationDao implements PasswordAuthenticationDao
this.defaultRole = defaultRole; this.defaultRole = defaultRole;
} }
/**
* @return Returns the userSearchBeans.
*/
public UserSearchBean[] getUserSearchBeans() {
return userSearchBeans;
}
/**
* @param userSearchBeans The userSearchBeans to set.
*/
public void setUserSearchBeans(UserSearchBean[] userSearchBeans) {
this.userSearchBeans = userSearchBeans;
}
/** Convience method to set only one userSearchBean.
* <b>NOTE:</b> this method resets the entire userSearchBeans array,
* and can therefore not be used to append entries to the array.
*
* @param userSearchBean
*/
public void setUserSearchBean(UserSearchBean userSearchBean) {
this.userSearchBeans = new UserSearchBean[]{userSearchBean};
}
/**
* @return Returns the ldapSupport.
*/
public LdapSupport getLdapSupport() {
return ldapSupport;
}
/**
* @param ldapSupport The ldapSupport to set.
*/
public void setLdapSupport(LdapSupport ldapSupport) {
this.ldapSupport = ldapSupport;
}
} }