fix 2nd NPE

This commit is contained in:
Stephen Connolly 2014-05-23 15:11:09 +01:00
parent 2d1ac33283
commit 7089a11e5f

View file

@ -27,6 +27,7 @@ import hudson.Extension;
import org.acegisecurity.GrantedAuthority; import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.GrantedAuthorityImpl; import org.acegisecurity.GrantedAuthorityImpl;
import org.acegisecurity.userdetails.ldap.LdapUserDetails; import org.acegisecurity.userdetails.ldap.LdapUserDetails;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundConstructor;
import javax.naming.InvalidNameException; import javax.naming.InvalidNameException;
@ -56,13 +57,14 @@ public class FromUserRecordLDAPGroupMembershipStrategy extends LDAPGroupMembersh
} }
public String getAttributeName() { public String getAttributeName() {
return attributeName; return StringUtils.defaultIfEmpty(attributeName, "memberOf");
} }
@Override @Override
public GrantedAuthority[] getGrantedAuthorities(LdapUserDetails ldapUser) { public GrantedAuthority[] getGrantedAuthorities(LdapUserDetails ldapUser) {
List<GrantedAuthority> result = new ArrayList<GrantedAuthority>(); List<GrantedAuthority> result = new ArrayList<GrantedAuthority>();
Attributes attributes = ldapUser.getAttributes(); Attributes attributes = ldapUser.getAttributes();
final String attributeName = getAttributeName();
Attribute attribute = attributes == null ? null : attributes.get(attributeName); Attribute attribute = attributes == null ? null : attributes.get(attributeName);
if (attribute != null) { if (attribute != null) {
try { try {