LDAP-257: Got rid of commons-lang dependency in core. Upped some versions.

This commit is contained in:
Mattias Hellborg Arthursson
2013-08-28 13:45:17 +02:00
parent 36cbb8894e
commit 7d50459ae1
35 changed files with 361 additions and 418 deletions

View File

@@ -10,7 +10,6 @@ idea.module.excludeDirs = [
dependencies {
compile "commons-logging:commons-logging:$commonsLoggingVersion",
"commons-lang:commons-lang:$commonsLangVersion",
"org.springframework:spring-core:$springVersion",
"org.springframework:spring-beans:$springVersion",
"org.springframework:spring-tx:$springVersion"
@@ -22,6 +21,7 @@ dependencies {
"org.springframework:spring-orm:$springVersion"
testCompile "junit:junit:$junitVersion",
"commons-lang:commons-lang:$commonsLangVersion",
"gsbase:gsbase:$gsbaseVersion",
"org.mockito:mockito-core:$mockitoVersion"
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.authentication;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.ldap.core.AuthenticationSource;
@@ -78,7 +77,7 @@ public class DefaultValuesAuthenticationSourceDecorator implements
* <code>defaultPassword</code> otherwise.
*/
public String getCredentials() {
if (StringUtils.isNotEmpty(target.getPrincipal())) {
if (StringUtils.hasText(target.getPrincipal())) {
return target.getCredentials();
} else {
return defaultPassword;
@@ -94,7 +93,7 @@ public class DefaultValuesAuthenticationSourceDecorator implements
*/
public String getPrincipal() {
String principal = target.getPrincipal();
if (StringUtils.isNotEmpty(principal)) {
if (StringUtils.hasText(principal)) {
return principal;
} else {
return defaultUser;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,6 @@ package org.springframework.ldap.control;
import java.util.List;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* Bean to encapsulate a result List and a {@link PagedResultsCookie} to use for
* returning the results when using {@link PagedResultsRequestControl}.
@@ -65,28 +62,23 @@ public class PagedResult {
return resultList;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj != null && this.getClass().equals(obj.getClass())) {
PagedResult that = (PagedResult) obj;
return new EqualsBuilder().append(this.resultList, that.resultList)
.append(this.cookie, that.cookie).isEquals();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return false;
PagedResult that = (PagedResult) o;
if (cookie != null ? !cookie.equals(that.cookie) : that.cookie != null) return false;
if (resultList != null ? !resultList.equals(that.resultList) : that.resultList != null) return false;
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return new HashCodeBuilder().append(this.resultList)
.append(this.cookie).toHashCode();
int result = resultList != null ? resultList.hashCode() : 0;
result = 31 * result + (cookie != null ? cookie.hashCode() : 0);
return result;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.control;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import com.sun.jndi.ldap.ctl.PagedResultsControl;
import java.util.Arrays;
/**
* Wrapper class for the cookie returned when using the
* {@link PagedResultsControl}.
@@ -40,7 +37,11 @@ public class PagedResultsCookie {
* the cookie returned by a PagedResultsResponseControl.
*/
public PagedResultsCookie(byte[] cookie) {
this.cookie = ArrayUtils.clone(cookie);
if (cookie != null) {
this.cookie = Arrays.copyOf(cookie, cookie.length);
} else {
this.cookie = null;
}
}
/**
@@ -49,30 +50,27 @@ public class PagedResultsCookie {
* @return the cookie.
*/
public byte[] getCookie() {
return ArrayUtils.clone(cookie);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj != null && this.getClass().equals(obj.getClass())) {
PagedResultsCookie that = (PagedResultsCookie) obj;
return new EqualsBuilder().append(this.cookie, that.cookie)
.isEquals();
if (cookie != null) {
return Arrays.copyOf(cookie, cookie.length);
} else {
return null;
}
return false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PagedResultsCookie that = (PagedResultsCookie) o;
if (!Arrays.equals(cookie, that.cookie)) return false;
return true;
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(this.cookie).toHashCode();
return cookie != null ? Arrays.hashCode(cookie) : 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.core;
import org.springframework.util.Assert;
import javax.naming.Binding;
import javax.naming.NameClassPair;
import org.apache.commons.lang.Validate;
/**
* A CollectingNameClassPairCallbackHandler to wrap a ContextMapper. That is,
* the found object is extracted from each {@link Binding}, and then passed to
@@ -41,7 +40,7 @@ public class ContextMapperCallbackHandler extends
* the mapper to be called for each entry.
*/
public ContextMapperCallbackHandler(ContextMapper mapper) {
Validate.notNull(mapper, "Mapper must not be empty");
Assert.notNull(mapper, "Mapper must not be empty");
this.mapper = mapper;
}

View File

@@ -13,16 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.core;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.NoSuchAttributeException;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.naming.Context;
@@ -483,7 +480,7 @@ public class DirContextAdapter implements DirContextOperations {
}
else {
// check all strings
if (!ArrayUtils.contains(values, obj)) {
if (!ObjectUtils.containsElement(values, obj)) {
return true;
}
}
@@ -513,7 +510,7 @@ public class DirContextAdapter implements DirContextOperations {
}
else {
// check all strings
if (!ArrayUtils.contains(values, obj)) {
if (!ObjectUtils.containsElement(values, obj)) {
return true;
}
}
@@ -1300,26 +1297,36 @@ public class DirContextAdapter implements DirContextOperations {
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
// A subclass with identical values should NOT be considered equal.
// EqualsBuilder in commons-lang cannot handle subclasses correctly.
if (obj == null || obj.getClass() != this.getClass()) {
return false;
}
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
/**
* @see Object#hashCode()
*/
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
DirContextAdapter that = (DirContextAdapter) o;
/**
if (updateMode != that.updateMode) return false;
if (base != null ? !base.equals(that.base) : that.base != null) return false;
if (dn != null ? !dn.equals(that.dn) : that.dn != null) return false;
if (originalAttrs != null ? !originalAttrs.equals(that.originalAttrs) : that.originalAttrs != null)
return false;
if (referralUrl != null ? !referralUrl.equals(that.referralUrl) : that.referralUrl != null) return false;
if (updatedAttrs != null ? !updatedAttrs.equals(that.updatedAttrs) : that.updatedAttrs != null) return false;
return true;
}
@Override
public int hashCode() {
int result = originalAttrs != null ? originalAttrs.hashCode() : 0;
result = 31 * result + (dn != null ? dn.hashCode() : 0);
result = 31 * result + (base != null ? base.hashCode() : 0);
result = 31 * result + (updateMode ? 1 : 0);
result = 31 * result + (updatedAttrs != null ? updatedAttrs.hashCode() : 0);
result = 31 * result + (referralUrl != null ? referralUrl.hashCode() : 0);
return result;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {

View File

@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.core;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.BadLdapGrammarException;
@@ -138,8 +138,8 @@ public class DistinguishedName implements Name {
public static final String KEY_CASE_FOLD_NONE = "none";
private static final String[] MANGLED_DOUBLE_QUOTES = new String[]{"\\\\\""};
private static final String[] PROPER_DOUBLE_QUOTES = new String[]{"\\\""};
private static final String MANGLED_DOUBLE_QUOTES = "\\\\\"";
private static final String PROPER_DOUBLE_QUOTES = "\\\"";
private static final Log log = LogFactory.getLog(DistinguishedName.class);
@@ -169,7 +169,7 @@ public class DistinguishedName implements Name {
* @param path a String corresponding to a (syntactically) valid LDAP path.
*/
public DistinguishedName(String path) {
if (StringUtils.isBlank(path)) {
if (!StringUtils.hasText(path)) {
names = new LinkedList();
}
else {
@@ -247,7 +247,7 @@ public class DistinguishedName implements Name {
tempPath = path;
}
tempPath = StringUtils.replaceEach(tempPath, MANGLED_DOUBLE_QUOTES, PROPER_DOUBLE_QUOTES);
tempPath = StringUtils.replace(tempPath, MANGLED_DOUBLE_QUOTES, PROPER_DOUBLE_QUOTES);
return tempPath;
}
@@ -273,7 +273,7 @@ public class DistinguishedName implements Name {
public LdapRdn getLdapRdn(String key) {
for (Iterator iter = names.iterator(); iter.hasNext();) {
LdapRdn rdn = (LdapRdn) iter.next();
if (StringUtils.equals(rdn.getKey(), key)) {
if (ObjectUtils.nullSafeEquals(rdn.getKey(), key)) {
return rdn;
}
}
@@ -317,7 +317,7 @@ public class DistinguishedName implements Name {
*/
public String toString() {
String spacedFormatting = System.getProperty(SPACED_DN_FORMAT_PROPERTY);
if (StringUtils.isBlank(spacedFormatting)) {
if (!StringUtils.hasText(spacedFormatting)) {
return format(COMPACT);
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,10 @@
package org.springframework.ldap.core;
import org.springframework.ldap.BadLdapGrammarException;
import org.springframework.ldap.support.ListComparator;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@@ -24,10 +28,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.ldap.BadLdapGrammarException;
import org.springframework.ldap.support.ListComparator;
/**
* Datatype for a LDAP name, a part of a path.
*
@@ -239,7 +239,7 @@ public class LdapRdn implements Serializable, Comparable {
public String getValue(String key) {
for (Iterator iter = components.iterator(); iter.hasNext();) {
LdapRdnComponent component = (LdapRdnComponent) iter.next();
if (StringUtils.equals(component.getKey(), key)) {
if (ObjectUtils.nullSafeEquals(component.getKey(), key)) {
return component.getValue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,15 +15,15 @@
*/
package org.springframework.ldap.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Represents part of an LdapRdn. As specified in RFC2253 an LdapRdn may be
* composed of several attributes, separated by &quot;+&quot;. An
@@ -68,14 +68,14 @@ public class LdapRdnComponent implements Comparable, Serializable {
* @see DistinguishedName#KEY_CASE_FOLD_PROPERTY
*/
public LdapRdnComponent(String key, String value, boolean decodeValue) {
Validate.notEmpty(key, "Key must not be empty");
Validate.notEmpty(value, "Value must not be empty");
Assert.hasText(key, "Key must not be empty");
Assert.hasText(value, "Value must not be empty");
String caseFold = System.getProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY);
if (StringUtils.isBlank(caseFold) || caseFold.equals(DistinguishedName.KEY_CASE_FOLD_LOWER)) {
this.key = StringUtils.lowerCase(key);
if (!StringUtils.hasText(caseFold) || caseFold.equals(DistinguishedName.KEY_CASE_FOLD_LOWER)) {
this.key = key.toLowerCase();
} else if (caseFold.equals(DistinguishedName.KEY_CASE_FOLD_UPPER)) {
this.key = StringUtils.upperCase(key);
this.key = key.toUpperCase();
} else if (caseFold.equals(DistinguishedName.KEY_CASE_FOLD_NONE)) {
this.key = key;
} else {
@@ -84,7 +84,7 @@ public class LdapRdnComponent implements Comparable, Serializable {
+ "; expected \"" + DistinguishedName.KEY_CASE_FOLD_LOWER + "\", \""
+ DistinguishedName.KEY_CASE_FOLD_UPPER + "\", or \""
+ DistinguishedName.KEY_CASE_FOLD_NONE + "\"");
this.key = StringUtils.lowerCase(key);
this.key = key.toLowerCase();
}
if (decodeValue) {
this.value = LdapEncoder.nameDecode(value);
@@ -201,8 +201,10 @@ public class LdapRdnComponent implements Comparable, Serializable {
// instances to equal mutable ones.
if (obj != null && obj instanceof LdapRdnComponent) {
LdapRdnComponent that = (LdapRdnComponent) obj;
return StringUtils.equalsIgnoreCase(this.key, that.key)
&& StringUtils.equalsIgnoreCase(this.value, that.value);
// It's safe to compare directly against key and value,
// because they are validated not to be null on instance creation.
return this.key.equalsIgnoreCase(that.key)
&& this.value.equalsIgnoreCase(that.value);
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2012 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,6 @@
*/
package org.springframework.ldap.core;
import org.apache.commons.lang.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -23,6 +22,7 @@ import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.ldap.NamingException;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.util.Assert;
import javax.naming.Binding;
import javax.naming.Name;
@@ -1256,7 +1256,7 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
* @param controls the SearchControls to check.
*/
private void assureReturnObjFlagSet(SearchControls controls) {
Validate.notNull(controls);
Assert.notNull(controls, "controls must not be null");
if (!controls.getReturningObjFlag()) {
log.debug("The returnObjFlag of supplied SearchControls is not set"
+ " but a ContextMapper is used - setting flag to true");

View File

@@ -16,8 +16,7 @@
package org.springframework.ldap.core.support;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -26,6 +25,7 @@ import org.springframework.ldap.core.AuthenticationSource;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.util.ObjectUtils;
import javax.naming.Context;
import javax.naming.NamingException;
@@ -335,7 +335,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
* the class outside of a Spring Context.
*/
public void afterPropertiesSet() throws Exception {
if (ArrayUtils.isEmpty(urls)) {
if (ObjectUtils.isEmpty(urls)) {
throw new IllegalArgumentException("At least one server url must be set");
}
@@ -345,10 +345,10 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
if (authenticationSource == null) {
log.debug("AuthenticationSource not set - " + "using default implementation");
if (StringUtils.isBlank(userDn)) {
if (!StringUtils.hasText(userDn)) {
log.info("Property 'userDn' not set - " + "anonymous context will be used for read-write operations");
}
else if (StringUtils.isBlank(password)) {
else if (!StringUtils.hasText(password)) {
log.info("Property 'password' not set - " + "blank password will be used");
}
authenticationSource = new SimpleAuthenticationSource();
@@ -378,7 +378,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
env.put(Context.OBJECT_FACTORIES, dirObjectFactory.getName());
}
if (!StringUtils.isBlank(referral)) {
if (StringUtils.hasText(referral)) {
env.put(Context.REFERRAL, referral);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,16 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.filter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* Abstract superclass for binary logical operations, that is &quot;AND&quot;
* and &quot;OR&quot; operations.
@@ -74,30 +70,24 @@ public abstract class BinaryLogicalFilter extends AbstractFilter {
*/
protected abstract String getLogicalOperator();
/**
* Compares each filter in turn.
*
* @see org.springframework.ldap.filter.Filter#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj instanceof BinaryLogicalFilter && this.getClass() == obj.getClass()) {
return EqualsBuilder.reflectionEquals(this, obj);
}
else {
return false;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
/**
* Hashes all contained data.
*
* @see org.springframework.ldap.filter.Filter#hashCode()
*/
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
BinaryLogicalFilter that = (BinaryLogicalFilter) o;
/**
if (queryList != null ? !queryList.equals(that.queryList) : that.queryList != null) return false;
return true;
}
@Override
public int hashCode() {
return queryList != null ? queryList.hashCode() : 0;
}
/**
* Add a query to this logical operation.
*
* @param query the query to add.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.filter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.springframework.ldap.core.LdapEncoder;
/**
@@ -81,39 +78,27 @@ public abstract class CompareFilter extends AbstractFilter {
return buff;
}
/**
* Compares key and value before encoding.
*
* @see org.springframework.ldap.filter.Filter#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
CompareFilter f = (CompareFilter) o;
EqualsBuilder builder = new EqualsBuilder();
return builder.append(this.attribute, f.attribute).append(this.value, f.value).isEquals();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
/**
* Calculate the hash code for the attribute and the value.
*
* @see org.springframework.ldap.filter.Filter#hashCode()
*/
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
builder.append(attribute);
builder.append(value);
return builder.toHashCode();
}
CompareFilter that = (CompareFilter) o;
/**
if (attribute != null ? !attribute.equals(that.attribute) : that.attribute != null) return false;
if (value != null ? !value.equals(that.value) : that.value != null) return false;
return true;
}
@Override
public int hashCode() {
int result = attribute != null ? attribute.hashCode() : 0;
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
/**
* Implement this method in subclass to return a String representing the
* operator. The {@link EqualsFilter#getCompareString()} would for example
* return an equals sign, &quot;=&quot;.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
*/
package org.springframework.ldap.filter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.springframework.util.StringUtils;
/**
@@ -73,28 +71,20 @@ public class HardcodedFilter extends AbstractFilter {
return buff;
}
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
HardcodedFilter f = (HardcodedFilter) o;
return new EqualsBuilder().append(this.filter, f.filter).isEquals();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
/*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder().append(filter);
return builder.toHashCode();
}
HardcodedFilter that = (HardcodedFilter) o;
if (filter != null ? !filter.equals(that.filter) : that.filter != null) return false;
return true;
}
@Override
public int hashCode() {
return filter != null ? filter.hashCode() : 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.filter;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.springframework.util.Assert;
/**
* A filter for 'not'. The following code:
@@ -39,15 +37,13 @@ public class NotFilter extends AbstractFilter {
private final Filter filter;
static private final int HASH = "!".hashCode();
/**
* Create a filter that negates the outcome of the given <code>filter</code>.
*
* @param filter The filter that should be negated.
*/
public NotFilter(Filter filter) {
Validate.notNull(filter);
Assert.notNull(filter, "Filter must not be null");
this.filter = filter;
}
@@ -63,27 +59,20 @@ public class NotFilter extends AbstractFilter {
return buff;
}
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
NotFilter f = (NotFilter) o;
return new EqualsBuilder().append(this.filter, f.filter).isEquals();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
/*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return HASH ^ filter.hashCode();
}
NotFilter notFilter = (NotFilter) o;
if (filter != null ? !filter.equals(notFilter.filter) : notFilter.filter != null) return false;
return true;
}
@Override
public int hashCode() {
return filter != null ? filter.hashCode() : 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,10 +15,6 @@
*/
package org.springframework.ldap.filter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.springframework.ldap.filter.AbstractFilter;
/**
* A convenience class that combines {@code NOT} behavior with {@code present}
* behavior to allow the user to check for the non-existence of a attribute. For
@@ -59,28 +55,20 @@ public class NotPresentFilter extends AbstractFilter {
return buff;
}
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
NotPresentFilter f = (NotPresentFilter) o;
return new EqualsBuilder().append(this.attribute, f.attribute).isEquals();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
/*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder().append(attribute);
return builder.toHashCode();
}
NotPresentFilter that = (NotPresentFilter) o;
if (attribute != null ? !attribute.equals(that.attribute) : that.attribute != null) return false;
return true;
}
@Override
public int hashCode() {
return attribute != null ? attribute.hashCode() : 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,6 @@
*/
package org.springframework.ldap.filter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* Filter that allows the user to check for the existence of a attribute. For an
* attribute to be {@code 'present'} it must contain a value. Attributes that do
@@ -58,28 +55,20 @@ public class PresentFilter extends AbstractFilter {
return buff;
}
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
PresentFilter f = (PresentFilter) o;
return new EqualsBuilder().append(this.attribute, f.attribute).isEquals();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
/*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder().append(attribute);
return builder.toHashCode();
}
PresentFilter that = (PresentFilter) o;
if (attribute != null ? !attribute.equals(that.attribute) : that.attribute != null) return false;
return true;
}
@Override
public int hashCode() {
return attribute != null ? attribute.hashCode() : 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.filter;
import org.springframework.util.StringUtils;
import org.springframework.ldap.core.LdapEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.springframework.ldap.core.LdapEncoder;
/**
* This filter automatically converts all whitespace to wildcards (*). The
* following code:
@@ -49,7 +48,7 @@ public class WhitespaceWildcardsFilter extends EqualsFilter {
protected String encodeValue(String value) {
// blank string means just ONE star
if (StringUtils.isBlank(value)) {
if (!StringUtils.hasText(value)) {
return "*";
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,20 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.pool;
import java.util.Hashtable;
import org.apache.commons.pool.KeyedObjectPool;
import org.springframework.ldap.pool.factory.PoolingContextSource;
import org.springframework.util.Assert;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import org.apache.commons.lang.Validate;
import org.apache.commons.pool.KeyedObjectPool;
import org.springframework.ldap.pool.factory.PoolingContextSource;
import java.util.Hashtable;
/**
* Used by {@link PoolingContextSource} to wrap a {@link Context}, delegating most methods
@@ -50,9 +48,9 @@ public class DelegatingContext implements Context {
* @throws IllegalArgumentException if any of the arguments are null
*/
public DelegatingContext(KeyedObjectPool keyedObjectPool, Context delegateContext, DirContextType dirContextType) {
Validate.notNull(keyedObjectPool, "keyedObjectPool may not be null");
Validate.notNull(delegateContext, "delegateContext may not be null");
Validate.notNull(dirContextType, "dirContextType may not be null");
Assert.notNull(keyedObjectPool, "keyedObjectPool may not be null");
Assert.notNull(delegateContext, "delegateContext may not be null");
Assert.notNull(dirContextType, "dirContextType may not be null");
this.keyedObjectPool = keyedObjectPool;
this.delegateContext = delegateContext;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.pool;
import org.apache.commons.pool.KeyedObjectPool;
import org.springframework.ldap.core.DirContextProxy;
import org.springframework.ldap.pool.factory.PoolingContextSource;
import org.springframework.util.Assert;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
@@ -25,11 +29,6 @@ import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import org.apache.commons.lang.Validate;
import org.apache.commons.pool.KeyedObjectPool;
import org.springframework.ldap.core.DirContextProxy;
import org.springframework.ldap.pool.factory.PoolingContextSource;
/**
* Used by {@link PoolingContextSource} to wrap a {@link DirContext}, delegating most methods
@@ -51,7 +50,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
*/
public DelegatingDirContext(KeyedObjectPool keyedObjectPool, DirContext delegateDirContext, DirContextType dirContextType) {
super(keyedObjectPool, delegateDirContext, dirContextType);
Validate.notNull(delegateDirContext, "delegateDirContext may not be null");
Assert.notNull(delegateDirContext, "delegateDirContext may not be null");
this.delegateDirContext = delegateDirContext;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.pool;
import org.apache.commons.pool.KeyedObjectPool;
import org.springframework.ldap.pool.factory.PoolingContextSource;
import org.springframework.util.Assert;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.ldap.Control;
@@ -23,10 +26,6 @@ import javax.naming.ldap.ExtendedRequest;
import javax.naming.ldap.ExtendedResponse;
import javax.naming.ldap.LdapContext;
import org.apache.commons.lang.Validate;
import org.apache.commons.pool.KeyedObjectPool;
import org.springframework.ldap.pool.factory.PoolingContextSource;
/**
* Used by {@link PoolingContextSource} to wrap a {@link LdapContext}, delegating most methods
* to the underlying context. This class extends {@link DelegatingDirContext} which handles returning
@@ -47,7 +46,7 @@ public class DelegatingLdapContext extends DelegatingDirContext implements LdapC
*/
public DelegatingLdapContext(KeyedObjectPool keyedObjectPool, LdapContext delegateLdapContext, DirContextType dirContextType) {
super(keyedObjectPool, delegateLdapContext, dirContextType);
Validate.notNull(delegateLdapContext, "delegateLdapContext may not be null");
Assert.notNull(delegateLdapContext, "delegateLdapContext may not be null");
this.delegateLdapContext = delegateLdapContext;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,18 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.pool.factory;
import javax.naming.directory.DirContext;
import org.apache.commons.lang.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.pool.BaseKeyedPoolableObjectFactory;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.pool.DirContextType;
import org.springframework.ldap.pool.validation.DirContextValidator;
import org.springframework.util.Assert;
import javax.naming.directory.DirContext;
/**
* Factory that creates {@link DirContext} instances for pooling via a
@@ -114,8 +113,8 @@ class DirContextPoolableObjectFactory extends BaseKeyedPoolableObjectFactory {
* @see org.apache.commons.pool.BaseKeyedPoolableObjectFactory#makeObject(java.lang.Object)
*/
public Object makeObject(Object key) throws Exception {
Validate.notNull(this.contextSource, "ContextSource may not be null");
Validate.isTrue(key instanceof DirContextType,
Assert.notNull(this.contextSource, "ContextSource may not be null");
Assert.isTrue(key instanceof DirContextType,
"key must be a DirContextType");
final DirContextType contextType = (DirContextType) key;
@@ -155,11 +154,11 @@ class DirContextPoolableObjectFactory extends BaseKeyedPoolableObjectFactory {
* java.lang.Object)
*/
public boolean validateObject(Object key, Object obj) {
Validate.notNull(this.dirContextValidator,
Assert.notNull(this.dirContextValidator,
"DirContextValidator may not be null");
Validate.isTrue(key instanceof DirContextType,
Assert.isTrue(key instanceof DirContextType,
"key must be a DirContextType");
Validate.isTrue(obj instanceof DirContext,
Assert.isTrue(obj instanceof DirContext,
"The Object to validate must be of type '" + DirContext.class
+ "'");
@@ -181,7 +180,7 @@ class DirContextPoolableObjectFactory extends BaseKeyedPoolableObjectFactory {
* java.lang.Object)
*/
public void destroyObject(Object key, Object obj) throws Exception {
Validate.isTrue(obj instanceof DirContext,
Assert.isTrue(obj instanceof DirContext,
"The Object to validate must be of type '" + DirContext.class
+ "'");

View File

@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.pool.validation;
import org.apache.commons.lang.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.pool.DirContextType;
import org.springframework.util.Assert;
import javax.naming.NamingEnumeration;
import javax.naming.directory.DirContext;
@@ -159,8 +158,8 @@ public class DefaultDirContextValidator implements DirContextValidator {
* @see DirContextValidator#validateDirContext(DirContextType, javax.naming.directory.DirContext)
*/
public boolean validateDirContext(DirContextType contextType, DirContext dirContext) {
Validate.notNull(contextType, "contextType may not be null");
Validate.notNull(dirContext, "dirContext may not be null");
Assert.notNull(contextType, "contextType may not be null");
Assert.notNull(dirContext, "dirContext may not be null");
try {
final NamingEnumeration searchResults = dirContext.search(this.base, this.filter, this.searchControls);

View File

@@ -16,21 +16,20 @@
package org.springframework.ldap.support;
import java.math.BigInteger;
import java.util.Collection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.NamingException;
import org.springframework.ldap.NoSuchAttributeException;
import org.springframework.util.Assert;
import javax.naming.CompositeName;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.NamingException;
import org.springframework.ldap.NoSuchAttributeException;
import org.springframework.util.Assert;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
/**
* Generic utility methods for working with LDAP. Mainly for internal use within
@@ -410,16 +409,23 @@ public final class LdapUtils {
String[] parts = string.split("-");
byte sidRevision = (byte) Integer.parseInt(parts[1]);
int subAuthCount = parts.length - 3;
byte[] sid = new byte[] {sidRevision, (byte) subAuthCount};
sid = ArrayUtils.addAll(sid, numberToBytes(parts[2], 6, true));
byte[] sid = new byte[] {sidRevision, (byte) subAuthCount};
sid = addAll(sid, numberToBytes(parts[2], 6, true));
for (int i = 0; i < subAuthCount; i++) {
sid = ArrayUtils.addAll(sid, numberToBytes(parts[3 + i], 4, false));
sid = addAll(sid, numberToBytes(parts[3 + i], 4, false));
}
return sid;
}
/**
private static byte[] addAll(byte[] array1, byte[] array2) {
byte[] joinedArray = new byte[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* Converts the given number to a binary representation of the specified
* length and "endian-ness".
*
@@ -434,18 +440,31 @@ public final class LdapUtils {
byte[] bytes = bi.toByteArray();
int remaining = length - bytes.length;
if (remaining < 0) {
bytes = ArrayUtils.subarray(bytes, -remaining, bytes.length);
bytes = Arrays.copyOfRange(bytes, -remaining, bytes.length);
} else {
byte[] fill = new byte[remaining];
bytes = ArrayUtils.addAll(fill, bytes);
bytes = addAll(fill, bytes);
}
if (!bigEndian) {
ArrayUtils.reverse(bytes);
reverse(bytes);
}
return bytes;
}
/**
private static void reverse(byte[] array) {
int i = 0;
int j = array.length - 1;
byte tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
/**
* Converts a byte into its hexadecimal representation, padding with a
* leading zero to get an even number of characters.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package org.springframework.ldap.transaction.compensating;
import javax.naming.directory.DirContext;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.core.LdapOperations;
@@ -26,6 +23,9 @@ import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.SingleContextSource;
import org.springframework.transaction.compensating.CompensatingTransactionOperationFactory;
import org.springframework.transaction.compensating.CompensatingTransactionOperationRecorder;
import org.springframework.util.ObjectUtils;
import javax.naming.directory.DirContext;
/**
* {@link CompensatingTransactionOperationRecorder} implementation for LDAP
@@ -55,22 +55,22 @@ public class LdapCompensatingTransactionOperationFactory implements Compensating
* #createRecordingOperation(java.lang.Object, java.lang.String)
*/
public CompensatingTransactionOperationRecorder createRecordingOperation(Object resource, String operation) {
if (StringUtils.equals(operation, LdapTransactionUtils.BIND_METHOD_NAME)) {
if (ObjectUtils.nullSafeEquals(operation, LdapTransactionUtils.BIND_METHOD_NAME)) {
log.debug("Bind operation recorded");
return new BindOperationRecorder(createLdapOperationsInstance((DirContext) resource));
}
else if (StringUtils.equals(operation, LdapTransactionUtils.REBIND_METHOD_NAME)) {
else if (ObjectUtils.nullSafeEquals(operation, LdapTransactionUtils.REBIND_METHOD_NAME)) {
log.debug("Rebind operation recorded");
return new RebindOperationRecorder(createLdapOperationsInstance((DirContext) resource), renamingStrategy);
}
else if (StringUtils.equals(operation, LdapTransactionUtils.RENAME_METHOD_NAME)) {
else if (ObjectUtils.nullSafeEquals(operation, LdapTransactionUtils.RENAME_METHOD_NAME)) {
log.debug("Rename operation recorded");
return new RenameOperationRecorder(createLdapOperationsInstance((DirContext) resource));
}
else if (StringUtils.equals(operation, LdapTransactionUtils.MODIFY_ATTRIBUTES_METHOD_NAME)) {
else if (ObjectUtils.nullSafeEquals(operation, LdapTransactionUtils.MODIFY_ATTRIBUTES_METHOD_NAME)) {
return new ModifyAttributesOperationRecorder(createLdapOperationsInstance((DirContext) resource));
}
else if (StringUtils.equals(operation, LdapTransactionUtils.UNBIND_METHOD_NAME)) {
else if (ObjectUtils.nullSafeEquals(operation, LdapTransactionUtils.UNBIND_METHOD_NAME)) {
return new UnbindOperationRecorder(createLdapOperationsInstance((DirContext) resource), renamingStrategy);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.transaction.compensating;
import javax.naming.Name;
import org.apache.commons.lang.StringUtils;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import javax.naming.Name;
/**
* Utility methods for working with LDAP transactions.
@@ -91,12 +90,11 @@ public final class LdapTransactionUtils {
* <code>false</code> otherwise.
*/
public static boolean isSupportedWriteTransactionOperation(String methodName) {
return (StringUtils.equals(methodName, BIND_METHOD_NAME)
|| StringUtils.equals(methodName, REBIND_METHOD_NAME)
|| StringUtils.equals(methodName, RENAME_METHOD_NAME)
|| StringUtils
.equals(methodName, MODIFY_ATTRIBUTES_METHOD_NAME) || StringUtils
.equals(methodName, UNBIND_METHOD_NAME));
return (ObjectUtils.nullSafeEquals(methodName, BIND_METHOD_NAME)
|| ObjectUtils.nullSafeEquals(methodName, REBIND_METHOD_NAME)
|| ObjectUtils.nullSafeEquals(methodName, RENAME_METHOD_NAME)
|| ObjectUtils.nullSafeEquals(methodName, MODIFY_ATTRIBUTES_METHOD_NAME)
|| ObjectUtils.nullSafeEquals(methodName, UNBIND_METHOD_NAME));
}
}

View File

@@ -1,15 +1,15 @@
apply plugin: 'java'
apply plugin: 'propdeps'
sourceCompatibility = '1.5'
targetCompatibility = '1.5'
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
ext.springVersion = '3.0.6.RELEASE'
ext.springBatchVersion = '2.0.3.RELEASE'
ext.springVersion = '3.2.4.RELEASE'
ext.springBatchVersion = '2.0.4.RELEASE'
ext.junitVersion = '4.10'
ext.commonsPoolVersion = '1.5.4'
ext.commonsLangVersion = '2.4'
ext.commonsLoggingVersion = '1.0.4'
ext.commonsLoggingVersion = '1.1.1'
ext.gsbaseVersion = '2.0.1'
ext.log4jVersion = '1.2.15'
ext.mockitoVersion = '1.9.5'

View File

@@ -1,10 +1,20 @@
dependencies {
compile project(':spring-ldap-ldif-core'),
"org.springframework.batch:spring-batch-core:$springBatchVersion",
"org.springframework.batch:spring-batch-infrastructure:$springBatchVersion"
"commons-lang:commons-lang:$commonsLangVersion"
compile("org.springframework.batch:spring-batch-infrastructure:$springBatchVersion") {
exclude group: "org.springframework", module: "spring-core"
exclude group: "org.springframework", module: "spring-context"
exclude group: "org.springframework", module: "spring-aop"
}
testCompile "junit:junit:$junitVersion",
"org.springframework.batch:spring-batch-test:$springBatchVersion"
"org.springframework:spring-context:$springVersion",
"org.springframework:spring-aop:$springVersion",
"org.springframework:spring-test:$springVersion",
testCompile("org.springframework.batch:spring-batch-test:$springBatchVersion") {
exclude group: "org.springframework", module: "spring-test"
}
}

View File

@@ -1,9 +1,6 @@
dependencies {
compile project(":spring-ldap-core"),
"commons-lang:commons-lang:$commonsLangVersion",
"org.springframework.batch:spring-batch-core:$springBatchVersion",
"org.springframework.batch:spring-batch-infrastructure:$springBatchVersion"
compile project(":spring-ldap-core")
testCompile "junit:junit:$junitVersion",
"commons-io:commons-io:2.4"

View File

@@ -16,7 +16,6 @@
package org.springframework.ldap.ldif.parser;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -32,6 +31,7 @@ import org.springframework.ldap.ldif.support.SeparatorPolicy;
import org.springframework.ldap.schema.DefaultSchemaSpecification;
import org.springframework.ldap.schema.Specification;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
@@ -324,7 +324,7 @@ public class LdifParser implements Parser, InitializingBean {
private void addAttributeToRecord(String buffer, LdapAttributes record) {
try {
if (StringUtils.isNotEmpty(buffer) && record != null) {
if (StringUtils.hasLength(buffer) && record != null) {
//Validate previous attribute and add to record.
Attribute attribute = attributePolicy.parse(buffer);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,14 @@
*/
package org.springframework.ldap.ldif.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.core.LdapAttribute;
import org.springframework.ldap.ldif.InvalidAttributeFormatException;
import org.springframework.util.StringUtils;
import sun.misc.BASE64Decoder;
import javax.naming.directory.Attribute;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -23,16 +31,6 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.naming.directory.Attribute;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.core.LdapAttribute;
import org.springframework.ldap.ldif.InvalidAttributeFormatException;
import sun.misc.BASE64Decoder;
/**
* Ensures the buffer represents a valid attribute as defined by RFC2849.
*
@@ -322,7 +320,7 @@ public class DefaultAttributeValidationPolicy implements AttributeValidationPoli
private LdapAttribute parseStringAttribute(Matcher matcher) {
String id = matcher.group(1);
String value = matcher.group(3);
List<String> options = Arrays.asList((StringUtils.isEmpty(matcher.group(2)) ? new String[] {} : matcher.group(2).replaceFirst(";","").split(OPTION_SEPARATOR)));
List<String> options = Arrays.asList((!StringUtils.hasLength(matcher.group(2)) ? new String[] {} : matcher.group(2).replaceFirst(";","").split(OPTION_SEPARATOR)));
if (options.isEmpty()) {
return new LdapAttribute(id, value, ordered);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,9 @@
*/
package org.springframework.ldap.ldif.support;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.StringUtils;
/**
* Policy object for enforcing LDIF record separation rules. Designed explicitly
@@ -70,7 +70,7 @@ public class SeparatorPolicy {
log.trace("Assessing --> [" + line + "]");
if (record) {
if (StringUtils.isEmpty(line)) {
if (!StringUtils.hasLength(line)) {
record = false;
skip = false;
return LineIdentifier.EndOfRecord;
@@ -99,11 +99,11 @@ public class SeparatorPolicy {
}
}
} else {
if (StringUtils.isNotEmpty(line) && line.matches(VERSION_IDENTIFIER) && !skip) {
if (StringUtils.hasLength(line) && line.matches(VERSION_IDENTIFIER) && !skip) {
//Version Identifiers are ignored by parser.
return LineIdentifier.VersionIdentifier;
} else if (StringUtils.isNotEmpty(line) && line.matches(NewRecord)) {
} else if (StringUtils.hasLength(line) && line.matches(NewRecord)) {
record = true;
skip = false;
return LineIdentifier.NewRecord;

View File

@@ -16,7 +16,6 @@
package org.springframework.ldap.ldif;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
@@ -25,6 +24,7 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.ldap.core.LdapAttribute;
import org.springframework.ldap.ldif.support.DefaultAttributeValidationPolicy;
import org.springframework.util.StringUtils;
import sun.misc.BASE64Decoder;
import java.net.URI;
@@ -138,7 +138,7 @@ public class DefaultAttributeValidationPolicyTest {
assertTrue("IDs do not match: [expected: " + attribute.getID() + ", obtained: " + id + "]", id.equalsIgnoreCase(attribute.getID()));
String[] expected = StringUtils.isEmpty(options) ? new String[] {} : options.replaceFirst(";","").split(";");
String[] expected = !StringUtils.hasLength(options) ? new String[] {} : options.replaceFirst(";","").split(";");
Arrays.sort(expected);
String[] obtained = attribute.getOptions().toArray(new String[] {});
Arrays.sort(obtained);
@@ -147,7 +147,7 @@ public class DefaultAttributeValidationPolicyTest {
switch(type) {
case STRING:
assertTrue("Value is not a string.", attribute.get() instanceof String);
assertEquals("Values do not match: ", value, (String) attribute.get());
assertEquals("Values do not match: ", value, attribute.get());
break;
case BASE64:
@@ -159,7 +159,7 @@ public class DefaultAttributeValidationPolicyTest {
case URL:
URI url = new URI(value);
assertTrue("Value is not a URL.", attribute.get() instanceof URI);
assertEquals("Values do not match: ", url, (URI) attribute.get());
assertEquals("Values do not match: ", url, attribute.get());
break;
}

View File

@@ -8,14 +8,14 @@ dependencies {
"org.springframework:spring-core:$springVersion",
"org.freemarker:freemarker:2.3.9",
"commons-logging:commons-logging:$commonsLoggingVersion",
"commons-lang:commons-lang:$commonsLangVersion",
"commons-cli:commons-cli:1.2"
runtime "org.springframework:spring-context:$springVersion"
provided "commons-pool:commons-pool:$commonsPoolVersion",
"com.sun:ldapbp:1.0",
"org.springframework:spring-context:$springVersion",
"commons-lang:commons-lang:$commonsLangVersion",
"org.springframework:spring-context:$springVersion",
"org.springframework:spring-jdbc:$springVersion",
"org.springframework:spring-orm:$springVersion"

View File

@@ -16,7 +16,7 @@
package org.springframework.ldap.odm.tools;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.StringUtils;
/**
* Simple value class to hold the schema of an attribute.