Always use 'this.' when accessing fields
Apply an Eclipse cleanup rules to ensure that fields are always accessed using `this.`. This aligns with the style used by Spring Framework and helps users quickly see the difference between a local and member variable. Issue gh-8945
This commit is contained in:
@@ -44,9 +44,9 @@ public class DefaultLdapUsernameToDnMapper implements LdapUsernameToDnMapper {
|
||||
* Assembles the Distinguished Name that should be used the given username.
|
||||
*/
|
||||
public DistinguishedName buildDn(String username) {
|
||||
DistinguishedName dn = new DistinguishedName(userDnBase);
|
||||
DistinguishedName dn = new DistinguishedName(this.userDnBase);
|
||||
|
||||
dn.add(usernameAttribute, username);
|
||||
dn.add(this.usernameAttribute, username);
|
||||
|
||||
return dn;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
|
||||
Assert.notNull(contextSource, "ContextSource cannot be null");
|
||||
setContextSource(contextSource);
|
||||
|
||||
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
this.searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +211,7 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
|
||||
};
|
||||
|
||||
SearchControls ctls = new SearchControls();
|
||||
ctls.setSearchScope(searchControls.getSearchScope());
|
||||
ctls.setSearchScope(this.searchControls.getSearchScope());
|
||||
ctls.setReturningAttributes(attributeNames != null && attributeNames.length > 0 ? attributeNames : null);
|
||||
|
||||
search(base, formattedFilter, ctls, roleMapper);
|
||||
@@ -284,7 +284,7 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
|
||||
public DirContextOperations searchForSingleEntry(final String base, final String filter, final Object[] params) {
|
||||
|
||||
return (DirContextOperations) executeReadOnly(
|
||||
(ContextExecutor) ctx -> searchForSingleEntryInternal(ctx, searchControls, base, filter, params));
|
||||
(ContextExecutor) ctx -> searchForSingleEntryInternal(ctx, this.searchControls, base, filter, params));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,16 +67,16 @@ public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, In
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
Assert.isTrue((userDnFormat != null) || (userSearch != null),
|
||||
Assert.isTrue((this.userDnFormat != null) || (this.userSearch != null),
|
||||
"Either an LdapUserSearch or DN pattern (or both) must be supplied.");
|
||||
}
|
||||
|
||||
protected ContextSource getContextSource() {
|
||||
return contextSource;
|
||||
return this.contextSource;
|
||||
}
|
||||
|
||||
public String[] getUserAttributes() {
|
||||
return userAttributes;
|
||||
return this.userAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,15 +87,15 @@ public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, In
|
||||
* set.
|
||||
*/
|
||||
protected List<String> getUserDns(String username) {
|
||||
if (userDnFormat == null) {
|
||||
if (this.userDnFormat == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> userDns = new ArrayList<>(userDnFormat.length);
|
||||
List<String> userDns = new ArrayList<>(this.userDnFormat.length);
|
||||
String[] args = new String[] { LdapEncoder.nameEncode(username) };
|
||||
|
||||
synchronized (userDnFormat) {
|
||||
for (MessageFormat formatter : userDnFormat) {
|
||||
synchronized (this.userDnFormat) {
|
||||
for (MessageFormat formatter : this.userDnFormat) {
|
||||
userDns.add(formatter.format(args));
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, In
|
||||
}
|
||||
|
||||
protected LdapUserSearch getUserSearch() {
|
||||
return userSearch;
|
||||
return this.userSearch;
|
||||
}
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
@@ -131,10 +131,10 @@ public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, In
|
||||
public void setUserDnPatterns(String[] dnPattern) {
|
||||
Assert.notNull(dnPattern, "The array of DN patterns cannot be set to null");
|
||||
// this.userDnPattern = dnPattern;
|
||||
userDnFormat = new MessageFormat[dnPattern.length];
|
||||
this.userDnFormat = new MessageFormat[dnPattern.length];
|
||||
|
||||
for (int i = 0; i < dnPattern.length; i++) {
|
||||
userDnFormat[i] = new MessageFormat(dnPattern[i]);
|
||||
this.userDnFormat[i] = new MessageFormat(dnPattern[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ public class BindAuthenticator extends AbstractLdapAuthenticator {
|
||||
|
||||
if (!StringUtils.hasLength(password)) {
|
||||
logger.debug("Rejecting empty password for user " + username);
|
||||
throw new BadCredentialsException(messages.getMessage("BindAuthenticator.emptyPassword", "Empty Password"));
|
||||
throw new BadCredentialsException(
|
||||
this.messages.getMessage("BindAuthenticator.emptyPassword", "Empty Password"));
|
||||
}
|
||||
|
||||
// If DN patterns are configured, try authenticating with them directly
|
||||
@@ -88,7 +89,7 @@ public class BindAuthenticator extends AbstractLdapAuthenticator {
|
||||
|
||||
if (user == null) {
|
||||
throw new BadCredentialsException(
|
||||
messages.getMessage("BindAuthenticator.badCredentials", "Bad credentials"));
|
||||
this.messages.getMessage("BindAuthenticator.badCredentials", "Bad credentials"));
|
||||
}
|
||||
|
||||
return user;
|
||||
|
||||
@@ -92,23 +92,23 @@ public final class PasswordComparisonAuthenticator extends AbstractLdapAuthentic
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Performing LDAP compare of password attribute '" + passwordAttributeName + "' for user '"
|
||||
logger.debug("Performing LDAP compare of password attribute '" + this.passwordAttributeName + "' for user '"
|
||||
+ user.getDn() + "'");
|
||||
}
|
||||
|
||||
if (usePasswordAttrCompare && isPasswordAttrCompare(user, password)) {
|
||||
if (this.usePasswordAttrCompare && isPasswordAttrCompare(user, password)) {
|
||||
return user;
|
||||
}
|
||||
else if (isLdapPasswordCompare(user, ldapTemplate, password)) {
|
||||
return user;
|
||||
}
|
||||
throw new BadCredentialsException(
|
||||
messages.getMessage("PasswordComparisonAuthenticator.badCredentials", "Bad credentials"));
|
||||
this.messages.getMessage("PasswordComparisonAuthenticator.badCredentials", "Bad credentials"));
|
||||
}
|
||||
|
||||
private boolean isPasswordAttrCompare(DirContextOperations user, String password) {
|
||||
String passwordAttrValue = getPassword(user);
|
||||
return passwordEncoder.matches(password, passwordAttrValue);
|
||||
return this.passwordEncoder.matches(password, passwordAttrValue);
|
||||
}
|
||||
|
||||
private String getPassword(DirContextOperations user) {
|
||||
@@ -124,9 +124,9 @@ public final class PasswordComparisonAuthenticator extends AbstractLdapAuthentic
|
||||
|
||||
private boolean isLdapPasswordCompare(DirContextOperations user, SpringSecurityLdapTemplate ldapTemplate,
|
||||
String password) {
|
||||
String encodedPassword = passwordEncoder.encode(password);
|
||||
String encodedPassword = this.passwordEncoder.encode(password);
|
||||
byte[] passwordBytes = Utf8.encode(encodedPassword);
|
||||
return ldapTemplate.compare(user.getDn().toString(), passwordAttributeName, passwordBytes);
|
||||
return ldapTemplate.compare(user.getDn().toString(), this.passwordAttributeName, passwordBytes);
|
||||
}
|
||||
|
||||
public void setPasswordAttributeName(String passwordAttribute) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class UserDetailsServiceLdapAuthoritiesPopulator implements LdapAuthoriti
|
||||
|
||||
public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData,
|
||||
String username) {
|
||||
return userDetailsService.loadUserByUsername(username).getAuthorities();
|
||||
return this.userDetailsService.loadUserByUsername(username).getAuthorities();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class ActiveDirectoryAuthenticationException extends Authentication
|
||||
}
|
||||
|
||||
public String getDataCode() {
|
||||
return dataCode;
|
||||
return this.dataCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
Assert.isTrue(StringUtils.hasText(url), "Url cannot be empty");
|
||||
this.domain = StringUtils.hasText(domain) ? domain.toLowerCase() : null;
|
||||
this.url = url;
|
||||
rootDn = this.domain == null ? null : rootDnFromDomain(this.domain);
|
||||
this.rootDn = this.domain == null ? null : rootDnFromDomain(this.domain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -169,7 +169,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
throw badLdapConnection(e);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
logger.error("Failed to locate directory entry for authenticated user: " + username, e);
|
||||
this.logger.error("Failed to locate directory entry for authenticated user: " + username, e);
|
||||
throw badCredentials(e);
|
||||
}
|
||||
finally {
|
||||
@@ -187,13 +187,13 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
String[] groups = userData.getStringAttributes("memberOf");
|
||||
|
||||
if (groups == null) {
|
||||
logger.debug("No values for 'memberOf' attribute.");
|
||||
this.logger.debug("No values for 'memberOf' attribute.");
|
||||
|
||||
return AuthorityUtils.NO_AUTHORITIES;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("'memberOf' attribute values: " + Arrays.asList(groups));
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("'memberOf' attribute values: " + Arrays.asList(groups));
|
||||
}
|
||||
|
||||
ArrayList<GrantedAuthority> authorities = new ArrayList<>(groups.length);
|
||||
@@ -207,7 +207,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
|
||||
private DirContext bindAsUser(String username, String password) {
|
||||
// TODO. add DNS lookup based on domain
|
||||
final String bindUrl = url;
|
||||
final String bindUrl = this.url;
|
||||
|
||||
Hashtable<String, Object> env = new Hashtable<>();
|
||||
env.put(Context.SECURITY_AUTHENTICATION, "simple");
|
||||
@@ -220,7 +220,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
env.putAll(this.contextEnvironmentProperties);
|
||||
|
||||
try {
|
||||
return contextFactory.createContext(env);
|
||||
return this.contextFactory.createContext(env);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
if ((e instanceof AuthenticationException) || (e instanceof OperationNotSupportedException)) {
|
||||
@@ -234,8 +234,8 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
}
|
||||
|
||||
private void handleBindException(String bindPrincipal, NamingException exception) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Authentication for " + bindPrincipal + " failed:" + exception);
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Authentication for " + bindPrincipal + " failed:" + exception);
|
||||
}
|
||||
|
||||
handleResolveObj(exception);
|
||||
@@ -243,13 +243,13 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
int subErrorCode = parseSubErrorCode(exception.getMessage());
|
||||
|
||||
if (subErrorCode <= 0) {
|
||||
logger.debug("Failed to locate AD-specific sub-error code in message");
|
||||
this.logger.debug("Failed to locate AD-specific sub-error code in message");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Active Directory authentication failed: " + subCodeToLogMessage(subErrorCode));
|
||||
this.logger.info("Active Directory authentication failed: " + subCodeToLogMessage(subErrorCode));
|
||||
|
||||
if (convertSubErrorCodesToExceptions) {
|
||||
if (this.convertSubErrorCodesToExceptions) {
|
||||
raiseExceptionForErrorCode(subErrorCode, exception);
|
||||
}
|
||||
}
|
||||
@@ -277,17 +277,17 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
Throwable cause = new ActiveDirectoryAuthenticationException(hexString, exception.getMessage(), exception);
|
||||
switch (code) {
|
||||
case PASSWORD_EXPIRED:
|
||||
throw new CredentialsExpiredException(messages.getMessage("LdapAuthenticationProvider.credentialsExpired",
|
||||
"User credentials have expired"), cause);
|
||||
throw new CredentialsExpiredException(this.messages.getMessage(
|
||||
"LdapAuthenticationProvider.credentialsExpired", "User credentials have expired"), cause);
|
||||
case ACCOUNT_DISABLED:
|
||||
throw new DisabledException(messages.getMessage("LdapAuthenticationProvider.disabled", "User is disabled"),
|
||||
cause);
|
||||
throw new DisabledException(
|
||||
this.messages.getMessage("LdapAuthenticationProvider.disabled", "User is disabled"), cause);
|
||||
case ACCOUNT_EXPIRED:
|
||||
throw new AccountExpiredException(
|
||||
messages.getMessage("LdapAuthenticationProvider.expired", "User account has expired"), cause);
|
||||
this.messages.getMessage("LdapAuthenticationProvider.expired", "User account has expired"), cause);
|
||||
case ACCOUNT_LOCKED:
|
||||
throw new LockedException(
|
||||
messages.getMessage("LdapAuthenticationProvider.locked", "User account is locked"), cause);
|
||||
this.messages.getMessage("LdapAuthenticationProvider.locked", "User account is locked"), cause);
|
||||
default:
|
||||
throw badCredentials(cause);
|
||||
}
|
||||
@@ -318,7 +318,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
|
||||
private BadCredentialsException badCredentials() {
|
||||
return new BadCredentialsException(
|
||||
messages.getMessage("LdapAuthenticationProvider.badCredentials", "Bad credentials"));
|
||||
this.messages.getMessage("LdapAuthenticationProvider.badCredentials", "Bad credentials"));
|
||||
}
|
||||
|
||||
private BadCredentialsException badCredentials(Throwable cause) {
|
||||
@@ -326,7 +326,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
}
|
||||
|
||||
private InternalAuthenticationServiceException badLdapConnection(Throwable cause) {
|
||||
return new InternalAuthenticationServiceException(messages.getMessage(
|
||||
return new InternalAuthenticationServiceException(this.messages.getMessage(
|
||||
"LdapAuthenticationProvider.badLdapConnection", "Connection to LDAP server failed."), cause);
|
||||
}
|
||||
|
||||
@@ -335,11 +335,11 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
|
||||
String bindPrincipal = createBindPrincipal(username);
|
||||
String searchRoot = rootDn != null ? rootDn : searchRootFromPrincipal(bindPrincipal);
|
||||
String searchRoot = this.rootDn != null ? this.rootDn : searchRootFromPrincipal(bindPrincipal);
|
||||
|
||||
try {
|
||||
return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context, searchControls, searchRoot,
|
||||
searchFilter, new Object[] { bindPrincipal, username });
|
||||
this.searchFilter, new Object[] { bindPrincipal, username });
|
||||
}
|
||||
catch (CommunicationException ldapCommunicationException) {
|
||||
throw badLdapConnection(ldapCommunicationException);
|
||||
@@ -361,7 +361,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
int atChar = bindPrincipal.lastIndexOf('@');
|
||||
|
||||
if (atChar < 0) {
|
||||
logger.debug("User principal '" + bindPrincipal
|
||||
this.logger.debug("User principal '" + bindPrincipal
|
||||
+ "' does not contain the domain, and no domain has been configured");
|
||||
throw badCredentials();
|
||||
}
|
||||
@@ -384,11 +384,11 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
}
|
||||
|
||||
String createBindPrincipal(String username) {
|
||||
if (domain == null || username.toLowerCase().endsWith(domain)) {
|
||||
if (this.domain == null || username.toLowerCase().endsWith(this.domain)) {
|
||||
return username;
|
||||
}
|
||||
|
||||
return username + "@" + domain;
|
||||
return username + "@" + this.domain;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,18 +45,18 @@ public class PasswordPolicyAwareContextSource extends DefaultSpringSecurityConte
|
||||
|
||||
@Override
|
||||
public DirContext getContext(String principal, String credentials) throws PasswordPolicyException {
|
||||
if (principal.equals(userDn)) {
|
||||
if (principal.equals(this.userDn)) {
|
||||
return super.getContext(principal, credentials);
|
||||
}
|
||||
|
||||
final boolean debug = logger.isDebugEnabled();
|
||||
final boolean debug = this.logger.isDebugEnabled();
|
||||
|
||||
if (debug) {
|
||||
logger.debug("Binding as '" + userDn + "', prior to reconnect as user '" + principal + "'");
|
||||
this.logger.debug("Binding as '" + this.userDn + "', prior to reconnect as user '" + principal + "'");
|
||||
}
|
||||
|
||||
// First bind as manager user before rebinding as the specific principal.
|
||||
LdapContext ctx = (LdapContext) super.getContext(userDn, password);
|
||||
LdapContext ctx = (LdapContext) super.getContext(this.userDn, this.password);
|
||||
|
||||
Control[] rctls = { new PasswordPolicyControl(false) };
|
||||
|
||||
@@ -68,8 +68,8 @@ public class PasswordPolicyAwareContextSource extends DefaultSpringSecurityConte
|
||||
catch (javax.naming.NamingException ne) {
|
||||
PasswordPolicyResponseControl ctrl = PasswordPolicyControlExtractor.extractControl(ctx);
|
||||
if (debug) {
|
||||
logger.debug("Failed to obtain context", ne);
|
||||
logger.debug("Password policy response: " + ctrl);
|
||||
this.logger.debug("Failed to obtain context", ne);
|
||||
this.logger.debug("Password policy response: " + ctrl);
|
||||
}
|
||||
|
||||
LdapUtils.closeContext(ctx);
|
||||
@@ -84,7 +84,7 @@ public class PasswordPolicyAwareContextSource extends DefaultSpringSecurityConte
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
logger.debug("PPolicy control returned: " + PasswordPolicyControlExtractor.extractControl(ctx));
|
||||
this.logger.debug("PPolicy control returned: " + PasswordPolicyControlExtractor.extractControl(ctx));
|
||||
}
|
||||
|
||||
return ctx;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class PasswordPolicyControl implements Control {
|
||||
* Returns whether the control is critical for the client.
|
||||
*/
|
||||
public boolean isCritical() {
|
||||
return critical;
|
||||
return this.critical;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ public enum PasswordPolicyErrorStatus {
|
||||
}
|
||||
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
return this.errorCode;
|
||||
}
|
||||
|
||||
public String getDefaultMessage() {
|
||||
return defaultMessage;
|
||||
return this.defaultMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PasswordPolicyException extends RuntimeException {
|
||||
}
|
||||
|
||||
public PasswordPolicyErrorStatus getStatus() {
|
||||
return status;
|
||||
return this.status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -99,13 +99,13 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
|
||||
logger.debug("Searching for user '" + username + "', with user search " + this);
|
||||
}
|
||||
|
||||
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(contextSource);
|
||||
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(this.contextSource);
|
||||
|
||||
template.setSearchControls(searchControls);
|
||||
template.setSearchControls(this.searchControls);
|
||||
|
||||
try {
|
||||
|
||||
return template.searchForSingleEntry(searchBase, searchFilter, new String[] { username });
|
||||
return template.searchForSingleEntry(this.searchBase, this.searchFilter, new String[] { username });
|
||||
|
||||
}
|
||||
catch (IncorrectResultSizeDataAccessException notFound) {
|
||||
@@ -124,7 +124,7 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
|
||||
* @param deref the derefLinkFlag value as defined in SearchControls..
|
||||
*/
|
||||
public void setDerefLinkFlag(boolean deref) {
|
||||
searchControls.setDerefLinkFlag(deref);
|
||||
this.searchControls.setDerefLinkFlag(deref);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +134,8 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
|
||||
* SearchControls.SUBTREE_SCOPE rather than SearchControls.ONELEVEL_SCOPE.
|
||||
*/
|
||||
public void setSearchSubtree(boolean searchSubtree) {
|
||||
searchControls.setSearchScope(searchSubtree ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE);
|
||||
this.searchControls
|
||||
.setSearchScope(searchSubtree ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +143,7 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
|
||||
* @param searchTimeLimit the time limit for the search (in milliseconds).
|
||||
*/
|
||||
public void setSearchTimeLimit(int searchTimeLimit) {
|
||||
searchControls.setTimeLimit(searchTimeLimit);
|
||||
this.searchControls.setTimeLimit(searchTimeLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,19 +155,19 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
|
||||
* returned. Can be null.
|
||||
*/
|
||||
public void setReturningAttributes(String[] attrs) {
|
||||
searchControls.setReturningAttributes(attrs);
|
||||
this.searchControls.setReturningAttributes(attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("[ searchFilter: '").append(searchFilter).append("', ");
|
||||
sb.append("searchBase: '").append(searchBase).append("'");
|
||||
sb.append(", scope: ")
|
||||
.append(searchControls.getSearchScope() == SearchControls.SUBTREE_SCOPE ? "subtree" : "single-level, ");
|
||||
sb.append(", searchTimeLimit: ").append(searchControls.getTimeLimit());
|
||||
sb.append(", derefLinkFlag: ").append(searchControls.getDerefLinkFlag()).append(" ]");
|
||||
sb.append("[ searchFilter: '").append(this.searchFilter).append("', ");
|
||||
sb.append("searchBase: '").append(this.searchBase).append("'");
|
||||
sb.append(", scope: ").append(
|
||||
this.searchControls.getSearchScope() == SearchControls.SUBTREE_SCOPE ? "subtree" : "single-level, ");
|
||||
sb.append(", searchTimeLimit: ").append(this.searchControls.getTimeLimit());
|
||||
sb.append(", derefLinkFlag: ").append(this.searchControls.getDerefLinkFlag()).append(" ]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
|
||||
public ApacheDSContainer(String root, String ldifs) throws Exception {
|
||||
this.ldifResources = ldifs;
|
||||
service = new DefaultDirectoryService();
|
||||
this.service = new DefaultDirectoryService();
|
||||
List<Interceptor> list = new ArrayList<>();
|
||||
|
||||
list.add(new NormalizationInterceptor());
|
||||
@@ -128,20 +128,20 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
// list.add( new TriggerInterceptor() );
|
||||
// list.add( new JournalInterceptor() );
|
||||
|
||||
service.setInterceptors(list);
|
||||
partition = new JdbmPartition();
|
||||
partition.setId("rootPartition");
|
||||
partition.setSuffix(root);
|
||||
this.service.setInterceptors(list);
|
||||
this.partition = new JdbmPartition();
|
||||
this.partition.setId("rootPartition");
|
||||
this.partition.setSuffix(root);
|
||||
this.root = root;
|
||||
service.addPartition(partition);
|
||||
service.setExitVmOnShutdown(false);
|
||||
service.setShutdownHookEnabled(false);
|
||||
service.getChangeLog().setEnabled(false);
|
||||
service.setDenormalizeOpAttrsEnabled(true);
|
||||
this.service.addPartition(this.partition);
|
||||
this.service.setExitVmOnShutdown(false);
|
||||
this.service.setShutdownHookEnabled(false);
|
||||
this.service.getChangeLog().setEnabled(false);
|
||||
this.service.setDenormalizeOpAttrsEnabled(true);
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (workingDir == null) {
|
||||
if (this.workingDir == null) {
|
||||
String apacheWorkDir = System.getProperty("apacheDSWorkDir");
|
||||
|
||||
if (apacheWorkDir == null) {
|
||||
@@ -154,17 +154,17 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
throw new IllegalArgumentException("When LdapOverSsl is enabled, the keyStoreFile property must be set.");
|
||||
}
|
||||
|
||||
server = new LdapServer();
|
||||
server.setDirectoryService(service);
|
||||
this.server = new LdapServer();
|
||||
this.server.setDirectoryService(this.service);
|
||||
// AbstractLdapIntegrationTests assume IPv4, so we specify the same here
|
||||
|
||||
this.transport = new TcpTransport(port);
|
||||
if (ldapOverSslEnabled) {
|
||||
transport.setEnableSSL(true);
|
||||
server.setKeystoreFile(this.keyStoreFile.getAbsolutePath());
|
||||
server.setCertificatePassword(this.certificatePassord);
|
||||
this.transport = new TcpTransport(this.port);
|
||||
if (this.ldapOverSslEnabled) {
|
||||
this.transport.setEnableSSL(true);
|
||||
this.server.setKeystoreFile(this.keyStoreFile.getAbsolutePath());
|
||||
this.server.setCertificatePassword(this.certificatePassord);
|
||||
}
|
||||
server.setTransports(transport);
|
||||
this.server.setTransports(this.transport);
|
||||
start();
|
||||
}
|
||||
|
||||
@@ -173,13 +173,13 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
ctxt = applicationContext;
|
||||
this.ctxt = applicationContext;
|
||||
}
|
||||
|
||||
public void setWorkingDirectory(File workingDir) {
|
||||
Assert.notNull(workingDir, "workingDir cannot be null");
|
||||
|
||||
logger.info("Setting working directory for LDAP_PROVIDER: " + workingDir.getAbsolutePath());
|
||||
this.logger.info("Setting working directory for LDAP_PROVIDER: " + workingDir.getAbsolutePath());
|
||||
|
||||
if (workingDir.exists()) {
|
||||
throw new IllegalArgumentException("The specified working directory '" + workingDir.getAbsolutePath()
|
||||
@@ -190,7 +190,7 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
|
||||
this.workingDir = workingDir;
|
||||
|
||||
service.setWorkingDirectory(workingDir);
|
||||
this.service.setWorkingDirectory(workingDir);
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
@@ -238,7 +238,7 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
}
|
||||
|
||||
public DefaultDirectoryService getService() {
|
||||
return service;
|
||||
return this.service;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -246,45 +246,45 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
return;
|
||||
}
|
||||
|
||||
if (service.isStarted()) {
|
||||
if (this.service.isStarted()) {
|
||||
throw new IllegalStateException("DirectoryService is already running.");
|
||||
}
|
||||
|
||||
logger.info("Starting directory server...");
|
||||
this.logger.info("Starting directory server...");
|
||||
try {
|
||||
service.startup();
|
||||
server.start();
|
||||
this.service.startup();
|
||||
this.server.start();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Server startup failed", e);
|
||||
}
|
||||
|
||||
try {
|
||||
service.getAdminSession().lookup(partition.getSuffixDn());
|
||||
this.service.getAdminSession().lookup(this.partition.getSuffixDn());
|
||||
}
|
||||
catch (LdapNameNotFoundException e) {
|
||||
try {
|
||||
LdapDN dn = new LdapDN(root);
|
||||
Assert.isTrue(root.startsWith("dc="), "root must start with dc=");
|
||||
String dc = root.substring(3, root.indexOf(','));
|
||||
ServerEntry entry = service.newEntry(dn);
|
||||
LdapDN dn = new LdapDN(this.root);
|
||||
Assert.isTrue(this.root.startsWith("dc="), "root must start with dc=");
|
||||
String dc = this.root.substring(3, this.root.indexOf(','));
|
||||
ServerEntry entry = this.service.newEntry(dn);
|
||||
entry.add("objectClass", "top", "domain", "extensibleObject");
|
||||
entry.add("dc", dc);
|
||||
service.getAdminSession().add(entry);
|
||||
this.service.getAdminSession().add(entry);
|
||||
}
|
||||
catch (Exception e1) {
|
||||
logger.error("Failed to create dc entry", e1);
|
||||
this.logger.error("Failed to create dc entry", e1);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Lookup failed", e);
|
||||
this.logger.error("Lookup failed", e);
|
||||
}
|
||||
|
||||
SocketAcceptor socketAcceptor = this.server.getSocketAcceptor(this.transport);
|
||||
InetSocketAddress localAddress = socketAcceptor.getLocalAddress();
|
||||
this.localPort = localAddress.getPort();
|
||||
|
||||
running = true;
|
||||
this.running = true;
|
||||
|
||||
try {
|
||||
importLdifs();
|
||||
@@ -299,21 +299,21 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Shutting down directory server ...");
|
||||
this.logger.info("Shutting down directory server ...");
|
||||
try {
|
||||
server.stop();
|
||||
service.shutdown();
|
||||
this.server.stop();
|
||||
this.service.shutdown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Shutdown failed", e);
|
||||
this.logger.error("Shutdown failed", e);
|
||||
return;
|
||||
}
|
||||
|
||||
running = false;
|
||||
this.running = false;
|
||||
|
||||
if (workingDir.exists()) {
|
||||
logger.info("Deleting working directory " + workingDir.getAbsolutePath());
|
||||
deleteDir(workingDir);
|
||||
if (this.workingDir.exists()) {
|
||||
this.logger.info("Deleting working directory " + this.workingDir.getAbsolutePath());
|
||||
deleteDir(this.workingDir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,12 +321,12 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
// Import any ldif files
|
||||
Resource[] ldifs;
|
||||
|
||||
if (ctxt == null) {
|
||||
if (this.ctxt == null) {
|
||||
// Not running within an app context
|
||||
ldifs = new PathMatchingResourcePatternResolver().getResources(ldifResources);
|
||||
ldifs = new PathMatchingResourcePatternResolver().getResources(this.ldifResources);
|
||||
}
|
||||
else {
|
||||
ldifs = ctxt.getResources(ldifResources);
|
||||
ldifs = this.ctxt.getResources(this.ldifResources);
|
||||
}
|
||||
|
||||
// Note that we can't just import using the ServerContext returned
|
||||
@@ -348,14 +348,14 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
catch (IOException e) {
|
||||
ldifFile = ldifs[0].getURI().toString();
|
||||
}
|
||||
logger.info("Loading LDIF file: " + ldifFile);
|
||||
LdifFileLoader loader = new LdifFileLoader(service.getAdminSession(), new File(ldifFile), null,
|
||||
this.logger.info("Loading LDIF file: " + ldifFile);
|
||||
LdifFileLoader loader = new LdifFileLoader(this.service.getAdminSession(), new File(ldifFile), null,
|
||||
getClass().getClassLoader());
|
||||
loader.execute();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("More than one LDIF resource found with the supplied pattern:"
|
||||
+ ldifResources + " Got " + Arrays.toString(ldifs));
|
||||
+ this.ldifResources + " Got " + Arrays.toString(ldifs));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
return this.running;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
|
||||
}
|
||||
|
||||
for (Map<String, List<String>> role : userRoles) {
|
||||
authorities.add(authorityMapper.apply(role));
|
||||
authorities.add(this.authorityMapper.apply(role));
|
||||
}
|
||||
|
||||
return authorities;
|
||||
|
||||
@@ -73,96 +73,96 @@ public class InetOrgPerson extends Person {
|
||||
private String uid;
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
return this.uid;
|
||||
}
|
||||
|
||||
public String getMail() {
|
||||
return mail;
|
||||
return this.mail;
|
||||
}
|
||||
|
||||
public String getEmployeeNumber() {
|
||||
return employeeNumber;
|
||||
return this.employeeNumber;
|
||||
}
|
||||
|
||||
public String getInitials() {
|
||||
return initials;
|
||||
return this.initials;
|
||||
}
|
||||
|
||||
public String getDestinationIndicator() {
|
||||
return destinationIndicator;
|
||||
return this.destinationIndicator;
|
||||
}
|
||||
|
||||
public String getO() {
|
||||
return o;
|
||||
return this.o;
|
||||
}
|
||||
|
||||
public String getOu() {
|
||||
return ou;
|
||||
return this.ou;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public String getCarLicense() {
|
||||
return carLicense;
|
||||
return this.carLicense;
|
||||
}
|
||||
|
||||
public String getDepartmentNumber() {
|
||||
return departmentNumber;
|
||||
return this.departmentNumber;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public String getHomePhone() {
|
||||
return homePhone;
|
||||
return this.homePhone;
|
||||
}
|
||||
|
||||
public String getRoomNumber() {
|
||||
return roomNumber;
|
||||
return this.roomNumber;
|
||||
}
|
||||
|
||||
public String getHomePostalAddress() {
|
||||
return homePostalAddress;
|
||||
return this.homePostalAddress;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
return this.mobile;
|
||||
}
|
||||
|
||||
public String getPostalAddress() {
|
||||
return postalAddress;
|
||||
return this.postalAddress;
|
||||
}
|
||||
|
||||
public String getPostalCode() {
|
||||
return postalCode;
|
||||
return this.postalCode;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
return this.street;
|
||||
}
|
||||
|
||||
protected void populateContext(DirContextAdapter adapter) {
|
||||
super.populateContext(adapter);
|
||||
adapter.setAttributeValue("carLicense", carLicense);
|
||||
adapter.setAttributeValue("departmentNumber", departmentNumber);
|
||||
adapter.setAttributeValue("destinationIndicator", destinationIndicator);
|
||||
adapter.setAttributeValue("displayName", displayName);
|
||||
adapter.setAttributeValue("employeeNumber", employeeNumber);
|
||||
adapter.setAttributeValue("homePhone", homePhone);
|
||||
adapter.setAttributeValue("homePostalAddress", homePostalAddress);
|
||||
adapter.setAttributeValue("initials", initials);
|
||||
adapter.setAttributeValue("mail", mail);
|
||||
adapter.setAttributeValue("mobile", mobile);
|
||||
adapter.setAttributeValue("postalAddress", postalAddress);
|
||||
adapter.setAttributeValue("postalCode", postalCode);
|
||||
adapter.setAttributeValue("ou", ou);
|
||||
adapter.setAttributeValue("o", o);
|
||||
adapter.setAttributeValue("roomNumber", roomNumber);
|
||||
adapter.setAttributeValue("street", street);
|
||||
adapter.setAttributeValue("uid", uid);
|
||||
adapter.setAttributeValue("carLicense", this.carLicense);
|
||||
adapter.setAttributeValue("departmentNumber", this.departmentNumber);
|
||||
adapter.setAttributeValue("destinationIndicator", this.destinationIndicator);
|
||||
adapter.setAttributeValue("displayName", this.displayName);
|
||||
adapter.setAttributeValue("employeeNumber", this.employeeNumber);
|
||||
adapter.setAttributeValue("homePhone", this.homePhone);
|
||||
adapter.setAttributeValue("homePostalAddress", this.homePostalAddress);
|
||||
adapter.setAttributeValue("initials", this.initials);
|
||||
adapter.setAttributeValue("mail", this.mail);
|
||||
adapter.setAttributeValue("mobile", this.mobile);
|
||||
adapter.setAttributeValue("postalAddress", this.postalAddress);
|
||||
adapter.setAttributeValue("postalCode", this.postalCode);
|
||||
adapter.setAttributeValue("ou", this.ou);
|
||||
adapter.setAttributeValue("o", this.o);
|
||||
adapter.setAttributeValue("roomNumber", this.roomNumber);
|
||||
adapter.setAttributeValue("street", this.street);
|
||||
adapter.setAttributeValue("uid", this.uid);
|
||||
adapter.setAttributeValues("objectclass",
|
||||
new String[] { "top", "person", "organizationalPerson", "inetOrgPerson" });
|
||||
}
|
||||
@@ -221,79 +221,79 @@ public class InetOrgPerson extends Person {
|
||||
}
|
||||
|
||||
public void setMail(String email) {
|
||||
((InetOrgPerson) instance).mail = email;
|
||||
((InetOrgPerson) this.instance).mail = email;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
((InetOrgPerson) instance).uid = uid;
|
||||
((InetOrgPerson) this.instance).uid = uid;
|
||||
|
||||
if (instance.getUsername() == null) {
|
||||
if (this.instance.getUsername() == null) {
|
||||
setUsername(uid);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInitials(String initials) {
|
||||
((InetOrgPerson) instance).initials = initials;
|
||||
((InetOrgPerson) this.instance).initials = initials;
|
||||
}
|
||||
|
||||
public void setO(String organization) {
|
||||
((InetOrgPerson) instance).o = organization;
|
||||
((InetOrgPerson) this.instance).o = organization;
|
||||
}
|
||||
|
||||
public void setOu(String ou) {
|
||||
((InetOrgPerson) instance).ou = ou;
|
||||
((InetOrgPerson) this.instance).ou = ou;
|
||||
}
|
||||
|
||||
public void setRoomNumber(String no) {
|
||||
((InetOrgPerson) instance).roomNumber = no;
|
||||
((InetOrgPerson) this.instance).roomNumber = no;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
((InetOrgPerson) instance).title = title;
|
||||
((InetOrgPerson) this.instance).title = title;
|
||||
}
|
||||
|
||||
public void setCarLicense(String carLicense) {
|
||||
((InetOrgPerson) instance).carLicense = carLicense;
|
||||
((InetOrgPerson) this.instance).carLicense = carLicense;
|
||||
}
|
||||
|
||||
public void setDepartmentNumber(String departmentNumber) {
|
||||
((InetOrgPerson) instance).departmentNumber = departmentNumber;
|
||||
((InetOrgPerson) this.instance).departmentNumber = departmentNumber;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
((InetOrgPerson) instance).displayName = displayName;
|
||||
((InetOrgPerson) this.instance).displayName = displayName;
|
||||
}
|
||||
|
||||
public void setEmployeeNumber(String no) {
|
||||
((InetOrgPerson) instance).employeeNumber = no;
|
||||
((InetOrgPerson) this.instance).employeeNumber = no;
|
||||
}
|
||||
|
||||
public void setDestinationIndicator(String destination) {
|
||||
((InetOrgPerson) instance).destinationIndicator = destination;
|
||||
((InetOrgPerson) this.instance).destinationIndicator = destination;
|
||||
}
|
||||
|
||||
public void setHomePhone(String homePhone) {
|
||||
((InetOrgPerson) instance).homePhone = homePhone;
|
||||
((InetOrgPerson) this.instance).homePhone = homePhone;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
((InetOrgPerson) instance).street = street;
|
||||
((InetOrgPerson) this.instance).street = street;
|
||||
}
|
||||
|
||||
public void setPostalCode(String postalCode) {
|
||||
((InetOrgPerson) instance).postalCode = postalCode;
|
||||
((InetOrgPerson) this.instance).postalCode = postalCode;
|
||||
}
|
||||
|
||||
public void setPostalAddress(String postalAddress) {
|
||||
((InetOrgPerson) instance).postalAddress = postalAddress;
|
||||
((InetOrgPerson) this.instance).postalAddress = postalAddress;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
((InetOrgPerson) instance).mobile = mobile;
|
||||
((InetOrgPerson) this.instance).mobile = mobile;
|
||||
}
|
||||
|
||||
public void setHomePostalAddress(String homePostalAddress) {
|
||||
((InetOrgPerson) instance).homePostalAddress = homePostalAddress;
|
||||
((InetOrgPerson) this.instance).homePostalAddress = homePostalAddress;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class LdapAuthority implements GrantedAuthority {
|
||||
* @return the LDAP attributes, map can be null
|
||||
*/
|
||||
public Map<String, List<String>> getAttributes() {
|
||||
return attributes;
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ public class LdapAuthority implements GrantedAuthority {
|
||||
* @return
|
||||
*/
|
||||
public String getDn() {
|
||||
return dn;
|
||||
return this.dn;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,8 +83,8 @@ public class LdapAuthority implements GrantedAuthority {
|
||||
*/
|
||||
public List<String> getAttributeValues(String name) {
|
||||
List<String> result = null;
|
||||
if (attributes != null) {
|
||||
result = attributes.get(name);
|
||||
if (this.attributes != null) {
|
||||
result = this.attributes.get(name);
|
||||
}
|
||||
if (result == null) {
|
||||
result = Collections.emptyList();
|
||||
@@ -112,7 +112,7 @@ public class LdapAuthority implements GrantedAuthority {
|
||||
*/
|
||||
@Override
|
||||
public String getAuthority() {
|
||||
return role;
|
||||
return this.role;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,22 +130,22 @@ public class LdapAuthority implements GrantedAuthority {
|
||||
|
||||
LdapAuthority that = (LdapAuthority) o;
|
||||
|
||||
if (!dn.equals(that.dn)) {
|
||||
if (!this.dn.equals(that.dn)) {
|
||||
return false;
|
||||
}
|
||||
return role.equals(that.role);
|
||||
return this.role.equals(that.role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = dn.hashCode();
|
||||
result = 31 * result + (role != null ? role.hashCode() : 0);
|
||||
int result = this.dn.hashCode();
|
||||
result = 31 * result + (this.role != null ? this.role.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LdapAuthority{" + "dn='" + dn + '\'' + ", role='" + role + '\'' + '}';
|
||||
return "LdapAuthority{" + "dn='" + this.dn + '\'' + ", role='" + this.role + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,77 +77,77 @@ public class LdapUserDetailsImpl implements LdapUserDetails, PasswordPolicyData
|
||||
|
||||
@Override
|
||||
public Collection<GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
return this.authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDn() {
|
||||
return dn;
|
||||
return this.dn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return accountNonExpired;
|
||||
return this.accountNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return accountNonLocked;
|
||||
return this.accountNonLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return credentialsNonExpired;
|
||||
return this.credentialsNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eraseCredentials() {
|
||||
password = null;
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeBeforeExpiration() {
|
||||
return timeBeforeExpiration;
|
||||
return this.timeBeforeExpiration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGraceLoginsRemaining() {
|
||||
return graceLoginsRemaining;
|
||||
return this.graceLoginsRemaining;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof LdapUserDetailsImpl) {
|
||||
return dn.equals(((LdapUserDetailsImpl) obj).dn);
|
||||
return this.dn.equals(((LdapUserDetailsImpl) obj).dn);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return dn.hashCode();
|
||||
return this.dn.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString()).append(": ");
|
||||
sb.append("Dn: ").append(dn).append("; ");
|
||||
sb.append("Dn: ").append(this.dn).append("; ");
|
||||
sb.append("Username: ").append(this.username).append("; ");
|
||||
sb.append("Password: [PROTECTED]; ");
|
||||
sb.append("Enabled: ").append(this.enabled).append("; ");
|
||||
@@ -214,12 +214,12 @@ public class LdapUserDetailsImpl implements LdapUserDetails, PasswordPolicyData
|
||||
*/
|
||||
public void addAuthority(GrantedAuthority a) {
|
||||
if (!hasAuthority(a)) {
|
||||
mutableAuthorities.add(a);
|
||||
this.mutableAuthorities.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasAuthority(GrantedAuthority a) {
|
||||
for (GrantedAuthority authority : mutableAuthorities) {
|
||||
for (GrantedAuthority authority : this.mutableAuthorities) {
|
||||
if (authority.equals(a)) {
|
||||
return true;
|
||||
}
|
||||
@@ -228,66 +228,66 @@ public class LdapUserDetailsImpl implements LdapUserDetails, PasswordPolicyData
|
||||
}
|
||||
|
||||
public LdapUserDetails createUserDetails() {
|
||||
Assert.notNull(instance, "Essence can only be used to create a single instance");
|
||||
Assert.notNull(instance.username, "username must not be null");
|
||||
Assert.notNull(instance.getDn(), "Distinguished name must not be null");
|
||||
Assert.notNull(this.instance, "Essence can only be used to create a single instance");
|
||||
Assert.notNull(this.instance.username, "username must not be null");
|
||||
Assert.notNull(this.instance.getDn(), "Distinguished name must not be null");
|
||||
|
||||
instance.authorities = Collections.unmodifiableList(mutableAuthorities);
|
||||
this.instance.authorities = Collections.unmodifiableList(this.mutableAuthorities);
|
||||
|
||||
LdapUserDetails newInstance = instance;
|
||||
LdapUserDetails newInstance = this.instance;
|
||||
|
||||
instance = null;
|
||||
this.instance = null;
|
||||
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
public Collection<GrantedAuthority> getGrantedAuthorities() {
|
||||
return mutableAuthorities;
|
||||
return this.mutableAuthorities;
|
||||
}
|
||||
|
||||
public void setAccountNonExpired(boolean accountNonExpired) {
|
||||
instance.accountNonExpired = accountNonExpired;
|
||||
this.instance.accountNonExpired = accountNonExpired;
|
||||
}
|
||||
|
||||
public void setAccountNonLocked(boolean accountNonLocked) {
|
||||
instance.accountNonLocked = accountNonLocked;
|
||||
this.instance.accountNonLocked = accountNonLocked;
|
||||
}
|
||||
|
||||
public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
|
||||
mutableAuthorities = new ArrayList<>();
|
||||
mutableAuthorities.addAll(authorities);
|
||||
this.mutableAuthorities = new ArrayList<>();
|
||||
this.mutableAuthorities.addAll(authorities);
|
||||
}
|
||||
|
||||
public void setCredentialsNonExpired(boolean credentialsNonExpired) {
|
||||
instance.credentialsNonExpired = credentialsNonExpired;
|
||||
this.instance.credentialsNonExpired = credentialsNonExpired;
|
||||
}
|
||||
|
||||
public void setDn(String dn) {
|
||||
instance.dn = dn;
|
||||
this.instance.dn = dn;
|
||||
}
|
||||
|
||||
public void setDn(Name dn) {
|
||||
instance.dn = dn.toString();
|
||||
this.instance.dn = dn.toString();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
instance.enabled = enabled;
|
||||
this.instance.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
instance.password = password;
|
||||
this.instance.password = password;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
instance.username = username;
|
||||
this.instance.username = username;
|
||||
}
|
||||
|
||||
public void setTimeBeforeExpiration(int timeBeforeExpiration) {
|
||||
instance.timeBeforeExpiration = timeBeforeExpiration;
|
||||
this.instance.timeBeforeExpiration = timeBeforeExpiration;
|
||||
}
|
||||
|
||||
public void setGraceLoginsRemaining(int graceLoginsRemaining) {
|
||||
instance.graceLoginsRemaining = graceLoginsRemaining;
|
||||
this.instance.graceLoginsRemaining = graceLoginsRemaining;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -114,14 +114,14 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
|
||||
/** Default context mapper used to create a set of roles from a list of attributes */
|
||||
private AttributesMapper roleMapper = attributes -> {
|
||||
Attribute roleAttr = attributes.get(groupRoleAttributeName);
|
||||
Attribute roleAttr = attributes.get(this.groupRoleAttributeName);
|
||||
|
||||
NamingEnumeration<?> ne = roleAttr.getAll();
|
||||
// assert ne.hasMore();
|
||||
Object group = ne.next();
|
||||
String role = group.toString();
|
||||
|
||||
return new SimpleGrantedAuthority(rolePrefix + role.toUpperCase());
|
||||
return new SimpleGrantedAuthority(this.rolePrefix + role.toUpperCase());
|
||||
};
|
||||
|
||||
private String[] attributesToRetrieve;
|
||||
@@ -129,24 +129,24 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
private boolean usePasswordModifyExtensionOperation = false;
|
||||
|
||||
public LdapUserDetailsManager(ContextSource contextSource) {
|
||||
template = new LdapTemplate(contextSource);
|
||||
this.template = new LdapTemplate(contextSource);
|
||||
}
|
||||
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
DistinguishedName dn = usernameMapper.buildDn(username);
|
||||
DistinguishedName dn = this.usernameMapper.buildDn(username);
|
||||
List<GrantedAuthority> authorities = getUserAuthorities(dn, username);
|
||||
|
||||
logger.debug("Loading user '" + username + "' with DN '" + dn + "'");
|
||||
this.logger.debug("Loading user '" + username + "' with DN '" + dn + "'");
|
||||
|
||||
DirContextAdapter userCtx = loadUserAsContext(dn, username);
|
||||
|
||||
return userDetailsMapper.mapUserFromContext(userCtx, username, authorities);
|
||||
return this.userDetailsMapper.mapUserFromContext(userCtx, username, authorities);
|
||||
}
|
||||
|
||||
private DirContextAdapter loadUserAsContext(final DistinguishedName dn, final String username) {
|
||||
return (DirContextAdapter) template.executeReadOnly((ContextExecutor) ctx -> {
|
||||
return (DirContextAdapter) this.template.executeReadOnly((ContextExecutor) ctx -> {
|
||||
try {
|
||||
Attributes attrs = ctx.getAttributes(dn, attributesToRetrieve);
|
||||
Attributes attrs = ctx.getAttributes(dn, this.attributesToRetrieve);
|
||||
return new DirContextAdapter(attrs, LdapUtils.getFullDn(dn, ctx));
|
||||
}
|
||||
catch (NameNotFoundException notFound) {
|
||||
@@ -187,11 +187,11 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
|
||||
String username = authentication.getName();
|
||||
|
||||
logger.debug("Changing password for user '" + username);
|
||||
this.logger.debug("Changing password for user '" + username);
|
||||
|
||||
DistinguishedName userDn = usernameMapper.buildDn(username);
|
||||
DistinguishedName userDn = this.usernameMapper.buildDn(username);
|
||||
|
||||
if (usePasswordModifyExtensionOperation) {
|
||||
if (this.usePasswordModifyExtensionOperation) {
|
||||
changePasswordUsingExtensionOperation(userDn, oldPassword, newPassword);
|
||||
}
|
||||
else {
|
||||
@@ -210,25 +210,26 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
SearchExecutor se = ctx -> {
|
||||
DistinguishedName fullDn = LdapUtils.getFullDn(dn, ctx);
|
||||
SearchControls ctrls = new SearchControls();
|
||||
ctrls.setReturningAttributes(new String[] { groupRoleAttributeName });
|
||||
ctrls.setReturningAttributes(new String[] { this.groupRoleAttributeName });
|
||||
|
||||
return ctx.search(groupSearchBase, groupSearchFilter, new String[] { fullDn.toUrl(), username }, ctrls);
|
||||
return ctx.search(this.groupSearchBase, this.groupSearchFilter, new String[] { fullDn.toUrl(), username },
|
||||
ctrls);
|
||||
};
|
||||
|
||||
AttributesMapperCallbackHandler roleCollector = new AttributesMapperCallbackHandler(roleMapper);
|
||||
AttributesMapperCallbackHandler roleCollector = new AttributesMapperCallbackHandler(this.roleMapper);
|
||||
|
||||
template.search(se, roleCollector);
|
||||
this.template.search(se, roleCollector);
|
||||
return roleCollector.getList();
|
||||
}
|
||||
|
||||
public void createUser(UserDetails user) {
|
||||
DirContextAdapter ctx = new DirContextAdapter();
|
||||
copyToContext(user, ctx);
|
||||
DistinguishedName dn = usernameMapper.buildDn(user.getUsername());
|
||||
DistinguishedName dn = this.usernameMapper.buildDn(user.getUsername());
|
||||
|
||||
logger.debug("Creating new user '" + user.getUsername() + "' with DN '" + dn + "'");
|
||||
this.logger.debug("Creating new user '" + user.getUsername() + "' with DN '" + dn + "'");
|
||||
|
||||
template.bind(dn, ctx, null);
|
||||
this.template.bind(dn, ctx, null);
|
||||
|
||||
// Check for any existing authorities which might be set for this DN and remove
|
||||
// them
|
||||
@@ -242,9 +243,9 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
}
|
||||
|
||||
public void updateUser(UserDetails user) {
|
||||
DistinguishedName dn = usernameMapper.buildDn(user.getUsername());
|
||||
DistinguishedName dn = this.usernameMapper.buildDn(user.getUsername());
|
||||
|
||||
logger.debug("Updating user '" + user.getUsername() + "' with DN '" + dn + "'");
|
||||
this.logger.debug("Updating user '" + user.getUsername() + "' with DN '" + dn + "'");
|
||||
|
||||
List<GrantedAuthority> authorities = getUserAuthorities(dn, user.getUsername());
|
||||
|
||||
@@ -264,7 +265,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
}
|
||||
}
|
||||
|
||||
template.modifyAttributes(dn, mods.toArray(new ModificationItem[0]));
|
||||
this.template.modifyAttributes(dn, mods.toArray(new ModificationItem[0]));
|
||||
|
||||
// template.rebind(dn, ctx, null);
|
||||
// Remove the old authorities and replace them with the new one
|
||||
@@ -273,16 +274,16 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
}
|
||||
|
||||
public void deleteUser(String username) {
|
||||
DistinguishedName dn = usernameMapper.buildDn(username);
|
||||
DistinguishedName dn = this.usernameMapper.buildDn(username);
|
||||
removeAuthorities(dn, getUserAuthorities(dn, username));
|
||||
template.unbind(dn);
|
||||
this.template.unbind(dn);
|
||||
}
|
||||
|
||||
public boolean userExists(String username) {
|
||||
DistinguishedName dn = usernameMapper.buildDn(username);
|
||||
DistinguishedName dn = this.usernameMapper.buildDn(username);
|
||||
|
||||
try {
|
||||
Object obj = template.lookup(dn);
|
||||
Object obj = this.template.lookup(dn);
|
||||
if (obj instanceof Context) {
|
||||
LdapUtils.closeContext((Context) obj);
|
||||
}
|
||||
@@ -299,14 +300,14 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
* @return the DN of the corresponding group, including the groupSearchBase
|
||||
*/
|
||||
protected DistinguishedName buildGroupDn(String group) {
|
||||
DistinguishedName dn = new DistinguishedName(groupSearchBase);
|
||||
dn.add(groupRoleAttributeName, group.toLowerCase());
|
||||
DistinguishedName dn = new DistinguishedName(this.groupSearchBase);
|
||||
dn.add(this.groupRoleAttributeName, group.toLowerCase());
|
||||
|
||||
return dn;
|
||||
}
|
||||
|
||||
protected void copyToContext(UserDetails user, DirContextAdapter ctx) {
|
||||
userDetailsMapper.mapUserToContext(user, ctx);
|
||||
this.userDetailsMapper.mapUserToContext(user, ctx);
|
||||
}
|
||||
|
||||
protected void addAuthorities(DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities) {
|
||||
@@ -319,12 +320,12 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
|
||||
private void modifyAuthorities(final DistinguishedName userDn,
|
||||
final Collection<? extends GrantedAuthority> authorities, final int modType) {
|
||||
template.executeReadWrite((ContextExecutor) ctx -> {
|
||||
this.template.executeReadWrite((ContextExecutor) ctx -> {
|
||||
for (GrantedAuthority authority : authorities) {
|
||||
String group = convertAuthorityToGroup(authority);
|
||||
DistinguishedName fullDn = LdapUtils.getFullDn(userDn, ctx);
|
||||
ModificationItem addGroup = new ModificationItem(modType,
|
||||
new BasicAttribute(groupMemberAttributeName, fullDn.toUrl()));
|
||||
new BasicAttribute(this.groupMemberAttributeName, fullDn.toUrl()));
|
||||
|
||||
ctx.modifyAttributes(buildGroupDn(group), new ModificationItem[] { addGroup });
|
||||
}
|
||||
@@ -335,8 +336,8 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
private String convertAuthorityToGroup(GrantedAuthority authority) {
|
||||
String group = authority.getAuthority();
|
||||
|
||||
if (group.startsWith(rolePrefix)) {
|
||||
group = group.substring(rolePrefix.length());
|
||||
if (group.startsWith(this.rolePrefix)) {
|
||||
group = group.substring(this.rolePrefix.length());
|
||||
}
|
||||
|
||||
return group;
|
||||
@@ -413,14 +414,14 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
String newPassword) {
|
||||
|
||||
final ModificationItem[] passwordChange = new ModificationItem[] { new ModificationItem(
|
||||
DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(passwordAttributeName, newPassword)) };
|
||||
DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(this.passwordAttributeName, newPassword)) };
|
||||
|
||||
if (oldPassword == null) {
|
||||
template.modifyAttributes(userDn, passwordChange);
|
||||
this.template.modifyAttributes(userDn, passwordChange);
|
||||
return;
|
||||
}
|
||||
|
||||
template.executeReadWrite(dirCtx -> {
|
||||
this.template.executeReadWrite(dirCtx -> {
|
||||
LdapContext ctx = (LdapContext) dirCtx;
|
||||
ctx.removeFromEnvironment("com.sun.jndi.ldap.connect.pool");
|
||||
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, LdapUtils.getFullDn(userDn, ctx).toString());
|
||||
@@ -443,7 +444,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
private void changePasswordUsingExtensionOperation(DistinguishedName userDn, String oldPassword,
|
||||
String newPassword) {
|
||||
|
||||
template.executeReadWrite(dirCtx -> {
|
||||
this.template.executeReadWrite(dirCtx -> {
|
||||
LdapContext ctx = (LdapContext) dirCtx;
|
||||
|
||||
String userIdentity = LdapUtils.getFullDn(userDn, ctx).encode();
|
||||
|
||||
@@ -54,10 +54,10 @@ public class LdapUserDetailsService implements UserDetailsService {
|
||||
}
|
||||
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
DirContextOperations userData = userSearch.searchForUser(username);
|
||||
DirContextOperations userData = this.userSearch.searchForUser(username);
|
||||
|
||||
return userDetailsMapper.mapUserFromContext(userData, username,
|
||||
authoritiesPopulator.getGrantedAuthorities(userData, username));
|
||||
return this.userDetailsMapper.mapUserFromContext(userData, username,
|
||||
this.authoritiesPopulator.getGrantedAuthorities(userData, username));
|
||||
}
|
||||
|
||||
public void setUserDetailsMapper(UserDetailsContextMapper userDetailsMapper) {
|
||||
|
||||
@@ -50,28 +50,28 @@ public class Person extends LdapUserDetailsImpl {
|
||||
}
|
||||
|
||||
public String getGivenName() {
|
||||
return givenName;
|
||||
return this.givenName;
|
||||
}
|
||||
|
||||
public String getSn() {
|
||||
return sn;
|
||||
return this.sn;
|
||||
}
|
||||
|
||||
public String[] getCn() {
|
||||
return cn.toArray(new String[0]);
|
||||
return this.cn.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public String getTelephoneNumber() {
|
||||
return telephoneNumber;
|
||||
return this.telephoneNumber;
|
||||
}
|
||||
|
||||
protected void populateContext(DirContextAdapter adapter) {
|
||||
adapter.setAttributeValue("givenName", givenName);
|
||||
adapter.setAttributeValue("sn", sn);
|
||||
adapter.setAttributeValue("givenName", this.givenName);
|
||||
adapter.setAttributeValue("sn", this.sn);
|
||||
adapter.setAttributeValues("cn", getCn());
|
||||
adapter.setAttributeValue("description", getDescription());
|
||||
adapter.setAttributeValue("telephoneNumber", getTelephoneNumber());
|
||||
@@ -108,7 +108,7 @@ public class Person extends LdapUserDetailsImpl {
|
||||
setSn(copyMe.sn);
|
||||
setDescription(copyMe.getDescription());
|
||||
setTelephoneNumber(copyMe.getTelephoneNumber());
|
||||
((Person) instance).cn = new ArrayList<>(copyMe.cn);
|
||||
((Person) this.instance).cn = new ArrayList<>(copyMe.cn);
|
||||
}
|
||||
|
||||
protected LdapUserDetailsImpl createTarget() {
|
||||
@@ -116,27 +116,27 @@ public class Person extends LdapUserDetailsImpl {
|
||||
}
|
||||
|
||||
public void setGivenName(String givenName) {
|
||||
((Person) instance).givenName = givenName;
|
||||
((Person) this.instance).givenName = givenName;
|
||||
}
|
||||
|
||||
public void setSn(String sn) {
|
||||
((Person) instance).sn = sn;
|
||||
((Person) this.instance).sn = sn;
|
||||
}
|
||||
|
||||
public void setCn(String[] cn) {
|
||||
((Person) instance).cn = Arrays.asList(cn);
|
||||
((Person) this.instance).cn = Arrays.asList(cn);
|
||||
}
|
||||
|
||||
public void addCn(String value) {
|
||||
((Person) instance).cn.add(value);
|
||||
((Person) this.instance).cn.add(value);
|
||||
}
|
||||
|
||||
public void setTelephoneNumber(String tel) {
|
||||
((Person) instance).telephoneNumber = tel;
|
||||
((Person) this.instance).telephoneNumber = tel;
|
||||
}
|
||||
|
||||
public void setDescription(String desc) {
|
||||
((Person) instance).description = desc;
|
||||
((Person) this.instance).description = desc;
|
||||
}
|
||||
|
||||
public LdapUserDetails createUserDetails() {
|
||||
|
||||
Reference in New Issue
Block a user