Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Level;
Expand All @@ -66,13 +65,6 @@
* @author Kohsuke Kawaguchi
*/
public class ActiveDirectoryAuthenticationProvider extends AbstractActiveDirectoryAuthenticationProvider {

/**
* See https://docs.microsoft.com/en-us/windows/desktop/adsi/example-code-for-reading-a-constructed-attribute
* And https://issues.jenkins-ci.org/browse/JENKINS-10086
*/
private static final int E_ADS_PROPERTY_NOT_FOUND = 0x8000_500D;

private final String defaultNamingContext;
/**
* ADO connection for searching Active Directory.
Expand Down Expand Up @@ -198,9 +190,7 @@ public UserDetails call() {
return new ActiveDirectoryUserDetail(
username, password,
!isAccountDisabled(usr),
!isAccountExpired(usr),
!isPasswordExpired(usr),
!isAccountLocked(usr),
true, true, true,
groups.toArray(new GrantedAuthority[0]),
getFullName(usr), getEmailAddress(usr), getTelephoneNumber(usr)
).updateUserInfo();
Expand Down Expand Up @@ -234,9 +224,8 @@ private String getTelephoneNumber(IADsUser usr) {
Object t = usr.telephoneNumber();
return t==null ? null : t.toString();
} catch (ComException e) {
if (e.getHRESULT() == E_ADS_PROPERTY_NOT_FOUND) {
if (e.getHRESULT()==0x8000500D) // see http://support.microsoft.com/kb/243440
return null;
}
throw e;
}
}
Expand All @@ -245,9 +234,8 @@ private String getEmailAddress(IADsUser usr) {
try {
return usr.emailAddress();
} catch (ComException e) {
if (e.getHRESULT() == E_ADS_PROPERTY_NOT_FOUND){
if (e.getHRESULT()==0x8000500D) // see http://support.microsoft.com/kb/243440
return null;
}
throw e;
}
}
Expand All @@ -256,9 +244,8 @@ private String getFullName(IADsUser usr) {
try {
return usr.fullName();
} catch (ComException e) {
if (e.getHRESULT() == E_ADS_PROPERTY_NOT_FOUND) {
if (e.getHRESULT()==0x8000500D) // see http://support.microsoft.com/kb/243440
return null;
}
throw e;
}
}
Expand All @@ -267,50 +254,13 @@ private boolean isAccountDisabled(IADsUser usr) {
try {
return usr.accountDisabled();
} catch (ComException e) {
if (e.getHRESULT() == E_ADS_PROPERTY_NOT_FOUND) {
return false;
}
throw e;
}
}

private boolean isAccountExpired(IADsUser usr) {
try {
Date expirationDate = usr.accountExpirationDate();
if (expirationDate != null) {
return new Date().after(expirationDate);
}
return false;
} catch (ComException e) {
if (e.getHRESULT() == E_ADS_PROPERTY_NOT_FOUND) {
return false;
}
throw e;
}
}

private boolean isPasswordExpired(IADsUser usr) {
try {
Date expirationDate = usr.passwordExpirationDate();
if (expirationDate != null) {
return new Date().after(expirationDate);
}
return false;
} catch (ComException e) {
if (e.getHRESULT() == E_ADS_PROPERTY_NOT_FOUND) {
return false;
}
throw e;
}
}

private boolean isAccountLocked(IADsUser usr) {
try {
return usr.isAccountLocked();
} catch (ComException e) {
if (e.getHRESULT() == E_ADS_PROPERTY_NOT_FOUND) {
if (e.getHRESULT()==0x8000500D)
/*
See http://support.microsoft.com/kb/243440 and JENKINS-10086
We suspect this to be caused by old directory items that do not have this value,
so assume this account is enabled.
*/
return false;
}
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@
import javax.naming.directory.SearchResult;
import javax.naming.ldap.LdapName;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
Expand Down Expand Up @@ -422,14 +420,7 @@ public UserDetails call() throws AuthenticationException, NamingException {
Set<GrantedAuthority> groups = resolveGroups(domainDN, dnFormatted, context);
groups.add(SecurityRealm.AUTHENTICATED_AUTHORITY);

boolean isEnabled = UserAttributesHelper.checkIfUserIsEnabled(user);
boolean isAccountNonExpired = UserAttributesHelper.checkIfAccountNonExpired(user);
boolean areCredentialsNotExpired = UserAttributesHelper.checkIfCredentialsAreNonExpired(user);
boolean isAccountNonLocked = UserAttributesHelper.checkIfAccountNonLocked(user);

cacheMiss[0] = new ActiveDirectoryUserDetail(username, password,
isEnabled, isAccountNonExpired, areCredentialsNotExpired, isAccountNonLocked,
groups.toArray(new GrantedAuthority[0]),
cacheMiss[0] = new ActiveDirectoryUserDetail(username, password, true, true, true, true, groups.toArray(new GrantedAuthority[0]),
getStringAttribute(user, "displayName"),
getStringAttribute(user, "mail"),
getStringAttribute(user, "telephoneNumber")
Expand Down

This file was deleted.