LDAP-258: General Java 5/6 cleanup throughout the code base.
This commit is contained in:
@@ -86,9 +86,9 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
|
||||
private static final boolean CRITICAL_CONTROL = true;
|
||||
|
||||
protected Class responseControlClass;
|
||||
protected Class<?> responseControlClass;
|
||||
|
||||
protected Class requestControlClass;
|
||||
protected Class<?> requestControlClass;
|
||||
|
||||
protected boolean critical = CRITICAL_CONTROL;
|
||||
|
||||
@@ -129,11 +129,11 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
*
|
||||
* @param responseControlClass Class of the expected response control.
|
||||
*/
|
||||
public void setResponseControlClass(Class responseControlClass) {
|
||||
public void setResponseControlClass(Class<?> responseControlClass) {
|
||||
this.responseControlClass = responseControlClass;
|
||||
}
|
||||
|
||||
public void setRequestControlClass(Class requestControlClass) {
|
||||
public void setRequestControlClass(Class<?> requestControlClass) {
|
||||
this.requestControlClass = requestControlClass;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
* @param control Instance that the method should be invoked on
|
||||
* @return the invocation result, if any
|
||||
*/
|
||||
protected Object invokeMethod(String method, Class clazz, Object control) {
|
||||
protected Object invokeMethod(String method, Class<?> clazz, Object control) {
|
||||
Method actualMethod = ReflectionUtils.findMethod(clazz, method);
|
||||
return ReflectionUtils.invokeMethod(actualMethod, control);
|
||||
}
|
||||
@@ -156,8 +156,8 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
* @param params Actual constructor parameters
|
||||
* @return Control to be used by the DirContextProcessor
|
||||
*/
|
||||
public Control createRequestControl(Class[] paramTypes, Object[] params) {
|
||||
Constructor constructor = ClassUtils.getConstructorIfAvailable(requestControlClass, paramTypes);
|
||||
public Control createRequestControl(Class<?>[] paramTypes, Object[] params) {
|
||||
Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(requestControlClass, paramTypes);
|
||||
if (constructor == null) {
|
||||
throw new IllegalArgumentException("Failed to find an appropriate RequestControl constructor");
|
||||
}
|
||||
@@ -187,16 +187,13 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
}
|
||||
|
||||
// Go through response controls and get info, regardless of class
|
||||
for (int i = 0; i < responseControls.length; i++) {
|
||||
Control responseControl = responseControls[i];
|
||||
|
||||
// check for match, try fallback otherwise
|
||||
if (responseControl.getClass().isAssignableFrom(responseControlClass)) {
|
||||
Object control = responseControl;
|
||||
handleResponse(control);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (Control responseControl : responseControls) {
|
||||
// check for match, try fallback otherwise
|
||||
if (responseControl.getClass().isAssignableFrom(responseControlClass)) {
|
||||
handleResponse(responseControl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("No matching response control found - looking for '" + responseControlClass);
|
||||
}
|
||||
|
||||
@@ -23,10 +23,11 @@ import java.util.List;
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
* @deprecated
|
||||
*/
|
||||
public class PagedResult {
|
||||
|
||||
private List resultList;
|
||||
private List<?> resultList;
|
||||
|
||||
private PagedResultsCookie cookie;
|
||||
|
||||
@@ -39,7 +40,7 @@ public class PagedResult {
|
||||
* @param cookie
|
||||
* the cookie.
|
||||
*/
|
||||
public PagedResult(List resultList, PagedResultsCookie cookie) {
|
||||
public PagedResult(List<?> resultList, PagedResultsCookie cookie) {
|
||||
this.resultList = resultList;
|
||||
this.cookie = cookie;
|
||||
}
|
||||
@@ -58,7 +59,7 @@ public class PagedResult {
|
||||
*
|
||||
* @return the result list.
|
||||
*/
|
||||
public List getResultList() {
|
||||
public List<?> getResultList() {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -118,8 +118,8 @@ public class PagedResultsDirContextProcessor extends AbstractFallbackRequestAndR
|
||||
if (cookie != null) {
|
||||
actualCookie = cookie.getCookie();
|
||||
}
|
||||
return super.createRequestControl(new Class[] { int.class, byte[].class, boolean.class },
|
||||
new Object[] {new Integer(pageSize), actualCookie, Boolean.valueOf(critical)});
|
||||
return super.createRequestControl(new Class<?>[] { int.class, byte[].class, boolean.class },
|
||||
new Object[] {pageSize, actualCookie, critical});
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -130,7 +130,6 @@ public class PagedResultsDirContextProcessor extends AbstractFallbackRequestAndR
|
||||
protected void handleResponse(Object control) {
|
||||
byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control);
|
||||
this.cookie = new PagedResultsCookie(result);
|
||||
Integer wrapper = (Integer) invokeMethod("getResultSize", responseControlClass, control);
|
||||
this.resultSize = wrapper.intValue();
|
||||
this.resultSize = (Integer) invokeMethod("getResultSize", responseControlClass, control);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -104,7 +104,7 @@ public class SortControlDirContextProcessor extends AbstractFallbackRequestAndRe
|
||||
*/
|
||||
public Control createRequestControl() {
|
||||
return super.createRequestControl(new Class[] { String[].class, boolean.class }, new Object[] {
|
||||
new String[] { sortKey }, Boolean.valueOf(critical) });
|
||||
new String[] { sortKey }, critical});
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -113,9 +113,7 @@ public class SortControlDirContextProcessor extends AbstractFallbackRequestAndRe
|
||||
* #handleResponse(java.lang.Object)
|
||||
*/
|
||||
protected void handleResponse(Object control) {
|
||||
Boolean result = (Boolean) invokeMethod("isSorted", responseControlClass, control);
|
||||
this.sorted = result.booleanValue();
|
||||
Integer code = (Integer) invokeMethod("getResultCode", responseControlClass, control);
|
||||
this.resultCode = code.intValue();
|
||||
this.sorted = (Boolean) invokeMethod("isSorted", responseControlClass, control);
|
||||
this.resultCode = (Integer) invokeMethod("getResultCode", responseControlClass, control);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,11 @@ import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
@@ -36,6 +38,7 @@ import javax.naming.directory.BasicAttributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.ModificationItem;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
@@ -223,9 +226,9 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
*/
|
||||
public String[] getNamesOfModifiedAttributes() {
|
||||
|
||||
List tmpList = new ArrayList();
|
||||
List<String> tmpList = new ArrayList<String>();
|
||||
|
||||
NamingEnumeration attributesEnumeration;
|
||||
NamingEnumeration<? extends Attribute> attributesEnumeration;
|
||||
if (isUpdateMode()) {
|
||||
attributesEnumeration = updatedAttrs.getAll();
|
||||
}
|
||||
@@ -235,7 +238,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
|
||||
try {
|
||||
while (attributesEnumeration.hasMore()) {
|
||||
Attribute oneAttribute = (Attribute) attributesEnumeration
|
||||
Attribute oneAttribute = attributesEnumeration
|
||||
.next();
|
||||
tmpList.add(oneAttribute.getID());
|
||||
}
|
||||
@@ -247,10 +250,10 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
closeNamingEnumeration(attributesEnumeration);
|
||||
}
|
||||
|
||||
return (String[]) tmpList.toArray(new String[0]);
|
||||
return tmpList.toArray(new String[tmpList.size()]);
|
||||
}
|
||||
|
||||
private void closeNamingEnumeration(NamingEnumeration enumeration) {
|
||||
private void closeNamingEnumeration(NamingEnumeration<?> enumeration) {
|
||||
try {
|
||||
if (enumeration != null) {
|
||||
enumeration.close();
|
||||
@@ -270,14 +273,14 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
return new ModificationItem[0];
|
||||
}
|
||||
|
||||
List tmpList = new LinkedList();
|
||||
NamingEnumeration attributesEnumeration = null;
|
||||
List<ModificationItem> tmpList = new LinkedList<ModificationItem>();
|
||||
NamingEnumeration<? extends Attribute> attributesEnumeration = null;
|
||||
try {
|
||||
attributesEnumeration = updatedAttrs.getAll();
|
||||
|
||||
// find attributes that have been changed, removed or added
|
||||
while (attributesEnumeration.hasMore()) {
|
||||
Attribute oneAttr = (Attribute) attributesEnumeration.next();
|
||||
Attribute oneAttr = attributesEnumeration.next();
|
||||
|
||||
collectModifications(oneAttr, tmpList);
|
||||
}
|
||||
@@ -293,8 +296,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
log.debug("Number of modifications:" + tmpList.size());
|
||||
}
|
||||
|
||||
return (ModificationItem[]) tmpList
|
||||
.toArray(new ModificationItem[tmpList.size()]);
|
||||
return tmpList.toArray(new ModificationItem[tmpList.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +314,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @throws NamingException if thrown by called Attribute methods.
|
||||
*/
|
||||
private void collectModifications(Attribute changedAttr,
|
||||
List modificationList) throws NamingException {
|
||||
List<ModificationItem> modificationList) throws NamingException {
|
||||
Attribute currentAttribute = originalAttrs.get(changedAttr.getID());
|
||||
|
||||
if (changedAttr.equals(currentAttribute)) {
|
||||
@@ -346,7 +348,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
else if (changedAttr.size() > 0) {
|
||||
// Change of multivalue Attribute. Collect additions and removals
|
||||
// individually.
|
||||
List myModifications = new LinkedList();
|
||||
List<ModificationItem> myModifications = new LinkedList<ModificationItem>();
|
||||
collectModifications(currentAttribute, changedAttr, myModifications);
|
||||
|
||||
if (myModifications.isEmpty()) {
|
||||
@@ -362,7 +364,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
}
|
||||
|
||||
private void collectModifications(Attribute originalAttr,
|
||||
Attribute changedAttr, List modificationList)
|
||||
Attribute changedAttr, List<ModificationItem> modificationList)
|
||||
throws NamingException {
|
||||
|
||||
Attribute originalClone = (Attribute) originalAttr.clone();
|
||||
@@ -443,11 +445,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
// removed)
|
||||
// TODO Also include prev in null check
|
||||
// TODO Also check if there is a single null element
|
||||
if (orig != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return orig != null;
|
||||
}
|
||||
|
||||
// NOT setting to empty -------------------
|
||||
|
||||
@@ -585,11 +584,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
*/
|
||||
public boolean attributeExists(String name) {
|
||||
Attribute oneAttr = originalAttrs.get(name);
|
||||
if (oneAttr == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return oneAttr != null;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -729,14 +724,14 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @see org.springframework.ldap.support.DirContextOperations#update()
|
||||
*/
|
||||
public void update() {
|
||||
NamingEnumeration attributesEnumeration = null;
|
||||
NamingEnumeration<? extends Attribute> attributesEnumeration = null;
|
||||
|
||||
try {
|
||||
attributesEnumeration = updatedAttrs.getAll();
|
||||
|
||||
// find what to update
|
||||
while (attributesEnumeration.hasMore()) {
|
||||
Attribute a = (Attribute) attributesEnumeration.next();
|
||||
Attribute a = attributesEnumeration.next();
|
||||
|
||||
// if it does not exist it should be added
|
||||
if (isEmptyAttribute(a)) {
|
||||
@@ -766,8 +761,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
*/
|
||||
public String[] getStringAttributes(String name) {
|
||||
try {
|
||||
return (String[]) collectAttributeValuesAsList(name).toArray(
|
||||
new String[0]);
|
||||
List<String> objects = collectAttributeValuesAsList(name, String.class);
|
||||
return objects.toArray(new String[objects.size()]);
|
||||
}
|
||||
catch (NoSuchAttributeException e) {
|
||||
// The attribute does not exist - contract says to return null.
|
||||
@@ -784,7 +779,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
*/
|
||||
public Object[] getObjectAttributes(String name) {
|
||||
try {
|
||||
return collectAttributeValuesAsList(name).toArray(new Object[0]);
|
||||
List<Object> list = collectAttributeValuesAsList(name, Object.class);
|
||||
return list.toArray(new Object[list.size()]);
|
||||
}
|
||||
catch (NoSuchAttributeException e) {
|
||||
// The attribute does not exist - contract says to return null.
|
||||
@@ -792,20 +788,17 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
}
|
||||
}
|
||||
|
||||
private List collectAttributeValuesAsList(String name) {
|
||||
List list = new LinkedList();
|
||||
LdapUtils.collectAttributeValues(originalAttrs, name, list);
|
||||
private <T> List<T> collectAttributeValuesAsList(String name, Class<T> clazz) {
|
||||
List<T> list = new LinkedList<T>();
|
||||
LdapUtils.collectAttributeValues(originalAttrs, name, list, clazz);
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* @seeorg.springframework.ldap.support.DirContextOperations#
|
||||
* getAttributeSortedStringSet(java.lang.String)
|
||||
*/
|
||||
public SortedSet getAttributeSortedStringSet(String name) {
|
||||
@Override
|
||||
public SortedSet<String> getAttributeSortedStringSet(String name) {
|
||||
try {
|
||||
TreeSet attrSet = new TreeSet();
|
||||
LdapUtils.collectAttributeValues(originalAttrs, name, attrSet);
|
||||
TreeSet<String> attrSet = new TreeSet<String>();
|
||||
LdapUtils.collectAttributeValues(originalAttrs, name, attrSet, String.class);
|
||||
return attrSet;
|
||||
}
|
||||
catch (NoSuchAttributeException e) {
|
||||
@@ -873,12 +866,12 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
|
||||
Attributes a = new BasicAttributes(true);
|
||||
Attribute target;
|
||||
for (int i = 0; i < attrIds.length; i++) {
|
||||
target = originalAttrs.get(attrIds[i]);
|
||||
if (target != null) {
|
||||
a.put(target);
|
||||
}
|
||||
}
|
||||
for (String attrId : attrIds) {
|
||||
target = originalAttrs.get(attrId);
|
||||
if (target != null) {
|
||||
a.put(target);
|
||||
}
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
@@ -1001,7 +994,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(Name, Attributes, String[])
|
||||
*/
|
||||
public NamingEnumeration search(Name name, Attributes matchingAttributes,
|
||||
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes,
|
||||
String[] attributesToReturn) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1010,7 +1003,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @see javax.naming.directory.DirContext#search(String, Attributes,
|
||||
* String[])
|
||||
*/
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes,
|
||||
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes,
|
||||
String[] attributesToReturn) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1018,7 +1011,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(Name, Attributes)
|
||||
*/
|
||||
public NamingEnumeration search(Name name, Attributes matchingAttributes)
|
||||
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes)
|
||||
throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1026,7 +1019,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(String, Attributes)
|
||||
*/
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes)
|
||||
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes)
|
||||
throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1035,7 +1028,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @see javax.naming.directory.DirContext#search(Name, String,
|
||||
* SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(Name name, String filter,
|
||||
public NamingEnumeration<SearchResult> search(Name name, String filter,
|
||||
SearchControls cons) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1044,7 +1037,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @see javax.naming.directory.DirContext#search(String, String,
|
||||
* SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(String name, String filter,
|
||||
public NamingEnumeration<SearchResult> search(String name, String filter,
|
||||
SearchControls cons) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1053,7 +1046,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @see javax.naming.directory.DirContext#search(Name, String, Object[],
|
||||
* SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(Name name, String filterExpr,
|
||||
public NamingEnumeration<SearchResult> search(Name name, String filterExpr,
|
||||
Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1062,7 +1055,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @see javax.naming.directory.DirContext#search(String, String, Object[],
|
||||
* SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(String name, String filterExpr,
|
||||
public NamingEnumeration<SearchResult> search(String name, String filterExpr,
|
||||
Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
@@ -1140,28 +1133,28 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
/**
|
||||
* @see javax.naming.Context#list(Name)
|
||||
*/
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.naming.Context#list(String)
|
||||
*/
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.naming.Context#listBindings(Name)
|
||||
*/
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.naming.Context#listBindings(String)
|
||||
*/
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
|
||||
@@ -1254,7 +1247,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
/**
|
||||
* @see javax.naming.Context#getEnvironment()
|
||||
*/
|
||||
public Hashtable getEnvironment() throws NamingException {
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
throw new UnsupportedOperationException("Not implemented.");
|
||||
}
|
||||
|
||||
@@ -1342,46 +1335,46 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(getClass().getName());
|
||||
buf.append(":");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(getClass().getName());
|
||||
builder.append(":");
|
||||
if (dn != null) {
|
||||
buf.append(" dn=" + dn);
|
||||
builder.append(" dn=").append(dn);
|
||||
}
|
||||
buf.append(" {");
|
||||
builder.append(" {");
|
||||
|
||||
try {
|
||||
for (NamingEnumeration i = originalAttrs.getAll(); i.hasMore();) {
|
||||
Attribute attribute = (Attribute) i.next();
|
||||
for (NamingEnumeration<? extends Attribute> i = originalAttrs.getAll(); i.hasMore();) {
|
||||
Attribute attribute = i.next();
|
||||
if (attribute.size() == 1) {
|
||||
buf.append(attribute.getID());
|
||||
buf.append('=');
|
||||
buf.append(attribute.get());
|
||||
builder.append(attribute.getID());
|
||||
builder.append('=');
|
||||
builder.append(attribute.get());
|
||||
}
|
||||
else {
|
||||
for (int j = 0; j < attribute.size(); j++) {
|
||||
if (j > 0) {
|
||||
buf.append(", ");
|
||||
builder.append(", ");
|
||||
}
|
||||
buf.append(attribute.getID());
|
||||
buf.append('[');
|
||||
buf.append(j);
|
||||
buf.append("]=");
|
||||
buf.append(attribute.get(j));
|
||||
builder.append(attribute.getID());
|
||||
builder.append('[');
|
||||
builder.append(j);
|
||||
builder.append("]=");
|
||||
builder.append(attribute.get(j));
|
||||
}
|
||||
}
|
||||
|
||||
if (i.hasMore()) {
|
||||
buf.append(", ");
|
||||
builder.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
log.warn("Error in toString()");
|
||||
}
|
||||
buf.append('}');
|
||||
builder.append('}');
|
||||
|
||||
return buf.toString();
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -182,7 +182,7 @@ public interface DirContextOperations extends DirContext,
|
||||
* @return a (possibly empty) array containing all registered values of the
|
||||
* attribute as Strings if the attribute is defined or <code>null</code>
|
||||
* otherwise.
|
||||
* @throws ArrayStoreException if any of the attribute values is not a
|
||||
* @throws IllegalArgumentException if any of the attribute values is not a
|
||||
* String.
|
||||
*/
|
||||
String[] getStringAttributes(String name);
|
||||
@@ -203,8 +203,9 @@ public interface DirContextOperations extends DirContext,
|
||||
* @param name name of the attribute.
|
||||
* @return a <code>SortedSet</code> containing all values of the attribute,
|
||||
* or <code>null</code> if the attribute does not exist.
|
||||
* @throws IllegalArgumentException if one of the found attribute values cannot be cast to a String.
|
||||
*/
|
||||
SortedSet getAttributeSortedStringSet(String name);
|
||||
SortedSet<String> getAttributeSortedStringSet(String name);
|
||||
|
||||
/**
|
||||
* Returns the DN relative to the base path.
|
||||
|
||||
@@ -94,7 +94,7 @@ public class LdapEncoder {
|
||||
return null;
|
||||
|
||||
// make buffer roomy
|
||||
StringBuffer encodedValue = new StringBuffer(value.length() * 2);
|
||||
StringBuilder encodedValue = new StringBuilder(value.length() * 2);
|
||||
|
||||
int length = value.length();
|
||||
|
||||
@@ -132,7 +132,7 @@ public class LdapEncoder {
|
||||
return null;
|
||||
|
||||
// make buffer roomy
|
||||
StringBuffer encodedValue = new StringBuffer(value.length() * 2);
|
||||
StringBuilder encodedValue = new StringBuilder(value.length() * 2);
|
||||
|
||||
int length = value.length();
|
||||
int last = length - 1;
|
||||
@@ -181,7 +181,7 @@ public class LdapEncoder {
|
||||
return null;
|
||||
|
||||
// make buffer same size
|
||||
StringBuffer decoded = new StringBuffer(value.length());
|
||||
StringBuilder decoded = new StringBuilder(value.length());
|
||||
|
||||
int i = 0;
|
||||
while (i < value.length()) {
|
||||
|
||||
@@ -15,21 +15,22 @@
|
||||
*/
|
||||
package org.springframework.ldap.core;
|
||||
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
|
||||
/**
|
||||
* <code>ContextMapper</code> implementation that maps the found entries to the
|
||||
* {@link LdapEntryIdentification} of each respective entry.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.3
|
||||
*/
|
||||
public class LdapEntryIdentificationContextMapper implements ContextMapper<LdapEntryIdentification> {
|
||||
public class LdapEntryIdentificationContextMapper extends AbstractContextMapper<LdapEntryIdentification> {
|
||||
|
||||
public LdapEntryIdentification mapFromContext(Object ctx) {
|
||||
DirContextOperations adapter = (DirContextOperations) ctx;
|
||||
return new LdapEntryIdentification(
|
||||
LdapUtils.newLdapName(adapter.getNameInNamespace()),
|
||||
LdapUtils.newLdapName(adapter.getDn()));
|
||||
}
|
||||
@Override
|
||||
public LdapEntryIdentification doMapFromContext(DirContextOperations adapter) {
|
||||
return new LdapEntryIdentification(
|
||||
LdapUtils.newLdapName(adapter.getNameInNamespace()),
|
||||
LdapUtils.newLdapName(adapter.getDn()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ public interface LdapOperations {
|
||||
* <code>NameNotFoundException</code> will be ignored. Instead this is
|
||||
* interpreted that no entries were found.
|
||||
*/
|
||||
List search(String base, String filter, SearchControls controls, ContextMapper mapper, DirContextProcessor processor)
|
||||
<T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor)
|
||||
throws NamingException;
|
||||
|
||||
/**
|
||||
@@ -289,7 +289,7 @@ public interface LdapOperations {
|
||||
* <code>NameNotFoundException</code> will be ignored. Instead this is
|
||||
* interpreted that no entries were found.
|
||||
*/
|
||||
List search(Name base, String filter, SearchControls controls, ContextMapper mapper, DirContextProcessor processor)
|
||||
<T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor)
|
||||
throws NamingException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -590,46 +590,24 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
return handler.getList();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.core.LdapOperations#search(java.lang.String,
|
||||
* java.lang.String, javax.naming.directory.SearchControls,
|
||||
* org.springframework.ldap.core.ContextMapper,
|
||||
* org.springframework.ldap.core.DirContextProcessor)
|
||||
*/
|
||||
public List search(String base, String filter, SearchControls controls, ContextMapper mapper,
|
||||
public <T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper,
|
||||
DirContextProcessor processor) {
|
||||
assureReturnObjFlagSet(controls);
|
||||
ContextMapperCallbackHandler handler = new ContextMapperCallbackHandler(mapper);
|
||||
ContextMapperCallbackHandler<T> handler = new ContextMapperCallbackHandler<T>(mapper);
|
||||
search(base, filter, controls, handler, processor);
|
||||
|
||||
return handler.getList();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.core.LdapOperations#search(javax.naming.Name,
|
||||
* java.lang.String, javax.naming.directory.SearchControls,
|
||||
* org.springframework.ldap.core.ContextMapper,
|
||||
* org.springframework.ldap.core.DirContextProcessor)
|
||||
*/
|
||||
public List search(Name base, String filter, SearchControls controls, ContextMapper mapper,
|
||||
public <T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper,
|
||||
DirContextProcessor processor) {
|
||||
assureReturnObjFlagSet(controls);
|
||||
ContextMapperCallbackHandler handler = new ContextMapperCallbackHandler(mapper);
|
||||
ContextMapperCallbackHandler<T> handler = new ContextMapperCallbackHandler<T>(mapper);
|
||||
search(base, filter, controls, handler, processor);
|
||||
|
||||
return handler.getList();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.core.LdapOperations#list(java.lang.String,
|
||||
* org.springframework.ldap.core.NameClassPairCallbackHandler)
|
||||
*/
|
||||
public void list(final String base, NameClassPairCallbackHandler handler) {
|
||||
SearchExecutor searchExecutor = new SearchExecutor() {
|
||||
public NamingEnumeration executeSearch(DirContext ctx) throws javax.naming.NamingException {
|
||||
|
||||
@@ -74,15 +74,16 @@ import java.util.Map;
|
||||
*/
|
||||
public abstract class AbstractContextSource implements BaseLdapPathContextSource, InitializingBean {
|
||||
|
||||
private static final Class DEFAULT_CONTEXT_FACTORY = com.sun.jndi.ldap.LdapCtxFactory.class;
|
||||
private static final Class<com.sun.jndi.ldap.LdapCtxFactory> DEFAULT_CONTEXT_FACTORY
|
||||
= com.sun.jndi.ldap.LdapCtxFactory.class;
|
||||
|
||||
private static final Class DEFAULT_DIR_OBJECT_FACTORY = DefaultDirObjectFactory.class;
|
||||
private static final Class<DefaultDirObjectFactory> DEFAULT_DIR_OBJECT_FACTORY = DefaultDirObjectFactory.class;
|
||||
private static final boolean DONT_DISABLE_POOLING = false;
|
||||
private static final boolean EXPLICITLY_DISABLE_POOLING = true;
|
||||
|
||||
private Class dirObjectFactory = DEFAULT_DIR_OBJECT_FACTORY;
|
||||
private Class<?> dirObjectFactory = DEFAULT_DIR_OBJECT_FACTORY;
|
||||
|
||||
private Class contextFactory = DEFAULT_CONTEXT_FACTORY;
|
||||
private Class<?> contextFactory = DEFAULT_CONTEXT_FACTORY;
|
||||
|
||||
private LdapName base = LdapUtils.emptyLdapName();
|
||||
|
||||
@@ -94,9 +95,9 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
private boolean pooled = false;
|
||||
|
||||
private Hashtable baseEnv = new Hashtable();
|
||||
private Hashtable<String, Object> baseEnv = new Hashtable<String, Object>();
|
||||
|
||||
private Hashtable anonymousEnv;
|
||||
private Hashtable<String, Object> anonymousEnv;
|
||||
|
||||
private AuthenticationSource authenticationSource;
|
||||
|
||||
@@ -121,7 +122,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
}
|
||||
|
||||
private DirContext doGetContext(String principal, String credentials, boolean explicitlyDisablePooling) {
|
||||
Hashtable env = getAuthenticatedEnv(principal, credentials);
|
||||
Hashtable<String, Object> env = getAuthenticatedEnv(principal, credentials);
|
||||
if(explicitlyDisablePooling) {
|
||||
env.remove(SUN_LDAP_POOLING_FLAG);
|
||||
}
|
||||
@@ -179,7 +180,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @see DirContextAuthenticationStrategy
|
||||
* @see #setAuthenticationStrategy(DirContextAuthenticationStrategy)
|
||||
*/
|
||||
protected void setupAuthenticatedEnvironment(Hashtable env, String principal, String credentials) {
|
||||
protected void setupAuthenticatedEnvironment(Hashtable<String, Object> env, String principal, String credentials) {
|
||||
try {
|
||||
authenticationStrategy.setupEnvironment(env, principal, credentials);
|
||||
}
|
||||
@@ -199,6 +200,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.debug("Exception closing context", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,17 +213,17 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @return the full url String
|
||||
*/
|
||||
protected String assembleProviderUrlString(String[] ldapUrls) {
|
||||
StringBuffer providerUrlBuffer = new StringBuffer(1024);
|
||||
for (int i = 0; i < ldapUrls.length; i++) {
|
||||
providerUrlBuffer.append(ldapUrls[i]);
|
||||
if (!base.isEmpty()) {
|
||||
if (!ldapUrls[i].endsWith("/")) {
|
||||
providerUrlBuffer.append("/");
|
||||
}
|
||||
}
|
||||
providerUrlBuffer.append(formatForUrl(base));
|
||||
providerUrlBuffer.append(' ');
|
||||
}
|
||||
StringBuilder providerUrlBuffer = new StringBuilder(1024);
|
||||
for (String ldapUrl : ldapUrls) {
|
||||
providerUrlBuffer.append(ldapUrl);
|
||||
if (!base.isEmpty()) {
|
||||
if (!ldapUrl.endsWith("/")) {
|
||||
providerUrlBuffer.append("/");
|
||||
}
|
||||
}
|
||||
providerUrlBuffer.append(formatForUrl(base));
|
||||
providerUrlBuffer.append(' ');
|
||||
}
|
||||
return providerUrlBuffer.toString().trim();
|
||||
}
|
||||
|
||||
@@ -300,7 +302,6 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @deprecated {@link DistinguishedName} and associated classes and methods are deprecated as of 2.0.
|
||||
*/
|
||||
@Override
|
||||
@@ -313,12 +314,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
return (LdapName) base.clone();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @seeorg.springframework.ldap.core.support.BaseLdapPathSource#
|
||||
* getBaseLdapPathAsString()
|
||||
*/
|
||||
@Override
|
||||
public String getBaseLdapPathAsString() {
|
||||
return getBaseLdapName().toString();
|
||||
}
|
||||
@@ -331,14 +327,14 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @return a new DirContext implementation initialized with the supplied
|
||||
* environment.
|
||||
*/
|
||||
protected DirContext createContext(Hashtable environment) {
|
||||
protected DirContext createContext(Hashtable<String, Object> environment) {
|
||||
DirContext ctx = null;
|
||||
|
||||
try {
|
||||
ctx = getDirContextInstance(environment);
|
||||
|
||||
if (log.isInfoEnabled()) {
|
||||
Hashtable ctxEnv = ctx.getEnvironment();
|
||||
Hashtable<?, ?> ctxEnv = ctx.getEnvironment();
|
||||
String ldapUrl = (String) ctxEnv.get(Context.PROVIDER_URL);
|
||||
log.debug("Got Ldap context on server '" + ldapUrl + "'");
|
||||
}
|
||||
@@ -356,7 +352,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
*
|
||||
* @param contextFactory the context factory used when creating Contexts.
|
||||
*/
|
||||
public void setContextFactory(Class contextFactory) {
|
||||
public void setContextFactory(Class<?> contextFactory) {
|
||||
this.contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
@@ -365,7 +361,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
*
|
||||
* @return the context factory used when creating Contexts.
|
||||
*/
|
||||
public Class getContextFactory() {
|
||||
public Class<?> getContextFactory() {
|
||||
return contextFactory;
|
||||
}
|
||||
|
||||
@@ -379,7 +375,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @param dirObjectFactory the DirObjectFactory to be used. Null means that
|
||||
* no DirObjectFactory will be used.
|
||||
*/
|
||||
public void setDirObjectFactory(Class dirObjectFactory) {
|
||||
public void setDirObjectFactory(Class<?> dirObjectFactory) {
|
||||
this.dirObjectFactory = dirObjectFactory;
|
||||
}
|
||||
|
||||
@@ -389,7 +385,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @return the DirObjectFactory to be used. <code>null</code> means that no
|
||||
* DirObjectFactory will be used.
|
||||
*/
|
||||
public Class getDirObjectFactory() {
|
||||
public Class<?> getDirObjectFactory() {
|
||||
return dirObjectFactory;
|
||||
}
|
||||
|
||||
@@ -424,7 +420,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
}
|
||||
}
|
||||
|
||||
private Hashtable setupAnonymousEnv() {
|
||||
private Hashtable<String, Object> setupAnonymousEnv() {
|
||||
if (pooled) {
|
||||
baseEnv.put(SUN_LDAP_POOLING_FLAG, "true");
|
||||
log.debug("Using LDAP pooling.");
|
||||
@@ -434,7 +430,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
log.debug("Not using LDAP pooling");
|
||||
}
|
||||
|
||||
Hashtable env = new Hashtable(baseEnv);
|
||||
Hashtable<String, Object> env = new Hashtable<String, Object>(baseEnv);
|
||||
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory.getName());
|
||||
env.put(Context.PROVIDER_URL, assembleProviderUrlString(urls));
|
||||
@@ -483,7 +479,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @param urls the urls of all servers.
|
||||
*/
|
||||
public void setUrls(String[] urls) {
|
||||
this.urls = (String[]) urls.clone();
|
||||
this.urls = urls.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -492,7 +488,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @return the urls of all servers.
|
||||
*/
|
||||
public String[] getUrls() {
|
||||
return (String[]) urls.clone();
|
||||
return urls.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,17 +536,18 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* If any custom environment properties are needed, these can be set using
|
||||
* this method.
|
||||
*
|
||||
* @param baseEnvironmentProperties
|
||||
* @param baseEnvironmentProperties the base environment properties that should always be used when
|
||||
* creating new Context instances.
|
||||
*/
|
||||
public void setBaseEnvironmentProperties(Map baseEnvironmentProperties) {
|
||||
this.baseEnv = new Hashtable(baseEnvironmentProperties);
|
||||
public void setBaseEnvironmentProperties(Map<String, Object> baseEnvironmentProperties) {
|
||||
this.baseEnv = new Hashtable<String, Object>(baseEnvironmentProperties);
|
||||
}
|
||||
|
||||
String getJdkVersion() {
|
||||
return JdkVersion.getJavaVersion();
|
||||
}
|
||||
|
||||
protected Hashtable getAnonymousEnv() {
|
||||
protected Hashtable<String, Object> getAnonymousEnv() {
|
||||
if (cacheEnvironmentProperties) {
|
||||
return anonymousEnv;
|
||||
}
|
||||
@@ -559,9 +556,9 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
}
|
||||
}
|
||||
|
||||
protected Hashtable getAuthenticatedEnv(String principal, String credentials) {
|
||||
protected Hashtable<String, Object> getAuthenticatedEnv(String principal, String credentials) {
|
||||
// The authenticated environment should always be rebuilt.
|
||||
Hashtable env = new Hashtable(getAnonymousEnv());
|
||||
Hashtable<String, Object> env = new Hashtable<String, Object>(getAnonymousEnv());
|
||||
setupAuthenticatedEnvironment(env, principal, credentials);
|
||||
return env;
|
||||
}
|
||||
@@ -657,7 +654,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* @return a new DirContext instance.
|
||||
* @throws NamingException if one is encountered when creating the instance.
|
||||
*/
|
||||
protected abstract DirContext getDirContextInstance(Hashtable environment) throws NamingException;
|
||||
protected abstract DirContext getDirContextInstance(Hashtable<String, Object> environment) throws NamingException;
|
||||
|
||||
class SimpleAuthenticationSource implements AuthenticationSource {
|
||||
|
||||
|
||||
@@ -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,11 +15,9 @@
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Hashtable;
|
||||
import org.springframework.ldap.UncategorizedLdapException;
|
||||
import org.springframework.ldap.core.DirContextProxy;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
@@ -28,10 +26,11 @@ import javax.naming.ldap.StartTlsRequest;
|
||||
import javax.naming.ldap.StartTlsResponse;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import org.springframework.ldap.UncategorizedLdapException;
|
||||
import org.springframework.ldap.core.DirContextProxy;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Abstract superclass for {@link DirContextAuthenticationStrategy}
|
||||
@@ -117,7 +116,7 @@ public abstract class AbstractTlsDirContextAuthenticationStrategy implements Dir
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#setupEnvironment(java.util.Hashtable, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public final void setupEnvironment(Hashtable env, String userDn, String password) {
|
||||
public final void setupEnvironment(Hashtable<String, Object> env, String userDn, String password) {
|
||||
// Nothing to do in this implementation - authentication should take
|
||||
// place after TLS has been negotiated.
|
||||
}
|
||||
@@ -142,7 +141,7 @@ public abstract class AbstractTlsDirContextAuthenticationStrategy implements Dir
|
||||
// Wrap the target context in a proxy to intercept any calls
|
||||
// to 'close', so that we can shut down the TLS connection
|
||||
// gracefully first.
|
||||
return (DirContext) Proxy.newProxyInstance(DirContextProxy.class.getClassLoader(), new Class[] {
|
||||
return (DirContext) Proxy.newProxyInstance(DirContextProxy.class.getClassLoader(), new Class<?>[] {
|
||||
LdapContext.class, DirContextProxy.class }, new TlsAwareDirContextProxy(ldapCtx,
|
||||
tlsResponse));
|
||||
}
|
||||
|
||||
@@ -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,14 +16,13 @@
|
||||
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.springframework.ldap.core.DirContextProcessor;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.springframework.ldap.core.DirContextProcessor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Manages a sequence of {@link DirContextProcessor} instances. Applies
|
||||
@@ -35,7 +34,7 @@ import org.springframework.ldap.core.DirContextProcessor;
|
||||
*/
|
||||
public class AggregateDirContextProcessor implements DirContextProcessor {
|
||||
|
||||
private List dirContextProcessors = new LinkedList();
|
||||
private List<DirContextProcessor> dirContextProcessors = new LinkedList<DirContextProcessor>();
|
||||
|
||||
/**
|
||||
* Add the supplied DirContextProcessor to the list of managed objects.
|
||||
@@ -52,7 +51,7 @@ public class AggregateDirContextProcessor implements DirContextProcessor {
|
||||
*
|
||||
* @return the managed list of {@link DirContextProcessor} instances.
|
||||
*/
|
||||
public List getDirContextProcessors() {
|
||||
public List<DirContextProcessor> getDirContextProcessors() {
|
||||
return dirContextProcessors;
|
||||
}
|
||||
|
||||
@@ -62,16 +61,15 @@ public class AggregateDirContextProcessor implements DirContextProcessor {
|
||||
* @param dirContextProcessors
|
||||
* the list of {@link DirContextProcessor} instances to set.
|
||||
*/
|
||||
public void setDirContextProcessors(List dirContextProcessors) {
|
||||
this.dirContextProcessors = dirContextProcessors;
|
||||
public void setDirContextProcessors(List<DirContextProcessor> dirContextProcessors) {
|
||||
this.dirContextProcessors = new ArrayList<DirContextProcessor>(dirContextProcessors);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.core.DirContextProcessor#preProcess(javax.naming.directory.DirContext)
|
||||
*/
|
||||
public void preProcess(DirContext ctx) throws NamingException {
|
||||
for (Iterator iter = dirContextProcessors.iterator(); iter.hasNext();) {
|
||||
DirContextProcessor processor = (DirContextProcessor) iter.next();
|
||||
for (DirContextProcessor processor : dirContextProcessors) {
|
||||
processor.preProcess(ctx);
|
||||
}
|
||||
}
|
||||
@@ -80,8 +78,7 @@ public class AggregateDirContextProcessor implements DirContextProcessor {
|
||||
* @see org.springframework.ldap.core.DirContextProcessor#postProcess(javax.naming.directory.DirContext)
|
||||
*/
|
||||
public void postProcess(DirContext ctx) throws NamingException {
|
||||
for (Iterator iter = dirContextProcessors.iterator(); iter.hasNext();) {
|
||||
DirContextProcessor processor = (DirContextProcessor) iter.next();
|
||||
for (DirContextProcessor processor : dirContextProcessors) {
|
||||
processor.postProcess(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -45,7 +45,7 @@ public class DefaultDirObjectFactory implements DirObjectFactory {
|
||||
* Key to use in the ContextSource implementation to store the value of the
|
||||
* base path suffix, if any, in the Ldap Environment.
|
||||
*
|
||||
* @deprecated Use {@link BaseLdapPathAware} and
|
||||
* @deprecated Use {@link BaseLdapNameAware} and
|
||||
* {@link BaseLdapPathBeanPostProcessor} instead.
|
||||
*/
|
||||
public static final String JNDI_ENV_BASE_PATH_KEY = "org.springframework.ldap.base.path";
|
||||
@@ -62,11 +62,15 @@ public class DefaultDirObjectFactory implements DirObjectFactory {
|
||||
* javax.naming.Name, javax.naming.Context, java.util.Hashtable,
|
||||
* javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment, Attributes attrs)
|
||||
throws Exception {
|
||||
public final Object getObjectInstance(
|
||||
Object obj,
|
||||
Name name,
|
||||
Context nameCtx,
|
||||
Hashtable<?, ?> environment,
|
||||
Attributes attrs) throws Exception {
|
||||
|
||||
try {
|
||||
String nameInNamespace = null;
|
||||
String nameInNamespace;
|
||||
if (nameCtx != null) {
|
||||
nameInNamespace = nameCtx.getNameInNamespace();
|
||||
}
|
||||
@@ -114,7 +118,7 @@ public class DefaultDirObjectFactory implements DirObjectFactory {
|
||||
* information.
|
||||
*/
|
||||
DirContextAdapter constructAdapterFromName(Attributes attrs, Name name, String nameInNamespace) {
|
||||
String nameString = "";
|
||||
String nameString;
|
||||
String referralUrl = "";
|
||||
|
||||
if (name instanceof CompositeName) {
|
||||
@@ -181,7 +185,7 @@ public class DefaultDirObjectFactory implements DirObjectFactory {
|
||||
* @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object,
|
||||
* javax.naming.Name, javax.naming.Context, java.util.Hashtable)
|
||||
*/
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,9 +173,9 @@ public class DefaultIncrementalAttributesMapper implements IncrementalAttributes
|
||||
// Reset the affected attributes.
|
||||
rangedAttributesInNextIteration = new HashSet<String>();
|
||||
|
||||
NamingEnumeration attributeNameEnum = attributes.getIDs();
|
||||
NamingEnumeration<String> attributeNameEnum = attributes.getIDs();
|
||||
while (attributeNameEnum.hasMore()) {
|
||||
String attributeName = (String) attributeNameEnum.next();
|
||||
String attributeName = attributeNameEnum.next();
|
||||
|
||||
String[] attributeNameSplit = attributeName.split(";");
|
||||
IncrementalAttributeState state = getState(attributeNameSplit[0]);
|
||||
@@ -222,7 +222,7 @@ public class DefaultIncrementalAttributesMapper implements IncrementalAttributes
|
||||
Set<String> attributeNames = stateMap.keySet();
|
||||
for (String attributeName : attributeNames) {
|
||||
BasicAttribute oneAttribute = new BasicAttribute(attributeName);
|
||||
List values = getValues(attributeName);
|
||||
List<Object> values = getValues(attributeName);
|
||||
if (values != null) {
|
||||
for (Object oneValue : values) {
|
||||
oneAttribute.add(oneValue);
|
||||
@@ -400,7 +400,7 @@ public class DefaultIncrementalAttributesMapper implements IncrementalAttributes
|
||||
@Override
|
||||
public void processValues(Attributes attributes, String attributeName) throws NamingException {
|
||||
Attribute attribute = attributes.get(attributeName);
|
||||
NamingEnumeration valueEnum = attribute.getAll();
|
||||
NamingEnumeration<?> valueEnum = attribute.getAll();
|
||||
|
||||
initValuesIfApplicable();
|
||||
while (valueEnum.hasMore()) {
|
||||
|
||||
@@ -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,9 @@
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Authentication strategy for LDAP DIGEST-MD5 SASL mechanism.
|
||||
@@ -45,7 +44,7 @@ public class DigestMd5DirContextAuthenticationStrategy implements DirContextAuth
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#setupEnvironment(java.util.Hashtable,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void setupEnvironment(Hashtable env, String userDn, String password) {
|
||||
public void setupEnvironment(Hashtable<String, Object> env, String userDn, String password) {
|
||||
env.put(Context.SECURITY_AUTHENTICATION, DIGEST_MD5_AUTHENTICATION);
|
||||
// userDn should be a bare username for DIGEST-MD5
|
||||
env.put(Context.SECURITY_PRINCIPAL, userDn);
|
||||
|
||||
@@ -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,13 +15,12 @@
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import org.springframework.ldap.core.AuthenticationSource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.springframework.ldap.core.AuthenticationSource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* A strategy to use when authenticating LDAP connections on creation. When
|
||||
@@ -57,7 +56,7 @@ public interface DirContextAuthenticationStrategy {
|
||||
* <code>DirContext</code> creation to be aborted and the exception to be
|
||||
* translated and rethrown.
|
||||
*/
|
||||
public void setupEnvironment(Hashtable env, String userDn, String password) throws NamingException;
|
||||
public void setupEnvironment(Hashtable<String, Object> env, String userDn, String password) throws NamingException;
|
||||
|
||||
/**
|
||||
* This method is responsible for post-processing the
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import javax.naming.Context;
|
||||
|
||||
@@ -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,11 +16,10 @@
|
||||
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.ldap.InitialLdapContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* ContextSource implementation which creates an <code>InitialLdapContext</code>
|
||||
@@ -38,7 +37,7 @@ public class LdapContextSource extends AbstractContextSource {
|
||||
/*
|
||||
* @see org.springframework.ldap.support.AbstractContextSource#getDirContextInstance(java.util.Hashtable)
|
||||
*/
|
||||
protected DirContext getDirContextInstance(Hashtable environment)
|
||||
protected DirContext getDirContextInstance(Hashtable<String, Object> environment)
|
||||
throws NamingException {
|
||||
return new InitialLdapContext(environment, null);
|
||||
}
|
||||
|
||||
@@ -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,9 @@
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* The default {@link DirContextAuthenticationStrategy} implementation, setting
|
||||
@@ -38,7 +37,7 @@ public class SimpleDirContextAuthenticationStrategy implements DirContextAuthent
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#setupEnvironment(java.util.Hashtable,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void setupEnvironment(Hashtable env, String userDn, String password) {
|
||||
public void setupEnvironment(Hashtable<String, Object> env, String userDn, String password) {
|
||||
env.put(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION);
|
||||
env.put(Context.SECURITY_PRINCIPAL, userDn);
|
||||
env.put(Context.SECURITY_CREDENTIALS, password);
|
||||
|
||||
@@ -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,20 +15,19 @@
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.ldap.NamingException;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DirContextProxy;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
/**
|
||||
* A {@link ContextSource} to be used as a decorator around a target ContextSource
|
||||
@@ -68,7 +67,7 @@ public class SingleContextSource implements ContextSource, DisposableBean {
|
||||
|
||||
private DirContext getNonClosingDirContextProxy(DirContext context) {
|
||||
return (DirContext) Proxy.newProxyInstance(DirContextProxy.class
|
||||
.getClassLoader(), new Class[]{
|
||||
.getClassLoader(), new Class<?>[]{
|
||||
LdapUtils.getActualTargetClass(context),
|
||||
DirContextProxy.class},
|
||||
new SingleContextSource.NonClosingDirContextInvocationHandler(
|
||||
@@ -125,7 +124,7 @@ public class SingleContextSource implements ContextSource, DisposableBean {
|
||||
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
|
||||
} else if (methodName.equals("hashCode")) {
|
||||
// Use hashCode of Connection proxy.
|
||||
return new Integer(proxy.hashCode());
|
||||
return proxy.hashCode();
|
||||
} else if (methodName.equals("close")) {
|
||||
// Never close the target context, as this class will only be
|
||||
// used for operations concerning the compensating transactions.
|
||||
|
||||
@@ -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.
|
||||
@@ -24,10 +24,6 @@ package org.springframework.ldap.filter;
|
||||
*/
|
||||
public abstract class AbstractFilter implements Filter {
|
||||
|
||||
protected AbstractFilter() {
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.Filter#encode(java.lang.StringBuffer)
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.ldap.filter;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,13 +26,8 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class BinaryLogicalFilter extends AbstractFilter {
|
||||
|
||||
protected List queryList = new LinkedList();
|
||||
protected List<Filter> queryList = new LinkedList<Filter>();
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.filter.AbstractFilter#encode(java.lang.StringBuffer
|
||||
* )
|
||||
*/
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
if (queryList.size() <= 0) {
|
||||
|
||||
@@ -44,17 +38,16 @@ public abstract class BinaryLogicalFilter extends AbstractFilter {
|
||||
else if (queryList.size() == 1) {
|
||||
|
||||
// don't add the &
|
||||
Filter query = (Filter) queryList.get(0);
|
||||
Filter query = queryList.get(0);
|
||||
return query.encode(buff);
|
||||
|
||||
}
|
||||
else {
|
||||
buff.append("(" + getLogicalOperator());
|
||||
buff.append("(").append(getLogicalOperator());
|
||||
|
||||
for (Iterator i = queryList.iterator(); i.hasNext();) {
|
||||
Filter query = (Filter) i.next();
|
||||
buff = query.encode(buff);
|
||||
}
|
||||
for (Filter query : queryList) {
|
||||
buff = query.encode(buff);
|
||||
}
|
||||
|
||||
buff.append(")");
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -45,9 +45,6 @@ public class GreaterThanOrEqualsFilter extends CompareFilter {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.CompareFilter#getCompareString()
|
||||
*/
|
||||
protected String getCompareString() {
|
||||
return GREATER_THAN_OR_EQUALS;
|
||||
}
|
||||
|
||||
@@ -58,10 +58,6 @@ public class HardcodedFilter extends AbstractFilter {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.filter.AbstractFilter#encode(java.lang.StringBuffer)
|
||||
*/
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
if (!StringUtils.hasLength(filter)) {
|
||||
return buff;
|
||||
|
||||
@@ -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.
|
||||
@@ -45,9 +45,6 @@ public class LessThanOrEqualsFilter extends CompareFilter {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.CompareFilter#getCompareString()
|
||||
*/
|
||||
protected String getCompareString() {
|
||||
return LESS_THAN_OR_EQUALS;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -42,9 +42,6 @@ public class LikeFilter extends EqualsFilter {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.CompareFilter#encodeValue(java.lang.String)
|
||||
*/
|
||||
protected String encodeValue(String value) {
|
||||
// just return if blank string
|
||||
if (value == null) {
|
||||
@@ -57,17 +54,12 @@ public class LikeFilter extends EqualsFilter {
|
||||
return LdapEncoder.filterEncode(substrings[0]);
|
||||
}
|
||||
|
||||
StringBuffer buff = new StringBuffer();
|
||||
StringBuilder buff = new StringBuilder();
|
||||
for (int i = 0; i < substrings.length; i++) {
|
||||
buff.append(LdapEncoder.filterEncode(substrings[i]));
|
||||
if (i < substrings.length - 1) {
|
||||
buff.append("*");
|
||||
}
|
||||
else {
|
||||
if (substrings[i].equals("")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buff.toString();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.filter;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
@@ -47,9 +48,6 @@ public class NotFilter extends AbstractFilter {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.AbstractFilter#encode(java.lang.StringBuffer)
|
||||
*/
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
|
||||
buff.append("(!");
|
||||
|
||||
@@ -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.
|
||||
@@ -47,9 +47,6 @@ public class OrFilter extends BinaryLogicalFilter {
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.BinaryLogicalFilter#getLogicalOperator()
|
||||
*/
|
||||
protected String getLogicalOperator() {
|
||||
return PIPE_SIGN;
|
||||
}
|
||||
|
||||
@@ -42,9 +42,6 @@ public class WhitespaceWildcardsFilter extends EqualsFilter {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.CompareFilter#encodeValue(java.lang.String)
|
||||
*/
|
||||
protected String encodeValue(String value) {
|
||||
|
||||
// blank string means just ONE star
|
||||
|
||||
@@ -19,8 +19,10 @@ import org.apache.commons.pool.KeyedObjectPool;
|
||||
import org.springframework.ldap.pool.factory.PoolingContextSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
@@ -229,7 +231,7 @@ public class DelegatingContext implements Context {
|
||||
/**
|
||||
* @see javax.naming.Context#getEnvironment()
|
||||
*/
|
||||
public Hashtable getEnvironment() throws NamingException {
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateContext().getEnvironment();
|
||||
}
|
||||
@@ -261,7 +263,7 @@ public class DelegatingContext implements Context {
|
||||
/**
|
||||
* @see javax.naming.Context#list(javax.naming.Name)
|
||||
*/
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateContext().list(name);
|
||||
}
|
||||
@@ -269,7 +271,7 @@ public class DelegatingContext implements Context {
|
||||
/**
|
||||
* @see javax.naming.Context#list(java.lang.String)
|
||||
*/
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateContext().list(name);
|
||||
}
|
||||
@@ -277,7 +279,7 @@ public class DelegatingContext implements Context {
|
||||
/**
|
||||
* @see javax.naming.Context#listBindings(javax.naming.Name)
|
||||
*/
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateContext().listBindings(name);
|
||||
}
|
||||
@@ -285,7 +287,7 @@ public class DelegatingContext implements Context {
|
||||
/**
|
||||
* @see javax.naming.Context#listBindings(java.lang.String)
|
||||
*/
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateContext().listBindings(name);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.ModificationItem;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
|
||||
/**
|
||||
@@ -285,7 +286,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(javax.naming.Name, javax.naming.directory.Attributes, java.lang.String[])
|
||||
*/
|
||||
public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, matchingAttributes, attributesToReturn);
|
||||
}
|
||||
@@ -293,7 +294,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(javax.naming.Name, javax.naming.directory.Attributes)
|
||||
*/
|
||||
public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, matchingAttributes);
|
||||
}
|
||||
@@ -301,7 +302,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(javax.naming.Name, java.lang.String, java.lang.Object[], javax.naming.directory.SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, filterExpr, filterArgs, cons);
|
||||
}
|
||||
@@ -309,7 +310,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(javax.naming.Name, java.lang.String, javax.naming.directory.SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, filter, cons);
|
||||
}
|
||||
@@ -317,7 +318,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(java.lang.String, javax.naming.directory.Attributes, java.lang.String[])
|
||||
*/
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, matchingAttributes, attributesToReturn);
|
||||
}
|
||||
@@ -325,7 +326,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(java.lang.String, javax.naming.directory.Attributes)
|
||||
*/
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, matchingAttributes);
|
||||
}
|
||||
@@ -333,7 +334,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(java.lang.String, java.lang.String, java.lang.Object[], javax.naming.directory.SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, filterExpr, filterArgs, cons);
|
||||
}
|
||||
@@ -341,7 +342,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
/**
|
||||
* @see javax.naming.directory.DirContext#search(java.lang.String, java.lang.String, javax.naming.directory.SearchControls)
|
||||
*/
|
||||
public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException {
|
||||
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons) throws NamingException {
|
||||
this.assertOpen();
|
||||
return this.getDelegateDirContext().search(name, filter, cons);
|
||||
}
|
||||
|
||||
@@ -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,10 +16,10 @@
|
||||
|
||||
package org.springframework.ldap.pool;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
|
||||
/**
|
||||
* An enum representing the two types of {@link DirContext}s that can be returned by a
|
||||
@@ -34,9 +34,6 @@ public final class DirContextType {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -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,13 +16,13 @@
|
||||
|
||||
package org.springframework.ldap.pool;
|
||||
|
||||
import org.apache.commons.pool.KeyedObjectPool;
|
||||
import org.springframework.ldap.pool.factory.MutablePoolingContextSource;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.ldap.Control;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
|
||||
import org.apache.commons.pool.KeyedObjectPool;
|
||||
import org.springframework.ldap.pool.factory.MutablePoolingContextSource;
|
||||
|
||||
/**
|
||||
* Used by {@link MutablePoolingContextSource} to wrap a {@link LdapContext},
|
||||
* delegating most methods to the underlying context. This class extends
|
||||
@@ -49,11 +49,6 @@ public class MutableDelegatingLdapContext extends DelegatingLdapContext {
|
||||
super(keyedObjectPool, delegateLdapContext, dirContextType);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.pool.DelegatingLdapContext#setRequestControls
|
||||
* (javax.naming.ldap.Control[])
|
||||
*/
|
||||
public void setRequestControls(Control[] requestControls) throws NamingException {
|
||||
assertOpen();
|
||||
getDelegateLdapContext().setRequestControls(requestControls);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.pool.validation;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -23,6 +24,7 @@ import org.springframework.util.Assert;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
/**
|
||||
* Default {@link DirContext} validator that executes {@link DirContext#search(String, String, SearchControls)}. The
|
||||
@@ -162,7 +164,7 @@ public class DefaultDirContextValidator implements DirContextValidator {
|
||||
Assert.notNull(dirContext, "dirContext may not be null");
|
||||
|
||||
try {
|
||||
final NamingEnumeration searchResults = dirContext.search(this.base, this.filter, this.searchControls);
|
||||
final NamingEnumeration<SearchResult> searchResults = dirContext.search(this.base, this.filter, this.searchControls);
|
||||
|
||||
if (searchResults.hasMore()) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
|
||||
/**
|
||||
* Helper class for building {@javax.naming.ldap.LdapName} instances.
|
||||
* Helper class for building {@link javax.naming.ldap.LdapName} instances.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 2.0
|
||||
|
||||
@@ -251,16 +251,39 @@ public final class LdapUtils {
|
||||
* exists.
|
||||
* @since 1.3
|
||||
*/
|
||||
public static void collectAttributeValues(Attributes attributes, String name, Collection collection) {
|
||||
Assert.notNull(attributes, "Attributes must not be null");
|
||||
Attribute attribute = attributes.get(name);
|
||||
if (attribute == null) {
|
||||
throw new NoSuchAttributeException("No attribute with name '" + name + "'");
|
||||
}
|
||||
|
||||
iterateAttributeValues(attribute, new CollectingAttributeValueCallbackHandler(collection));
|
||||
public static void collectAttributeValues(Attributes attributes, String name, Collection<Object> collection) {
|
||||
collectAttributeValues(attributes, name, collection, Object.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all the values of a the specified attribute from the supplied
|
||||
* Attributes as the specified class.
|
||||
*
|
||||
* @param attributes The Attributes; not <code>null</code>.
|
||||
* @param name The name of the Attribute to get values for.
|
||||
* @param collection the collection to collect the values in.
|
||||
* @param clazz the class of the collected attribute values
|
||||
* @throws NoSuchAttributeException if no attribute with the specified name
|
||||
* exists.
|
||||
* @throws IllegalArgumentException if an attribute value cannot be cast to the specified class.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static <T> void collectAttributeValues(
|
||||
Attributes attributes, String name, Collection<T> collection, Class<T> clazz) {
|
||||
|
||||
Assert.notNull(attributes, "Attributes must not be null");
|
||||
Assert.hasText(name, "Name must not be empty");
|
||||
Assert.notNull(collection, "Collection must not be null");
|
||||
|
||||
Attribute attribute = attributes.get(name);
|
||||
if (attribute == null) {
|
||||
throw new NoSuchAttributeException("No attribute with name '" + name + "'");
|
||||
}
|
||||
|
||||
iterateAttributeValues(attribute, new CollectingAttributeValueCallbackHandler<T>(collection, clazz));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through all the values of the specified Attribute calling back to
|
||||
* the specified callbackHandler.
|
||||
@@ -288,16 +311,21 @@ public final class LdapUtils {
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
private final static class CollectingAttributeValueCallbackHandler implements AttributeValueCallbackHandler {
|
||||
private final Collection collection;
|
||||
private final static class CollectingAttributeValueCallbackHandler<T> implements AttributeValueCallbackHandler {
|
||||
private final Collection<T> collection;
|
||||
private final Class<T> clazz;
|
||||
|
||||
public CollectingAttributeValueCallbackHandler(Collection<T> collection, Class<T> clazz) {
|
||||
Assert.notNull(collection, "Collection must not be null");
|
||||
Assert.notNull(clazz, "Clazz parameter must not be null");
|
||||
|
||||
public CollectingAttributeValueCallbackHandler(Collection collection) {
|
||||
Assert.notNull(collection, "Collection must not be null");
|
||||
this.collection = collection;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public final void handleAttributeValue(String attributeName, Object attributeValue, int index) {
|
||||
collection.add(attributeValue);
|
||||
Assert.isTrue(attributeName == null || clazz.isAssignableFrom(attributeValue.getClass()));
|
||||
collection.add(clazz.cast(attributeValue));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.ldap.transaction.compensating;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.directory.ModificationItem;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.ldap.core.LdapOperations;
|
||||
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.directory.ModificationItem;
|
||||
|
||||
/**
|
||||
* A {@link CompensatingTransactionOperationExecutor} to manage a
|
||||
* <code>modifyAttributes</code> operation. Performs a
|
||||
@@ -65,8 +65,8 @@ public class ModifyAttributesOperationExecutor implements
|
||||
ModificationItem[] compensatingModifications) {
|
||||
this.ldapOperations = ldapOperations;
|
||||
this.dn = dn;
|
||||
this.actualModifications = (ModificationItem[]) actualModifications.clone();
|
||||
this.compensatingModifications = (ModificationItem[]) compensatingModifications.clone();
|
||||
this.actualModifications = actualModifications.clone();
|
||||
this.compensatingModifications = compensatingModifications.clone();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -64,19 +64,18 @@ public class ModifyAttributesOperationRecorder implements
|
||||
|
||||
ModificationItem[] incomingModifications = (ModificationItem[]) args[1];
|
||||
|
||||
Set set = new HashSet();
|
||||
for (int i = 0; i < incomingModifications.length; i++) {
|
||||
set.add(incomingModifications[i].getAttribute().getID());
|
||||
Set<String> set = new HashSet<String>();
|
||||
for (ModificationItem incomingModification : incomingModifications) {
|
||||
set.add(incomingModification.getAttribute().getID());
|
||||
}
|
||||
|
||||
// Get the current values of all referred Attributes.
|
||||
String[] attributeNameArray = (String[]) set.toArray(new String[set
|
||||
.size()]);
|
||||
String[] attributeNameArray = set.toArray(new String[set.size()]);
|
||||
|
||||
// LDAP-234: We need to explicitly an IncrementalAttributesMapper in
|
||||
// case we're working against AD and there are too many attribute values to be returned
|
||||
// by one query.
|
||||
IncrementalAttributesMapper attributesMapper = getAttributesMapper(attributeNameArray);
|
||||
IncrementalAttributesMapper<?> attributesMapper = getAttributesMapper(attributeNameArray);
|
||||
while (attributesMapper.hasMore()) {
|
||||
ldapOperations.lookup(dn, attributesMapper.getAttributesForLookup(), attributesMapper);
|
||||
}
|
||||
@@ -102,7 +101,7 @@ public class ModifyAttributesOperationRecorder implements
|
||||
* @return the {@link AttributesMapper} to use for getting the current
|
||||
* Attributes of the target DN.
|
||||
*/
|
||||
IncrementalAttributesMapper getAttributesMapper(String[] attributeNames) {
|
||||
IncrementalAttributesMapper<?> getAttributesMapper(String[] attributeNames) {
|
||||
return new DefaultIncrementalAttributesMapper(attributeNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,11 +85,10 @@ public class ContextSourceTransactionManagerDelegate extends
|
||||
*/
|
||||
protected CompensatingTransactionHolderSupport getNewHolder() {
|
||||
DirContext newCtx = getContextSource().getReadWriteContext();
|
||||
DirContextHolder contextHolder = new DirContextHolder(
|
||||
return new DirContextHolder(
|
||||
new DefaultCompensatingTransactionOperationManager(
|
||||
new LdapCompensatingTransactionOperationFactory(
|
||||
renamingStrategy)), newCtx);
|
||||
return contextHolder;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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,12 +15,6 @@
|
||||
*/
|
||||
package org.springframework.ldap.transaction.compensating.manager;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.ldap.NamingException;
|
||||
@@ -29,6 +23,11 @@ import org.springframework.ldap.transaction.compensating.LdapTransactionUtils;
|
||||
import org.springframework.transaction.compensating.support.CompensatingTransactionUtils;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Proxy implementation for DirContext, making sure that the instance is not
|
||||
* closed during a transaction, and that all modifying operations are recorded,
|
||||
@@ -77,7 +76,7 @@ public class TransactionAwareDirContextInvocationHandler implements
|
||||
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
|
||||
} else if (methodName.equals("hashCode")) {
|
||||
// Use hashCode of Connection proxy.
|
||||
return new Integer(hashCode());
|
||||
return hashCode();
|
||||
} else if (methodName.equals("close")) {
|
||||
doCloseConnection(target, contextSource);
|
||||
return null;
|
||||
|
||||
@@ -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.
|
||||
@@ -68,8 +68,7 @@ public abstract class AbstractCompensatingTransactionManagerDelegate {
|
||||
public Object doGetTransaction() throws TransactionException {
|
||||
CompensatingTransactionHolderSupport holder = (CompensatingTransactionHolderSupport) TransactionSynchronizationManager
|
||||
.getResource(getTransactionSynchronizationKey());
|
||||
CompensatingTransactionObject txObject = new CompensatingTransactionObject(holder);
|
||||
return txObject;
|
||||
return new CompensatingTransactionObject(holder);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -122,8 +121,7 @@ public abstract class AbstractCompensatingTransactionManagerDelegate {
|
||||
TransactionSynchronizationManager.unbindResource(getTransactionSynchronizationKey());
|
||||
|
||||
CompensatingTransactionObject txObject = (CompensatingTransactionObject) transaction;
|
||||
CompensatingTransactionHolderSupport transactionHolderSupport = (CompensatingTransactionHolderSupport) txObject
|
||||
.getHolder();
|
||||
CompensatingTransactionHolderSupport transactionHolderSupport = txObject.getHolder();
|
||||
|
||||
closeTargetResource(transactionHolderSupport);
|
||||
|
||||
|
||||
@@ -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.transaction.compensating.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.transaction.TransactionSystemException;
|
||||
@@ -26,6 +23,8 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera
|
||||
import org.springframework.transaction.compensating.CompensatingTransactionOperationManager;
|
||||
import org.springframework.transaction.compensating.CompensatingTransactionOperationRecorder;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link CompensatingTransactionOperationManager}.
|
||||
* Manages a stack of {@link CompensatingTransactionOperationExecutor} objects
|
||||
@@ -40,7 +39,8 @@ public class DefaultCompensatingTransactionOperationManager implements
|
||||
private static Log log = LogFactory
|
||||
.getLog(DefaultCompensatingTransactionOperationManager.class);
|
||||
|
||||
private Stack operationExecutors = new Stack();
|
||||
private Stack<CompensatingTransactionOperationExecutor> operationExecutors =
|
||||
new Stack<CompensatingTransactionOperationExecutor>();
|
||||
|
||||
private CompensatingTransactionOperationFactory operationFactory;
|
||||
|
||||
@@ -78,8 +78,7 @@ public class DefaultCompensatingTransactionOperationManager implements
|
||||
public void rollback() {
|
||||
log.debug("Performing rollback");
|
||||
while (!operationExecutors.isEmpty()) {
|
||||
CompensatingTransactionOperationExecutor rollbackOperation = (CompensatingTransactionOperationExecutor) operationExecutors
|
||||
.pop();
|
||||
CompensatingTransactionOperationExecutor rollbackOperation = operationExecutors.pop();
|
||||
try {
|
||||
rollbackOperation.rollback();
|
||||
} catch (Exception e) {
|
||||
@@ -94,7 +93,7 @@ public class DefaultCompensatingTransactionOperationManager implements
|
||||
*
|
||||
* @return the rollback operations.
|
||||
*/
|
||||
protected Stack getOperationExecutors() {
|
||||
protected Stack<CompensatingTransactionOperationExecutor> getOperationExecutors() {
|
||||
return operationExecutors;
|
||||
}
|
||||
|
||||
@@ -105,7 +104,7 @@ public class DefaultCompensatingTransactionOperationManager implements
|
||||
* @param operationExecutors
|
||||
* the rollback operations.
|
||||
*/
|
||||
void setOperationExecutors(Stack operationExecutors) {
|
||||
void setOperationExecutors(Stack<CompensatingTransactionOperationExecutor> operationExecutors) {
|
||||
this.operationExecutors = operationExecutors;
|
||||
}
|
||||
|
||||
@@ -114,9 +113,7 @@ public class DefaultCompensatingTransactionOperationManager implements
|
||||
*/
|
||||
public void commit() {
|
||||
log.debug("Performing commit");
|
||||
for (Iterator iter = operationExecutors.iterator(); iter.hasNext();) {
|
||||
CompensatingTransactionOperationExecutor operationExecutor = (CompensatingTransactionOperationExecutor) iter
|
||||
.next();
|
||||
for (CompensatingTransactionOperationExecutor operationExecutor : operationExecutors) {
|
||||
try {
|
||||
operationExecutor.commit();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -174,7 +174,7 @@ public class DirContextAdapterTest {
|
||||
tested.getStringAttributes("abc");
|
||||
fail("ClassCastException expected");
|
||||
}
|
||||
catch (ArrayStoreException expected) {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user