Convert to Linux Line Endings
This commit is contained in:
@@ -1,220 +1,220 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.ContextMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate on OpenLdap.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapTemplateLookupOpenLdapITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private LdapTemplate tested;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
public void testLookup_Plain() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person2, ou=company1,c=Sweden");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertEquals("Sweden, Company1, Some Person2", result
|
||||
.getStringAttribute("description"));
|
||||
}
|
||||
|
||||
public void testLookup_AttributesMapper() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
public void testLookup_AttributesMapper_DistinguishedName() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(new DistinguishedName(
|
||||
"cn=Some Person2, ou=company1,c=Sweden"), mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributesMapper} that only maps a subset of the full
|
||||
* attributes list. Used in tests where the return attributes list has been
|
||||
* limited.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
private final class SubsetPersonAttributesMapper implements
|
||||
AttributesMapper {
|
||||
/**
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object.
|
||||
* Also verifies that the other attributes haven't been set.
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object mapFromAttributes(Attributes attributes)
|
||||
throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullname((String) attributes.get("cn").get());
|
||||
assertThat(attributes.get("sn")).as("sn should be null").isNull();
|
||||
assertNull("description should be null", attributes
|
||||
.get("description"));
|
||||
return person;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
*/
|
||||
public void testLookup_ReturnAttributes_AttributesMapper() {
|
||||
AttributesMapper mapper = new SubsetPersonAttributesMapper();
|
||||
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" },
|
||||
mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes. Uses DistinguishedName instead
|
||||
* of plain string as name.
|
||||
*/
|
||||
public void testLookup_ReturnAttributes_AttributesMapper_DistinguishedName() {
|
||||
AttributesMapper mapper = new SubsetPersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(new DistinguishedName(
|
||||
"cn=Some Person2, ou=company1,c=Sweden"),
|
||||
new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
public void testLookup_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
*/
|
||||
public void testLookup_ReturnAttributes_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" },
|
||||
mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
*/
|
||||
public void testLookup_MultiValuedRdn() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person+sn=Person, ou=company1,c=Norway", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getLastname()).isEqualTo("Person");
|
||||
assertEquals("Norway, Company1, Some Person+Person", person
|
||||
.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
*/
|
||||
public void testLookup_MultiValuedRdn_DirContextAdapter() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person");
|
||||
assertEquals("Norway, Company1, Some Person+Person", result
|
||||
.getStringAttribute("description"));
|
||||
}
|
||||
|
||||
public void testLookup_GetNameInNamespace_Plain() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person2, ou=company1,c=Sweden");
|
||||
|
||||
assertThat(result.getDn().isEqualTo("cn=Some Person2, ou=company1, c=Sweden")
|
||||
.toString());
|
||||
assertEquals(
|
||||
"cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se",
|
||||
result.getNameInNamespace());
|
||||
}
|
||||
|
||||
public void testLookup_GetNameInNamespace_MultiRdn() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
|
||||
|
||||
assertEquals("cn=Some Person+sn=Person, ou=company1, c=Norway", result
|
||||
.getDn().toString());
|
||||
assertEquals(
|
||||
"cn=Some Person+sn=Person, ou=company1, c=Norway, dc=jayway, dc=se",
|
||||
result.getNameInNamespace());
|
||||
}
|
||||
|
||||
public void setTested(LdapTemplate tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.ContextMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate on OpenLdap.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapTemplateLookupOpenLdapITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private LdapTemplate tested;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
public void testLookup_Plain() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person2, ou=company1,c=Sweden");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertEquals("Sweden, Company1, Some Person2", result
|
||||
.getStringAttribute("description"));
|
||||
}
|
||||
|
||||
public void testLookup_AttributesMapper() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
public void testLookup_AttributesMapper_DistinguishedName() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(new DistinguishedName(
|
||||
"cn=Some Person2, ou=company1,c=Sweden"), mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributesMapper} that only maps a subset of the full
|
||||
* attributes list. Used in tests where the return attributes list has been
|
||||
* limited.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
private final class SubsetPersonAttributesMapper implements
|
||||
AttributesMapper {
|
||||
/**
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object.
|
||||
* Also verifies that the other attributes haven't been set.
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object mapFromAttributes(Attributes attributes)
|
||||
throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullname((String) attributes.get("cn").get());
|
||||
assertThat(attributes.get("sn")).as("sn should be null").isNull();
|
||||
assertNull("description should be null", attributes
|
||||
.get("description"));
|
||||
return person;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
*/
|
||||
public void testLookup_ReturnAttributes_AttributesMapper() {
|
||||
AttributesMapper mapper = new SubsetPersonAttributesMapper();
|
||||
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" },
|
||||
mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes. Uses DistinguishedName instead
|
||||
* of plain string as name.
|
||||
*/
|
||||
public void testLookup_ReturnAttributes_AttributesMapper_DistinguishedName() {
|
||||
AttributesMapper mapper = new SubsetPersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(new DistinguishedName(
|
||||
"cn=Some Person2, ou=company1,c=Sweden"),
|
||||
new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
public void testLookup_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
*/
|
||||
public void testLookup_ReturnAttributes_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" },
|
||||
mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
*/
|
||||
public void testLookup_MultiValuedRdn() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(
|
||||
"cn=Some Person+sn=Person, ou=company1,c=Norway", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getLastname()).isEqualTo("Person");
|
||||
assertEquals("Norway, Company1, Some Person+Person", person
|
||||
.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
*/
|
||||
public void testLookup_MultiValuedRdn_DirContextAdapter() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person");
|
||||
assertEquals("Norway, Company1, Some Person+Person", result
|
||||
.getStringAttribute("description"));
|
||||
}
|
||||
|
||||
public void testLookup_GetNameInNamespace_Plain() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person2, ou=company1,c=Sweden");
|
||||
|
||||
assertThat(result.getDn().isEqualTo("cn=Some Person2, ou=company1, c=Sweden")
|
||||
.toString());
|
||||
assertEquals(
|
||||
"cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se",
|
||||
result.getNameInNamespace());
|
||||
}
|
||||
|
||||
public void testLookup_GetNameInNamespace_MultiRdn() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
|
||||
|
||||
assertEquals("cn=Some Person+sn=Person, ou=company1, c=Norway", result
|
||||
.getDn().toString());
|
||||
assertEquals(
|
||||
"cn=Some Person+sn=Person, ou=company1, c=Norway, dc=jayway, dc=se",
|
||||
result.getNameInNamespace());
|
||||
}
|
||||
|
||||
public void setTested(LdapTemplate tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,157 +1,157 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
|
||||
import org.springframework.ldap.Person;
|
||||
import org.springframework.ldap.PersonAttributesMapper;
|
||||
import org.springframework.ldap.core.AttributesMapperCallbackHandler;
|
||||
import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.SearchExecutor;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests the paged search result capability of LdapTemplate.
|
||||
* <p>
|
||||
* Note: Currently, ApacheDS does not support paged results controls, so this
|
||||
* test must be run under another directory server, for example OpenLdap. This
|
||||
* test will not run under ApacheDS, and the other integration tests assume
|
||||
* ApacheDS and will probably not run under OpenLdap.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapTemplatePagedSearchITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private static final Name BASE = DistinguishedName.EMPTY_PATH;
|
||||
|
||||
private static final String FILTER_STRING = "(&(objectclass=person))";
|
||||
|
||||
private LdapTemplate tested;
|
||||
|
||||
private CollectingNameClassPairCallbackHandler callbackHandler;
|
||||
|
||||
private SearchControls searchControls;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
PersonAttributesMapper mapper = new PersonAttributesMapper();
|
||||
callbackHandler = new AttributesMapperCallbackHandler(mapper);
|
||||
searchControls = new SearchControls();
|
||||
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
callbackHandler = null;
|
||||
tested = null;
|
||||
searchControls = null;
|
||||
}
|
||||
|
||||
public void testSearch_PagedResult() {
|
||||
SearchExecutor searchExecutor = new SearchExecutor() {
|
||||
public NamingEnumeration executeSearch(DirContext ctx)
|
||||
throws NamingException {
|
||||
return ctx.search(BASE, FILTER_STRING, searchControls);
|
||||
}
|
||||
};
|
||||
Person person;
|
||||
List list;
|
||||
PagedResultsCookie cookie;
|
||||
PagedResultsRequestControl requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new PagedResultsRequestControl(3);
|
||||
tested.search(searchExecutor, callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull();
|
||||
list = callbackHandler.getList();
|
||||
assertThat(list).hasSize(3);
|
||||
person = (Person) list.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-123456");
|
||||
person = (Person) list.get(1);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-654321");
|
||||
person = (Person) list.get(2);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person3");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-123654");
|
||||
|
||||
// Prepare for second and last search
|
||||
requestControl = new PagedResultsRequestControl(3, cookie);
|
||||
tested.search(searchExecutor, callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should be null now").isNull();
|
||||
assertThat(list).hasSize(5);
|
||||
person = (Person) list.get(3);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-456321");
|
||||
person = (Person) list.get(4);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getPhone()).isEqualTo("+45 555-654123");
|
||||
}
|
||||
|
||||
public void testSearch_PagedResult_ConvenienceMethod() {
|
||||
Person person;
|
||||
List list;
|
||||
PagedResultsCookie cookie;
|
||||
PagedResultsRequestControl requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new PagedResultsRequestControl(3);
|
||||
tested.search(BASE, FILTER_STRING, searchControls,
|
||||
callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull();
|
||||
list = callbackHandler.getList();
|
||||
assertThat(list).hasSize(3);
|
||||
person = (Person) list.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
person = (Person) list.get(1);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
person = (Person) list.get(2);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person3");
|
||||
|
||||
// Prepare for second and last search
|
||||
requestControl = new PagedResultsRequestControl(3, cookie);
|
||||
tested.search(BASE, FILTER_STRING, searchControls,
|
||||
callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should be null now").isNull();
|
||||
assertThat(list).hasSize(5);
|
||||
person = (Person) list.get(3);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
person = (Person) list.get(4);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
}
|
||||
|
||||
public void setTested(LdapTemplate tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
|
||||
import org.springframework.ldap.Person;
|
||||
import org.springframework.ldap.PersonAttributesMapper;
|
||||
import org.springframework.ldap.core.AttributesMapperCallbackHandler;
|
||||
import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.SearchExecutor;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests the paged search result capability of LdapTemplate.
|
||||
* <p>
|
||||
* Note: Currently, ApacheDS does not support paged results controls, so this
|
||||
* test must be run under another directory server, for example OpenLdap. This
|
||||
* test will not run under ApacheDS, and the other integration tests assume
|
||||
* ApacheDS and will probably not run under OpenLdap.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapTemplatePagedSearchITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private static final Name BASE = DistinguishedName.EMPTY_PATH;
|
||||
|
||||
private static final String FILTER_STRING = "(&(objectclass=person))";
|
||||
|
||||
private LdapTemplate tested;
|
||||
|
||||
private CollectingNameClassPairCallbackHandler callbackHandler;
|
||||
|
||||
private SearchControls searchControls;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
PersonAttributesMapper mapper = new PersonAttributesMapper();
|
||||
callbackHandler = new AttributesMapperCallbackHandler(mapper);
|
||||
searchControls = new SearchControls();
|
||||
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
callbackHandler = null;
|
||||
tested = null;
|
||||
searchControls = null;
|
||||
}
|
||||
|
||||
public void testSearch_PagedResult() {
|
||||
SearchExecutor searchExecutor = new SearchExecutor() {
|
||||
public NamingEnumeration executeSearch(DirContext ctx)
|
||||
throws NamingException {
|
||||
return ctx.search(BASE, FILTER_STRING, searchControls);
|
||||
}
|
||||
};
|
||||
Person person;
|
||||
List list;
|
||||
PagedResultsCookie cookie;
|
||||
PagedResultsRequestControl requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new PagedResultsRequestControl(3);
|
||||
tested.search(searchExecutor, callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull();
|
||||
list = callbackHandler.getList();
|
||||
assertThat(list).hasSize(3);
|
||||
person = (Person) list.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-123456");
|
||||
person = (Person) list.get(1);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-654321");
|
||||
person = (Person) list.get(2);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person3");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-123654");
|
||||
|
||||
// Prepare for second and last search
|
||||
requestControl = new PagedResultsRequestControl(3, cookie);
|
||||
tested.search(searchExecutor, callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should be null now").isNull();
|
||||
assertThat(list).hasSize(5);
|
||||
person = (Person) list.get(3);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getPhone()).isEqualTo("+46 555-456321");
|
||||
person = (Person) list.get(4);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getPhone()).isEqualTo("+45 555-654123");
|
||||
}
|
||||
|
||||
public void testSearch_PagedResult_ConvenienceMethod() {
|
||||
Person person;
|
||||
List list;
|
||||
PagedResultsCookie cookie;
|
||||
PagedResultsRequestControl requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new PagedResultsRequestControl(3);
|
||||
tested.search(BASE, FILTER_STRING, searchControls,
|
||||
callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull();
|
||||
list = callbackHandler.getList();
|
||||
assertThat(list).hasSize(3);
|
||||
person = (Person) list.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
person = (Person) list.get(1);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
person = (Person) list.get(2);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person3");
|
||||
|
||||
// Prepare for second and last search
|
||||
requestControl = new PagedResultsRequestControl(3, cookie);
|
||||
tested.search(BASE, FILTER_STRING, searchControls,
|
||||
callbackHandler, requestControl);
|
||||
cookie = requestControl.getCookie();
|
||||
assertThat(cookie.getCookie()).as("Cookie should be null now").isNull();
|
||||
assertThat(list).hasSize(5);
|
||||
person = (Person) list.get(3);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
person = (Person) list.get(4);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
}
|
||||
|
||||
public void setTested(LdapTemplate tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,143 +1,143 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
|
||||
import org.springframework.ldap.Person;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.AttributesMapperCallbackHandler;
|
||||
import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.SearchExecutor;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests the still experimental sorted search result capability of LdapTemplate.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapTemplateSortedSearchITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private static final Name BASE = DistinguishedName.EMPTY_PATH;
|
||||
|
||||
private static final String FILTER_STRING = "(&(objectclass=ikeaperson)(cn=gor*))";
|
||||
|
||||
private LdapTemplate tested;
|
||||
|
||||
private CollectingNameClassPairCallbackHandler callbackHandler;
|
||||
|
||||
private SearchControls searchControls;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
PersonAttributesMapper mapper = new PersonAttributesMapper();
|
||||
callbackHandler = new AttributesMapperCallbackHandler(mapper);
|
||||
searchControls = new SearchControls();
|
||||
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
callbackHandler = null;
|
||||
tested = null;
|
||||
searchControls = null;
|
||||
}
|
||||
|
||||
public void testSearch_SortControl() {
|
||||
SearchExecutor searchExecutor = new SearchExecutor() {
|
||||
public NamingEnumeration executeSearch(DirContext ctx)
|
||||
throws NamingException {
|
||||
return ctx.search(BASE, FILTER_STRING, searchControls);
|
||||
}
|
||||
};
|
||||
SortControlDirContextProcessor requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new SortControlDirContextProcessor("cn");
|
||||
tested.search(searchExecutor, callbackHandler, requestControl);
|
||||
int resultCode = requestControl.getResultCode();
|
||||
boolean sorted = requestControl.isSorted();
|
||||
assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue();
|
||||
List list = callbackHandler.getList();
|
||||
assertSortedList(list);
|
||||
}
|
||||
|
||||
public void testSearch_SortControl_ConvenienceMethod() {
|
||||
SortControlDirContextProcessor requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new SortControlDirContextProcessor("cn");
|
||||
tested.search(BASE, FILTER_STRING, searchControls, callbackHandler,
|
||||
requestControl);
|
||||
int resultCode = requestControl.getResultCode();
|
||||
boolean sorted = requestControl.isSorted();
|
||||
assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue();
|
||||
List list = callbackHandler.getList();
|
||||
assertSortedList(list);
|
||||
}
|
||||
|
||||
private void assertSortedList(List list) {
|
||||
Person person;
|
||||
assertThat(list).hasSize(6);
|
||||
person = (Person) list.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Goran Milenkovic");
|
||||
person = (Person) list.get(1);
|
||||
assertThat(person.getFullname()).isEqualTo("Goran Sundberg");
|
||||
person = (Person) list.get(2);
|
||||
assertThat(person.getFullname()).isEqualTo("Goran Westerberg");
|
||||
person = (Person) list.get(3);
|
||||
assertThat(person.getFullname()).isEqualTo("Gorana Milicevic");
|
||||
person = (Person) list.get(4);
|
||||
assertThat(person.getFullname()).isEqualTo("Gordana Canic");
|
||||
person = (Person) list.get(5);
|
||||
assertThat(person.getFullname()).isEqualTo("Gordana Russ");
|
||||
}
|
||||
|
||||
public void setTested(LdapTemplate tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
|
||||
private class PersonAttributesMapper implements AttributesMapper {
|
||||
|
||||
/**
|
||||
* Maps the given attributes into a {@link Person} object.
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object mapFromAttributes(Attributes attributes)
|
||||
throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullname((String) attributes.get("cn").get());
|
||||
person.setLastname((String) attributes.get("sn").get());
|
||||
person.setDescription((String) attributes.get("givenName").get());
|
||||
return person;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
|
||||
import org.springframework.ldap.Person;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.AttributesMapperCallbackHandler;
|
||||
import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.SearchExecutor;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests the still experimental sorted search result capability of LdapTemplate.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapTemplateSortedSearchITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private static final Name BASE = DistinguishedName.EMPTY_PATH;
|
||||
|
||||
private static final String FILTER_STRING = "(&(objectclass=ikeaperson)(cn=gor*))";
|
||||
|
||||
private LdapTemplate tested;
|
||||
|
||||
private CollectingNameClassPairCallbackHandler callbackHandler;
|
||||
|
||||
private SearchControls searchControls;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
PersonAttributesMapper mapper = new PersonAttributesMapper();
|
||||
callbackHandler = new AttributesMapperCallbackHandler(mapper);
|
||||
searchControls = new SearchControls();
|
||||
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
callbackHandler = null;
|
||||
tested = null;
|
||||
searchControls = null;
|
||||
}
|
||||
|
||||
public void testSearch_SortControl() {
|
||||
SearchExecutor searchExecutor = new SearchExecutor() {
|
||||
public NamingEnumeration executeSearch(DirContext ctx)
|
||||
throws NamingException {
|
||||
return ctx.search(BASE, FILTER_STRING, searchControls);
|
||||
}
|
||||
};
|
||||
SortControlDirContextProcessor requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new SortControlDirContextProcessor("cn");
|
||||
tested.search(searchExecutor, callbackHandler, requestControl);
|
||||
int resultCode = requestControl.getResultCode();
|
||||
boolean sorted = requestControl.isSorted();
|
||||
assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue();
|
||||
List list = callbackHandler.getList();
|
||||
assertSortedList(list);
|
||||
}
|
||||
|
||||
public void testSearch_SortControl_ConvenienceMethod() {
|
||||
SortControlDirContextProcessor requestControl;
|
||||
|
||||
// Prepare for first search
|
||||
requestControl = new SortControlDirContextProcessor("cn");
|
||||
tested.search(BASE, FILTER_STRING, searchControls, callbackHandler,
|
||||
requestControl);
|
||||
int resultCode = requestControl.getResultCode();
|
||||
boolean sorted = requestControl.isSorted();
|
||||
assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue();
|
||||
List list = callbackHandler.getList();
|
||||
assertSortedList(list);
|
||||
}
|
||||
|
||||
private void assertSortedList(List list) {
|
||||
Person person;
|
||||
assertThat(list).hasSize(6);
|
||||
person = (Person) list.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Goran Milenkovic");
|
||||
person = (Person) list.get(1);
|
||||
assertThat(person.getFullname()).isEqualTo("Goran Sundberg");
|
||||
person = (Person) list.get(2);
|
||||
assertThat(person.getFullname()).isEqualTo("Goran Westerberg");
|
||||
person = (Person) list.get(3);
|
||||
assertThat(person.getFullname()).isEqualTo("Gorana Milicevic");
|
||||
person = (Person) list.get(4);
|
||||
assertThat(person.getFullname()).isEqualTo("Gordana Canic");
|
||||
person = (Person) list.get(5);
|
||||
assertThat(person.getFullname()).isEqualTo("Gordana Russ");
|
||||
}
|
||||
|
||||
public void setTested(LdapTemplate tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
|
||||
private class PersonAttributesMapper implements AttributesMapper {
|
||||
|
||||
/**
|
||||
* Maps the given attributes into a {@link Person} object.
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object mapFromAttributes(Attributes attributes)
|
||||
throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullname((String) attributes.get("cn").get());
|
||||
person.setLastname((String) attributes.get("sn").get());
|
||||
person.setDescription((String) attributes.get("givenName").get());
|
||||
return person;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AttributeInUseException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.AttributeInUseException
|
||||
*/
|
||||
public class AttributeInUseException extends NamingException {
|
||||
|
||||
public AttributeInUseException(
|
||||
javax.naming.directory.AttributeInUseException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AttributeInUseException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.AttributeInUseException
|
||||
*/
|
||||
public class AttributeInUseException extends NamingException {
|
||||
|
||||
public AttributeInUseException(
|
||||
javax.naming.directory.AttributeInUseException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AttributeModificationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.AttributeModificationException
|
||||
*/
|
||||
public class AttributeModificationException extends NamingException {
|
||||
|
||||
public AttributeModificationException(
|
||||
javax.naming.directory.AttributeModificationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AttributeModificationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.AttributeModificationException
|
||||
*/
|
||||
public class AttributeModificationException extends NamingException {
|
||||
|
||||
public AttributeModificationException(
|
||||
javax.naming.directory.AttributeModificationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AuthenticationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.AuthenticationException
|
||||
*/
|
||||
public class AuthenticationException extends NamingSecurityException {
|
||||
|
||||
public AuthenticationException(javax.naming.AuthenticationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public AuthenticationException() {
|
||||
this(null);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AuthenticationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.AuthenticationException
|
||||
*/
|
||||
public class AuthenticationException extends NamingSecurityException {
|
||||
|
||||
public AuthenticationException(javax.naming.AuthenticationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public AuthenticationException() {
|
||||
this(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AuthenticationNotSupportedException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.AuthenticationNotSupportedException
|
||||
*/
|
||||
public class AuthenticationNotSupportedException extends
|
||||
NamingSecurityException {
|
||||
|
||||
public AuthenticationNotSupportedException(
|
||||
javax.naming.AuthenticationNotSupportedException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI AuthenticationNotSupportedException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.AuthenticationNotSupportedException
|
||||
*/
|
||||
public class AuthenticationNotSupportedException extends
|
||||
NamingSecurityException {
|
||||
|
||||
public AuthenticationNotSupportedException(
|
||||
javax.naming.AuthenticationNotSupportedException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that an invalid value has been supplied to an LDAP
|
||||
* operation. This could be an invalid filter or dn.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BadLdapGrammarException extends NamingException {
|
||||
|
||||
private static final long serialVersionUID = 961612585331409470L;
|
||||
|
||||
public BadLdapGrammarException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BadLdapGrammarException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that an invalid value has been supplied to an LDAP
|
||||
* operation. This could be an invalid filter or dn.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BadLdapGrammarException extends NamingException {
|
||||
|
||||
private static final long serialVersionUID = 961612585331409470L;
|
||||
|
||||
public BadLdapGrammarException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BadLdapGrammarException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI CannotProceedException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.CannotProceedException
|
||||
*/
|
||||
public class CannotProceedException extends NamingException {
|
||||
|
||||
public CannotProceedException(javax.naming.CannotProceedException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI CannotProceedException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.CannotProceedException
|
||||
*/
|
||||
public class CannotProceedException extends NamingException {
|
||||
|
||||
public CannotProceedException(javax.naming.CannotProceedException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI CommunicationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.CommunicationException
|
||||
*/
|
||||
public class CommunicationException extends NamingException {
|
||||
|
||||
public CommunicationException(javax.naming.CommunicationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI CommunicationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.CommunicationException
|
||||
*/
|
||||
public class CommunicationException extends NamingException {
|
||||
|
||||
public CommunicationException(javax.naming.CommunicationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ConfigurationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ConfigurationException
|
||||
*/
|
||||
public class ConfigurationException extends NamingException {
|
||||
|
||||
public ConfigurationException(javax.naming.ConfigurationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ConfigurationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ConfigurationException
|
||||
*/
|
||||
public class ConfigurationException extends NamingException {
|
||||
|
||||
public ConfigurationException(javax.naming.ConfigurationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ContextNotEmptyException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ContextNotEmptyException
|
||||
*/
|
||||
public class ContextNotEmptyException extends NamingException {
|
||||
|
||||
public ContextNotEmptyException(javax.naming.ContextNotEmptyException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ContextNotEmptyException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ContextNotEmptyException
|
||||
*/
|
||||
public class ContextNotEmptyException extends NamingException {
|
||||
|
||||
public ContextNotEmptyException(javax.naming.ContextNotEmptyException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InsufficientResourcesException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.InsufficientResourcesException
|
||||
*/
|
||||
public class InsufficientResourcesException extends NamingException {
|
||||
|
||||
public InsufficientResourcesException(
|
||||
javax.naming.InsufficientResourcesException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InsufficientResourcesException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.InsufficientResourcesException
|
||||
*/
|
||||
public class InsufficientResourcesException extends NamingException {
|
||||
|
||||
public InsufficientResourcesException(
|
||||
javax.naming.InsufficientResourcesException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InterruptedNamingException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.InterruptedNamingException
|
||||
*/
|
||||
public class InterruptedNamingException extends NamingException {
|
||||
|
||||
public InterruptedNamingException(
|
||||
javax.naming.InterruptedNamingException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InterruptedNamingException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.InterruptedNamingException
|
||||
*/
|
||||
public class InterruptedNamingException extends NamingException {
|
||||
|
||||
public InterruptedNamingException(
|
||||
javax.naming.InterruptedNamingException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidAttributeIdentifierException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidAttributeIdentifierException
|
||||
*/
|
||||
public class InvalidAttributeIdentifierException extends NamingException {
|
||||
|
||||
public InvalidAttributeIdentifierException(
|
||||
javax.naming.directory.InvalidAttributeIdentifierException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidAttributeIdentifierException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidAttributeIdentifierException
|
||||
*/
|
||||
public class InvalidAttributeIdentifierException extends NamingException {
|
||||
|
||||
public InvalidAttributeIdentifierException(
|
||||
javax.naming.directory.InvalidAttributeIdentifierException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidAttributeValueException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidAttributeValueException
|
||||
*/
|
||||
public class InvalidAttributeValueException extends NamingException {
|
||||
|
||||
public InvalidAttributeValueException(
|
||||
javax.naming.directory.InvalidAttributeValueException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidAttributeValueException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidAttributeValueException
|
||||
*/
|
||||
public class InvalidAttributeValueException extends NamingException {
|
||||
|
||||
public InvalidAttributeValueException(
|
||||
javax.naming.directory.InvalidAttributeValueException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidAttributesException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidAttributesException
|
||||
*/
|
||||
public class InvalidAttributesException extends NamingException {
|
||||
|
||||
public InvalidAttributesException(
|
||||
javax.naming.directory.InvalidAttributesException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidAttributesException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidAttributesException
|
||||
*/
|
||||
public class InvalidAttributesException extends NamingException {
|
||||
|
||||
public InvalidAttributesException(
|
||||
javax.naming.directory.InvalidAttributesException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidNameException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.InvalidNameException
|
||||
*/
|
||||
public class InvalidNameException extends NamingException {
|
||||
|
||||
public InvalidNameException(javax.naming.InvalidNameException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidNameException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.InvalidNameException
|
||||
*/
|
||||
public class InvalidNameException extends NamingException {
|
||||
|
||||
public InvalidNameException(javax.naming.InvalidNameException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidSearchControlsException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidSearchControlsException
|
||||
*/
|
||||
public class InvalidSearchControlsException extends NamingException {
|
||||
|
||||
public InvalidSearchControlsException(
|
||||
javax.naming.directory.InvalidSearchControlsException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidSearchControlsException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidSearchControlsException
|
||||
*/
|
||||
public class InvalidSearchControlsException extends NamingException {
|
||||
|
||||
public InvalidSearchControlsException(
|
||||
javax.naming.directory.InvalidSearchControlsException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidSearchFilterException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidSearchFilterException
|
||||
*/
|
||||
public class InvalidSearchFilterException extends NamingException {
|
||||
|
||||
public InvalidSearchFilterException(
|
||||
javax.naming.directory.InvalidSearchFilterException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI InvalidSearchFilterException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.InvalidSearchFilterException
|
||||
*/
|
||||
public class InvalidSearchFilterException extends NamingException {
|
||||
|
||||
public InvalidSearchFilterException(
|
||||
javax.naming.directory.InvalidSearchFilterException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LdapReferralException.
|
||||
*
|
||||
* This class is not abstract. We need to be able to instantiate it, should the
|
||||
* caught exception be a provider-specific subclass of
|
||||
* {@link javax.naming.ldap.LdapReferralException}.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ldap.LdapReferralException
|
||||
*/
|
||||
public class LdapReferralException extends ReferralException {
|
||||
|
||||
public LdapReferralException(javax.naming.ldap.LdapReferralException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LdapReferralException.
|
||||
*
|
||||
* This class is not abstract. We need to be able to instantiate it, should the
|
||||
* caught exception be a provider-specific subclass of
|
||||
* {@link javax.naming.ldap.LdapReferralException}.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ldap.LdapReferralException
|
||||
*/
|
||||
public class LdapReferralException extends ReferralException {
|
||||
|
||||
public LdapReferralException(javax.naming.ldap.LdapReferralException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LimitExceededException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.LimitExceededException
|
||||
*/
|
||||
public class LimitExceededException extends NamingException {
|
||||
|
||||
public LimitExceededException(javax.naming.LimitExceededException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LimitExceededException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.LimitExceededException
|
||||
*/
|
||||
public class LimitExceededException extends NamingException {
|
||||
|
||||
public LimitExceededException(javax.naming.LimitExceededException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LinkException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.LinkException
|
||||
*/
|
||||
public class LinkException extends NamingException {
|
||||
|
||||
public LinkException(javax.naming.LinkException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LinkException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.LinkException
|
||||
*/
|
||||
public class LinkException extends NamingException {
|
||||
|
||||
public LinkException(javax.naming.LinkException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LinkLoopException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.LinkLoopException
|
||||
*/
|
||||
public class LinkLoopException extends LinkException {
|
||||
|
||||
public LinkLoopException(javax.naming.LinkLoopException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI LinkLoopException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.LinkLoopException
|
||||
*/
|
||||
public class LinkLoopException extends LinkException {
|
||||
|
||||
public LinkLoopException(javax.naming.LinkLoopException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI MalformedLinkException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.MalformedLinkException
|
||||
*/
|
||||
public class MalformedLinkException extends LinkException {
|
||||
|
||||
public MalformedLinkException(javax.naming.MalformedLinkException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI MalformedLinkException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.MalformedLinkException
|
||||
*/
|
||||
public class MalformedLinkException extends LinkException {
|
||||
|
||||
public MalformedLinkException(javax.naming.MalformedLinkException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NameAlreadyBoundException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NameAlreadyBoundException
|
||||
*/
|
||||
public class NameAlreadyBoundException extends NamingException {
|
||||
|
||||
public NameAlreadyBoundException(
|
||||
javax.naming.NameAlreadyBoundException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NameAlreadyBoundException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NameAlreadyBoundException
|
||||
*/
|
||||
public class NameAlreadyBoundException extends NamingException {
|
||||
|
||||
public NameAlreadyBoundException(
|
||||
javax.naming.NameAlreadyBoundException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NameNotFoundException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NameNotFoundException
|
||||
*/
|
||||
public class NameNotFoundException extends NamingException {
|
||||
|
||||
public NameNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public NameNotFoundException(javax.naming.NameNotFoundException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NameNotFoundException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NameNotFoundException
|
||||
*/
|
||||
public class NameNotFoundException extends NamingException {
|
||||
|
||||
public NameNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public NameNotFoundException(javax.naming.NameNotFoundException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,186 +1,186 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
|
||||
/**
|
||||
* Base class for exception thrown by the framework whenever it encounters a
|
||||
* problem related to LDAP.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public abstract class NamingException extends NestedRuntimeException {
|
||||
|
||||
private Throwable cause;
|
||||
|
||||
/**
|
||||
* Overrides {@link NestedRuntimeException#getCause()} since serialization
|
||||
* always tries to serialize the base class before the subclass. Our
|
||||
* <tt>cause</tt> may have a <tt>resolvedObj</tt> that is not
|
||||
* serializable. By storing the cause in this class, we get a chance at
|
||||
* temporarily nulling the cause before serialization, thus in effect making
|
||||
* the current instance serializable.
|
||||
*/
|
||||
public Throwable getCause() {
|
||||
// Even if you cannot set the cause of this exception other than through
|
||||
// the constructor, we check for the cause being "this" here, as the cause
|
||||
// could still be set to "this" via reflection: for example, by a remoting
|
||||
// deserializer like Hessian's.
|
||||
return (this.cause == this ? null : this.cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes a message.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public NamingException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows a message and a root cause.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
* @param cause
|
||||
* the cause of the exception. This argument is generally
|
||||
* expected to be a proper subclass of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*/
|
||||
public NamingException(String msg, Throwable cause) {
|
||||
super(msg);
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows a plain root cause, intended for subclasses
|
||||
* mirroring corresponding <code>javax.naming</code> exceptions.
|
||||
*
|
||||
* @param cause
|
||||
* the cause of the exception. This argument is generally
|
||||
* expected to be a proper subclass of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*/
|
||||
public NamingException(Throwable cause) {
|
||||
this(cause != null ? cause.getMessage() : null, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the explanation associated with this exception,
|
||||
* if the root cause was an instance of {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return a detail string explaining more about this exception if the root
|
||||
* cause is an instance of javax.naming.NamingException, or
|
||||
* <code>null</code> if there is no detail message for this
|
||||
* exception
|
||||
*/
|
||||
public String getExplanation() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause()).getExplanation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the unresolved part of the name associated with
|
||||
* this exception, if the root cause was an instance of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return a composite name describing the part of the name that has not
|
||||
* been resolved if the root cause is an instance of
|
||||
* javax.naming.NamingException, or <code>null</code> if the
|
||||
* remaining name field has not been set
|
||||
*/
|
||||
public Name getRemainingName() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause())
|
||||
.getRemainingName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the leading portion of the resolved name
|
||||
* associated with this exception, if the root cause was an instance of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return a composite name describing the leading portion of the name
|
||||
* that was resolved successfully if the root cause is an instance
|
||||
* of javax.naming.NamingException, or <code>null</code> if the
|
||||
* resolved name field has not been set
|
||||
*/
|
||||
public Name getResolvedName() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause())
|
||||
.getResolvedName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the resolved object associated with this
|
||||
* exception, if the root cause was an instance of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return the object that was resolved so far if the root cause is an
|
||||
* instance of javax.naming.NamingException, or <code>null</code>
|
||||
* if the resolved object field has not been set
|
||||
*/
|
||||
public Object getResolvedObj() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause()).getResolvedObj();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the <tt>resolvedObj</tt> of the causing exception is
|
||||
* suspected to be non-serializable, and if so temporarily nulls it before
|
||||
* calling the default serialization mechanism.
|
||||
*
|
||||
* @param stream
|
||||
* the stream onto which this object is serialized
|
||||
* @throws IOException
|
||||
* if there is an error writing this object to the stream
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||
Object resolvedObj = getResolvedObj();
|
||||
boolean serializable = resolvedObj instanceof Serializable;
|
||||
if (resolvedObj != null && !serializable) {
|
||||
// the cause is of this type, since resolvedObj is not null
|
||||
javax.naming.NamingException namingException = (javax.naming.NamingException) getCause();
|
||||
namingException.setResolvedObj(null);
|
||||
try {
|
||||
stream.defaultWriteObject();
|
||||
} finally {
|
||||
namingException.setResolvedObj(resolvedObj);
|
||||
}
|
||||
} else {
|
||||
stream.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
|
||||
/**
|
||||
* Base class for exception thrown by the framework whenever it encounters a
|
||||
* problem related to LDAP.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public abstract class NamingException extends NestedRuntimeException {
|
||||
|
||||
private Throwable cause;
|
||||
|
||||
/**
|
||||
* Overrides {@link NestedRuntimeException#getCause()} since serialization
|
||||
* always tries to serialize the base class before the subclass. Our
|
||||
* <tt>cause</tt> may have a <tt>resolvedObj</tt> that is not
|
||||
* serializable. By storing the cause in this class, we get a chance at
|
||||
* temporarily nulling the cause before serialization, thus in effect making
|
||||
* the current instance serializable.
|
||||
*/
|
||||
public Throwable getCause() {
|
||||
// Even if you cannot set the cause of this exception other than through
|
||||
// the constructor, we check for the cause being "this" here, as the cause
|
||||
// could still be set to "this" via reflection: for example, by a remoting
|
||||
// deserializer like Hessian's.
|
||||
return (this.cause == this ? null : this.cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes a message.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public NamingException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows a message and a root cause.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
* @param cause
|
||||
* the cause of the exception. This argument is generally
|
||||
* expected to be a proper subclass of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*/
|
||||
public NamingException(String msg, Throwable cause) {
|
||||
super(msg);
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows a plain root cause, intended for subclasses
|
||||
* mirroring corresponding <code>javax.naming</code> exceptions.
|
||||
*
|
||||
* @param cause
|
||||
* the cause of the exception. This argument is generally
|
||||
* expected to be a proper subclass of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*/
|
||||
public NamingException(Throwable cause) {
|
||||
this(cause != null ? cause.getMessage() : null, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the explanation associated with this exception,
|
||||
* if the root cause was an instance of {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return a detail string explaining more about this exception if the root
|
||||
* cause is an instance of javax.naming.NamingException, or
|
||||
* <code>null</code> if there is no detail message for this
|
||||
* exception
|
||||
*/
|
||||
public String getExplanation() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause()).getExplanation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the unresolved part of the name associated with
|
||||
* this exception, if the root cause was an instance of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return a composite name describing the part of the name that has not
|
||||
* been resolved if the root cause is an instance of
|
||||
* javax.naming.NamingException, or <code>null</code> if the
|
||||
* remaining name field has not been set
|
||||
*/
|
||||
public Name getRemainingName() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause())
|
||||
.getRemainingName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the leading portion of the resolved name
|
||||
* associated with this exception, if the root cause was an instance of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return a composite name describing the leading portion of the name
|
||||
* that was resolved successfully if the root cause is an instance
|
||||
* of javax.naming.NamingException, or <code>null</code> if the
|
||||
* resolved name field has not been set
|
||||
*/
|
||||
public Name getResolvedName() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause())
|
||||
.getResolvedName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the resolved object associated with this
|
||||
* exception, if the root cause was an instance of
|
||||
* {@link javax.naming.NamingException}.
|
||||
*
|
||||
* @return the object that was resolved so far if the root cause is an
|
||||
* instance of javax.naming.NamingException, or <code>null</code>
|
||||
* if the resolved object field has not been set
|
||||
*/
|
||||
public Object getResolvedObj() {
|
||||
if (getCause() instanceof javax.naming.NamingException) {
|
||||
return ((javax.naming.NamingException) getCause()).getResolvedObj();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the <tt>resolvedObj</tt> of the causing exception is
|
||||
* suspected to be non-serializable, and if so temporarily nulls it before
|
||||
* calling the default serialization mechanism.
|
||||
*
|
||||
* @param stream
|
||||
* the stream onto which this object is serialized
|
||||
* @throws IOException
|
||||
* if there is an error writing this object to the stream
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||
Object resolvedObj = getResolvedObj();
|
||||
boolean serializable = resolvedObj instanceof Serializable;
|
||||
if (resolvedObj != null && !serializable) {
|
||||
// the cause is of this type, since resolvedObj is not null
|
||||
javax.naming.NamingException namingException = (javax.naming.NamingException) getCause();
|
||||
namingException.setResolvedObj(null);
|
||||
try {
|
||||
stream.defaultWriteObject();
|
||||
} finally {
|
||||
namingException.setResolvedObj(resolvedObj);
|
||||
}
|
||||
} else {
|
||||
stream.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NamingSecurityException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NamingSecurityException
|
||||
*/
|
||||
public class NamingSecurityException extends NamingException {
|
||||
|
||||
public NamingSecurityException(javax.naming.NamingSecurityException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NamingSecurityException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NamingSecurityException
|
||||
*/
|
||||
public class NamingSecurityException extends NamingException {
|
||||
|
||||
public NamingSecurityException(javax.naming.NamingSecurityException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NoInitialContextException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NoInitialContextException
|
||||
*/
|
||||
public class NoInitialContextException extends NamingException {
|
||||
|
||||
public NoInitialContextException(
|
||||
javax.naming.NoInitialContextException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NoInitialContextException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NoInitialContextException
|
||||
*/
|
||||
public class NoInitialContextException extends NamingException {
|
||||
|
||||
public NoInitialContextException(
|
||||
javax.naming.NoInitialContextException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NoPermissionException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NoPermissionException
|
||||
*/
|
||||
public class NoPermissionException extends NamingSecurityException {
|
||||
|
||||
public NoPermissionException(javax.naming.NoPermissionException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NoPermissionException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NoPermissionException
|
||||
*/
|
||||
public class NoPermissionException extends NamingSecurityException {
|
||||
|
||||
public NoPermissionException(javax.naming.NoPermissionException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NoSuchAttributeException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.NoSuchAttributeException
|
||||
*/
|
||||
public class NoSuchAttributeException extends NamingException {
|
||||
|
||||
public NoSuchAttributeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NoSuchAttributeException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.NoSuchAttributeException
|
||||
*/
|
||||
public class NoSuchAttributeException extends NamingException {
|
||||
|
||||
public NoSuchAttributeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NotContextException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NotContextException
|
||||
*/
|
||||
public class NotContextException extends NamingException {
|
||||
|
||||
public NotContextException(javax.naming.NotContextException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI NotContextException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.NotContextException
|
||||
*/
|
||||
public class NotContextException extends NamingException {
|
||||
|
||||
public NotContextException(javax.naming.NotContextException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI OperationNotSupportedException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.OperationNotSupportedException
|
||||
*/
|
||||
public class OperationNotSupportedException extends NamingException {
|
||||
|
||||
public OperationNotSupportedException(
|
||||
javax.naming.OperationNotSupportedException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI OperationNotSupportedException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.OperationNotSupportedException
|
||||
*/
|
||||
public class OperationNotSupportedException extends NamingException {
|
||||
|
||||
public OperationNotSupportedException(
|
||||
javax.naming.OperationNotSupportedException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI PartialResultException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.PartialResultException
|
||||
*/
|
||||
public class PartialResultException extends NamingException {
|
||||
|
||||
public PartialResultException(javax.naming.PartialResultException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI PartialResultException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.PartialResultException
|
||||
*/
|
||||
public class PartialResultException extends NamingException {
|
||||
|
||||
public PartialResultException(javax.naming.PartialResultException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ReferralException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ReferralException
|
||||
*/
|
||||
public class ReferralException extends NamingException {
|
||||
|
||||
public ReferralException(javax.naming.ReferralException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ReferralException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ReferralException
|
||||
*/
|
||||
public class ReferralException extends NamingException {
|
||||
|
||||
public ReferralException(javax.naming.ReferralException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI SchemaViolationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.SchemaViolationException
|
||||
*/
|
||||
public class SchemaViolationException extends NamingException {
|
||||
|
||||
public SchemaViolationException(
|
||||
javax.naming.directory.SchemaViolationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI SchemaViolationException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.directory.SchemaViolationException
|
||||
*/
|
||||
public class SchemaViolationException extends NamingException {
|
||||
|
||||
public SchemaViolationException(
|
||||
javax.naming.directory.SchemaViolationException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ServiceUnavailableException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ServiceUnavailableException
|
||||
*/
|
||||
public class ServiceUnavailableException extends NamingException {
|
||||
|
||||
public ServiceUnavailableException(
|
||||
javax.naming.ServiceUnavailableException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI ServiceUnavailableException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.ServiceUnavailableException
|
||||
*/
|
||||
public class ServiceUnavailableException extends NamingException {
|
||||
|
||||
public ServiceUnavailableException(
|
||||
javax.naming.ServiceUnavailableException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI SizeLimitExceededException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.SizeLimitExceededException
|
||||
*/
|
||||
public class SizeLimitExceededException extends LimitExceededException {
|
||||
|
||||
public SizeLimitExceededException(
|
||||
javax.naming.SizeLimitExceededException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI SizeLimitExceededException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.SizeLimitExceededException
|
||||
*/
|
||||
public class SizeLimitExceededException extends LimitExceededException {
|
||||
|
||||
public SizeLimitExceededException(
|
||||
javax.naming.SizeLimitExceededException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI TimeLimitExceededException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.TimeLimitExceededException
|
||||
*/
|
||||
public class TimeLimitExceededException extends LimitExceededException {
|
||||
|
||||
public TimeLimitExceededException(
|
||||
javax.naming.TimeLimitExceededException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Runtime exception mirroring the JNDI TimeLimitExceededException.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
* @see javax.naming.TimeLimitExceededException
|
||||
*/
|
||||
public class TimeLimitExceededException extends LimitExceededException {
|
||||
|
||||
public TimeLimitExceededException(
|
||||
javax.naming.TimeLimitExceededException cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* NamingException to be thrown when no other matching subclass is found.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public class UncategorizedLdapException extends NamingException {
|
||||
|
||||
public UncategorizedLdapException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public UncategorizedLdapException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public UncategorizedLdapException(Throwable cause) {
|
||||
super("Uncategorized exception occured during LDAP processing", cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* NamingException to be thrown when no other matching subclass is found.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public class UncategorizedLdapException extends NamingException {
|
||||
|
||||
public UncategorizedLdapException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public UncategorizedLdapException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public UncategorizedLdapException(Throwable cause) {
|
||||
super("Uncategorized exception occured during LDAP processing", cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,156 +1,156 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.authentication;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.ldap.core.AuthenticationSource;
|
||||
|
||||
/**
|
||||
* Decorator on AuthenticationSource to have default authentication information
|
||||
* be returned should the target return empty principal and credentials. Useful
|
||||
* in combination with <code>AcegiAuthenticationSource</code> if users are to be
|
||||
* allowed to read some information even though they are not logged in.
|
||||
* <p>
|
||||
* <b>Note:</b> The <code>defaultUser</code> should be an non-privileged
|
||||
* user. This is important as this is the one that will be used when no user is
|
||||
* logged in (i.e. empty principal is returned from the target
|
||||
* AuthenticationSource).
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public class DefaultValuesAuthenticationSourceDecorator implements
|
||||
AuthenticationSource, InitializingBean {
|
||||
|
||||
private AuthenticationSource target;
|
||||
|
||||
private String defaultUser;
|
||||
|
||||
private String defaultPassword;
|
||||
|
||||
/**
|
||||
* Constructor for bean usage.
|
||||
*/
|
||||
public DefaultValuesAuthenticationSourceDecorator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to setup instance directly.
|
||||
*
|
||||
* @param target
|
||||
* the target AuthenticationSource.
|
||||
* @param defaultUser
|
||||
* dn of the user to use when the target returns an empty
|
||||
* principal.
|
||||
* @param defaultPassword
|
||||
* password of the user to use when the target returns an empty
|
||||
* principal.
|
||||
*/
|
||||
public DefaultValuesAuthenticationSourceDecorator(
|
||||
AuthenticationSource target, String defaultUser,
|
||||
String defaultPassword) {
|
||||
this.target = target;
|
||||
this.defaultUser = defaultUser;
|
||||
this.defaultPassword = defaultPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the target's principal is not empty; if not, the credentials
|
||||
* from the target is returned - otherwise return the
|
||||
* <code>defaultPassword</code>.
|
||||
*
|
||||
* @return the target's password if the target's principal is not empty, the
|
||||
* <code>defaultPassword</code> otherwise.
|
||||
*/
|
||||
public String getCredentials() {
|
||||
if (StringUtils.hasText(target.getPrincipal())) {
|
||||
return target.getCredentials();
|
||||
} else {
|
||||
return defaultPassword;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the target's principal is not empty; if not, this is returned -
|
||||
* otherwise return the <code>defaultPassword</code>.
|
||||
*
|
||||
* @return the target's principal if it is not empty, the
|
||||
* <code>defaultPassword</code> otherwise.
|
||||
*/
|
||||
public String getPrincipal() {
|
||||
String principal = target.getPrincipal();
|
||||
if (StringUtils.hasText(principal)) {
|
||||
return principal;
|
||||
} else {
|
||||
return defaultUser;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the password of the default user.
|
||||
*
|
||||
* @param defaultPassword
|
||||
* the password of the default user.
|
||||
*/
|
||||
public void setDefaultPassword(String defaultPassword) {
|
||||
this.defaultPassword = defaultPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default user DN. This should be a non-privileged user, since it
|
||||
* will be used when no authentication information is returned from the
|
||||
* target.
|
||||
*
|
||||
* @param defaultUser
|
||||
* DN of the default user.
|
||||
*/
|
||||
public void setDefaultUser(String defaultUser) {
|
||||
this.defaultUser = defaultUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target AuthenticationSource.
|
||||
*
|
||||
* @param target
|
||||
* the target AuthenticationSource.
|
||||
*/
|
||||
public void setTarget(AuthenticationSource target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Property 'target' must be set.'");
|
||||
}
|
||||
|
||||
if (defaultUser == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Property 'defaultUser' must be set.'");
|
||||
}
|
||||
|
||||
if (defaultPassword == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Property 'defaultPassword' must be set.'");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.authentication;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.ldap.core.AuthenticationSource;
|
||||
|
||||
/**
|
||||
* Decorator on AuthenticationSource to have default authentication information
|
||||
* be returned should the target return empty principal and credentials. Useful
|
||||
* in combination with <code>AcegiAuthenticationSource</code> if users are to be
|
||||
* allowed to read some information even though they are not logged in.
|
||||
* <p>
|
||||
* <b>Note:</b> The <code>defaultUser</code> should be an non-privileged
|
||||
* user. This is important as this is the one that will be used when no user is
|
||||
* logged in (i.e. empty principal is returned from the target
|
||||
* AuthenticationSource).
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public class DefaultValuesAuthenticationSourceDecorator implements
|
||||
AuthenticationSource, InitializingBean {
|
||||
|
||||
private AuthenticationSource target;
|
||||
|
||||
private String defaultUser;
|
||||
|
||||
private String defaultPassword;
|
||||
|
||||
/**
|
||||
* Constructor for bean usage.
|
||||
*/
|
||||
public DefaultValuesAuthenticationSourceDecorator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to setup instance directly.
|
||||
*
|
||||
* @param target
|
||||
* the target AuthenticationSource.
|
||||
* @param defaultUser
|
||||
* dn of the user to use when the target returns an empty
|
||||
* principal.
|
||||
* @param defaultPassword
|
||||
* password of the user to use when the target returns an empty
|
||||
* principal.
|
||||
*/
|
||||
public DefaultValuesAuthenticationSourceDecorator(
|
||||
AuthenticationSource target, String defaultUser,
|
||||
String defaultPassword) {
|
||||
this.target = target;
|
||||
this.defaultUser = defaultUser;
|
||||
this.defaultPassword = defaultPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the target's principal is not empty; if not, the credentials
|
||||
* from the target is returned - otherwise return the
|
||||
* <code>defaultPassword</code>.
|
||||
*
|
||||
* @return the target's password if the target's principal is not empty, the
|
||||
* <code>defaultPassword</code> otherwise.
|
||||
*/
|
||||
public String getCredentials() {
|
||||
if (StringUtils.hasText(target.getPrincipal())) {
|
||||
return target.getCredentials();
|
||||
} else {
|
||||
return defaultPassword;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the target's principal is not empty; if not, this is returned -
|
||||
* otherwise return the <code>defaultPassword</code>.
|
||||
*
|
||||
* @return the target's principal if it is not empty, the
|
||||
* <code>defaultPassword</code> otherwise.
|
||||
*/
|
||||
public String getPrincipal() {
|
||||
String principal = target.getPrincipal();
|
||||
if (StringUtils.hasText(principal)) {
|
||||
return principal;
|
||||
} else {
|
||||
return defaultUser;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the password of the default user.
|
||||
*
|
||||
* @param defaultPassword
|
||||
* the password of the default user.
|
||||
*/
|
||||
public void setDefaultPassword(String defaultPassword) {
|
||||
this.defaultPassword = defaultPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default user DN. This should be a non-privileged user, since it
|
||||
* will be used when no authentication information is returned from the
|
||||
* target.
|
||||
*
|
||||
* @param defaultUser
|
||||
* DN of the default user.
|
||||
*/
|
||||
public void setDefaultUser(String defaultUser) {
|
||||
this.defaultUser = defaultUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target AuthenticationSource.
|
||||
*
|
||||
* @param target
|
||||
* the target AuthenticationSource.
|
||||
*/
|
||||
public void setTarget(AuthenticationSource target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Property 'target' must be set.'");
|
||||
}
|
||||
|
||||
if (defaultUser == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Property 'defaultUser' must be set.'");
|
||||
}
|
||||
|
||||
if (defaultPassword == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Property 'defaultPassword' must be set.'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
/**
|
||||
* Thrown by an AbstractRequestControlDirContextProcessor when it cannot create
|
||||
* a request control.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public class CreateControlFailedException extends NamingException {
|
||||
|
||||
/**
|
||||
* Create a new CreateControlFailedException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public CreateControlFailedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new CreateControlFailedException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
* @param cause
|
||||
* the root cause (if any)
|
||||
*/
|
||||
public CreateControlFailedException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
/**
|
||||
* Thrown by an AbstractRequestControlDirContextProcessor when it cannot create
|
||||
* a request control.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public class CreateControlFailedException extends NamingException {
|
||||
|
||||
/**
|
||||
* Create a new CreateControlFailedException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*/
|
||||
public CreateControlFailedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new CreateControlFailedException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
* @param cause
|
||||
* the root cause (if any)
|
||||
*/
|
||||
public CreateControlFailedException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Bean to encapsulate a result List and a {@link PagedResultsCookie} to use for
|
||||
* returning the results when using {@link PagedResultsRequestControl}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
* @deprecated
|
||||
*/
|
||||
public class PagedResult {
|
||||
|
||||
private List<?> resultList;
|
||||
|
||||
private PagedResultsCookie cookie;
|
||||
|
||||
/**
|
||||
* Constructs a PagedResults using the supplied List and
|
||||
* {@link PagedResultsCookie}.
|
||||
*
|
||||
* @param resultList
|
||||
* the result list.
|
||||
* @param cookie
|
||||
* the cookie.
|
||||
*/
|
||||
public PagedResult(List<?> resultList, PagedResultsCookie cookie) {
|
||||
this.resultList = resultList;
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie.
|
||||
*/
|
||||
public PagedResultsCookie getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result list.
|
||||
*
|
||||
* @return the result list.
|
||||
*/
|
||||
public List<?> getResultList() {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PagedResult that = (PagedResult) o;
|
||||
|
||||
if (cookie != null ? !cookie.equals(that.cookie) : that.cookie != null) return false;
|
||||
if (resultList != null ? !resultList.equals(that.resultList) : that.resultList != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = resultList != null ? resultList.hashCode() : 0;
|
||||
result = 31 * result + (cookie != null ? cookie.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Bean to encapsulate a result List and a {@link PagedResultsCookie} to use for
|
||||
* returning the results when using {@link PagedResultsRequestControl}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
* @deprecated
|
||||
*/
|
||||
public class PagedResult {
|
||||
|
||||
private List<?> resultList;
|
||||
|
||||
private PagedResultsCookie cookie;
|
||||
|
||||
/**
|
||||
* Constructs a PagedResults using the supplied List and
|
||||
* {@link PagedResultsCookie}.
|
||||
*
|
||||
* @param resultList
|
||||
* the result list.
|
||||
* @param cookie
|
||||
* the cookie.
|
||||
*/
|
||||
public PagedResult(List<?> resultList, PagedResultsCookie cookie) {
|
||||
this.resultList = resultList;
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie.
|
||||
*/
|
||||
public PagedResultsCookie getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result list.
|
||||
*
|
||||
* @return the result list.
|
||||
*/
|
||||
public List<?> getResultList() {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PagedResult that = (PagedResult) o;
|
||||
|
||||
if (cookie != null ? !cookie.equals(that.cookie) : that.cookie != null) return false;
|
||||
if (resultList != null ? !resultList.equals(that.resultList) : that.resultList != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = resultList != null ? resultList.hashCode() : 0;
|
||||
result = 31 * result + (cookie != null ? cookie.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import javax.naming.ldap.PagedResultsControl;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Wrapper class for the cookie returned when using the
|
||||
* {@link PagedResultsControl}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PagedResultsCookie {
|
||||
|
||||
private byte[] cookie;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param cookie
|
||||
* the cookie returned by a PagedResultsResponseControl.
|
||||
*/
|
||||
public PagedResultsCookie(byte[] cookie) {
|
||||
if (cookie != null) {
|
||||
this.cookie = Arrays.copyOf(cookie, cookie.length);
|
||||
} else {
|
||||
this.cookie = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie. This value may be <code>null</code>, indicating that there are no more requests,
|
||||
* or that the control wasn't supported by the server.
|
||||
*/
|
||||
public byte[] getCookie() {
|
||||
if (cookie != null) {
|
||||
return Arrays.copyOf(cookie, cookie.length);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PagedResultsCookie that = (PagedResultsCookie) o;
|
||||
|
||||
if (!Arrays.equals(cookie, that.cookie)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return cookie != null ? Arrays.hashCode(cookie) : 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import javax.naming.ldap.PagedResultsControl;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Wrapper class for the cookie returned when using the
|
||||
* {@link PagedResultsControl}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PagedResultsCookie {
|
||||
|
||||
private byte[] cookie;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param cookie
|
||||
* the cookie returned by a PagedResultsResponseControl.
|
||||
*/
|
||||
public PagedResultsCookie(byte[] cookie) {
|
||||
if (cookie != null) {
|
||||
this.cookie = Arrays.copyOf(cookie, cookie.length);
|
||||
} else {
|
||||
this.cookie = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie. This value may be <code>null</code>, indicating that there are no more requests,
|
||||
* or that the control wasn't supported by the server.
|
||||
*/
|
||||
public byte[] getCookie() {
|
||||
if (cookie != null) {
|
||||
return Arrays.copyOf(cookie, cookie.length);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PagedResultsCookie that = (PagedResultsCookie) o;
|
||||
|
||||
if (!Arrays.equals(cookie, that.cookie)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return cookie != null ? Arrays.hashCode(cookie) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,155 +1,155 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import javax.naming.ldap.Control;
|
||||
|
||||
/**
|
||||
* DirContextProcessor implementation for managing the paged results control.
|
||||
* Note that due to the internal workings of <code>LdapTemplate</code>, the
|
||||
* target connection is closed after each LDAP call. The PagedResults control
|
||||
* require the same connection be used for each call, which means we need to
|
||||
* make sure the target connection is never actually closed. There's basically
|
||||
* two ways of making this happen: use the <code>SingleContextSource</code>
|
||||
* implementation or make sure all calls happen within a single LDAP transaction
|
||||
* (using <code>ContextSourceTransactionManager</code>).
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PagedResultsDirContextProcessor extends AbstractFallbackRequestAndResponseControlDirContextProcessor {
|
||||
|
||||
private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.PagedResultsControl";
|
||||
|
||||
private static final String FALLBACK_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsControl";
|
||||
|
||||
private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.PagedResultsResponseControl";
|
||||
|
||||
private static final String FALLBACK_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsResponseControl";
|
||||
|
||||
private int pageSize;
|
||||
|
||||
private PagedResultsCookie cookie;
|
||||
|
||||
private int resultSize;
|
||||
|
||||
private boolean more = true;
|
||||
|
||||
/**
|
||||
* Constructs a new instance. This constructor should be used when
|
||||
* performing the first paged search operation, when no other results have
|
||||
* been retrieved.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
*/
|
||||
public PagedResultsDirContextProcessor(int pageSize) {
|
||||
this(pageSize, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance with the supplied page size and cookie. The
|
||||
* cookie must be the exact same instance as received from a previous paged
|
||||
* results search, or <code>null</code> if it is the first in an operation
|
||||
* sequence.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
* @param cookie the cookie, as received from a previous search.
|
||||
*/
|
||||
public PagedResultsDirContextProcessor(int pageSize, PagedResultsCookie cookie) {
|
||||
this.pageSize = pageSize;
|
||||
this.cookie = cookie;
|
||||
|
||||
defaultRequestControl = DEFAULT_REQUEST_CONTROL;
|
||||
defaultResponseControl = DEFAULT_RESPONSE_CONTROL;
|
||||
fallbackRequestControl = FALLBACK_REQUEST_CONTROL;
|
||||
fallbackResponseControl = FALLBACK_RESPONSE_CONTROL;
|
||||
|
||||
loadControlClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie. The cookie will always be set after at leas one query, however the actual cookie content
|
||||
* can be <code>null</code>, indicating that there are no more results, in which case {@link #hasMore()} will return
|
||||
* <code>false</code>.
|
||||
* @see #hasMore()
|
||||
*/
|
||||
public PagedResultsCookie getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page size.
|
||||
*
|
||||
* @return the page size.
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total estimated number of entries that matches the issued search.
|
||||
* Note that this value is optional for the LDAP server to return, so it
|
||||
* does not always contain any valid data.
|
||||
*
|
||||
* @return the estimated result size, if returned from the server.
|
||||
*/
|
||||
public int getResultSize() {
|
||||
return resultSize;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
|
||||
* #createRequestControl()
|
||||
*/
|
||||
public Control createRequestControl() {
|
||||
byte[] actualCookie = null;
|
||||
if (cookie != null) {
|
||||
actualCookie = cookie.getCookie();
|
||||
}
|
||||
return super.createRequestControl(new Class<?>[] { int.class, byte[].class, boolean.class },
|
||||
new Object[] {pageSize, actualCookie, critical});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there are more results to retrieved. When there are no more results to retrieve,
|
||||
* this is indicated by a <code>null</code> cookie being returned from the server.
|
||||
* When this happen, the internal status will set to false.
|
||||
*
|
||||
* @return <code>true</code> if there are more results to retrieve, <code>false</code> otherwise.
|
||||
* @since 2.0
|
||||
*/
|
||||
public boolean hasMore() {
|
||||
return more;
|
||||
}
|
||||
|
||||
/*
|
||||
* @seeorg.springframework.ldap.control.
|
||||
* AbstractFallbackRequestAndResponseControlDirContextProcessor
|
||||
* #handleResponse(java.lang.Object)
|
||||
*/
|
||||
protected void handleResponse(Object control) {
|
||||
byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control);
|
||||
if(result == null) {
|
||||
more = false;
|
||||
}
|
||||
this.cookie = new PagedResultsCookie(result);
|
||||
this.resultSize = (Integer) invokeMethod("getResultSize", responseControlClass, control);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import javax.naming.ldap.Control;
|
||||
|
||||
/**
|
||||
* DirContextProcessor implementation for managing the paged results control.
|
||||
* Note that due to the internal workings of <code>LdapTemplate</code>, the
|
||||
* target connection is closed after each LDAP call. The PagedResults control
|
||||
* require the same connection be used for each call, which means we need to
|
||||
* make sure the target connection is never actually closed. There's basically
|
||||
* two ways of making this happen: use the <code>SingleContextSource</code>
|
||||
* implementation or make sure all calls happen within a single LDAP transaction
|
||||
* (using <code>ContextSourceTransactionManager</code>).
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PagedResultsDirContextProcessor extends AbstractFallbackRequestAndResponseControlDirContextProcessor {
|
||||
|
||||
private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.PagedResultsControl";
|
||||
|
||||
private static final String FALLBACK_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsControl";
|
||||
|
||||
private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.PagedResultsResponseControl";
|
||||
|
||||
private static final String FALLBACK_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsResponseControl";
|
||||
|
||||
private int pageSize;
|
||||
|
||||
private PagedResultsCookie cookie;
|
||||
|
||||
private int resultSize;
|
||||
|
||||
private boolean more = true;
|
||||
|
||||
/**
|
||||
* Constructs a new instance. This constructor should be used when
|
||||
* performing the first paged search operation, when no other results have
|
||||
* been retrieved.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
*/
|
||||
public PagedResultsDirContextProcessor(int pageSize) {
|
||||
this(pageSize, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance with the supplied page size and cookie. The
|
||||
* cookie must be the exact same instance as received from a previous paged
|
||||
* results search, or <code>null</code> if it is the first in an operation
|
||||
* sequence.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
* @param cookie the cookie, as received from a previous search.
|
||||
*/
|
||||
public PagedResultsDirContextProcessor(int pageSize, PagedResultsCookie cookie) {
|
||||
this.pageSize = pageSize;
|
||||
this.cookie = cookie;
|
||||
|
||||
defaultRequestControl = DEFAULT_REQUEST_CONTROL;
|
||||
defaultResponseControl = DEFAULT_RESPONSE_CONTROL;
|
||||
fallbackRequestControl = FALLBACK_REQUEST_CONTROL;
|
||||
fallbackResponseControl = FALLBACK_RESPONSE_CONTROL;
|
||||
|
||||
loadControlClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie. The cookie will always be set after at leas one query, however the actual cookie content
|
||||
* can be <code>null</code>, indicating that there are no more results, in which case {@link #hasMore()} will return
|
||||
* <code>false</code>.
|
||||
* @see #hasMore()
|
||||
*/
|
||||
public PagedResultsCookie getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page size.
|
||||
*
|
||||
* @return the page size.
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total estimated number of entries that matches the issued search.
|
||||
* Note that this value is optional for the LDAP server to return, so it
|
||||
* does not always contain any valid data.
|
||||
*
|
||||
* @return the estimated result size, if returned from the server.
|
||||
*/
|
||||
public int getResultSize() {
|
||||
return resultSize;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
|
||||
* #createRequestControl()
|
||||
*/
|
||||
public Control createRequestControl() {
|
||||
byte[] actualCookie = null;
|
||||
if (cookie != null) {
|
||||
actualCookie = cookie.getCookie();
|
||||
}
|
||||
return super.createRequestControl(new Class<?>[] { int.class, byte[].class, boolean.class },
|
||||
new Object[] {pageSize, actualCookie, critical});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there are more results to retrieved. When there are no more results to retrieve,
|
||||
* this is indicated by a <code>null</code> cookie being returned from the server.
|
||||
* When this happen, the internal status will set to false.
|
||||
*
|
||||
* @return <code>true</code> if there are more results to retrieve, <code>false</code> otherwise.
|
||||
* @since 2.0
|
||||
*/
|
||||
public boolean hasMore() {
|
||||
return more;
|
||||
}
|
||||
|
||||
/*
|
||||
* @seeorg.springframework.ldap.control.
|
||||
* AbstractFallbackRequestAndResponseControlDirContextProcessor
|
||||
* #handleResponse(java.lang.Object)
|
||||
*/
|
||||
protected void handleResponse(Object control) {
|
||||
byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control);
|
||||
if(result == null) {
|
||||
more = false;
|
||||
}
|
||||
this.cookie = new PagedResultsCookie(result);
|
||||
this.resultSize = (Integer) invokeMethod("getResultSize", responseControlClass, control);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,223 +1,223 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import org.springframework.ldap.UncategorizedLdapException;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.ldap.Control;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* DirContextProcessor implementation for managing the paged results control.
|
||||
* Note that due to the internal workings of <code>LdapTemplate</code>, the
|
||||
* target connection is closed after each LDAP call. The PagedResults control
|
||||
* require the same connection be used for each call, which means we need to
|
||||
* make sure the target connection is never actually closed. There's basically
|
||||
* two ways of making this happen: use the <code>SingleContextSource</code>
|
||||
* implementation or make sure all calls happen within a single LDAP transaction
|
||||
* (using <code>ContextSourceTransactionManager</code>).
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
* @deprecated Use PagedResultsDirContextProcessor instead.
|
||||
*/
|
||||
public class PagedResultsRequestControl extends AbstractRequestControlDirContextProcessor {
|
||||
|
||||
private static final boolean CRITICAL_CONTROL = true;
|
||||
|
||||
private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.PagedResultsControl";
|
||||
|
||||
private static final String LDAPBP_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsControl";
|
||||
|
||||
private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.PagedResultsResponseControl";
|
||||
|
||||
private static final String LDAPBP_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsResponseControl";
|
||||
|
||||
private int pageSize;
|
||||
|
||||
private PagedResultsCookie cookie;
|
||||
|
||||
private int resultSize;
|
||||
|
||||
private boolean critical = CRITICAL_CONTROL;
|
||||
|
||||
private Class responseControlClass;
|
||||
|
||||
private Class requestControlClass;
|
||||
|
||||
/**
|
||||
* Constructs a new instance. This constructor should be used when
|
||||
* performing the first paged search operation, when no other results have
|
||||
* been retrieved.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
*/
|
||||
public PagedResultsRequestControl(int pageSize) {
|
||||
this(pageSize, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance with the supplied page size and cookie. The
|
||||
* cookie must be the exact same instance as received from a previous paged
|
||||
* resullts search, or <code>null</code> if it is the first in an operation
|
||||
* sequence.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
* @param cookie the cookie, as received from a previous search.
|
||||
*/
|
||||
public PagedResultsRequestControl(int pageSize, PagedResultsCookie cookie) {
|
||||
this.pageSize = pageSize;
|
||||
this.cookie = cookie;
|
||||
|
||||
loadControlClasses();
|
||||
}
|
||||
|
||||
private void loadControlClasses() {
|
||||
try {
|
||||
requestControlClass = Class.forName(DEFAULT_REQUEST_CONTROL);
|
||||
responseControlClass = Class.forName(DEFAULT_RESPONSE_CONTROL);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
log.debug("Default control classes not found - falling back to LdapBP classes", e);
|
||||
|
||||
try {
|
||||
requestControlClass = Class.forName(LDAPBP_REQUEST_CONTROL);
|
||||
responseControlClass = Class.forName(LDAPBP_RESPONSE_CONTROL);
|
||||
}
|
||||
catch (ClassNotFoundException e1) {
|
||||
throw new UncategorizedLdapException(
|
||||
"Neither default nor fallback classes are available - unable to proceed", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie.
|
||||
*/
|
||||
public PagedResultsCookie getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page size.
|
||||
*
|
||||
* @return the page size.
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total estimated number of entries that matches the issued search.
|
||||
* Note that this value is optional for the LDAP server to return, so it
|
||||
* does not always contain any valid data.
|
||||
*
|
||||
* @return the estimated result size, if returned from the server.
|
||||
*/
|
||||
public int getResultSize() {
|
||||
return resultSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class of the expected ResponseControl for the paged results
|
||||
* response.
|
||||
*
|
||||
* @param responseControlClass Class of the expected response control.
|
||||
*/
|
||||
public void setResponseControlClass(Class responseControlClass) {
|
||||
this.responseControlClass = responseControlClass;
|
||||
}
|
||||
|
||||
public void setRequestControlClass(Class requestControlClass) {
|
||||
this.requestControlClass = requestControlClass;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
|
||||
* #createRequestControl()
|
||||
*/
|
||||
|
||||
public Control createRequestControl() {
|
||||
byte[] actualCookie = null;
|
||||
if (cookie != null) {
|
||||
actualCookie = cookie.getCookie();
|
||||
}
|
||||
Constructor constructor = ClassUtils.getConstructorIfAvailable(requestControlClass, new Class[] { int.class,
|
||||
byte[].class, boolean.class });
|
||||
if (constructor == null) {
|
||||
throw new IllegalArgumentException("Failed to find an appropriate RequestControl constructor");
|
||||
}
|
||||
|
||||
Control result = null;
|
||||
try {
|
||||
result = (Control) constructor.newInstance(pageSize, actualCookie,
|
||||
critical);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ReflectionUtils.handleReflectionException(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.core.DirContextProcessor#postProcess(javax.naming
|
||||
* .directory.DirContext)
|
||||
*/
|
||||
|
||||
public void postProcess(DirContext ctx) throws NamingException {
|
||||
|
||||
LdapContext ldapContext = (LdapContext) ctx;
|
||||
Control[] responseControls = ldapContext.getResponseControls();
|
||||
if (responseControls == null) {
|
||||
responseControls = new Control[0];
|
||||
}
|
||||
|
||||
// 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;
|
||||
byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control);
|
||||
this.cookie = new PagedResultsCookie(result);
|
||||
Integer wrapper = (Integer) invokeMethod("getResultSize", responseControlClass, control);
|
||||
this.resultSize = wrapper.intValue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
log.error("No matching response control found for paged results - looking for '{}", responseControlClass);
|
||||
}
|
||||
|
||||
private Object invokeMethod(String method, Class clazz, Object control) {
|
||||
Method actualMethod = ReflectionUtils.findMethod(clazz, method);
|
||||
return ReflectionUtils.invokeMethod(actualMethod, control);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import org.springframework.ldap.UncategorizedLdapException;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.ldap.Control;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* DirContextProcessor implementation for managing the paged results control.
|
||||
* Note that due to the internal workings of <code>LdapTemplate</code>, the
|
||||
* target connection is closed after each LDAP call. The PagedResults control
|
||||
* require the same connection be used for each call, which means we need to
|
||||
* make sure the target connection is never actually closed. There's basically
|
||||
* two ways of making this happen: use the <code>SingleContextSource</code>
|
||||
* implementation or make sure all calls happen within a single LDAP transaction
|
||||
* (using <code>ContextSourceTransactionManager</code>).
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
* @deprecated Use PagedResultsDirContextProcessor instead.
|
||||
*/
|
||||
public class PagedResultsRequestControl extends AbstractRequestControlDirContextProcessor {
|
||||
|
||||
private static final boolean CRITICAL_CONTROL = true;
|
||||
|
||||
private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.PagedResultsControl";
|
||||
|
||||
private static final String LDAPBP_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsControl";
|
||||
|
||||
private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.PagedResultsResponseControl";
|
||||
|
||||
private static final String LDAPBP_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsResponseControl";
|
||||
|
||||
private int pageSize;
|
||||
|
||||
private PagedResultsCookie cookie;
|
||||
|
||||
private int resultSize;
|
||||
|
||||
private boolean critical = CRITICAL_CONTROL;
|
||||
|
||||
private Class responseControlClass;
|
||||
|
||||
private Class requestControlClass;
|
||||
|
||||
/**
|
||||
* Constructs a new instance. This constructor should be used when
|
||||
* performing the first paged search operation, when no other results have
|
||||
* been retrieved.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
*/
|
||||
public PagedResultsRequestControl(int pageSize) {
|
||||
this(pageSize, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance with the supplied page size and cookie. The
|
||||
* cookie must be the exact same instance as received from a previous paged
|
||||
* resullts search, or <code>null</code> if it is the first in an operation
|
||||
* sequence.
|
||||
*
|
||||
* @param pageSize the page size.
|
||||
* @param cookie the cookie, as received from a previous search.
|
||||
*/
|
||||
public PagedResultsRequestControl(int pageSize, PagedResultsCookie cookie) {
|
||||
this.pageSize = pageSize;
|
||||
this.cookie = cookie;
|
||||
|
||||
loadControlClasses();
|
||||
}
|
||||
|
||||
private void loadControlClasses() {
|
||||
try {
|
||||
requestControlClass = Class.forName(DEFAULT_REQUEST_CONTROL);
|
||||
responseControlClass = Class.forName(DEFAULT_RESPONSE_CONTROL);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
log.debug("Default control classes not found - falling back to LdapBP classes", e);
|
||||
|
||||
try {
|
||||
requestControlClass = Class.forName(LDAPBP_REQUEST_CONTROL);
|
||||
responseControlClass = Class.forName(LDAPBP_RESPONSE_CONTROL);
|
||||
}
|
||||
catch (ClassNotFoundException e1) {
|
||||
throw new UncategorizedLdapException(
|
||||
"Neither default nor fallback classes are available - unable to proceed", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie.
|
||||
*
|
||||
* @return the cookie.
|
||||
*/
|
||||
public PagedResultsCookie getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page size.
|
||||
*
|
||||
* @return the page size.
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total estimated number of entries that matches the issued search.
|
||||
* Note that this value is optional for the LDAP server to return, so it
|
||||
* does not always contain any valid data.
|
||||
*
|
||||
* @return the estimated result size, if returned from the server.
|
||||
*/
|
||||
public int getResultSize() {
|
||||
return resultSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class of the expected ResponseControl for the paged results
|
||||
* response.
|
||||
*
|
||||
* @param responseControlClass Class of the expected response control.
|
||||
*/
|
||||
public void setResponseControlClass(Class responseControlClass) {
|
||||
this.responseControlClass = responseControlClass;
|
||||
}
|
||||
|
||||
public void setRequestControlClass(Class requestControlClass) {
|
||||
this.requestControlClass = requestControlClass;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
|
||||
* #createRequestControl()
|
||||
*/
|
||||
|
||||
public Control createRequestControl() {
|
||||
byte[] actualCookie = null;
|
||||
if (cookie != null) {
|
||||
actualCookie = cookie.getCookie();
|
||||
}
|
||||
Constructor constructor = ClassUtils.getConstructorIfAvailable(requestControlClass, new Class[] { int.class,
|
||||
byte[].class, boolean.class });
|
||||
if (constructor == null) {
|
||||
throw new IllegalArgumentException("Failed to find an appropriate RequestControl constructor");
|
||||
}
|
||||
|
||||
Control result = null;
|
||||
try {
|
||||
result = (Control) constructor.newInstance(pageSize, actualCookie,
|
||||
critical);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ReflectionUtils.handleReflectionException(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.core.DirContextProcessor#postProcess(javax.naming
|
||||
* .directory.DirContext)
|
||||
*/
|
||||
|
||||
public void postProcess(DirContext ctx) throws NamingException {
|
||||
|
||||
LdapContext ldapContext = (LdapContext) ctx;
|
||||
Control[] responseControls = ldapContext.getResponseControls();
|
||||
if (responseControls == null) {
|
||||
responseControls = new Control[0];
|
||||
}
|
||||
|
||||
// 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;
|
||||
byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control);
|
||||
this.cookie = new PagedResultsCookie(result);
|
||||
Integer wrapper = (Integer) invokeMethod("getResultSize", responseControlClass, control);
|
||||
this.resultSize = wrapper.intValue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
log.error("No matching response control found for paged results - looking for '{}", responseControlClass);
|
||||
}
|
||||
|
||||
private Object invokeMethod(String method, Class clazz, Object control) {
|
||||
Method actualMethod = ReflectionUtils.findMethod(clazz, method);
|
||||
return ReflectionUtils.invokeMethod(actualMethod, control);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import javax.naming.ldap.Control;
|
||||
|
||||
/**
|
||||
* DirContextProcessor implementation for managing the SortControl. Note that
|
||||
* this class is stateful, so a new instance needs to be instantiated for each
|
||||
* new search.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class SortControlDirContextProcessor extends AbstractFallbackRequestAndResponseControlDirContextProcessor {
|
||||
|
||||
private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.SortControl";
|
||||
|
||||
private static final String FALLBACK_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.SortControl";
|
||||
|
||||
private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.SortResponseControl";
|
||||
|
||||
private static final String FALLBACK_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.SortResponseControl";
|
||||
|
||||
/**
|
||||
* What key to sort on.
|
||||
*/
|
||||
String sortKey;
|
||||
|
||||
/**
|
||||
* Whether the search result actually was sorted.
|
||||
*/
|
||||
private boolean sorted;
|
||||
|
||||
/**
|
||||
* The result code of the supposedly sorted search.
|
||||
*/
|
||||
private int resultCode;
|
||||
|
||||
/**
|
||||
* Constructs a new instance using the supplied sort key.
|
||||
*
|
||||
* @param sortKey the sort key, i.e. the attribute name to sort on.
|
||||
*/
|
||||
public SortControlDirContextProcessor(String sortKey) {
|
||||
this.sortKey = sortKey;
|
||||
this.sorted = false;
|
||||
this.resultCode = -1;
|
||||
|
||||
defaultRequestControl = DEFAULT_REQUEST_CONTROL;
|
||||
defaultResponseControl = DEFAULT_RESPONSE_CONTROL;
|
||||
|
||||
fallbackRequestControl = FALLBACK_REQUEST_CONTROL;
|
||||
fallbackResponseControl = FALLBACK_RESPONSE_CONTROL;
|
||||
|
||||
loadControlClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the returned values were actually sorted by the server.
|
||||
*
|
||||
* @return <code>true</code> if the result was sorted, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isSorted() {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result code returned by the control.
|
||||
*
|
||||
* @return result code.
|
||||
*/
|
||||
public int getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sort key.
|
||||
*
|
||||
* @return the sort key.
|
||||
*/
|
||||
public String getSortKey() {
|
||||
return sortKey;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
|
||||
* #createRequestControl()
|
||||
*/
|
||||
public Control createRequestControl() {
|
||||
return super.createRequestControl(new Class<?>[] { String[].class, boolean.class }, new Object[] {
|
||||
new String[] { sortKey }, critical});
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.control.
|
||||
* AbstractFallbackRequestAndResponseControlDirContextProcessor
|
||||
* #handleResponse(java.lang.Object)
|
||||
*/
|
||||
protected void handleResponse(Object control) {
|
||||
this.sorted = (Boolean) invokeMethod("isSorted", responseControlClass, control);
|
||||
this.resultCode = (Integer) invokeMethod("getResultCode", responseControlClass, control);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.control;
|
||||
|
||||
import javax.naming.ldap.Control;
|
||||
|
||||
/**
|
||||
* DirContextProcessor implementation for managing the SortControl. Note that
|
||||
* this class is stateful, so a new instance needs to be instantiated for each
|
||||
* new search.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class SortControlDirContextProcessor extends AbstractFallbackRequestAndResponseControlDirContextProcessor {
|
||||
|
||||
private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.SortControl";
|
||||
|
||||
private static final String FALLBACK_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.SortControl";
|
||||
|
||||
private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.SortResponseControl";
|
||||
|
||||
private static final String FALLBACK_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.SortResponseControl";
|
||||
|
||||
/**
|
||||
* What key to sort on.
|
||||
*/
|
||||
String sortKey;
|
||||
|
||||
/**
|
||||
* Whether the search result actually was sorted.
|
||||
*/
|
||||
private boolean sorted;
|
||||
|
||||
/**
|
||||
* The result code of the supposedly sorted search.
|
||||
*/
|
||||
private int resultCode;
|
||||
|
||||
/**
|
||||
* Constructs a new instance using the supplied sort key.
|
||||
*
|
||||
* @param sortKey the sort key, i.e. the attribute name to sort on.
|
||||
*/
|
||||
public SortControlDirContextProcessor(String sortKey) {
|
||||
this.sortKey = sortKey;
|
||||
this.sorted = false;
|
||||
this.resultCode = -1;
|
||||
|
||||
defaultRequestControl = DEFAULT_REQUEST_CONTROL;
|
||||
defaultResponseControl = DEFAULT_RESPONSE_CONTROL;
|
||||
|
||||
fallbackRequestControl = FALLBACK_REQUEST_CONTROL;
|
||||
fallbackResponseControl = FALLBACK_RESPONSE_CONTROL;
|
||||
|
||||
loadControlClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the returned values were actually sorted by the server.
|
||||
*
|
||||
* @return <code>true</code> if the result was sorted, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isSorted() {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result code returned by the control.
|
||||
*
|
||||
* @return result code.
|
||||
*/
|
||||
public int getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sort key.
|
||||
*
|
||||
* @return the sort key.
|
||||
*/
|
||||
public String getSortKey() {
|
||||
return sortKey;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.ldap.control.AbstractRequestControlDirContextProcessor
|
||||
* #createRequestControl()
|
||||
*/
|
||||
public Control createRequestControl() {
|
||||
return super.createRequestControl(new Class<?>[] { String[].class, boolean.class }, new Object[] {
|
||||
new String[] { sortKey }, critical});
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.control.
|
||||
* AbstractFallbackRequestAndResponseControlDirContextProcessor
|
||||
* #handleResponse(java.lang.Object)
|
||||
*/
|
||||
protected void handleResponse(Object control) {
|
||||
this.sorted = (Boolean) invokeMethod("isSorted", responseControlClass, control);
|
||||
this.resultCode = (Integer) invokeMethod("getResultCode", responseControlClass, control);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.directory.ModificationItem;
|
||||
|
||||
/**
|
||||
* Indicates that the implementing class is capable of keeping track of any
|
||||
* attribute modifications and return them as ModificationItems.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public interface AttributeModificationsAware {
|
||||
|
||||
/**
|
||||
* Creates an array of which attributes have been changed, added or removed
|
||||
* since the initialization of this object.
|
||||
*
|
||||
* @return an array of modification items.
|
||||
*/
|
||||
ModificationItem[] getModificationItems();
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.directory.ModificationItem;
|
||||
|
||||
/**
|
||||
* Indicates that the implementing class is capable of keeping track of any
|
||||
* attribute modifications and return them as ModificationItems.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public interface AttributeModificationsAware {
|
||||
|
||||
/**
|
||||
* Creates an array of which attributes have been changed, added or removed
|
||||
* since the initialization of this object.
|
||||
*
|
||||
* @return an array of modification items.
|
||||
*/
|
||||
ModificationItem[] getModificationItems();
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
/**
|
||||
* An interface used by LdapTemplate for mapping LDAP Attributes to beans.
|
||||
* Implementions of this interface perform the actual work of extracting
|
||||
* results, but need not worry about exception handling. <code>NamingExceptions</code> will
|
||||
* be caught and handled correctly by the {@link LdapTemplate} class.
|
||||
* <p>
|
||||
* Typically used in search methods of {@link LdapTemplate}.
|
||||
* <code>AttributeMapper</code> objects are normally stateless and thus
|
||||
* reusable; they are ideal for implementing attribute-mapping logic in one
|
||||
* place.
|
||||
* <p>
|
||||
* Alternatively, consider using a {@link ContextMapper} in stead.
|
||||
*
|
||||
* @see LdapTemplate#search(Name, String, AttributesMapper)
|
||||
* @see LdapTemplate#lookup(Name, AttributesMapper)
|
||||
* @see ContextMapper
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface AttributesMapper<T> {
|
||||
/**
|
||||
* Map Attributes to an object. The supplied attributes are the attributes
|
||||
* from a single SearchResult.
|
||||
*
|
||||
* @param attributes
|
||||
* attributes from a SearchResult.
|
||||
* @return an object built from the attributes.
|
||||
* @throws NamingException
|
||||
* if any error occurs mapping the attributes
|
||||
*/
|
||||
T mapFromAttributes(Attributes attributes)
|
||||
throws NamingException;
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
/**
|
||||
* An interface used by LdapTemplate for mapping LDAP Attributes to beans.
|
||||
* Implementions of this interface perform the actual work of extracting
|
||||
* results, but need not worry about exception handling. <code>NamingExceptions</code> will
|
||||
* be caught and handled correctly by the {@link LdapTemplate} class.
|
||||
* <p>
|
||||
* Typically used in search methods of {@link LdapTemplate}.
|
||||
* <code>AttributeMapper</code> objects are normally stateless and thus
|
||||
* reusable; they are ideal for implementing attribute-mapping logic in one
|
||||
* place.
|
||||
* <p>
|
||||
* Alternatively, consider using a {@link ContextMapper} in stead.
|
||||
*
|
||||
* @see LdapTemplate#search(Name, String, AttributesMapper)
|
||||
* @see LdapTemplate#lookup(Name, AttributesMapper)
|
||||
* @see ContextMapper
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface AttributesMapper<T> {
|
||||
/**
|
||||
* Map Attributes to an object. The supplied attributes are the attributes
|
||||
* from a single SearchResult.
|
||||
*
|
||||
* @param attributes
|
||||
* attributes from a SearchResult.
|
||||
* @return an object built from the attributes.
|
||||
* @throws NamingException
|
||||
* if any error occurs mapping the attributes
|
||||
*/
|
||||
T mapFromAttributes(Attributes attributes)
|
||||
throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* An <code>AuthenticationSource</code> is responsible for providing the
|
||||
* principal (user DN) and credentials to be used when creating a new context.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public interface AuthenticationSource {
|
||||
/**
|
||||
* Get the principal to use when creating an authenticated context.
|
||||
*
|
||||
* @return the principal (userDn).
|
||||
*/
|
||||
String getPrincipal();
|
||||
|
||||
/**
|
||||
* Get the credentials to use when creating an authenticated context.
|
||||
*
|
||||
* @return the credentials (password).
|
||||
*/
|
||||
String getCredentials();
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* An <code>AuthenticationSource</code> is responsible for providing the
|
||||
* principal (user DN) and credentials to be used when creating a new context.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public interface AuthenticationSource {
|
||||
/**
|
||||
* Get the principal to use when creating an authenticated context.
|
||||
*
|
||||
* @return the principal (userDn).
|
||||
*/
|
||||
String getPrincipal();
|
||||
|
||||
/**
|
||||
* Get the credentials to use when creating an authenticated context.
|
||||
*
|
||||
* @return the credentials (password).
|
||||
*/
|
||||
String getCredentials();
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A NameClassPairCallbackHandler to collect all results in an internal List.
|
||||
*
|
||||
* @see LdapTemplate
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class CollectingNameClassPairCallbackHandler<T> implements
|
||||
NameClassPairCallbackHandler {
|
||||
|
||||
private List<T> list = new LinkedList<T>();
|
||||
|
||||
/**
|
||||
* Get the assembled list.
|
||||
*
|
||||
* @return the list of all assembled objects.
|
||||
*/
|
||||
public List<T> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass on the supplied NameClassPair to
|
||||
* {@link #getObjectFromNameClassPair(NameClassPair)} and add the result to
|
||||
* the internal list.
|
||||
*/
|
||||
public final void handleNameClassPair(NameClassPair nameClassPair) throws NamingException {
|
||||
list.add(getObjectFromNameClassPair(nameClassPair));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a NameClassPair and transform it to an Object of the desired type
|
||||
* and with data from the NameClassPair.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* a NameClassPair from a search operation.
|
||||
* @return an object constructed from the data in the NameClassPair.
|
||||
* @throws NamingException if an error occurs.
|
||||
*/
|
||||
public abstract T getObjectFromNameClassPair(
|
||||
NameClassPair nameClassPair) throws NamingException;
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A NameClassPairCallbackHandler to collect all results in an internal List.
|
||||
*
|
||||
* @see LdapTemplate
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class CollectingNameClassPairCallbackHandler<T> implements
|
||||
NameClassPairCallbackHandler {
|
||||
|
||||
private List<T> list = new LinkedList<T>();
|
||||
|
||||
/**
|
||||
* Get the assembled list.
|
||||
*
|
||||
* @return the list of all assembled objects.
|
||||
*/
|
||||
public List<T> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass on the supplied NameClassPair to
|
||||
* {@link #getObjectFromNameClassPair(NameClassPair)} and add the result to
|
||||
* the internal list.
|
||||
*/
|
||||
public final void handleNameClassPair(NameClassPair nameClassPair) throws NamingException {
|
||||
list.add(getObjectFromNameClassPair(nameClassPair));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a NameClassPair and transform it to an Object of the desired type
|
||||
* and with data from the NameClassPair.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* a NameClassPair from a search operation.
|
||||
* @return an object constructed from the data in the NameClassPair.
|
||||
* @throws NamingException if an error occurs.
|
||||
*/
|
||||
public abstract T getObjectFromNameClassPair(
|
||||
NameClassPair nameClassPair) throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Helper interface to be used by Dao implementations for assembling to and from
|
||||
* context. Useful if we have assembler classes responsible for mapping to and
|
||||
* from a specific entry.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextAssembler extends ContextMapper {
|
||||
/**
|
||||
* Map the supplied object to the specified context.
|
||||
*
|
||||
* @param obj
|
||||
* the object to read data from.
|
||||
* @param ctx
|
||||
* the context to map to.
|
||||
*/
|
||||
void mapToContext(Object obj, Object ctx);
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* Helper interface to be used by Dao implementations for assembling to and from
|
||||
* context. Useful if we have assembler classes responsible for mapping to and
|
||||
* from a specific entry.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextAssembler extends ContextMapper {
|
||||
/**
|
||||
* Map the supplied object to the specified context.
|
||||
*
|
||||
* @param obj
|
||||
* the object to read data from.
|
||||
* @param ctx
|
||||
* the context to map to.
|
||||
*/
|
||||
void mapToContext(Object obj, Object ctx);
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Interface for delegating an actual operation to be performed on a
|
||||
* <code>DirContext</code>. For searches, use {@link SearchExecutor} in
|
||||
* stead. A typical usage of this interface could be e.g.:
|
||||
*
|
||||
* <pre>
|
||||
* ContextExecutor executor = new ContextExecutor() {
|
||||
* public Object executeWithContext(DirContext ctx) throws NamingException {
|
||||
* return ctx.lookup(dn);
|
||||
* }
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* @see LdapTemplate#executeReadOnly(ContextExecutor)
|
||||
* @see LdapTemplate#executeReadWrite(ContextExecutor)
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextExecutor<T> {
|
||||
/**
|
||||
* Perform any operation on the context.
|
||||
*
|
||||
* @param ctx
|
||||
* the DirContext to perform the operation on.
|
||||
* @return any object resulting from the operation - might be null.
|
||||
* @throws NamingException
|
||||
* if the operation resulted in one.
|
||||
*/
|
||||
T executeWithContext(DirContext ctx) throws NamingException;
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Interface for delegating an actual operation to be performed on a
|
||||
* <code>DirContext</code>. For searches, use {@link SearchExecutor} in
|
||||
* stead. A typical usage of this interface could be e.g.:
|
||||
*
|
||||
* <pre>
|
||||
* ContextExecutor executor = new ContextExecutor() {
|
||||
* public Object executeWithContext(DirContext ctx) throws NamingException {
|
||||
* return ctx.lookup(dn);
|
||||
* }
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* @see LdapTemplate#executeReadOnly(ContextExecutor)
|
||||
* @see LdapTemplate#executeReadWrite(ContextExecutor)
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextExecutor<T> {
|
||||
/**
|
||||
* Perform any operation on the context.
|
||||
*
|
||||
* @param ctx
|
||||
* the DirContext to perform the operation on.
|
||||
* @return any object resulting from the operation - might be null.
|
||||
* @throws NamingException
|
||||
* if the operation resulted in one.
|
||||
*/
|
||||
T executeWithContext(DirContext ctx) throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
/**
|
||||
* An interface used by LdapTemplate to map LDAP Contexts to beans. When a
|
||||
* DirObjectFactory is set on the ContextSource, the objects returned from
|
||||
* <code>search</code> and <code>listBindings</code> operations are
|
||||
* automatically transformed to DirContext objects (when using the
|
||||
* {@link DefaultDirObjectFactory} - which is typically the case, unless
|
||||
* something else has been explicitly specified - you get a
|
||||
* {@link DirContextAdapter} object). This object will then be passed to the
|
||||
* ContextMapper implementation for transformation to the desired bean.
|
||||
* <p>
|
||||
* ContextMapper implementations are typically stateless and thus reusable; they
|
||||
* are ideal for implementing mapping logic in one place.
|
||||
* <p>
|
||||
* Alternatively, consider using an {@link AttributesMapper} in stead.
|
||||
*
|
||||
* @see LdapTemplate#search(Name, String, ContextMapper)
|
||||
* @see LdapTemplate#listBindings(Name, ContextMapper)
|
||||
* @see LdapTemplate#lookup(Name, ContextMapper)
|
||||
* @see AttributesMapper
|
||||
* @see DefaultDirObjectFactory
|
||||
* @see DirContextAdapter
|
||||
* @see AbstractContextMapper
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextMapper<T> {
|
||||
/**
|
||||
* Map a single LDAP Context to an object. The supplied Object
|
||||
* <code>ctx</code> is the object from a single {@link SearchResult},
|
||||
* {@link Binding}, or a lookup operation.
|
||||
*
|
||||
* @param ctx
|
||||
* the context to map to an object. Typically this will be a
|
||||
* {@link DirContextAdapter} instance, unless a project specific
|
||||
* <code>DirObjectFactory</code> has been specified on the
|
||||
* <code>ContextSource</code>.
|
||||
* @return an object built from the data in the context.
|
||||
* @throws NamingException if an error occurs.
|
||||
*/
|
||||
T mapFromContext(Object ctx) throws NamingException;
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
/**
|
||||
* An interface used by LdapTemplate to map LDAP Contexts to beans. When a
|
||||
* DirObjectFactory is set on the ContextSource, the objects returned from
|
||||
* <code>search</code> and <code>listBindings</code> operations are
|
||||
* automatically transformed to DirContext objects (when using the
|
||||
* {@link DefaultDirObjectFactory} - which is typically the case, unless
|
||||
* something else has been explicitly specified - you get a
|
||||
* {@link DirContextAdapter} object). This object will then be passed to the
|
||||
* ContextMapper implementation for transformation to the desired bean.
|
||||
* <p>
|
||||
* ContextMapper implementations are typically stateless and thus reusable; they
|
||||
* are ideal for implementing mapping logic in one place.
|
||||
* <p>
|
||||
* Alternatively, consider using an {@link AttributesMapper} in stead.
|
||||
*
|
||||
* @see LdapTemplate#search(Name, String, ContextMapper)
|
||||
* @see LdapTemplate#listBindings(Name, ContextMapper)
|
||||
* @see LdapTemplate#lookup(Name, ContextMapper)
|
||||
* @see AttributesMapper
|
||||
* @see DefaultDirObjectFactory
|
||||
* @see DirContextAdapter
|
||||
* @see AbstractContextMapper
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextMapper<T> {
|
||||
/**
|
||||
* Map a single LDAP Context to an object. The supplied Object
|
||||
* <code>ctx</code> is the object from a single {@link SearchResult},
|
||||
* {@link Binding}, or a lookup operation.
|
||||
*
|
||||
* @param ctx
|
||||
* the context to map to an object. Typically this will be a
|
||||
* {@link DirContextAdapter} instance, unless a project specific
|
||||
* <code>DirObjectFactory</code> has been specified on the
|
||||
* <code>ContextSource</code>.
|
||||
* @return an object built from the data in the context.
|
||||
* @throws NamingException if an error occurs.
|
||||
*/
|
||||
T mapFromContext(Object ctx) throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* A <code>ContextSource</code> is responsible for configuring and creating
|
||||
* <code>DirContext</code> instances. It is typically used from
|
||||
* {@link LdapTemplate} to acquiring contexts for LDAP operations, but may be
|
||||
* used standalone to perform LDAP authentication.
|
||||
*
|
||||
* @see org.springframework.ldap.core.LdapTemplate
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextSource {
|
||||
|
||||
/**
|
||||
* Gets a read-only <code>DirContext</code>. The returned
|
||||
* <code>DirContext</code> must be possible to perform read-only operations
|
||||
* on.
|
||||
*
|
||||
* @return A DirContext instance, never null.
|
||||
* @throws NamingException if some error occurs creating an DirContext.
|
||||
*/
|
||||
DirContext getReadOnlyContext() throws NamingException;
|
||||
|
||||
/**
|
||||
* Gets a read-write <code>DirContext</code> instance.
|
||||
*
|
||||
* @return A <code>DirContext</code> instance, never <code>null</code>.
|
||||
* @throws NamingException if some error occurs creating an
|
||||
* <code>DirContext</code>.
|
||||
*/
|
||||
DirContext getReadWriteContext() throws NamingException;
|
||||
|
||||
/**
|
||||
* Gets a <code>DirContext</code> instance authenticated using the supplied
|
||||
* principal and credentials. Typically to be used for plain authentication
|
||||
* purposes. <strong>Note</strong> that this method will never make use
|
||||
* of native Java LDAP pooling, even though this instance is configured to do so.
|
||||
* This is to force password changes in the target directory to take effect
|
||||
* as soon as possible.
|
||||
*
|
||||
* @param principal The principal (typically a distinguished name of a user
|
||||
* in the LDAP tree) to use for authentication.
|
||||
* @param credentials The credentials to use for authentication.
|
||||
* @return an authenticated <code>DirContext</code> instance, never
|
||||
* <code>null</code>.
|
||||
* @since 1.3
|
||||
*/
|
||||
DirContext getContext(String principal, String credentials) throws NamingException;
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* A <code>ContextSource</code> is responsible for configuring and creating
|
||||
* <code>DirContext</code> instances. It is typically used from
|
||||
* {@link LdapTemplate} to acquiring contexts for LDAP operations, but may be
|
||||
* used standalone to perform LDAP authentication.
|
||||
*
|
||||
* @see org.springframework.ldap.core.LdapTemplate
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface ContextSource {
|
||||
|
||||
/**
|
||||
* Gets a read-only <code>DirContext</code>. The returned
|
||||
* <code>DirContext</code> must be possible to perform read-only operations
|
||||
* on.
|
||||
*
|
||||
* @return A DirContext instance, never null.
|
||||
* @throws NamingException if some error occurs creating an DirContext.
|
||||
*/
|
||||
DirContext getReadOnlyContext() throws NamingException;
|
||||
|
||||
/**
|
||||
* Gets a read-write <code>DirContext</code> instance.
|
||||
*
|
||||
* @return A <code>DirContext</code> instance, never <code>null</code>.
|
||||
* @throws NamingException if some error occurs creating an
|
||||
* <code>DirContext</code>.
|
||||
*/
|
||||
DirContext getReadWriteContext() throws NamingException;
|
||||
|
||||
/**
|
||||
* Gets a <code>DirContext</code> instance authenticated using the supplied
|
||||
* principal and credentials. Typically to be used for plain authentication
|
||||
* purposes. <strong>Note</strong> that this method will never make use
|
||||
* of native Java LDAP pooling, even though this instance is configured to do so.
|
||||
* This is to force password changes in the target directory to take effect
|
||||
* as soon as possible.
|
||||
*
|
||||
* @param principal The principal (typically a distinguished name of a user
|
||||
* in the LDAP tree) to use for authentication.
|
||||
* @param credentials The credentials to use for authentication.
|
||||
* @return an authenticated <code>DirContext</code> instance, never
|
||||
* <code>null</code>.
|
||||
* @since 1.3
|
||||
*/
|
||||
DirContext getContext(String principal, String credentials) throws NamingException;
|
||||
}
|
||||
@@ -1,45 +1,45 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* A factory for creating DnParser instances. The actual implementation of
|
||||
* DnParser is generated using javacc and should not be constructed directly.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public final class DefaultDnParserFactory {
|
||||
/**
|
||||
* Not to be instantiated.
|
||||
*/
|
||||
private DefaultDnParserFactory() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DnParser instance.
|
||||
*
|
||||
* @param string
|
||||
* the DN String to be parsed.
|
||||
* @return a new DnParser instance for parsing the supplied DN string.
|
||||
*/
|
||||
public static DnParser createDnParser(String string) {
|
||||
return new DnParserImpl(new StringReader(string));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* A factory for creating DnParser instances. The actual implementation of
|
||||
* DnParser is generated using javacc and should not be constructed directly.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public final class DefaultDnParserFactory {
|
||||
/**
|
||||
* Not to be instantiated.
|
||||
*/
|
||||
private DefaultDnParserFactory() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DnParser instance.
|
||||
*
|
||||
* @param string
|
||||
* the DN String to be parsed.
|
||||
* @return a new DnParser instance for parsing the supplied DN string.
|
||||
*/
|
||||
public static DnParser createDnParser(String string) {
|
||||
return new DnParserImpl(new StringReader(string));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* The default NameClassPairMapper implementation. This implementation simply
|
||||
* takes the Name string from the supplied NameClassPair and returns it as
|
||||
* result.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public class DefaultNameClassPairMapper implements NameClassPairMapper<String> {
|
||||
|
||||
/**
|
||||
* Gets the Name from the supplied NameClassPair and returns it as the
|
||||
* result.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* the NameClassPair to transform.
|
||||
* @return the Name string from the NameClassPair.
|
||||
*/
|
||||
@Override
|
||||
public String mapFromNameClassPair(NameClassPair nameClassPair)
|
||||
throws NamingException {
|
||||
|
||||
return nameClassPair.getName();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* The default NameClassPairMapper implementation. This implementation simply
|
||||
* takes the Name string from the supplied NameClassPair and returns it as
|
||||
* result.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public class DefaultNameClassPairMapper implements NameClassPairMapper<String> {
|
||||
|
||||
/**
|
||||
* Gets the Name from the supplied NameClassPair and returns it as the
|
||||
* result.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* the NameClassPair to transform.
|
||||
* @return the Name string from the NameClassPair.
|
||||
*/
|
||||
@Override
|
||||
public String mapFromNameClassPair(NameClassPair nameClassPair)
|
||||
throws NamingException {
|
||||
|
||||
return nameClassPair.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Interface to be called in search by {@link LdapTemplate} before and after the
|
||||
* actual search and enumeration traversal. Implementations may be used to apply
|
||||
* search controls on the <code>Context</code> and retrieve the results of
|
||||
* such controls afterwards.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public interface DirContextProcessor {
|
||||
/**
|
||||
* Perform pre-processing on the supplied DirContext.
|
||||
*
|
||||
* @param ctx
|
||||
* the <code>DirContext</code> instance.
|
||||
* @throws NamingException
|
||||
* if thrown by the underlying operation.
|
||||
*/
|
||||
void preProcess(DirContext ctx) throws NamingException;
|
||||
|
||||
/**
|
||||
* Perform post-processing on the supplied <code>DirContext</code>.
|
||||
*
|
||||
* @param ctx
|
||||
* the <code>DirContext</code> instance.
|
||||
* @throws NamingException
|
||||
* if thrown by the underlying operation.
|
||||
*/
|
||||
void postProcess(DirContext ctx) throws NamingException;
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Interface to be called in search by {@link LdapTemplate} before and after the
|
||||
* actual search and enumeration traversal. Implementations may be used to apply
|
||||
* search controls on the <code>Context</code> and retrieve the results of
|
||||
* such controls afterwards.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public interface DirContextProcessor {
|
||||
/**
|
||||
* Perform pre-processing on the supplied DirContext.
|
||||
*
|
||||
* @param ctx
|
||||
* the <code>DirContext</code> instance.
|
||||
* @throws NamingException
|
||||
* if thrown by the underlying operation.
|
||||
*/
|
||||
void preProcess(DirContext ctx) throws NamingException;
|
||||
|
||||
/**
|
||||
* Perform post-processing on the supplied <code>DirContext</code>.
|
||||
*
|
||||
* @param ctx
|
||||
* the <code>DirContext</code> instance.
|
||||
* @throws NamingException
|
||||
* if thrown by the underlying operation.
|
||||
*/
|
||||
void postProcess(DirContext ctx) throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Helper interface to be able to get hold of the target <code>DirContext</code>
|
||||
* from proxies created by <code>ContextSource</code> proxies.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
*/
|
||||
public interface DirContextProxy {
|
||||
/**
|
||||
* Get the target <code>DirContext</code> of the proxy.
|
||||
*
|
||||
* @return the target <code>DirContext</code>.
|
||||
*/
|
||||
DirContext getTargetContext();
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Helper interface to be able to get hold of the target <code>DirContext</code>
|
||||
* from proxies created by <code>ContextSource</code> proxies.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
*/
|
||||
public interface DirContextProxy {
|
||||
/**
|
||||
* Get the target <code>DirContext</code> of the proxy.
|
||||
*
|
||||
* @return the target <code>DirContext</code>.
|
||||
*/
|
||||
DirContext getTargetContext();
|
||||
}
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* Property editor for use with {@link DistinguishedName} instances. The
|
||||
* {@link #setAsText(String)} method sets the value as an <i>immutable</i>
|
||||
* instance of a DistinguishedName.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public class DistinguishedNameEditor extends PropertyEditorSupport {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
if (text == null) {
|
||||
setValue(null);
|
||||
}
|
||||
else {
|
||||
setValue(new DistinguishedName(text).immutableDistinguishedName());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#getAsText()
|
||||
*/
|
||||
public String getAsText() {
|
||||
Object theValue = getValue();
|
||||
if (theValue == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return ((DistinguishedName) theValue).toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* Property editor for use with {@link DistinguishedName} instances. The
|
||||
* {@link #setAsText(String)} method sets the value as an <i>immutable</i>
|
||||
* instance of a DistinguishedName.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public class DistinguishedNameEditor extends PropertyEditorSupport {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
if (text == null) {
|
||||
setValue(null);
|
||||
}
|
||||
else {
|
||||
setValue(new DistinguishedName(text).immutableDistinguishedName());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#getAsText()
|
||||
*/
|
||||
public String getAsText() {
|
||||
Object theValue = getValue();
|
||||
if (theValue == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return ((DistinguishedName) theValue).toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* A parser for RFC2253-compliant Distinguished Names.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public interface DnParser {
|
||||
/**
|
||||
* Parse a full Distinguished Name.
|
||||
*
|
||||
* @return the <code>DistinguishedName</code> corresponding to the parsed
|
||||
* stream.
|
||||
*/
|
||||
public DistinguishedName dn() throws ParseException;
|
||||
|
||||
/**
|
||||
* Parse a Relative Distinguished Name.
|
||||
*
|
||||
* @return the next rdn on the stream.
|
||||
*/
|
||||
public LdapRdn rdn() throws ParseException;
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
/**
|
||||
* A parser for RFC2253-compliant Distinguished Names.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public interface DnParser {
|
||||
/**
|
||||
* Parse a full Distinguished Name.
|
||||
*
|
||||
* @return the <code>DistinguishedName</code> corresponding to the parsed
|
||||
* stream.
|
||||
*/
|
||||
public DistinguishedName dn() throws ParseException;
|
||||
|
||||
/**
|
||||
* Parse a Relative Distinguished Name.
|
||||
*
|
||||
* @return the next rdn on the stream.
|
||||
*/
|
||||
public LdapRdn rdn() throws ParseException;
|
||||
}
|
||||
|
||||
@@ -1,224 +1,224 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Extends {@link javax.naming.directory.BasicAttribute} to add support for
|
||||
* options as defined in RFC2849.
|
||||
* <p>
|
||||
* While uncommon, options can be used to specify additional descriptors for
|
||||
* the attribute. Options are backed by a {@link java.util.HashSet} of
|
||||
* {@link java.lang.String}.
|
||||
*
|
||||
* @author Keith Barlow
|
||||
*
|
||||
*/
|
||||
public class LdapAttribute extends BasicAttribute {
|
||||
|
||||
private static final long serialVersionUID = -5263905906016179429L;
|
||||
|
||||
/**
|
||||
* Holds the attributes options.
|
||||
*/
|
||||
protected Set<String> options = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Creates an unordered attribute with the specified ID.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
*/
|
||||
public LdapAttribute(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unordered attribute with the specified ID and value.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value) {
|
||||
super(id, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unordered attribute with the specified ID, value, and options.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} attribute options.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value, Collection<String> options) {
|
||||
super(id, value);
|
||||
this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, boolean ordered) {
|
||||
super(id, ordered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID and options whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} attribute options.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, Collection<String> options, boolean ordered) {
|
||||
super(id, ordered);
|
||||
this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID and value whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value, boolean ordered) {
|
||||
super(id, value, ordered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID, value, and options whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} attribute options.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value, Collection<String> options, boolean ordered) {
|
||||
super(id, value, ordered);
|
||||
this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options.
|
||||
*
|
||||
* @return returns a {@link java.util.Set} of {@link java.lang.String}
|
||||
*/
|
||||
public Set<String> getOptions() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options.
|
||||
*
|
||||
* @param options {@link java.util.Set} of {@link java.lang.String}
|
||||
*/
|
||||
public void setOptions(Set<String> options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an option.
|
||||
*
|
||||
* @param option {@link java.lang.String} option.
|
||||
* @return boolean indication successful addition of option.
|
||||
*/
|
||||
public boolean addOption(String option) {
|
||||
return this.options.add(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all values in the collection to the options.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} values.
|
||||
* @return boolean indication successful addition of options.
|
||||
*/
|
||||
public boolean addAllOptions(Collection<String> options) {
|
||||
return this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all stored options.
|
||||
*/
|
||||
public void clearOptions() {
|
||||
this.options.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for existence of a particular option on the set.
|
||||
*
|
||||
* @param option {@link java.lang.String} option.
|
||||
* @return boolean indicating result.
|
||||
*/
|
||||
public boolean contains(String option) {
|
||||
return this.options.contains(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for existence of a series of options on the set.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} options.
|
||||
* @return boolean indicating result.
|
||||
*/
|
||||
public boolean containsAll(Collection<String> options) {
|
||||
return this.options.containsAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the presence of options.
|
||||
*
|
||||
* @return boolean indicating result.
|
||||
*/
|
||||
public boolean hasOptions() {
|
||||
return !options.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an option from the the set.
|
||||
*
|
||||
* @param option {@link java.lang.String} option.
|
||||
* @return boolean indicating successful removal of option.
|
||||
*/
|
||||
public boolean removeOption(String option) {
|
||||
return this.options.remove(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all options listed in the supplied set.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} options.
|
||||
* @return boolean indicating successful removal of options.
|
||||
*/
|
||||
public boolean removeAllOptions(Collection<String> options) {
|
||||
return this.options.removeAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any options not on the set of supplied options.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} options.
|
||||
* @return boolean indicating successful retention of options.
|
||||
*/
|
||||
public boolean retainAllOptions(Collection<String> options) {
|
||||
return this.options.retainAll(options);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Extends {@link javax.naming.directory.BasicAttribute} to add support for
|
||||
* options as defined in RFC2849.
|
||||
* <p>
|
||||
* While uncommon, options can be used to specify additional descriptors for
|
||||
* the attribute. Options are backed by a {@link java.util.HashSet} of
|
||||
* {@link java.lang.String}.
|
||||
*
|
||||
* @author Keith Barlow
|
||||
*
|
||||
*/
|
||||
public class LdapAttribute extends BasicAttribute {
|
||||
|
||||
private static final long serialVersionUID = -5263905906016179429L;
|
||||
|
||||
/**
|
||||
* Holds the attributes options.
|
||||
*/
|
||||
protected Set<String> options = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Creates an unordered attribute with the specified ID.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
*/
|
||||
public LdapAttribute(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unordered attribute with the specified ID and value.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value) {
|
||||
super(id, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unordered attribute with the specified ID, value, and options.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} attribute options.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value, Collection<String> options) {
|
||||
super(id, value);
|
||||
this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, boolean ordered) {
|
||||
super(id, ordered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID and options whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} attribute options.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, Collection<String> options, boolean ordered) {
|
||||
super(id, ordered);
|
||||
this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID and value whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value, boolean ordered) {
|
||||
super(id, value, ordered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an attribute with the specified ID, value, and options whose values may be ordered.
|
||||
*
|
||||
* @param id {@link java.lang.String} ID of the attribute.
|
||||
* @param value Attribute value.
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} attribute options.
|
||||
* @param ordered boolean indicating whether or not the attributes values are ordered.
|
||||
*/
|
||||
public LdapAttribute(String id, Object value, Collection<String> options, boolean ordered) {
|
||||
super(id, value, ordered);
|
||||
this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options.
|
||||
*
|
||||
* @return returns a {@link java.util.Set} of {@link java.lang.String}
|
||||
*/
|
||||
public Set<String> getOptions() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options.
|
||||
*
|
||||
* @param options {@link java.util.Set} of {@link java.lang.String}
|
||||
*/
|
||||
public void setOptions(Set<String> options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an option.
|
||||
*
|
||||
* @param option {@link java.lang.String} option.
|
||||
* @return boolean indication successful addition of option.
|
||||
*/
|
||||
public boolean addOption(String option) {
|
||||
return this.options.add(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all values in the collection to the options.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} values.
|
||||
* @return boolean indication successful addition of options.
|
||||
*/
|
||||
public boolean addAllOptions(Collection<String> options) {
|
||||
return this.options.addAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all stored options.
|
||||
*/
|
||||
public void clearOptions() {
|
||||
this.options.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for existence of a particular option on the set.
|
||||
*
|
||||
* @param option {@link java.lang.String} option.
|
||||
* @return boolean indicating result.
|
||||
*/
|
||||
public boolean contains(String option) {
|
||||
return this.options.contains(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for existence of a series of options on the set.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} options.
|
||||
* @return boolean indicating result.
|
||||
*/
|
||||
public boolean containsAll(Collection<String> options) {
|
||||
return this.options.containsAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the presence of options.
|
||||
*
|
||||
* @return boolean indicating result.
|
||||
*/
|
||||
public boolean hasOptions() {
|
||||
return !options.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an option from the the set.
|
||||
*
|
||||
* @param option {@link java.lang.String} option.
|
||||
* @return boolean indicating successful removal of option.
|
||||
*/
|
||||
public boolean removeOption(String option) {
|
||||
return this.options.remove(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all options listed in the supplied set.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} options.
|
||||
* @return boolean indicating successful removal of options.
|
||||
*/
|
||||
public boolean removeAllOptions(Collection<String> options) {
|
||||
return this.options.removeAll(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any options not on the set of supplied options.
|
||||
*
|
||||
* @param options {@link java.util.Collection} of {@link java.lang.String} options.
|
||||
* @return boolean indicating successful retention of options.
|
||||
*/
|
||||
public boolean retainAllOptions(Collection<String> options) {
|
||||
return this.options.retainAll(options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,308 +1,308 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.BadLdapGrammarException;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Datatype for a LDAP name, a part of a path.
|
||||
*
|
||||
* The name: uid=adam.skogman Key: uid Value: adam.skogman
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public class LdapRdn implements Serializable, Comparable {
|
||||
private static final long serialVersionUID = 5681397547245228750L;
|
||||
private static final int DEFAULT_BUFFER_SIZE = 100;
|
||||
|
||||
private Map<String, LdapRdnComponent> components = new LinkedHashMap<String, LdapRdnComponent>();
|
||||
|
||||
/**
|
||||
* Default constructor. Create an empty, uninitialized LdapRdn.
|
||||
*/
|
||||
public LdapRdn() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the supplied string and construct this instance accordingly.
|
||||
*
|
||||
* @param string the string to parse.
|
||||
*/
|
||||
public LdapRdn(String string) {
|
||||
DnParser parser = DefaultDnParserFactory.createDnParser(string);
|
||||
LdapRdn rdn;
|
||||
try {
|
||||
rdn = parser.rdn();
|
||||
}
|
||||
catch (ParseException e) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", e);
|
||||
}
|
||||
catch (TokenMgrError e) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", e);
|
||||
}
|
||||
this.components = rdn.components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an LdapRdn using the supplied key and value.
|
||||
*
|
||||
* @param key the attribute name.
|
||||
* @param value the attribute value.
|
||||
*/
|
||||
public LdapRdn(String key, String value) {
|
||||
components.put(key, new LdapRdnComponent(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an LdapRdnComponent to this LdapRdn.
|
||||
*
|
||||
* @param rdnComponent the LdapRdnComponent to add.s
|
||||
*/
|
||||
public void addComponent(LdapRdnComponent rdnComponent) {
|
||||
components.put(rdnComponent.getKey(), rdnComponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all components in this LdapRdn.
|
||||
*
|
||||
* @return the List of all LdapRdnComponents composing this LdapRdn.
|
||||
*/
|
||||
public List getComponents() {
|
||||
return new ArrayList(components.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first LdapRdnComponent of this LdapRdn.
|
||||
*
|
||||
* @return The first LdapRdnComponent of this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public LdapRdnComponent getComponent() {
|
||||
if(components.size() == 0) {
|
||||
throw new IndexOutOfBoundsException("No components");
|
||||
}
|
||||
|
||||
return components.values().iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the LdapRdnComponent at index <code>idx</code>.
|
||||
*
|
||||
* @param idx the 0-based index of the component to get.
|
||||
* @return the LdapRdnComponent at index <code>idx</code>.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public LdapRdnComponent getComponent(int idx) {
|
||||
if(idx >= components.size()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
return (LdapRdnComponent) new ArrayList(components.values()).get(idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a properly rfc2253-encoded String representation of this LdapRdn.
|
||||
*
|
||||
* @return an escaped String corresponding to this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public String getLdapEncoded() {
|
||||
if (components.size() == 0) {
|
||||
throw new IndexOutOfBoundsException("No components in Rdn.");
|
||||
}
|
||||
StringBuffer sb = new StringBuffer(DEFAULT_BUFFER_SIZE);
|
||||
for (Iterator iter = components.values().iterator(); iter.hasNext();) {
|
||||
LdapRdnComponent component = (LdapRdnComponent) iter.next();
|
||||
sb.append(component.encodeLdap());
|
||||
if (iter.hasNext()) {
|
||||
sb.append("+");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a String representation of this LdapRdn for use in urls.
|
||||
*
|
||||
* @return a String representation of this LdapRdn for use in urls.
|
||||
*/
|
||||
public String encodeUrl() {
|
||||
StringBuffer sb = new StringBuffer(DEFAULT_BUFFER_SIZE);
|
||||
for (Iterator iter = components.values().iterator(); iter.hasNext();) {
|
||||
LdapRdnComponent component = (LdapRdnComponent) iter.next();
|
||||
sb.append(component.encodeUrl());
|
||||
if (iter.hasNext()) {
|
||||
sb.append("+");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this LdapRdn to another object.
|
||||
*
|
||||
* @param obj the object to compare to.
|
||||
* @throws ClassCastException if the supplied object is not an LdapRdn
|
||||
* instance.
|
||||
*/
|
||||
public int compareTo(Object obj) {
|
||||
LdapRdn that = (LdapRdn) obj;
|
||||
|
||||
if(this.components.size() != that.components.size()) {
|
||||
return this.components.size() - that.components.size();
|
||||
}
|
||||
|
||||
Set<Map.Entry<String,LdapRdnComponent>> theseEntries = this.components.entrySet();
|
||||
for (Map.Entry<String, LdapRdnComponent> oneEntry : theseEntries) {
|
||||
LdapRdnComponent thatEntry = that.components.get(oneEntry.getKey());
|
||||
if(thatEntry == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int compared = oneEntry.getValue().compareTo(thatEntry);
|
||||
if(compared != 0) {
|
||||
return compared;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || obj.getClass() != this.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LdapRdn that = (LdapRdn) obj;
|
||||
|
||||
if(this.components.size() != that.components.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<Map.Entry<String,LdapRdnComponent>> theseEntries = this.components.entrySet();
|
||||
for (Map.Entry<String, LdapRdnComponent> oneEntry : theseEntries) {
|
||||
if(!oneEntry.getValue().equals(that.components.get(oneEntry.getKey()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return this.getClass().hashCode() ^ new HashSet(getComponents()).hashCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return getLdapEncoded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of this LdapRdn. Note that if this Rdn is multi-value the
|
||||
* first value will be returned. E.g. for the Rdn
|
||||
* <code>cn=john doe+sn=doe</code>, the return value would be
|
||||
* <code>john doe</code>.
|
||||
*
|
||||
* @return the (first) value of this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public String getValue() {
|
||||
return getComponent().getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key of this LdapRdn. Note that if this Rdn is multi-value the
|
||||
* first key will be returned. E.g. for the Rdn
|
||||
* <code>cn=john doe+sn=doe</code>, the return value would be
|
||||
* <code>cn</code>.
|
||||
*
|
||||
* @return the (first) key of this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public String getKey() {
|
||||
return getComponent().getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the LdapComponent with the specified key (Attribute
|
||||
* name).
|
||||
*
|
||||
* @param key the key
|
||||
* @return the value.
|
||||
* @throws IllegalArgumentException if there is no component with the
|
||||
* specified key.
|
||||
*/
|
||||
public String getValue(String key) {
|
||||
for (Iterator iter = components.values().iterator(); iter.hasNext();) {
|
||||
LdapRdnComponent component = (LdapRdnComponent) iter.next();
|
||||
if (ObjectUtils.nullSafeEquals(component.getKey(), key)) {
|
||||
return component.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No RdnComponent with the key " + key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an immutable copy of this instance. It will not be possible to add
|
||||
* or remove components or modify the keys and values of these components.
|
||||
*
|
||||
* @return an immutable copy of this instance.
|
||||
* @since 1.3
|
||||
*/
|
||||
public LdapRdn immutableLdapRdn() {
|
||||
Map<String, LdapRdnComponent> mapWithImmutableRdns = new LinkedHashMap<String, LdapRdnComponent>(components.size());
|
||||
for (Iterator iterator = components.values().iterator(); iterator.hasNext();) {
|
||||
LdapRdnComponent rdnComponent = (LdapRdnComponent) iterator.next();
|
||||
mapWithImmutableRdns.put(rdnComponent.getKey(), rdnComponent.immutableLdapRdnComponent());
|
||||
}
|
||||
Map<String, LdapRdnComponent> unmodifiableMapOfImmutableRdns = Collections.unmodifiableMap(mapWithImmutableRdns);
|
||||
LdapRdn immutableRdn = new LdapRdn();
|
||||
immutableRdn.components = unmodifiableMapOfImmutableRdns;
|
||||
return immutableRdn;
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.BadLdapGrammarException;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Datatype for a LDAP name, a part of a path.
|
||||
*
|
||||
* The name: uid=adam.skogman Key: uid Value: adam.skogman
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @deprecated {@link DistinguishedName} and associated classes are deprecated as of 2.0.
|
||||
*/
|
||||
public class LdapRdn implements Serializable, Comparable {
|
||||
private static final long serialVersionUID = 5681397547245228750L;
|
||||
private static final int DEFAULT_BUFFER_SIZE = 100;
|
||||
|
||||
private Map<String, LdapRdnComponent> components = new LinkedHashMap<String, LdapRdnComponent>();
|
||||
|
||||
/**
|
||||
* Default constructor. Create an empty, uninitialized LdapRdn.
|
||||
*/
|
||||
public LdapRdn() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the supplied string and construct this instance accordingly.
|
||||
*
|
||||
* @param string the string to parse.
|
||||
*/
|
||||
public LdapRdn(String string) {
|
||||
DnParser parser = DefaultDnParserFactory.createDnParser(string);
|
||||
LdapRdn rdn;
|
||||
try {
|
||||
rdn = parser.rdn();
|
||||
}
|
||||
catch (ParseException e) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", e);
|
||||
}
|
||||
catch (TokenMgrError e) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", e);
|
||||
}
|
||||
this.components = rdn.components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an LdapRdn using the supplied key and value.
|
||||
*
|
||||
* @param key the attribute name.
|
||||
* @param value the attribute value.
|
||||
*/
|
||||
public LdapRdn(String key, String value) {
|
||||
components.put(key, new LdapRdnComponent(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an LdapRdnComponent to this LdapRdn.
|
||||
*
|
||||
* @param rdnComponent the LdapRdnComponent to add.s
|
||||
*/
|
||||
public void addComponent(LdapRdnComponent rdnComponent) {
|
||||
components.put(rdnComponent.getKey(), rdnComponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all components in this LdapRdn.
|
||||
*
|
||||
* @return the List of all LdapRdnComponents composing this LdapRdn.
|
||||
*/
|
||||
public List getComponents() {
|
||||
return new ArrayList(components.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first LdapRdnComponent of this LdapRdn.
|
||||
*
|
||||
* @return The first LdapRdnComponent of this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public LdapRdnComponent getComponent() {
|
||||
if(components.size() == 0) {
|
||||
throw new IndexOutOfBoundsException("No components");
|
||||
}
|
||||
|
||||
return components.values().iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the LdapRdnComponent at index <code>idx</code>.
|
||||
*
|
||||
* @param idx the 0-based index of the component to get.
|
||||
* @return the LdapRdnComponent at index <code>idx</code>.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public LdapRdnComponent getComponent(int idx) {
|
||||
if(idx >= components.size()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
return (LdapRdnComponent) new ArrayList(components.values()).get(idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a properly rfc2253-encoded String representation of this LdapRdn.
|
||||
*
|
||||
* @return an escaped String corresponding to this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public String getLdapEncoded() {
|
||||
if (components.size() == 0) {
|
||||
throw new IndexOutOfBoundsException("No components in Rdn.");
|
||||
}
|
||||
StringBuffer sb = new StringBuffer(DEFAULT_BUFFER_SIZE);
|
||||
for (Iterator iter = components.values().iterator(); iter.hasNext();) {
|
||||
LdapRdnComponent component = (LdapRdnComponent) iter.next();
|
||||
sb.append(component.encodeLdap());
|
||||
if (iter.hasNext()) {
|
||||
sb.append("+");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a String representation of this LdapRdn for use in urls.
|
||||
*
|
||||
* @return a String representation of this LdapRdn for use in urls.
|
||||
*/
|
||||
public String encodeUrl() {
|
||||
StringBuffer sb = new StringBuffer(DEFAULT_BUFFER_SIZE);
|
||||
for (Iterator iter = components.values().iterator(); iter.hasNext();) {
|
||||
LdapRdnComponent component = (LdapRdnComponent) iter.next();
|
||||
sb.append(component.encodeUrl());
|
||||
if (iter.hasNext()) {
|
||||
sb.append("+");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this LdapRdn to another object.
|
||||
*
|
||||
* @param obj the object to compare to.
|
||||
* @throws ClassCastException if the supplied object is not an LdapRdn
|
||||
* instance.
|
||||
*/
|
||||
public int compareTo(Object obj) {
|
||||
LdapRdn that = (LdapRdn) obj;
|
||||
|
||||
if(this.components.size() != that.components.size()) {
|
||||
return this.components.size() - that.components.size();
|
||||
}
|
||||
|
||||
Set<Map.Entry<String,LdapRdnComponent>> theseEntries = this.components.entrySet();
|
||||
for (Map.Entry<String, LdapRdnComponent> oneEntry : theseEntries) {
|
||||
LdapRdnComponent thatEntry = that.components.get(oneEntry.getKey());
|
||||
if(thatEntry == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int compared = oneEntry.getValue().compareTo(thatEntry);
|
||||
if(compared != 0) {
|
||||
return compared;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || obj.getClass() != this.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LdapRdn that = (LdapRdn) obj;
|
||||
|
||||
if(this.components.size() != that.components.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<Map.Entry<String,LdapRdnComponent>> theseEntries = this.components.entrySet();
|
||||
for (Map.Entry<String, LdapRdnComponent> oneEntry : theseEntries) {
|
||||
if(!oneEntry.getValue().equals(that.components.get(oneEntry.getKey()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
return this.getClass().hashCode() ^ new HashSet(getComponents()).hashCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return getLdapEncoded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of this LdapRdn. Note that if this Rdn is multi-value the
|
||||
* first value will be returned. E.g. for the Rdn
|
||||
* <code>cn=john doe+sn=doe</code>, the return value would be
|
||||
* <code>john doe</code>.
|
||||
*
|
||||
* @return the (first) value of this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public String getValue() {
|
||||
return getComponent().getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key of this LdapRdn. Note that if this Rdn is multi-value the
|
||||
* first key will be returned. E.g. for the Rdn
|
||||
* <code>cn=john doe+sn=doe</code>, the return value would be
|
||||
* <code>cn</code>.
|
||||
*
|
||||
* @return the (first) key of this LdapRdn.
|
||||
* @throws IndexOutOfBoundsException if there are no components in this Rdn.
|
||||
*/
|
||||
public String getKey() {
|
||||
return getComponent().getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the LdapComponent with the specified key (Attribute
|
||||
* name).
|
||||
*
|
||||
* @param key the key
|
||||
* @return the value.
|
||||
* @throws IllegalArgumentException if there is no component with the
|
||||
* specified key.
|
||||
*/
|
||||
public String getValue(String key) {
|
||||
for (Iterator iter = components.values().iterator(); iter.hasNext();) {
|
||||
LdapRdnComponent component = (LdapRdnComponent) iter.next();
|
||||
if (ObjectUtils.nullSafeEquals(component.getKey(), key)) {
|
||||
return component.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No RdnComponent with the key " + key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an immutable copy of this instance. It will not be possible to add
|
||||
* or remove components or modify the keys and values of these components.
|
||||
*
|
||||
* @return an immutable copy of this instance.
|
||||
* @since 1.3
|
||||
*/
|
||||
public LdapRdn immutableLdapRdn() {
|
||||
Map<String, LdapRdnComponent> mapWithImmutableRdns = new LinkedHashMap<String, LdapRdnComponent>(components.size());
|
||||
for (Iterator iterator = components.values().iterator(); iterator.hasNext();) {
|
||||
LdapRdnComponent rdnComponent = (LdapRdnComponent) iterator.next();
|
||||
mapWithImmutableRdns.put(rdnComponent.getKey(), rdnComponent.immutableLdapRdnComponent());
|
||||
}
|
||||
Map<String, LdapRdnComponent> unmodifiableMapOfImmutableRdns = Collections.unmodifiableMap(mapWithImmutableRdns);
|
||||
LdapRdn immutableRdn = new LdapRdn();
|
||||
immutableRdn.components = unmodifiableMapOfImmutableRdns;
|
||||
return immutableRdn;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Callback interface used by {@link LdapTemplate} search, list and listBindings
|
||||
* methods. Implementations of this interface perform the actual work of
|
||||
* extracting results from a single <code>NameClassPair</code> (a
|
||||
* <code>NameClassPair</code>, <code>Binding</code> or
|
||||
* <code>SearchResult</code> depending on the search operation) returned by an
|
||||
* LDAP seach operation, such as search(), list(), and listBindings().
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface NameClassPairCallbackHandler {
|
||||
/**
|
||||
* Handle one entry. This method will be called once for each entry returned
|
||||
* by a search or list.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* the NameClassPair returned from the
|
||||
* <code>NamingEnumeration</code>.
|
||||
* @throws NamingException if an error occurs.
|
||||
*/
|
||||
void handleNameClassPair(NameClassPair nameClassPair) throws NamingException;
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Callback interface used by {@link LdapTemplate} search, list and listBindings
|
||||
* methods. Implementations of this interface perform the actual work of
|
||||
* extracting results from a single <code>NameClassPair</code> (a
|
||||
* <code>NameClassPair</code>, <code>Binding</code> or
|
||||
* <code>SearchResult</code> depending on the search operation) returned by an
|
||||
* LDAP seach operation, such as search(), list(), and listBindings().
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface NameClassPairCallbackHandler {
|
||||
/**
|
||||
* Handle one entry. This method will be called once for each entry returned
|
||||
* by a search or list.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* the NameClassPair returned from the
|
||||
* <code>NamingEnumeration</code>.
|
||||
* @throws NamingException if an error occurs.
|
||||
*/
|
||||
void handleNameClassPair(NameClassPair nameClassPair) throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Responsible for mapping <code>NameClassPair</code> objects to beans.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface NameClassPairMapper<T> {
|
||||
/**
|
||||
* Map <code>NameClassPair</code> to an Object. The supplied
|
||||
* <code>NameClassPair</code> is one of the results from a search
|
||||
* operation (search, list or listBindings). Depending on which search
|
||||
* operation is being performed, the <code>NameClassPair</code> might be a
|
||||
* <code>SearchResult</code>, <code>Binding</code> or
|
||||
* <code>NameClassPair</code>.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* <code>NameClassPair</code> from a search operation.
|
||||
* @return and Object built from the <code>NameClassPair</code>.
|
||||
* @throws NamingException
|
||||
* if one is encountered in the operation.
|
||||
*/
|
||||
T mapFromNameClassPair(NameClassPair nameClassPair)
|
||||
throws NamingException;
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Responsible for mapping <code>NameClassPair</code> objects to beans.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface NameClassPairMapper<T> {
|
||||
/**
|
||||
* Map <code>NameClassPair</code> to an Object. The supplied
|
||||
* <code>NameClassPair</code> is one of the results from a search
|
||||
* operation (search, list or listBindings). Depending on which search
|
||||
* operation is being performed, the <code>NameClassPair</code> might be a
|
||||
* <code>SearchResult</code>, <code>Binding</code> or
|
||||
* <code>NameClassPair</code>.
|
||||
*
|
||||
* @param nameClassPair
|
||||
* <code>NameClassPair</code> from a search operation.
|
||||
* @return and Object built from the <code>NameClassPair</code>.
|
||||
* @throws NamingException
|
||||
* if one is encountered in the operation.
|
||||
*/
|
||||
T mapFromNameClassPair(NameClassPair nameClassPair)
|
||||
throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
/**
|
||||
* Thrown by a {@link ContextMapperCallbackHandler} when it cannot retrieve an
|
||||
* object from the given <code>Binding</code>.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public class ObjectRetrievalException extends NamingException {
|
||||
|
||||
/**
|
||||
* Create a new ObjectRetrievalException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*
|
||||
*/
|
||||
public ObjectRetrievalException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectRetrievalException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
* @param cause
|
||||
* the root cause (if any)
|
||||
*/
|
||||
public ObjectRetrievalException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
/**
|
||||
* Thrown by a {@link ContextMapperCallbackHandler} when it cannot retrieve an
|
||||
* object from the given <code>Binding</code>.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
* @since 1.2
|
||||
*/
|
||||
public class ObjectRetrievalException extends NamingException {
|
||||
|
||||
/**
|
||||
* Create a new ObjectRetrievalException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
*
|
||||
*/
|
||||
public ObjectRetrievalException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectRetrievalException.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message
|
||||
* @param cause
|
||||
* the root cause (if any)
|
||||
*/
|
||||
public ObjectRetrievalException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Interface for delegating an actual search operation. The typical
|
||||
* implementation of executeSearch would be something like:
|
||||
*
|
||||
* <pre>
|
||||
* SearchExecutor executor = new SearchExecutor(){
|
||||
* public NamingEnumeration executeSearch(DirContext ctx) throws NamingException{
|
||||
* return ctx.search(dn, filter, searchControls);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see org.springframework.ldap.core.LdapTemplate#search(SearchExecutor,
|
||||
* NameClassPairCallbackHandler)
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface SearchExecutor {
|
||||
/**
|
||||
* Execute the actual search.
|
||||
*
|
||||
* @param ctx
|
||||
* the <code>DirContext</code> on which to work.
|
||||
* @return the <code>NamingEnumeration</code> resulting from the search
|
||||
* operation.
|
||||
* @throws NamingException
|
||||
* if the search results in one.
|
||||
*/
|
||||
NamingEnumeration executeSearch(DirContext ctx)
|
||||
throws NamingException;
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
/**
|
||||
* Interface for delegating an actual search operation. The typical
|
||||
* implementation of executeSearch would be something like:
|
||||
*
|
||||
* <pre>
|
||||
* SearchExecutor executor = new SearchExecutor(){
|
||||
* public NamingEnumeration executeSearch(DirContext ctx) throws NamingException{
|
||||
* return ctx.search(dn, filter, searchControls);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see org.springframework.ldap.core.LdapTemplate#search(SearchExecutor,
|
||||
* NameClassPairCallbackHandler)
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface SearchExecutor {
|
||||
/**
|
||||
* Execute the actual search.
|
||||
*
|
||||
* @param ctx
|
||||
* the <code>DirContext</code> on which to work.
|
||||
* @return the <code>NamingEnumeration</code> resulting from the search
|
||||
* operation.
|
||||
* @throws NamingException
|
||||
* if the search results in one.
|
||||
*/
|
||||
NamingEnumeration executeSearch(DirContext ctx)
|
||||
throws NamingException;
|
||||
}
|
||||
|
||||
@@ -1,206 +1,206 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 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;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import javax.naming.ldap.StartTlsRequest;
|
||||
import javax.naming.ldap.StartTlsResponse;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
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}
|
||||
* implementations that apply TLS security to the connections. The supported TLS
|
||||
* behavior differs between servers. E.g., some servers expect the TLS
|
||||
* connection be shut down gracefully before the actual target context is
|
||||
* closed, whereas other servers do not support that. The
|
||||
* <code>shutdownTlsGracefully</code> property controls this behavior; the
|
||||
* property defaults to <code>false</code>.
|
||||
* <p>
|
||||
* The <code>SSLSocketFactory</code> used for TLS negotiation can be customized
|
||||
* using the <code>sslSocketFactory</code> property. This allows for example a
|
||||
* socket factory that can load the keystore/truststore using the Spring
|
||||
* Resource abstraction. This provides a much more Spring-like strategy for
|
||||
* configuring PKI credentials for authentication, in addition to allowing
|
||||
* application-specific keystores and truststores running in the same JVM.
|
||||
* <p>
|
||||
* In some rare occasions there is a need to supply a
|
||||
* <code>HostnameVerifier</code> to the TLS processing instructions in order to
|
||||
* have the returned certificate properly validated. If a
|
||||
* <code>HostnameVerifier</code> is supplied to
|
||||
* {@link #setHostnameVerifier(HostnameVerifier)}, that will be applied to the
|
||||
* processing.
|
||||
* <p>
|
||||
* For further information regarding TLS, refer to <a
|
||||
* href="https://java.sun.com/products/jndi/tutorial/ldap/ext/starttls.html">this
|
||||
* page</a>.
|
||||
* <p>
|
||||
* <b>NB:</b> TLS negotiation is an expensive process, which is why you will
|
||||
* most likely want to use connection pooling, to make sure new connections are
|
||||
* not created for each individual request. It is imperative however, that the
|
||||
* built-in LDAP connection pooling is not used in combination with the TLS
|
||||
* AuthenticationStrategy implementations - this will not work. You should use
|
||||
* the Spring LDAP PoolingContextSource instead.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class AbstractTlsDirContextAuthenticationStrategy implements DirContextAuthenticationStrategy {
|
||||
|
||||
/** Hostname verifier to use for cert subject validation */
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
|
||||
/** Flag to cause graceful shutdown required by some LDAP DSAs */
|
||||
private boolean shutdownTlsGracefully = false;
|
||||
|
||||
/** SSL socket factory to use for startTLS negotiation */
|
||||
private SSLSocketFactory sslSocketFactory;
|
||||
|
||||
/**
|
||||
* Specify whether the TLS should be shut down gracefully before the target
|
||||
* context is closed. Defaults to <code>false</code>.
|
||||
*
|
||||
* @param shutdownTlsGracefully <code>true</code> to shut down the TLS
|
||||
* connection explicitly, <code>false</code> closes the target context
|
||||
* immediately.
|
||||
*/
|
||||
public void setShutdownTlsGracefully(boolean shutdownTlsGracefully) {
|
||||
this.shutdownTlsGracefully = shutdownTlsGracefully;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the optional
|
||||
* <code>HostnameVerifier</code> to use for verifying incoming certificates. Defaults to <code>null</code>
|
||||
* , meaning that the default hostname verification will take place.
|
||||
*
|
||||
* @param hostnameVerifier The <code>HostnameVerifier</code> to use, if any.
|
||||
*/
|
||||
public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional SSL socket factory used for startTLS negotiation.
|
||||
* Defaults to <code>null</code> to indicate that the default socket factory
|
||||
* provided by the underlying JSSE provider should be used.
|
||||
* @param sslSocketFactory SSL socket factory to use, if any.
|
||||
*/
|
||||
public void setSslSocketFactory(final SSLSocketFactory sslSocketFactory) {
|
||||
this.sslSocketFactory = sslSocketFactory;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#setupEnvironment(java.util.Hashtable, java.lang.String, java.lang.String)
|
||||
*/
|
||||
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.
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#processContextAfterCreation(javax.naming.directory.DirContext, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public final DirContext processContextAfterCreation(DirContext ctx, String userDn, String password)
|
||||
throws NamingException {
|
||||
|
||||
if (ctx instanceof LdapContext) {
|
||||
final LdapContext ldapCtx = (LdapContext) ctx;
|
||||
final StartTlsResponse tlsResponse = (StartTlsResponse) ldapCtx.extendedOperation(new StartTlsRequest());
|
||||
try {
|
||||
if (hostnameVerifier != null) {
|
||||
tlsResponse.setHostnameVerifier(hostnameVerifier);
|
||||
}
|
||||
tlsResponse.negotiate(sslSocketFactory); // If null, the default SSL socket factory is used
|
||||
applyAuthentication(ldapCtx, userDn, password);
|
||||
|
||||
if (shutdownTlsGracefully) {
|
||||
// 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<?>[] {
|
||||
LdapContext.class, DirContextProxy.class }, new TlsAwareDirContextProxy(ldapCtx,
|
||||
tlsResponse));
|
||||
}
|
||||
else {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LdapUtils.closeContext(ctx);
|
||||
throw new UncategorizedLdapException("Failed to negotiate TLS session", e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Processed Context must be an LDAPv3 context, i.e. an LdapContext implementation");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the actual authentication to the specified <code>LdapContext</code>
|
||||
* . Typically, this will involve adding stuff to the environment.
|
||||
*
|
||||
* @param ctx the <code>LdapContext</code> instance.
|
||||
* @param userDn the user dn of the user to authenticate.
|
||||
* @param password the password of the user to authenticate.
|
||||
* @throws NamingException if any error occurs.
|
||||
*/
|
||||
protected abstract void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException;
|
||||
|
||||
private static final class TlsAwareDirContextProxy implements DirContextProxy, InvocationHandler {
|
||||
|
||||
private static final String GET_TARGET_CONTEXT_METHOD_NAME = "getTargetContext";
|
||||
|
||||
private static final String CLOSE_METHOD_NAME = "close";
|
||||
|
||||
private final LdapContext target;
|
||||
|
||||
private final StartTlsResponse tlsResponse;
|
||||
|
||||
public TlsAwareDirContextProxy(LdapContext target, StartTlsResponse tlsResponse) {
|
||||
this.target = target;
|
||||
this.tlsResponse = tlsResponse;
|
||||
}
|
||||
|
||||
public DirContext getTargetContext() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if (method.getName().equals(CLOSE_METHOD_NAME)) {
|
||||
tlsResponse.close();
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
else if (method.getName().equals(GET_TARGET_CONTEXT_METHOD_NAME)) {
|
||||
return target;
|
||||
}
|
||||
else {
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 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;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import javax.naming.ldap.StartTlsRequest;
|
||||
import javax.naming.ldap.StartTlsResponse;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
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}
|
||||
* implementations that apply TLS security to the connections. The supported TLS
|
||||
* behavior differs between servers. E.g., some servers expect the TLS
|
||||
* connection be shut down gracefully before the actual target context is
|
||||
* closed, whereas other servers do not support that. The
|
||||
* <code>shutdownTlsGracefully</code> property controls this behavior; the
|
||||
* property defaults to <code>false</code>.
|
||||
* <p>
|
||||
* The <code>SSLSocketFactory</code> used for TLS negotiation can be customized
|
||||
* using the <code>sslSocketFactory</code> property. This allows for example a
|
||||
* socket factory that can load the keystore/truststore using the Spring
|
||||
* Resource abstraction. This provides a much more Spring-like strategy for
|
||||
* configuring PKI credentials for authentication, in addition to allowing
|
||||
* application-specific keystores and truststores running in the same JVM.
|
||||
* <p>
|
||||
* In some rare occasions there is a need to supply a
|
||||
* <code>HostnameVerifier</code> to the TLS processing instructions in order to
|
||||
* have the returned certificate properly validated. If a
|
||||
* <code>HostnameVerifier</code> is supplied to
|
||||
* {@link #setHostnameVerifier(HostnameVerifier)}, that will be applied to the
|
||||
* processing.
|
||||
* <p>
|
||||
* For further information regarding TLS, refer to <a
|
||||
* href="https://java.sun.com/products/jndi/tutorial/ldap/ext/starttls.html">this
|
||||
* page</a>.
|
||||
* <p>
|
||||
* <b>NB:</b> TLS negotiation is an expensive process, which is why you will
|
||||
* most likely want to use connection pooling, to make sure new connections are
|
||||
* not created for each individual request. It is imperative however, that the
|
||||
* built-in LDAP connection pooling is not used in combination with the TLS
|
||||
* AuthenticationStrategy implementations - this will not work. You should use
|
||||
* the Spring LDAP PoolingContextSource instead.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class AbstractTlsDirContextAuthenticationStrategy implements DirContextAuthenticationStrategy {
|
||||
|
||||
/** Hostname verifier to use for cert subject validation */
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
|
||||
/** Flag to cause graceful shutdown required by some LDAP DSAs */
|
||||
private boolean shutdownTlsGracefully = false;
|
||||
|
||||
/** SSL socket factory to use for startTLS negotiation */
|
||||
private SSLSocketFactory sslSocketFactory;
|
||||
|
||||
/**
|
||||
* Specify whether the TLS should be shut down gracefully before the target
|
||||
* context is closed. Defaults to <code>false</code>.
|
||||
*
|
||||
* @param shutdownTlsGracefully <code>true</code> to shut down the TLS
|
||||
* connection explicitly, <code>false</code> closes the target context
|
||||
* immediately.
|
||||
*/
|
||||
public void setShutdownTlsGracefully(boolean shutdownTlsGracefully) {
|
||||
this.shutdownTlsGracefully = shutdownTlsGracefully;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the optional
|
||||
* <code>HostnameVerifier</code> to use for verifying incoming certificates. Defaults to <code>null</code>
|
||||
* , meaning that the default hostname verification will take place.
|
||||
*
|
||||
* @param hostnameVerifier The <code>HostnameVerifier</code> to use, if any.
|
||||
*/
|
||||
public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional SSL socket factory used for startTLS negotiation.
|
||||
* Defaults to <code>null</code> to indicate that the default socket factory
|
||||
* provided by the underlying JSSE provider should be used.
|
||||
* @param sslSocketFactory SSL socket factory to use, if any.
|
||||
*/
|
||||
public void setSslSocketFactory(final SSLSocketFactory sslSocketFactory) {
|
||||
this.sslSocketFactory = sslSocketFactory;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#setupEnvironment(java.util.Hashtable, java.lang.String, java.lang.String)
|
||||
*/
|
||||
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.
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#processContextAfterCreation(javax.naming.directory.DirContext, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public final DirContext processContextAfterCreation(DirContext ctx, String userDn, String password)
|
||||
throws NamingException {
|
||||
|
||||
if (ctx instanceof LdapContext) {
|
||||
final LdapContext ldapCtx = (LdapContext) ctx;
|
||||
final StartTlsResponse tlsResponse = (StartTlsResponse) ldapCtx.extendedOperation(new StartTlsRequest());
|
||||
try {
|
||||
if (hostnameVerifier != null) {
|
||||
tlsResponse.setHostnameVerifier(hostnameVerifier);
|
||||
}
|
||||
tlsResponse.negotiate(sslSocketFactory); // If null, the default SSL socket factory is used
|
||||
applyAuthentication(ldapCtx, userDn, password);
|
||||
|
||||
if (shutdownTlsGracefully) {
|
||||
// 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<?>[] {
|
||||
LdapContext.class, DirContextProxy.class }, new TlsAwareDirContextProxy(ldapCtx,
|
||||
tlsResponse));
|
||||
}
|
||||
else {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LdapUtils.closeContext(ctx);
|
||||
throw new UncategorizedLdapException("Failed to negotiate TLS session", e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Processed Context must be an LDAPv3 context, i.e. an LdapContext implementation");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the actual authentication to the specified <code>LdapContext</code>
|
||||
* . Typically, this will involve adding stuff to the environment.
|
||||
*
|
||||
* @param ctx the <code>LdapContext</code> instance.
|
||||
* @param userDn the user dn of the user to authenticate.
|
||||
* @param password the password of the user to authenticate.
|
||||
* @throws NamingException if any error occurs.
|
||||
*/
|
||||
protected abstract void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException;
|
||||
|
||||
private static final class TlsAwareDirContextProxy implements DirContextProxy, InvocationHandler {
|
||||
|
||||
private static final String GET_TARGET_CONTEXT_METHOD_NAME = "getTargetContext";
|
||||
|
||||
private static final String CLOSE_METHOD_NAME = "close";
|
||||
|
||||
private final LdapContext target;
|
||||
|
||||
private final StartTlsResponse tlsResponse;
|
||||
|
||||
public TlsAwareDirContextProxy(LdapContext target, StartTlsResponse tlsResponse) {
|
||||
this.target = target;
|
||||
this.tlsResponse = tlsResponse;
|
||||
}
|
||||
|
||||
public DirContext getTargetContext() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if (method.getName().equals(CLOSE_METHOD_NAME)) {
|
||||
tlsResponse.close();
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
else if (method.getName().equals(GET_TARGET_CONTEXT_METHOD_NAME)) {
|
||||
return target;
|
||||
}
|
||||
else {
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 org.springframework.ldap.core.DirContextProcessor;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Manages a sequence of {@link DirContextProcessor} instances. Applies
|
||||
* {@link #preProcess(DirContext)} and {@link #postProcess(DirContext)}
|
||||
* respectively in sequence on the managed objects.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class AggregateDirContextProcessor implements DirContextProcessor {
|
||||
|
||||
private List<DirContextProcessor> dirContextProcessors = new LinkedList<DirContextProcessor>();
|
||||
|
||||
/**
|
||||
* Add the supplied DirContextProcessor to the list of managed objects.
|
||||
*
|
||||
* @param processor
|
||||
* the DirContextpProcessor to add.
|
||||
*/
|
||||
public void addDirContextProcessor(DirContextProcessor processor) {
|
||||
dirContextProcessors.add(processor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of managed {@link DirContextProcessor} instances.
|
||||
*
|
||||
* @return the managed list of {@link DirContextProcessor} instances.
|
||||
*/
|
||||
public List<DirContextProcessor> getDirContextProcessors() {
|
||||
return dirContextProcessors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of managed {@link DirContextProcessor} instances.
|
||||
*
|
||||
* @param dirContextProcessors
|
||||
* the list of {@link DirContextProcessor} instances to set.
|
||||
*/
|
||||
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 (DirContextProcessor processor : dirContextProcessors) {
|
||||
processor.preProcess(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.core.DirContextProcessor#postProcess(javax.naming.directory.DirContext)
|
||||
*/
|
||||
public void postProcess(DirContext ctx) throws NamingException {
|
||||
for (DirContextProcessor processor : dirContextProcessors) {
|
||||
processor.postProcess(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 org.springframework.ldap.core.DirContextProcessor;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Manages a sequence of {@link DirContextProcessor} instances. Applies
|
||||
* {@link #preProcess(DirContext)} and {@link #postProcess(DirContext)}
|
||||
* respectively in sequence on the managed objects.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class AggregateDirContextProcessor implements DirContextProcessor {
|
||||
|
||||
private List<DirContextProcessor> dirContextProcessors = new LinkedList<DirContextProcessor>();
|
||||
|
||||
/**
|
||||
* Add the supplied DirContextProcessor to the list of managed objects.
|
||||
*
|
||||
* @param processor
|
||||
* the DirContextpProcessor to add.
|
||||
*/
|
||||
public void addDirContextProcessor(DirContextProcessor processor) {
|
||||
dirContextProcessors.add(processor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of managed {@link DirContextProcessor} instances.
|
||||
*
|
||||
* @return the managed list of {@link DirContextProcessor} instances.
|
||||
*/
|
||||
public List<DirContextProcessor> getDirContextProcessors() {
|
||||
return dirContextProcessors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of managed {@link DirContextProcessor} instances.
|
||||
*
|
||||
* @param dirContextProcessors
|
||||
* the list of {@link DirContextProcessor} instances to set.
|
||||
*/
|
||||
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 (DirContextProcessor processor : dirContextProcessors) {
|
||||
processor.preProcess(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.core.DirContextProcessor#postProcess(javax.naming.directory.DirContext)
|
||||
*/
|
||||
public void postProcess(DirContext ctx) throws NamingException {
|
||||
for (DirContextProcessor processor : dirContextProcessors) {
|
||||
processor.postProcess(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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 org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by classes that want to have access to the base
|
||||
* context used in the active <code>ContextSource</code>. There are several
|
||||
* cases in which services may want to have access to the base context, e.g.
|
||||
* when working with groups (<code>groupOfNames</code> objectclass), in which
|
||||
* case the full DN of each group member needs to be specified in the attribute
|
||||
* value.
|
||||
* <p>
|
||||
* If a class implements this interface and a
|
||||
* {@link BaseLdapPathBeanPostProcessor} is defined in the
|
||||
* <code>ApplicationContext</code>, the default base path will automatically
|
||||
* passed to the {@link #setBaseLdapPath(DistinguishedName)} method on
|
||||
* initialization.
|
||||
* <p>
|
||||
* <b>NB:</b>The <code>ContextSource</code> needs to be a subclass of
|
||||
* {@link AbstractContextSource} for this mechanism to work.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
* @deprecated {@link DistinguishedName} and associated classes and methods are deprecated as of 2.0.
|
||||
* Use {@link BaseLdapNameAware} instead.
|
||||
*/
|
||||
public interface BaseLdapPathAware {
|
||||
|
||||
/**
|
||||
* Set the base LDAP path specified in the current
|
||||
* <code>ApplicationContext</code>.
|
||||
* @param baseLdapPath the base path used in the <code>ContextSource</code>
|
||||
*/
|
||||
void setBaseLdapPath(DistinguishedName baseLdapPath);
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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 org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by classes that want to have access to the base
|
||||
* context used in the active <code>ContextSource</code>. There are several
|
||||
* cases in which services may want to have access to the base context, e.g.
|
||||
* when working with groups (<code>groupOfNames</code> objectclass), in which
|
||||
* case the full DN of each group member needs to be specified in the attribute
|
||||
* value.
|
||||
* <p>
|
||||
* If a class implements this interface and a
|
||||
* {@link BaseLdapPathBeanPostProcessor} is defined in the
|
||||
* <code>ApplicationContext</code>, the default base path will automatically
|
||||
* passed to the {@link #setBaseLdapPath(DistinguishedName)} method on
|
||||
* initialization.
|
||||
* <p>
|
||||
* <b>NB:</b>The <code>ContextSource</code> needs to be a subclass of
|
||||
* {@link AbstractContextSource} for this mechanism to work.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
* @deprecated {@link DistinguishedName} and associated classes and methods are deprecated as of 2.0.
|
||||
* Use {@link BaseLdapNameAware} instead.
|
||||
*/
|
||||
public interface BaseLdapPathAware {
|
||||
|
||||
/**
|
||||
* Set the base LDAP path specified in the current
|
||||
* <code>ApplicationContext</code>.
|
||||
* @param baseLdapPath the base path used in the <code>ContextSource</code>
|
||||
*/
|
||||
void setBaseLdapPath(DistinguishedName baseLdapPath);
|
||||
}
|
||||
|
||||
@@ -1,183 +1,183 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.naming.ldap.LdapName;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This <code>BeanPostProcessor</code> checks each bean if it implements
|
||||
* {@link BaseLdapNameAware} or {@link BaseLdapPathAware}.
|
||||
* If it does, the default context base LDAP path will be determined,
|
||||
* and that value will be injected to the {@link BaseLdapNameAware#setBaseLdapPath(javax.naming.ldap.LdapName)}
|
||||
* or {@link BaseLdapPathAware#setBaseLdapPath(DistinguishedName)} method of the
|
||||
* processed bean.
|
||||
* <p>
|
||||
* If the <code>baseLdapPath</code> property of this
|
||||
* <code>BeanPostProcessor</code> is set, that value will be used. Otherwise, in
|
||||
* order to determine which base LDAP path to supply to the instance the
|
||||
* <code>ApplicationContext</code> is searched for any beans that are
|
||||
* implementations of {@link BaseLdapPathSource}. If one single occurrence is
|
||||
* found, that instance is queried for its base path, and that is what will be
|
||||
* injected. If more than one {@link BaseLdapPathSource} instance is configured
|
||||
* in the <code>ApplicationContext</code>, the name of the one to use will need
|
||||
* to be specified to the <code>baseLdapPathSourceName</code> property;
|
||||
* otherwise the post processing will fail. If no {@link BaseLdapPathSource}
|
||||
* implementing bean is found in the context and the <code>basePath</code>
|
||||
* property is not set, post processing will also fail.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
*/
|
||||
public class BaseLdapPathBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private LdapName basePath;
|
||||
|
||||
private String baseLdapPathSourceName;
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) {
|
||||
if(bean instanceof BaseLdapNameAware) {
|
||||
BaseLdapNameAware baseLdapNameAware = (BaseLdapNameAware) bean;
|
||||
|
||||
if (basePath != null) {
|
||||
baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(basePath));
|
||||
}
|
||||
else {
|
||||
BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext();
|
||||
baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(ldapPathSource.getBaseLdapName()));
|
||||
}
|
||||
} else if (bean instanceof BaseLdapPathAware) {
|
||||
BaseLdapPathAware baseLdapPathAware = (BaseLdapPathAware) bean;
|
||||
|
||||
if (basePath != null) {
|
||||
baseLdapPathAware.setBaseLdapPath(new DistinguishedName(basePath));
|
||||
}
|
||||
else {
|
||||
BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext();
|
||||
baseLdapPathAware.setBaseLdapPath(ldapPathSource.getBaseLdapPath().immutableDistinguishedName());
|
||||
}
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() {
|
||||
if (StringUtils.hasLength(baseLdapPathSourceName)) {
|
||||
return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class);
|
||||
}
|
||||
|
||||
Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values();
|
||||
if (beans.isEmpty()) {
|
||||
throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found");
|
||||
} else if (beans.size() == 1) {
|
||||
return beans.iterator().next();
|
||||
} else {
|
||||
BaseLdapPathSource found = null;
|
||||
|
||||
// Try to find the correct one
|
||||
for (BaseLdapPathSource bean : beans) {
|
||||
if(bean instanceof AbstractContextSource) {
|
||||
if(found != null) {
|
||||
// More than one found - nothing much to do.
|
||||
throw new NoSuchBeanDefinitionException(
|
||||
"More than BaseLdapPathSource implementation definition found in current ApplicationContext; " +
|
||||
"unable to determine the one to use. Please specify 'baseLdapPathSourceName'");
|
||||
}
|
||||
|
||||
found = bean;
|
||||
}
|
||||
}
|
||||
|
||||
if(found == null) {
|
||||
throw new NoSuchBeanDefinitionException(
|
||||
"More than BaseLdapPathSource implementation definition found in current ApplicationContext; " +
|
||||
"unable to determine the one to use (one of them should be an AbstractContextSource instance). " +
|
||||
"Please specify 'baseLdapPathSourceName'");
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
||||
// Do nothing for this implementation
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base path to be injected in all {@link BaseLdapPathAware} beans.
|
||||
* If this property is not set, the default base path will be determined
|
||||
* from any defined {@link BaseLdapPathSource} instances available in the
|
||||
* <code>ApplicationContext</code>.
|
||||
*
|
||||
* @param basePath the base path.
|
||||
* @deprecated {@link DistinguishedName} and associated classes and methods are deprecated as of 2.0.
|
||||
*/
|
||||
public void setBasePath(DistinguishedName basePath) {
|
||||
this.basePath = LdapUtils.newLdapName(basePath);
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = LdapUtils.newLdapName(basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the <code>ContextSource</code> bean to use for getting
|
||||
* the base path. This method is typically useful if several ContextSource
|
||||
* instances have been configured.
|
||||
*
|
||||
* @param contextSourceName the name of the <code>ContextSource</code> bean
|
||||
* to use for determining the base path.
|
||||
*/
|
||||
public void setBaseLdapPathSourceName(String contextSourceName) {
|
||||
this.baseLdapPathSourceName = contextSourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order value of this object for sorting purposes.
|
||||
*
|
||||
* @param order the order of this instance. Defaults to <code>Ordered.LOWEST_PRECEDENCE</code>.
|
||||
* @see Ordered
|
||||
* @since 1.3.2
|
||||
*/
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.naming.ldap.LdapName;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This <code>BeanPostProcessor</code> checks each bean if it implements
|
||||
* {@link BaseLdapNameAware} or {@link BaseLdapPathAware}.
|
||||
* If it does, the default context base LDAP path will be determined,
|
||||
* and that value will be injected to the {@link BaseLdapNameAware#setBaseLdapPath(javax.naming.ldap.LdapName)}
|
||||
* or {@link BaseLdapPathAware#setBaseLdapPath(DistinguishedName)} method of the
|
||||
* processed bean.
|
||||
* <p>
|
||||
* If the <code>baseLdapPath</code> property of this
|
||||
* <code>BeanPostProcessor</code> is set, that value will be used. Otherwise, in
|
||||
* order to determine which base LDAP path to supply to the instance the
|
||||
* <code>ApplicationContext</code> is searched for any beans that are
|
||||
* implementations of {@link BaseLdapPathSource}. If one single occurrence is
|
||||
* found, that instance is queried for its base path, and that is what will be
|
||||
* injected. If more than one {@link BaseLdapPathSource} instance is configured
|
||||
* in the <code>ApplicationContext</code>, the name of the one to use will need
|
||||
* to be specified to the <code>baseLdapPathSourceName</code> property;
|
||||
* otherwise the post processing will fail. If no {@link BaseLdapPathSource}
|
||||
* implementing bean is found in the context and the <code>basePath</code>
|
||||
* property is not set, post processing will also fail.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 1.2
|
||||
*/
|
||||
public class BaseLdapPathBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private LdapName basePath;
|
||||
|
||||
private String baseLdapPathSourceName;
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) {
|
||||
if(bean instanceof BaseLdapNameAware) {
|
||||
BaseLdapNameAware baseLdapNameAware = (BaseLdapNameAware) bean;
|
||||
|
||||
if (basePath != null) {
|
||||
baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(basePath));
|
||||
}
|
||||
else {
|
||||
BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext();
|
||||
baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(ldapPathSource.getBaseLdapName()));
|
||||
}
|
||||
} else if (bean instanceof BaseLdapPathAware) {
|
||||
BaseLdapPathAware baseLdapPathAware = (BaseLdapPathAware) bean;
|
||||
|
||||
if (basePath != null) {
|
||||
baseLdapPathAware.setBaseLdapPath(new DistinguishedName(basePath));
|
||||
}
|
||||
else {
|
||||
BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext();
|
||||
baseLdapPathAware.setBaseLdapPath(ldapPathSource.getBaseLdapPath().immutableDistinguishedName());
|
||||
}
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() {
|
||||
if (StringUtils.hasLength(baseLdapPathSourceName)) {
|
||||
return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class);
|
||||
}
|
||||
|
||||
Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values();
|
||||
if (beans.isEmpty()) {
|
||||
throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found");
|
||||
} else if (beans.size() == 1) {
|
||||
return beans.iterator().next();
|
||||
} else {
|
||||
BaseLdapPathSource found = null;
|
||||
|
||||
// Try to find the correct one
|
||||
for (BaseLdapPathSource bean : beans) {
|
||||
if(bean instanceof AbstractContextSource) {
|
||||
if(found != null) {
|
||||
// More than one found - nothing much to do.
|
||||
throw new NoSuchBeanDefinitionException(
|
||||
"More than BaseLdapPathSource implementation definition found in current ApplicationContext; " +
|
||||
"unable to determine the one to use. Please specify 'baseLdapPathSourceName'");
|
||||
}
|
||||
|
||||
found = bean;
|
||||
}
|
||||
}
|
||||
|
||||
if(found == null) {
|
||||
throw new NoSuchBeanDefinitionException(
|
||||
"More than BaseLdapPathSource implementation definition found in current ApplicationContext; " +
|
||||
"unable to determine the one to use (one of them should be an AbstractContextSource instance). " +
|
||||
"Please specify 'baseLdapPathSourceName'");
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
||||
// Do nothing for this implementation
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base path to be injected in all {@link BaseLdapPathAware} beans.
|
||||
* If this property is not set, the default base path will be determined
|
||||
* from any defined {@link BaseLdapPathSource} instances available in the
|
||||
* <code>ApplicationContext</code>.
|
||||
*
|
||||
* @param basePath the base path.
|
||||
* @deprecated {@link DistinguishedName} and associated classes and methods are deprecated as of 2.0.
|
||||
*/
|
||||
public void setBasePath(DistinguishedName basePath) {
|
||||
this.basePath = LdapUtils.newLdapName(basePath);
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = LdapUtils.newLdapName(basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the <code>ContextSource</code> bean to use for getting
|
||||
* the base path. This method is typically useful if several ContextSource
|
||||
* instances have been configured.
|
||||
*
|
||||
* @param contextSourceName the name of the <code>ContextSource</code> bean
|
||||
* to use for determining the base path.
|
||||
*/
|
||||
public void setBaseLdapPathSourceName(String contextSourceName) {
|
||||
this.baseLdapPathSourceName = contextSourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order value of this object for sorting purposes.
|
||||
*
|
||||
* @param order the order of this instance. Defaults to <code>Ordered.LOWEST_PRECEDENCE</code>.
|
||||
* @see Ordered
|
||||
* @since 1.3.2
|
||||
*/
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.NameClassPair;
|
||||
|
||||
import org.springframework.ldap.core.NameClassPairCallbackHandler;
|
||||
|
||||
/**
|
||||
* A {@link NameClassPairCallbackHandler} for counting all returned entries.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public class CountNameClassPairCallbackHandler implements
|
||||
NameClassPairCallbackHandler {
|
||||
|
||||
private int noOfRows = 0;
|
||||
|
||||
/**
|
||||
* Get the number of rows that was returned by the search.
|
||||
*
|
||||
* @return the number of entries that have been handled.
|
||||
*/
|
||||
public int getNoOfRows() {
|
||||
return noOfRows;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.SearchResultCallbackHandler#handleSearchResult(javax.naming.directory.SearchResult)
|
||||
*/
|
||||
public void handleNameClassPair(NameClassPair nameClassPair) {
|
||||
noOfRows++;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.NameClassPair;
|
||||
|
||||
import org.springframework.ldap.core.NameClassPairCallbackHandler;
|
||||
|
||||
/**
|
||||
* A {@link NameClassPairCallbackHandler} for counting all returned entries.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*/
|
||||
public class CountNameClassPairCallbackHandler implements
|
||||
NameClassPairCallbackHandler {
|
||||
|
||||
private int noOfRows = 0;
|
||||
|
||||
/**
|
||||
* Get the number of rows that was returned by the search.
|
||||
*
|
||||
* @return the number of entries that have been handled.
|
||||
*/
|
||||
public int getNoOfRows() {
|
||||
return noOfRows;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.SearchResultCallbackHandler#handleSearchResult(javax.naming.directory.SearchResult)
|
||||
*/
|
||||
public void handleNameClassPair(NameClassPair nameClassPair) {
|
||||
noOfRows++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
|
||||
/**
|
||||
* Default implementation of TLS authentication. Applies <code>SIMPLE</code>
|
||||
* authentication on top of the negotiated TLS session. Refer to
|
||||
* {@link AbstractTlsDirContextAuthenticationStrategy} for configuration
|
||||
* options.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @see AbstractTlsDirContextAuthenticationStrategy
|
||||
* @see AbstractContextSource
|
||||
*/
|
||||
public class DefaultTlsDirContextAuthenticationStrategy extends AbstractTlsDirContextAuthenticationStrategy {
|
||||
private static final String SIMPLE_AUTHENTICATION = "simple";
|
||||
|
||||
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
|
||||
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION);
|
||||
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn);
|
||||
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
|
||||
// Force a server call as we have updated the environment (gh-430, gh-502)
|
||||
ctx.lookup("");
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
|
||||
/**
|
||||
* Default implementation of TLS authentication. Applies <code>SIMPLE</code>
|
||||
* authentication on top of the negotiated TLS session. Refer to
|
||||
* {@link AbstractTlsDirContextAuthenticationStrategy} for configuration
|
||||
* options.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @see AbstractTlsDirContextAuthenticationStrategy
|
||||
* @see AbstractContextSource
|
||||
*/
|
||||
public class DefaultTlsDirContextAuthenticationStrategy extends AbstractTlsDirContextAuthenticationStrategy {
|
||||
private static final String SIMPLE_AUTHENTICATION = "simple";
|
||||
|
||||
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
|
||||
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION);
|
||||
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn);
|
||||
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
|
||||
// Force a server call as we have updated the environment (gh-430, gh-502)
|
||||
ctx.lookup("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 org.springframework.ldap.core.AuthenticationSource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* A strategy to use when authenticating LDAP connections on creation. When
|
||||
* authenticating LDAP connections different strategies are needed depending on
|
||||
* the authentication mechanism used. Furthermore, depending on the mechanism
|
||||
* the work to be done needs to be applied at different stages of the
|
||||
* <code>DirContext</code> creation process. A
|
||||
* DirContextAuthenticationStrategy contains the logic to perform a particular
|
||||
* type of authentication mechanism and will be called by its
|
||||
* {@link ContextSource} at appropriate stages of the process.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface DirContextAuthenticationStrategy {
|
||||
|
||||
/**
|
||||
* This method is responsible for preparing the environment to be used when
|
||||
* creating the <code>DirContext</code> instance. The base environment
|
||||
* (including URL, <code>ContextFactory</code> etc. will already be set,
|
||||
* and this method is called just before the actual Context is to be
|
||||
* created.
|
||||
*
|
||||
* @param env The <code>Hashtable</code> to be sent to the
|
||||
* <code>DirContext</code> instance on initialization. Pre-configured with
|
||||
* the basic settings; the implementation of this method is responsible for
|
||||
* manipulating the environment as appropriate for the particular
|
||||
* authentication mechanism.
|
||||
* @param userDn the user DN to authenticate, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @param password the password to authenticate with, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @throws NamingException if anything goes wrong. This will cause the
|
||||
* <code>DirContext</code> creation to be aborted and the exception to be
|
||||
* translated and rethrown.
|
||||
*/
|
||||
void setupEnvironment(Hashtable<String, Object> env, String userDn, String password) throws NamingException;
|
||||
|
||||
/**
|
||||
* This method is responsible for post-processing the
|
||||
* <code>DirContext</code> instance after it has been created. It will be
|
||||
* called immediately after the instance has been created. Some
|
||||
* authentication mechanisms, e.g. TLS, require particular stuff to happen
|
||||
* before the actual target Context is closed. This method provides the
|
||||
* possibility to replace or wrap the actual DirContext with a proxy so that
|
||||
* any calls on it may be intercepted.
|
||||
*
|
||||
* @param ctx the freshly created <code>DirContext</code> instance. The
|
||||
* actual implementation class (e.g. <code>InitialLdapContext</code>)
|
||||
* depends on the {@link ContextSource} implementation.
|
||||
* @param userDn the user DN to authenticate, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @param password the password to authenticate with, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @return the DirContext, possibly modified, replaced or wrapped.
|
||||
* @throws NamingException if anything goes wrong. This will cause the
|
||||
* <code>DirContext</code> creation to be aborted and the exception to be
|
||||
* translated and rethrown.
|
||||
*/
|
||||
DirContext processContextAfterCreation(DirContext ctx, String userDn, String password)
|
||||
throws NamingException;
|
||||
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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 org.springframework.ldap.core.AuthenticationSource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* A strategy to use when authenticating LDAP connections on creation. When
|
||||
* authenticating LDAP connections different strategies are needed depending on
|
||||
* the authentication mechanism used. Furthermore, depending on the mechanism
|
||||
* the work to be done needs to be applied at different stages of the
|
||||
* <code>DirContext</code> creation process. A
|
||||
* DirContextAuthenticationStrategy contains the logic to perform a particular
|
||||
* type of authentication mechanism and will be called by its
|
||||
* {@link ContextSource} at appropriate stages of the process.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface DirContextAuthenticationStrategy {
|
||||
|
||||
/**
|
||||
* This method is responsible for preparing the environment to be used when
|
||||
* creating the <code>DirContext</code> instance. The base environment
|
||||
* (including URL, <code>ContextFactory</code> etc. will already be set,
|
||||
* and this method is called just before the actual Context is to be
|
||||
* created.
|
||||
*
|
||||
* @param env The <code>Hashtable</code> to be sent to the
|
||||
* <code>DirContext</code> instance on initialization. Pre-configured with
|
||||
* the basic settings; the implementation of this method is responsible for
|
||||
* manipulating the environment as appropriate for the particular
|
||||
* authentication mechanism.
|
||||
* @param userDn the user DN to authenticate, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @param password the password to authenticate with, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @throws NamingException if anything goes wrong. This will cause the
|
||||
* <code>DirContext</code> creation to be aborted and the exception to be
|
||||
* translated and rethrown.
|
||||
*/
|
||||
void setupEnvironment(Hashtable<String, Object> env, String userDn, String password) throws NamingException;
|
||||
|
||||
/**
|
||||
* This method is responsible for post-processing the
|
||||
* <code>DirContext</code> instance after it has been created. It will be
|
||||
* called immediately after the instance has been created. Some
|
||||
* authentication mechanisms, e.g. TLS, require particular stuff to happen
|
||||
* before the actual target Context is closed. This method provides the
|
||||
* possibility to replace or wrap the actual DirContext with a proxy so that
|
||||
* any calls on it may be intercepted.
|
||||
*
|
||||
* @param ctx the freshly created <code>DirContext</code> instance. The
|
||||
* actual implementation class (e.g. <code>InitialLdapContext</code>)
|
||||
* depends on the {@link ContextSource} implementation.
|
||||
* @param userDn the user DN to authenticate, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @param password the password to authenticate with, as received from the
|
||||
* {@link AuthenticationSource} of the {@link ContextSource}.
|
||||
* @return the DirContext, possibly modified, replaced or wrapped.
|
||||
* @throws NamingException if anything goes wrong. This will cause the
|
||||
* <code>DirContext</code> creation to be aborted and the exception to be
|
||||
* translated and rethrown.
|
||||
*/
|
||||
DirContext processContextAfterCreation(DirContext ctx, String userDn, String password)
|
||||
throws NamingException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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 java.util.Hashtable;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
|
||||
|
||||
/**
|
||||
* ContextSource implementation which creates InitialDirContext instances, for
|
||||
* LDAPv2 compatibility. For configuration information, see
|
||||
* {@link org.springframework.ldap.core.support.AbstractContextSource AbstractContextSource}.
|
||||
*
|
||||
* @see org.springframework.ldap.core.support.AbstractContextSource
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DirContextSource extends AbstractContextSource {
|
||||
|
||||
/**
|
||||
* Create a new InitialDirContext instance.
|
||||
*
|
||||
* @param environment
|
||||
* the environment to use when creating the context.
|
||||
* @return a new InitialDirContext implementation.
|
||||
*/
|
||||
protected DirContext getDirContextInstance(Hashtable environment)
|
||||
throws NamingException {
|
||||
return new InitialDirContext(environment);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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 java.util.Hashtable;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
|
||||
|
||||
/**
|
||||
* ContextSource implementation which creates InitialDirContext instances, for
|
||||
* LDAPv2 compatibility. For configuration information, see
|
||||
* {@link org.springframework.ldap.core.support.AbstractContextSource AbstractContextSource}.
|
||||
*
|
||||
* @see org.springframework.ldap.core.support.AbstractContextSource
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DirContextSource extends AbstractContextSource {
|
||||
|
||||
/**
|
||||
* Create a new InitialDirContext instance.
|
||||
*
|
||||
* @param environment
|
||||
* the environment to use when creating the context.
|
||||
* @return a new InitialDirContext implementation.
|
||||
*/
|
||||
protected DirContext getDirContextInstance(Hashtable environment)
|
||||
throws NamingException {
|
||||
return new InitialDirContext(environment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
|
||||
/**
|
||||
* {@link DirContextAuthenticationStrategy} for using TLS and external (SASL)
|
||||
* authentication. This implementation requires a client certificate to be
|
||||
* pointed out using system variables, as described <a
|
||||
* href="https://java.sun.com/products/jndi/tutorial/ldap/ext/starttls.html"
|
||||
* >here</a>. Refer to {@link AbstractTlsDirContextAuthenticationStrategy} for
|
||||
* other configuration options.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @see AbstractTlsDirContextAuthenticationStrategy
|
||||
* @see AbstractContextSource
|
||||
*/
|
||||
public class ExternalTlsDirContextAuthenticationStrategy extends AbstractTlsDirContextAuthenticationStrategy {
|
||||
|
||||
private static final String EXTERNAL_AUTHENTICATION = "EXTERNAL";
|
||||
|
||||
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
|
||||
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, EXTERNAL_AUTHENTICATION);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
|
||||
/**
|
||||
* {@link DirContextAuthenticationStrategy} for using TLS and external (SASL)
|
||||
* authentication. This implementation requires a client certificate to be
|
||||
* pointed out using system variables, as described <a
|
||||
* href="https://java.sun.com/products/jndi/tutorial/ldap/ext/starttls.html"
|
||||
* >here</a>. Refer to {@link AbstractTlsDirContextAuthenticationStrategy} for
|
||||
* other configuration options.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @see AbstractTlsDirContextAuthenticationStrategy
|
||||
* @see AbstractContextSource
|
||||
*/
|
||||
public class ExternalTlsDirContextAuthenticationStrategy extends AbstractTlsDirContextAuthenticationStrategy {
|
||||
|
||||
private static final String EXTERNAL_AUTHENTICATION = "EXTERNAL";
|
||||
|
||||
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
|
||||
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, EXTERNAL_AUTHENTICATION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.ldap.InitialLdapContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* ContextSource implementation which creates an <code>InitialLdapContext</code>
|
||||
* instance. For configuration information, see
|
||||
* {@link org.springframework.ldap.core.support.AbstractContextSource AbstractContextSource}.
|
||||
*
|
||||
* @see org.springframework.ldap.core.support.AbstractContextSource
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Adam Skogman
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapContextSource extends AbstractContextSource {
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.support.AbstractContextSource#getDirContextInstance(java.util.Hashtable)
|
||||
*/
|
||||
protected DirContext getDirContextInstance(Hashtable<String, Object> environment)
|
||||
throws NamingException {
|
||||
return new InitialLdapContext(environment, null);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.ldap.InitialLdapContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* ContextSource implementation which creates an <code>InitialLdapContext</code>
|
||||
* instance. For configuration information, see
|
||||
* {@link org.springframework.ldap.core.support.AbstractContextSource AbstractContextSource}.
|
||||
*
|
||||
* @see org.springframework.ldap.core.support.AbstractContextSource
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Adam Skogman
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class LdapContextSource extends AbstractContextSource {
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.support.AbstractContextSource#getDirContextInstance(java.util.Hashtable)
|
||||
*/
|
||||
protected DirContext getDirContextInstance(Hashtable<String, Object> environment)
|
||||
throws NamingException {
|
||||
return new InitialLdapContext(environment, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* The default {@link DirContextAuthenticationStrategy} implementation, setting
|
||||
* the <code>DirContext</code> environment up for 'SIMPLE' authentication, and
|
||||
* specifying the user DN and password as SECURITY_PRINCIPAL and
|
||||
* SECURITY_CREDENTIALS respectively in the authenticated environment before the
|
||||
* context is created.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class SimpleDirContextAuthenticationStrategy implements DirContextAuthenticationStrategy {
|
||||
|
||||
private static final String SIMPLE_AUTHENTICATION = "simple";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#setupEnvironment(java.util.Hashtable,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#processContextAfterCreation(javax.naming.directory.DirContext,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public DirContext processContextAfterCreation(DirContext ctx, String userDn, String password) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* The default {@link DirContextAuthenticationStrategy} implementation, setting
|
||||
* the <code>DirContext</code> environment up for 'SIMPLE' authentication, and
|
||||
* specifying the user DN and password as SECURITY_PRINCIPAL and
|
||||
* SECURITY_CREDENTIALS respectively in the authenticated environment before the
|
||||
* context is created.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class SimpleDirContextAuthenticationStrategy implements DirContextAuthenticationStrategy {
|
||||
|
||||
private static final String SIMPLE_AUTHENTICATION = "simple";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#setupEnvironment(java.util.Hashtable,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.support.DirContextAuthenticationStrategy#processContextAfterCreation(javax.naming.directory.DirContext,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public DirContext processContextAfterCreation(DirContext ctx, String userDn, String password) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* Convenience class that implements most of the methods in the Filter
|
||||
* interface.
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public abstract class AbstractFilter implements Filter {
|
||||
|
||||
private static final int DEFAULT_BUFFER_SIZE = 256;
|
||||
|
||||
@Override
|
||||
public String encode() {
|
||||
StringBuffer buf = new StringBuffer(DEFAULT_BUFFER_SIZE);
|
||||
buf = encode(buf);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return encode();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* Convenience class that implements most of the methods in the Filter
|
||||
* interface.
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public abstract class AbstractFilter implements Filter {
|
||||
|
||||
private static final int DEFAULT_BUFFER_SIZE = 256;
|
||||
|
||||
@Override
|
||||
public String encode() {
|
||||
StringBuffer buf = new StringBuffer(DEFAULT_BUFFER_SIZE);
|
||||
buf = encode(buf);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return encode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter for a logical AND. Example:
|
||||
*
|
||||
* <pre>
|
||||
* AndFilter filter = new AndFilter();
|
||||
* filter.and(new EqualsFilter("objectclass", "person");
|
||||
* filter.and(new EqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.encode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in: <code>(&(objectclass=person)(cn=Some CN))</code>
|
||||
*
|
||||
* @see org.springframework.ldap.filter.EqualsFilter
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class AndFilter extends BinaryLogicalFilter {
|
||||
|
||||
private static final String AMPERSAND = "&";
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.BinaryLogicalFilter#getLogicalOperator()
|
||||
*/
|
||||
protected String getLogicalOperator() {
|
||||
return AMPERSAND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a query to the AND expression.
|
||||
*
|
||||
* @param query The expression to AND with the rest of the AND:ed
|
||||
* expressions.
|
||||
* @return This LdapAndQuery
|
||||
*/
|
||||
public AndFilter and(Filter query) {
|
||||
append(query);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter for a logical AND. Example:
|
||||
*
|
||||
* <pre>
|
||||
* AndFilter filter = new AndFilter();
|
||||
* filter.and(new EqualsFilter("objectclass", "person");
|
||||
* filter.and(new EqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.encode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in: <code>(&(objectclass=person)(cn=Some CN))</code>
|
||||
*
|
||||
* @see org.springframework.ldap.filter.EqualsFilter
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class AndFilter extends BinaryLogicalFilter {
|
||||
|
||||
private static final String AMPERSAND = "&";
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.BinaryLogicalFilter#getLogicalOperator()
|
||||
*/
|
||||
protected String getLogicalOperator() {
|
||||
return AMPERSAND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a query to the AND expression.
|
||||
*
|
||||
* @param query The expression to AND with the rest of the AND:ed
|
||||
* expressions.
|
||||
* @return This LdapAndQuery
|
||||
*/
|
||||
public AndFilter and(Filter query) {
|
||||
append(query);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract superclass for binary logical operations, that is "AND"
|
||||
* and "OR" operations.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class BinaryLogicalFilter extends AbstractFilter {
|
||||
|
||||
private List<Filter> queryList = new LinkedList<Filter>();
|
||||
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
if (queryList.size() <= 0) {
|
||||
|
||||
// only output query if contains anything
|
||||
return buff;
|
||||
|
||||
}
|
||||
else if (queryList.size() == 1) {
|
||||
|
||||
// don't add the &
|
||||
Filter query = queryList.get(0);
|
||||
return query.encode(buff);
|
||||
|
||||
}
|
||||
else {
|
||||
buff.append("(").append(getLogicalOperator());
|
||||
|
||||
for (Filter query : queryList) {
|
||||
query.encode(buff);
|
||||
}
|
||||
|
||||
buff.append(")");
|
||||
|
||||
return buff;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this in subclass to return the logical operator, for example
|
||||
* "&".
|
||||
*
|
||||
* @return the logical operator.
|
||||
*/
|
||||
protected abstract String getLogicalOperator();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
BinaryLogicalFilter that = (BinaryLogicalFilter) o;
|
||||
|
||||
if (queryList != null ? !queryList.equals(that.queryList) : that.queryList != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return queryList != null ? queryList.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a query to this logical operation.
|
||||
*
|
||||
* @param query the query to add.
|
||||
* @return This instance.
|
||||
*/
|
||||
public final BinaryLogicalFilter append(Filter query) {
|
||||
queryList.add(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final BinaryLogicalFilter appendAll(Collection<Filter> subQueries) {
|
||||
queryList.addAll(subQueries);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract superclass for binary logical operations, that is "AND"
|
||||
* and "OR" operations.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class BinaryLogicalFilter extends AbstractFilter {
|
||||
|
||||
private List<Filter> queryList = new LinkedList<Filter>();
|
||||
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
if (queryList.size() <= 0) {
|
||||
|
||||
// only output query if contains anything
|
||||
return buff;
|
||||
|
||||
}
|
||||
else if (queryList.size() == 1) {
|
||||
|
||||
// don't add the &
|
||||
Filter query = queryList.get(0);
|
||||
return query.encode(buff);
|
||||
|
||||
}
|
||||
else {
|
||||
buff.append("(").append(getLogicalOperator());
|
||||
|
||||
for (Filter query : queryList) {
|
||||
query.encode(buff);
|
||||
}
|
||||
|
||||
buff.append(")");
|
||||
|
||||
return buff;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this in subclass to return the logical operator, for example
|
||||
* "&".
|
||||
*
|
||||
* @return the logical operator.
|
||||
*/
|
||||
protected abstract String getLogicalOperator();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
BinaryLogicalFilter that = (BinaryLogicalFilter) o;
|
||||
|
||||
if (queryList != null ? !queryList.equals(that.queryList) : that.queryList != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return queryList != null ? queryList.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a query to this logical operation.
|
||||
*
|
||||
* @param query the query to add.
|
||||
* @return This instance.
|
||||
*/
|
||||
public final BinaryLogicalFilter append(Filter query) {
|
||||
queryList.add(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final BinaryLogicalFilter appendAll(Collection<Filter> subQueries) {
|
||||
queryList.addAll(subQueries);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,110 +1,110 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.ldap.support.LdapEncoder;
|
||||
|
||||
/**
|
||||
* Abstract superclass for filters that compare values.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class CompareFilter extends AbstractFilter {
|
||||
|
||||
private final String attribute;
|
||||
|
||||
private final String value;
|
||||
|
||||
private final String encodedValue;
|
||||
|
||||
public CompareFilter(String attribute, String value) {
|
||||
this.attribute = attribute;
|
||||
this.value = value;
|
||||
this.encodedValue = encodeValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* For testing purposes.
|
||||
*
|
||||
* @return the encoded value.
|
||||
*/
|
||||
String getEncodedValue() {
|
||||
return encodedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to perform special encoding in subclass.
|
||||
*
|
||||
* @param value the value to encode.
|
||||
* @return properly escaped value.
|
||||
*/
|
||||
protected String encodeValue(String value) {
|
||||
return LdapEncoder.filterEncode(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for <code>int</code> values.
|
||||
*
|
||||
* @param attribute Name of attribute in filter.
|
||||
* @param value The value of the attribute in the filter.
|
||||
*/
|
||||
public CompareFilter(String attribute, int value) {
|
||||
this.attribute = attribute;
|
||||
this.value = String.valueOf(value);
|
||||
this.encodedValue = LdapEncoder.filterEncode(this.value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.AbstractFilter#encode(java.lang.StringBuffer)
|
||||
*/
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
buff.append('(');
|
||||
buff.append(attribute).append(getCompareString()).append(encodedValue);
|
||||
buff.append(')');
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
CompareFilter that = (CompareFilter) o;
|
||||
|
||||
if (attribute != null ? !attribute.equals(that.attribute) : that.attribute != null) return false;
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = attribute != null ? attribute.hashCode() : 0;
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this method in subclass to return a String representing the
|
||||
* operator. The {@link EqualsFilter#getCompareString()} would for example
|
||||
* return an equals sign, "=".
|
||||
*
|
||||
* @return the String to use as operator in the comparison for the specific
|
||||
* subclass.
|
||||
*/
|
||||
protected abstract String getCompareString();
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.ldap.support.LdapEncoder;
|
||||
|
||||
/**
|
||||
* Abstract superclass for filters that compare values.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public abstract class CompareFilter extends AbstractFilter {
|
||||
|
||||
private final String attribute;
|
||||
|
||||
private final String value;
|
||||
|
||||
private final String encodedValue;
|
||||
|
||||
public CompareFilter(String attribute, String value) {
|
||||
this.attribute = attribute;
|
||||
this.value = value;
|
||||
this.encodedValue = encodeValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* For testing purposes.
|
||||
*
|
||||
* @return the encoded value.
|
||||
*/
|
||||
String getEncodedValue() {
|
||||
return encodedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to perform special encoding in subclass.
|
||||
*
|
||||
* @param value the value to encode.
|
||||
* @return properly escaped value.
|
||||
*/
|
||||
protected String encodeValue(String value) {
|
||||
return LdapEncoder.filterEncode(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for <code>int</code> values.
|
||||
*
|
||||
* @param attribute Name of attribute in filter.
|
||||
* @param value The value of the attribute in the filter.
|
||||
*/
|
||||
public CompareFilter(String attribute, int value) {
|
||||
this.attribute = attribute;
|
||||
this.value = String.valueOf(value);
|
||||
this.encodedValue = LdapEncoder.filterEncode(this.value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.AbstractFilter#encode(java.lang.StringBuffer)
|
||||
*/
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
buff.append('(');
|
||||
buff.append(attribute).append(getCompareString()).append(encodedValue);
|
||||
buff.append(')');
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
CompareFilter that = (CompareFilter) o;
|
||||
|
||||
if (attribute != null ? !attribute.equals(that.attribute) : that.attribute != null) return false;
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = attribute != null ? attribute.hashCode() : 0;
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this method in subclass to return a String representing the
|
||||
* operator. The {@link EqualsFilter#getCompareString()} would for example
|
||||
* return an equals sign, "=".
|
||||
*
|
||||
* @return the String to use as operator in the comparison for the specific
|
||||
* subclass.
|
||||
*/
|
||||
protected abstract String getCompareString();
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter for 'equals'. The following code:
|
||||
*
|
||||
* <pre>
|
||||
* EqualsFilter filter = new EqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.encode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn=Some CN)
|
||||
* </pre>
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public class EqualsFilter extends CompareFilter {
|
||||
|
||||
private static final String EQUALS_SIGN = "=";
|
||||
|
||||
public EqualsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for int values.
|
||||
*
|
||||
* @param attribute Name of attribute in filter.
|
||||
* @param value The value of the attribute in the filter.
|
||||
*/
|
||||
public EqualsFilter(String attribute, int value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.CompareFilter#getCompareString()
|
||||
*/
|
||||
protected String getCompareString() {
|
||||
return EQUALS_SIGN;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter for 'equals'. The following code:
|
||||
*
|
||||
* <pre>
|
||||
* EqualsFilter filter = new EqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.encode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn=Some CN)
|
||||
* </pre>
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public class EqualsFilter extends CompareFilter {
|
||||
|
||||
private static final String EQUALS_SIGN = "=";
|
||||
|
||||
public EqualsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for int values.
|
||||
*
|
||||
* @param attribute Name of attribute in filter.
|
||||
* @param value The value of the attribute in the filter.
|
||||
*/
|
||||
public EqualsFilter(String attribute, int value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.filter.CompareFilter#getCompareString()
|
||||
*/
|
||||
protected String getCompareString() {
|
||||
return EQUALS_SIGN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* Common interface for LDAP filters.
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @see <a href="https://www.ietf.org/rfc/rfc1960.txt">RFC 1960: A String
|
||||
* Representation of LDAP Search Filters</a>
|
||||
*/
|
||||
public interface Filter {
|
||||
|
||||
/**
|
||||
* Encodes the filter to a String.
|
||||
*
|
||||
* @return The encoded filter in the standard String format
|
||||
*/
|
||||
String encode();
|
||||
|
||||
/**
|
||||
* Encodes the filter to a StringBuffer.
|
||||
*
|
||||
* @param buf The StringBuffer to encode the filter to
|
||||
* @return The same StringBuffer as was given
|
||||
*/
|
||||
StringBuffer encode(StringBuffer buf);
|
||||
|
||||
/**
|
||||
* All filters must implement equals.
|
||||
*
|
||||
* @param o
|
||||
* @return <code>true</code> if the objects are equal.
|
||||
*/
|
||||
boolean equals(Object o);
|
||||
|
||||
/**
|
||||
* All filters must implement hashCode.
|
||||
*
|
||||
* @return the hash code according to the contract in
|
||||
* {@link Object#hashCode()}
|
||||
*/
|
||||
int hashCode();
|
||||
/*
|
||||
* Copyright 2005-2010 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* Common interface for LDAP filters.
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @see <a href="https://www.ietf.org/rfc/rfc1960.txt">RFC 1960: A String
|
||||
* Representation of LDAP Search Filters</a>
|
||||
*/
|
||||
public interface Filter {
|
||||
|
||||
/**
|
||||
* Encodes the filter to a String.
|
||||
*
|
||||
* @return The encoded filter in the standard String format
|
||||
*/
|
||||
String encode();
|
||||
|
||||
/**
|
||||
* Encodes the filter to a StringBuffer.
|
||||
*
|
||||
* @param buf The StringBuffer to encode the filter to
|
||||
* @return The same StringBuffer as was given
|
||||
*/
|
||||
StringBuffer encode(StringBuffer buf);
|
||||
|
||||
/**
|
||||
* All filters must implement equals.
|
||||
*
|
||||
* @param o
|
||||
* @return <code>true</code> if the objects are equal.
|
||||
*/
|
||||
boolean equals(Object o);
|
||||
|
||||
/**
|
||||
* All filters must implement hashCode.
|
||||
*
|
||||
* @return the hash code according to the contract in
|
||||
* {@link Object#hashCode()}
|
||||
*/
|
||||
int hashCode();
|
||||
}
|
||||
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter to compare >=. LDAP RFC does not allow > comparison. The following
|
||||
* code:
|
||||
*
|
||||
* <pre>
|
||||
* GreaterThanOrEqualsFilter filter = new GreaterThanOrEqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn>=Some CN)
|
||||
* </pre>
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class GreaterThanOrEqualsFilter extends CompareFilter {
|
||||
|
||||
private static final String GREATER_THAN_OR_EQUALS = ">=";
|
||||
|
||||
public GreaterThanOrEqualsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
public GreaterThanOrEqualsFilter(String attribute, int value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String getCompareString() {
|
||||
return GREATER_THAN_OR_EQUALS;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter to compare >=. LDAP RFC does not allow > comparison. The following
|
||||
* code:
|
||||
*
|
||||
* <pre>
|
||||
* GreaterThanOrEqualsFilter filter = new GreaterThanOrEqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn>=Some CN)
|
||||
* </pre>
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class GreaterThanOrEqualsFilter extends CompareFilter {
|
||||
|
||||
private static final String GREATER_THAN_OR_EQUALS = ">=";
|
||||
|
||||
public GreaterThanOrEqualsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
public GreaterThanOrEqualsFilter(String attribute, int value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String getCompareString() {
|
||||
return GREATER_THAN_OR_EQUALS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter to compare <=. LDAP RFC does not allow < comparison. The following
|
||||
* code:
|
||||
*
|
||||
* <pre>
|
||||
* LessThanOrEqualsFilter filter = new LessThanOrEqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn<=Some CN)
|
||||
* </pre>
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class LessThanOrEqualsFilter extends CompareFilter {
|
||||
|
||||
private static final String LESS_THAN_OR_EQUALS = "<=";
|
||||
|
||||
public LessThanOrEqualsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
public LessThanOrEqualsFilter(String attribute, int value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String getCompareString() {
|
||||
return LESS_THAN_OR_EQUALS;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
/**
|
||||
* A filter to compare <=. LDAP RFC does not allow < comparison. The following
|
||||
* code:
|
||||
*
|
||||
* <pre>
|
||||
* LessThanOrEqualsFilter filter = new LessThanOrEqualsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn<=Some CN)
|
||||
* </pre>
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class LessThanOrEqualsFilter extends CompareFilter {
|
||||
|
||||
private static final String LESS_THAN_OR_EQUALS = "<=";
|
||||
|
||||
public LessThanOrEqualsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
public LessThanOrEqualsFilter(String attribute, int value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String getCompareString() {
|
||||
return LESS_THAN_OR_EQUALS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.ldap.support.LdapEncoder;
|
||||
|
||||
/**
|
||||
* This filter allows the user to specify wildcards (*) by not escaping them in
|
||||
* the filter. The following code:
|
||||
*
|
||||
* <pre>
|
||||
* LikeFilter filter = new LikeFilter("cn", "foo*");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn=foo*)
|
||||
* </pre>
|
||||
*
|
||||
* @author Anders Henja
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class LikeFilter extends EqualsFilter {
|
||||
|
||||
public LikeFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String encodeValue(String value) {
|
||||
// just return if blank string
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String[] substrings = value.split("\\*", -2);
|
||||
|
||||
if (substrings.length == 1) {
|
||||
return LdapEncoder.filterEncode(substrings[0]);
|
||||
}
|
||||
|
||||
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("*");
|
||||
}
|
||||
}
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.ldap.support.LdapEncoder;
|
||||
|
||||
/**
|
||||
* This filter allows the user to specify wildcards (*) by not escaping them in
|
||||
* the filter. The following code:
|
||||
*
|
||||
* <pre>
|
||||
* LikeFilter filter = new LikeFilter("cn", "foo*");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (cn=foo*)
|
||||
* </pre>
|
||||
*
|
||||
* @author Anders Henja
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class LikeFilter extends EqualsFilter {
|
||||
|
||||
public LikeFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String encodeValue(String value) {
|
||||
// just return if blank string
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String[] substrings = value.split("\\*", -2);
|
||||
|
||||
if (substrings.length == 1) {
|
||||
return LdapEncoder.filterEncode(substrings[0]);
|
||||
}
|
||||
|
||||
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("*");
|
||||
}
|
||||
}
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A filter for 'not'. The following code:
|
||||
*
|
||||
* <pre>
|
||||
* Filter filter = new NotFilter(new EqualsFilter("cn", "foo");
|
||||
* System.out.println(filter.encode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (!(cn = foo))
|
||||
* </pre>
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public class NotFilter extends AbstractFilter {
|
||||
|
||||
private final Filter filter;
|
||||
|
||||
/**
|
||||
* Create a filter that negates the outcome of the given <code>filter</code>.
|
||||
*
|
||||
* @param filter The filter that should be negated.
|
||||
*/
|
||||
public NotFilter(Filter filter) {
|
||||
Assert.notNull(filter, "Filter must not be null");
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
|
||||
buff.append("(!");
|
||||
filter.encode(buff);
|
||||
buff.append(')');
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
NotFilter notFilter = (NotFilter) o;
|
||||
|
||||
if (filter != null ? !filter.equals(notFilter.filter) : notFilter.filter != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return filter != null ? filter.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A filter for 'not'. The following code:
|
||||
*
|
||||
* <pre>
|
||||
* Filter filter = new NotFilter(new EqualsFilter("cn", "foo");
|
||||
* System.out.println(filter.encode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <pre>
|
||||
* (!(cn = foo))
|
||||
* </pre>
|
||||
*
|
||||
* @author Adam Skogman
|
||||
*/
|
||||
public class NotFilter extends AbstractFilter {
|
||||
|
||||
private final Filter filter;
|
||||
|
||||
/**
|
||||
* Create a filter that negates the outcome of the given <code>filter</code>.
|
||||
*
|
||||
* @param filter The filter that should be negated.
|
||||
*/
|
||||
public NotFilter(Filter filter) {
|
||||
Assert.notNull(filter, "Filter must not be null");
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public StringBuffer encode(StringBuffer buff) {
|
||||
|
||||
buff.append("(!");
|
||||
filter.encode(buff);
|
||||
buff.append(')');
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
NotFilter notFilter = (NotFilter) o;
|
||||
|
||||
if (filter != null ? !filter.equals(notFilter.filter) : notFilter.filter != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return filter != null ? filter.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ldap.support.LdapEncoder;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* This filter automatically converts all whitespace to wildcards (*). The
|
||||
* following code:
|
||||
*
|
||||
* <pre>
|
||||
* WhitespaceWildcardsFilter filter = new WhitespaceWildcardsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in: <code>(cn=*Some*CN*)</code>
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class WhitespaceWildcardsFilter extends EqualsFilter {
|
||||
private static Pattern starReplacePattern = Pattern.compile("\\s+");
|
||||
|
||||
public WhitespaceWildcardsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String encodeValue(String value) {
|
||||
|
||||
// blank string means just ONE star
|
||||
if (!StringUtils.hasText(value)) {
|
||||
return "*";
|
||||
}
|
||||
|
||||
// filter encode so that any stars etc. are preserved
|
||||
String filterEncoded = LdapEncoder.filterEncode(value.trim());
|
||||
|
||||
// Now replace all whitespace with stars
|
||||
Matcher m = starReplacePattern.matcher(filterEncoded);
|
||||
|
||||
// possibly 2 longer (stars at ends)
|
||||
StringBuffer buff = new StringBuffer(value.length() + 2);
|
||||
|
||||
buff.append('*');
|
||||
|
||||
while (m.find()) {
|
||||
m.appendReplacement(buff, "*");
|
||||
}
|
||||
m.appendTail(buff);
|
||||
|
||||
buff.append('*');
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.filter;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ldap.support.LdapEncoder;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* This filter automatically converts all whitespace to wildcards (*). The
|
||||
* following code:
|
||||
*
|
||||
* <pre>
|
||||
* WhitespaceWildcardsFilter filter = new WhitespaceWildcardsFilter("cn", "Some CN");
|
||||
* System.out.println(filter.ecode());
|
||||
* </pre>
|
||||
*
|
||||
* would result in: <code>(cn=*Some*CN*)</code>
|
||||
*
|
||||
* @author Adam Skogman
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class WhitespaceWildcardsFilter extends EqualsFilter {
|
||||
private static Pattern starReplacePattern = Pattern.compile("\\s+");
|
||||
|
||||
public WhitespaceWildcardsFilter(String attribute, String value) {
|
||||
super(attribute, value);
|
||||
}
|
||||
|
||||
protected String encodeValue(String value) {
|
||||
|
||||
// blank string means just ONE star
|
||||
if (!StringUtils.hasText(value)) {
|
||||
return "*";
|
||||
}
|
||||
|
||||
// filter encode so that any stars etc. are preserved
|
||||
String filterEncoded = LdapEncoder.filterEncode(value.trim());
|
||||
|
||||
// Now replace all whitespace with stars
|
||||
Matcher m = starReplacePattern.matcher(filterEncoded);
|
||||
|
||||
// possibly 2 longer (stars at ends)
|
||||
StringBuffer buff = new StringBuffer(value.length() + 2);
|
||||
|
||||
buff.append('*');
|
||||
|
||||
while (m.find()) {
|
||||
m.appendReplacement(buff, "*");
|
||||
}
|
||||
m.appendTail(buff);
|
||||
|
||||
buff.append('*');
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* This annotation describes the mapping of a Java field to an LDAP attribute.
|
||||
* <p>
|
||||
* The containing class must be annotated with {@link Entry}.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
* @see Entry
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Attribute {
|
||||
/**
|
||||
* The Type attribute indicates whether a field is regarded as binary based
|
||||
* or string based by the LDAP JNDI provider.
|
||||
*/
|
||||
enum Type {
|
||||
/**
|
||||
* A string field - returned by the JNDI LDAP provider as a {@link java.lang.String}.
|
||||
*/
|
||||
STRING, /**
|
||||
* A binary field - returned by the JNDI LDAP provider as a <code>byte[]</code>.
|
||||
*/
|
||||
BINARY
|
||||
}
|
||||
|
||||
/**
|
||||
* The LDAP attribute name that this field represents.
|
||||
* <p>
|
||||
* Defaults to "" in which case the Java field name is used as the LDAP attribute name.
|
||||
*
|
||||
* @return The LDAP attribute name.
|
||||
*
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Indicates whether this field is returned by the LDAP JNDI provider as a
|
||||
* <code>String</code> (<code>Type.STRING</code>) or as a
|
||||
* <code>byte[]</code> (<code>Type.BINARY</code>).
|
||||
*
|
||||
* @return Either <code>Type.STRING</code> to indicate a string attribute
|
||||
* or <code>Type.BINARY</code> to indicate a binary attribute.
|
||||
*/
|
||||
Type type() default Type.STRING;
|
||||
|
||||
/**
|
||||
* The LDAP syntax of the attribute that this field represents.
|
||||
* <p>
|
||||
* This optional value is typically used to affect the precision of conversion
|
||||
* of values between LDAP and Java,
|
||||
* see {@link org.springframework.ldap.odm.typeconversion.ConverterManager}
|
||||
* and {@link org.springframework.ldap.odm.typeconversion.impl.ConverterManagerImpl}.
|
||||
*
|
||||
* @return The LDAP syntax of this attribute.
|
||||
*/
|
||||
String syntax() default "";
|
||||
|
||||
/**
|
||||
* A boolean parameter to indicate if the attribute should be read only.
|
||||
* <p>
|
||||
* This value allows attributes to be read on read, but not persisted, there
|
||||
* are many operational and read-only ldap attributes which will throw errors
|
||||
* if they are persisted back to ldap.
|
||||
*
|
||||
* @return {@code true} is the attribute should not be written to ldap.
|
||||
*/
|
||||
boolean readonly() default false;
|
||||
|
||||
}
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* This annotation describes the mapping of a Java field to an LDAP attribute.
|
||||
* <p>
|
||||
* The containing class must be annotated with {@link Entry}.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
* @see Entry
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Attribute {
|
||||
/**
|
||||
* The Type attribute indicates whether a field is regarded as binary based
|
||||
* or string based by the LDAP JNDI provider.
|
||||
*/
|
||||
enum Type {
|
||||
/**
|
||||
* A string field - returned by the JNDI LDAP provider as a {@link java.lang.String}.
|
||||
*/
|
||||
STRING, /**
|
||||
* A binary field - returned by the JNDI LDAP provider as a <code>byte[]</code>.
|
||||
*/
|
||||
BINARY
|
||||
}
|
||||
|
||||
/**
|
||||
* The LDAP attribute name that this field represents.
|
||||
* <p>
|
||||
* Defaults to "" in which case the Java field name is used as the LDAP attribute name.
|
||||
*
|
||||
* @return The LDAP attribute name.
|
||||
*
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Indicates whether this field is returned by the LDAP JNDI provider as a
|
||||
* <code>String</code> (<code>Type.STRING</code>) or as a
|
||||
* <code>byte[]</code> (<code>Type.BINARY</code>).
|
||||
*
|
||||
* @return Either <code>Type.STRING</code> to indicate a string attribute
|
||||
* or <code>Type.BINARY</code> to indicate a binary attribute.
|
||||
*/
|
||||
Type type() default Type.STRING;
|
||||
|
||||
/**
|
||||
* The LDAP syntax of the attribute that this field represents.
|
||||
* <p>
|
||||
* This optional value is typically used to affect the precision of conversion
|
||||
* of values between LDAP and Java,
|
||||
* see {@link org.springframework.ldap.odm.typeconversion.ConverterManager}
|
||||
* and {@link org.springframework.ldap.odm.typeconversion.impl.ConverterManagerImpl}.
|
||||
*
|
||||
* @return The LDAP syntax of this attribute.
|
||||
*/
|
||||
String syntax() default "";
|
||||
|
||||
/**
|
||||
* A boolean parameter to indicate if the attribute should be read only.
|
||||
* <p>
|
||||
* This value allows attributes to be read on read, but not persisted, there
|
||||
* are many operational and read-only ldap attributes which will throw errors
|
||||
* if they are persisted back to ldap.
|
||||
*
|
||||
* @return {@code true} is the attribute should not be written to ldap.
|
||||
*/
|
||||
boolean readonly() default false;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation marks a Java class to be persisted in an LDAP directory.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Entry {
|
||||
/**
|
||||
* A list of LDAP object classes that the annotated Java class represents.
|
||||
* <p>
|
||||
* All fields will be persisted to LDAP unless annotated {@link Transient}.
|
||||
*
|
||||
* @return A list of LDAP classes which the annotated Java class represents.
|
||||
*/
|
||||
String[] objectClasses();
|
||||
|
||||
/**
|
||||
* The base DN of this entry. If specified, this will be prepended to all calculated
|
||||
* distinguished names for entries of the annotated class.
|
||||
*
|
||||
* @return the base DN for entries of this class
|
||||
*/
|
||||
String base() default "";
|
||||
}
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation marks a Java class to be persisted in an LDAP directory.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Entry {
|
||||
/**
|
||||
* A list of LDAP object classes that the annotated Java class represents.
|
||||
* <p>
|
||||
* All fields will be persisted to LDAP unless annotated {@link Transient}.
|
||||
*
|
||||
* @return A list of LDAP classes which the annotated Java class represents.
|
||||
*/
|
||||
String[] objectClasses();
|
||||
|
||||
/**
|
||||
* The base DN of this entry. If specified, this will be prepended to all calculated
|
||||
* distinguished names for entries of the annotated class.
|
||||
*
|
||||
* @return the base DN for entries of this class
|
||||
*/
|
||||
String base() default "";
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* This annotation marks a Java field as containing the Distinguished Name of an LDAP Entry.
|
||||
* <p>
|
||||
* The marked field must be of type {@link javax.naming.Name} and must <em>not</em>
|
||||
* be annotated {@link Attribute}.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*
|
||||
* @see Attribute
|
||||
* @see javax.naming.Name
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Id {
|
||||
}
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* This annotation marks a Java field as containing the Distinguished Name of an LDAP Entry.
|
||||
* <p>
|
||||
* The marked field must be of type {@link javax.naming.Name} and must <em>not</em>
|
||||
* be annotated {@link Attribute}.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*
|
||||
* @see Attribute
|
||||
* @see javax.naming.Name
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Id {
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation identifies a field in an {@link Entry} annotated class that
|
||||
* should <em>not</em> be persisted to LDAP.
|
||||
*
|
||||
* @author Paul Harvey <paul@pauls-place.me.uk>
|
||||
*
|
||||
* @see Entry
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Transient {
|
||||
}
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation identifies a field in an {@link Entry} annotated class that
|
||||
* should <em>not</em> be persisted to LDAP.
|
||||
*
|
||||
* @author Paul Harvey <paul@pauls-place.me.uk>
|
||||
*
|
||||
* @see Entry
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Transient {
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* Provides a set of annotations to describe the mapping of a Java class to an LDAP entry.
|
||||
* <p>
|
||||
* These annotations are for use with <a href="{@docRoot}/org/springframework/ldap/odm/core/OdmManager.html">OdmManager</a>.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a set of annotations to describe the mapping of a Java class to an LDAP entry.
|
||||
* <p>
|
||||
* These annotations are for use with <a href="{@docRoot}/org/springframework/ldap/odm/core/OdmManager.html">OdmManager</a>.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
/**
|
||||
* The root of the Spring LDAP ODM exception hierarchy.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class OdmException extends NamingException {
|
||||
public OdmException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public OdmException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core;
|
||||
|
||||
import org.springframework.ldap.NamingException;
|
||||
|
||||
/**
|
||||
* The root of the Spring LDAP ODM exception hierarchy.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class OdmException extends NamingException {
|
||||
public OdmException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public OdmException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,330 +1,330 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core.impl;
|
||||
|
||||
import org.springframework.ldap.UncategorizedLdapException;
|
||||
import org.springframework.ldap.odm.annotations.Attribute;
|
||||
import org.springframework.ldap.odm.annotations.DnAttribute;
|
||||
import org.springframework.ldap.odm.annotations.Id;
|
||||
import org.springframework.ldap.odm.annotations.Transient;
|
||||
|
||||
import javax.naming.Name;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/*
|
||||
* Extract attribute meta-data from the @Attribute annotation, the @Id annotation
|
||||
* and via reflection.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
/* package */ final class AttributeMetaData {
|
||||
private static final CaseIgnoreString OBJECT_CLASS_ATTRIBUTE_CI=new CaseIgnoreString("objectclass");
|
||||
|
||||
// Name of the LDAP attribute from the @Attribute annotation
|
||||
private CaseIgnoreString name;
|
||||
|
||||
// Syntax of the LDAP attribute from the @Attribute annotation
|
||||
private String syntax;
|
||||
|
||||
// Whether this attribute is binary from the @Attribute annotation
|
||||
private boolean isBinary;
|
||||
|
||||
// The Java field corresponding to this meta-data
|
||||
private final Field field;
|
||||
|
||||
// The Java class of the field corresponding to this meta data
|
||||
// This is the actual scalar type meaning that if the field is
|
||||
// List<String> then the valueClass will be String
|
||||
private Class<?> valueClass;
|
||||
|
||||
// Is this field annotated @Id
|
||||
private boolean isId;
|
||||
|
||||
// Is this field multi-valued represented by a List
|
||||
private boolean isCollection;
|
||||
|
||||
private Class<? extends Collection> collectionClass;
|
||||
|
||||
// Is this the objectClass attribute
|
||||
private boolean isObjectClass;
|
||||
|
||||
private boolean isTransient = false;
|
||||
|
||||
private boolean isReadOnly = false;
|
||||
|
||||
private String[] attributes;
|
||||
|
||||
private DnAttribute dnAttribute;
|
||||
|
||||
// Extract information from the @Attribute annotation:
|
||||
// syntax, isBinary, isObjectClass and name.
|
||||
private boolean processAttributeAnnotation(Field field) {
|
||||
// Default to no syntax specified
|
||||
syntax = "";
|
||||
|
||||
// Default to a String based attribute
|
||||
isBinary = false;
|
||||
|
||||
// Default name of attribute to the name of the field
|
||||
name = new CaseIgnoreString(field.getName());
|
||||
|
||||
// We have not yet found the @Attribute annotation
|
||||
boolean foundAnnotation=false;
|
||||
|
||||
// Grab the @Attribute annotation
|
||||
Attribute attribute = field.getAnnotation(Attribute.class);
|
||||
|
||||
List<String> attrList = new ArrayList<String>();
|
||||
// Did we find the annotation?
|
||||
if (attribute != null) {
|
||||
// Pull attribute name, syntax and whether attribute is binary
|
||||
// from the annotation
|
||||
foundAnnotation=true;
|
||||
String localAttributeName = attribute.name();
|
||||
// Would be more efficient to use !isEmpty - but that then makes us Java 6 dependent
|
||||
if (localAttributeName != null && localAttributeName.length()>0) {
|
||||
name = new CaseIgnoreString(localAttributeName);
|
||||
attrList.add(localAttributeName);
|
||||
}
|
||||
syntax = attribute.syntax();
|
||||
isBinary = attribute.type() == Attribute.Type.BINARY;
|
||||
isReadOnly = attribute.readonly();
|
||||
}
|
||||
attributes = attrList.toArray(new String[attrList.size()]);
|
||||
|
||||
isObjectClass=name.equals(OBJECT_CLASS_ATTRIBUTE_CI);
|
||||
|
||||
return foundAnnotation;
|
||||
}
|
||||
|
||||
// Extract reflection information from the field:
|
||||
// valueClass, isList
|
||||
private void determineFieldType(Field field) {
|
||||
// Determine the class of data stored in the field
|
||||
Class<?> fieldType = field.getType();
|
||||
|
||||
isCollection = Collection.class.isAssignableFrom(fieldType);
|
||||
|
||||
valueClass=null;
|
||||
if (!isCollection) {
|
||||
// It's not a list so assume its single valued - so just take the field type
|
||||
valueClass = fieldType;
|
||||
} else {
|
||||
determineCollectionClass(fieldType);
|
||||
// It's multi-valued - so we need to look at the signature in
|
||||
// the class file to find the generic type - this is supported for class file
|
||||
// format 49 and greater which corresponds to java 5 and later.
|
||||
ParameterizedType paramType;
|
||||
try {
|
||||
paramType = (ParameterizedType)field.getGenericType();
|
||||
} catch (ClassCastException e) {
|
||||
throw new MetaDataException(String.format("Can't determine destination type for field %1$s in Entry class %2$s",
|
||||
field, field.getDeclaringClass()), e);
|
||||
}
|
||||
Type[] actualParamArguments = paramType.getActualTypeArguments();
|
||||
if (actualParamArguments.length == 1) {
|
||||
if (actualParamArguments[0] instanceof Class) {
|
||||
valueClass = (Class<?>)actualParamArguments[0];
|
||||
} else {
|
||||
if (actualParamArguments[0] instanceof GenericArrayType) {
|
||||
// Deal with arrays
|
||||
Type type=((GenericArrayType)actualParamArguments[0]).getGenericComponentType();
|
||||
if (type instanceof Class) {
|
||||
valueClass=Array.newInstance((Class<?>)type, 0).getClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check we have been able to determine the value class
|
||||
if (valueClass==null) {
|
||||
throw new MetaDataException(String.format("Can't determine destination type for field %1$s in class %2$s",
|
||||
field, field.getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void determineCollectionClass(Class<?> fieldType) {
|
||||
if(fieldType.isInterface()) {
|
||||
if(Collection.class.equals(fieldType) || List.class.equals(fieldType)) {
|
||||
collectionClass = ArrayList.class;
|
||||
} else if(SortedSet.class.equals(fieldType)) {
|
||||
collectionClass = TreeSet.class;
|
||||
} else if(Set.class.isAssignableFrom(fieldType)) {
|
||||
collectionClass = LinkedHashSet.class;
|
||||
} else {
|
||||
throw new MetaDataException(String.format("Collection class %s is not supported", fieldType));
|
||||
}
|
||||
} else {
|
||||
collectionClass = (Class<? extends Collection>) fieldType;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Object> newCollectionInstance() {
|
||||
try {
|
||||
return (Collection<Object>) collectionClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new UncategorizedLdapException("Failed to instantiate collection class", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Extract information from the @Id annotation:
|
||||
// isId
|
||||
private boolean processIdAnnotation(Field field, Class<?> fieldType) {
|
||||
// Are we dealing with the Id field?
|
||||
isId=field.getAnnotation(Id.class)!=null;
|
||||
|
||||
if (isId) {
|
||||
// It must be of type Name or a subclass of that of
|
||||
if (!Name.class.isAssignableFrom(fieldType)) {
|
||||
throw new MetaDataException(
|
||||
String.format("The id field must be of type javax.naming.Name or a subclass that of in Entry class %1$s",
|
||||
field.getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
return isId;
|
||||
}
|
||||
|
||||
// Extract meta-data from the given field
|
||||
public AttributeMetaData(Field field) {
|
||||
this.field=field;
|
||||
|
||||
this.dnAttribute = field.getAnnotation(DnAttribute.class);
|
||||
if(this.dnAttribute != null && !field.getType().equals(String.class)) {
|
||||
throw new MetaDataException(String.format("%s is of type %s, but only String attributes can be declared as @DnAttributes",
|
||||
field.toString(),
|
||||
field.getType().toString()));
|
||||
}
|
||||
|
||||
Transient transientAnnotation = field.getAnnotation(Transient.class);
|
||||
if(transientAnnotation != null) {
|
||||
this.isTransient = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Reflection data
|
||||
determineFieldType(field);
|
||||
|
||||
|
||||
// Data from the @Attribute annotation
|
||||
boolean foundAttributeAnnotation=processAttributeAnnotation(field);
|
||||
|
||||
// Data from the @Id annotation
|
||||
boolean foundIdAnnoation=processIdAnnotation(field, valueClass);
|
||||
|
||||
// Check that the field has not been annotated with both @Attribute and with @Id
|
||||
if (foundAttributeAnnotation && foundIdAnnoation) {
|
||||
throw new MetaDataException(
|
||||
String.format("You may not specifiy an %1$s annoation and an %2$s annotation on the same field, error in field %3$s in Entry class %4$s",
|
||||
Id.class, Attribute.class, field.getName(), field.getDeclaringClass()));
|
||||
}
|
||||
|
||||
// If this is the objectclass attribute then it must be of type List<String>
|
||||
if (isObjectClass() && (!isCollection() || valueClass!=String.class)) {
|
||||
throw new MetaDataException(String.format("The type of the objectclass attribute must be List<String> in classs %1$s",
|
||||
field.getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
public boolean isBinary() {
|
||||
return isBinary;
|
||||
}
|
||||
|
||||
public Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public CaseIgnoreString getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isCollection() {
|
||||
return isCollection;
|
||||
}
|
||||
|
||||
public boolean isId() {
|
||||
return isId;
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return isReadOnly;
|
||||
}
|
||||
|
||||
public boolean isTransient() {
|
||||
return isTransient;
|
||||
}
|
||||
|
||||
public DnAttribute getDnAttribute() {
|
||||
return dnAttribute;
|
||||
}
|
||||
|
||||
public boolean isDnAttribute() {
|
||||
return dnAttribute != null;
|
||||
}
|
||||
|
||||
public boolean isObjectClass() {
|
||||
return isObjectClass;
|
||||
}
|
||||
|
||||
public Class<?> getValueClass() {
|
||||
return valueClass;
|
||||
}
|
||||
|
||||
public String[] getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public Class<?> getJndiClass() {
|
||||
if(isBinary()) {
|
||||
return byte[].class;
|
||||
} else if(Name.class.isAssignableFrom(valueClass)) {
|
||||
return Name.class;
|
||||
} else {
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("name=%1$s | field=%2$s | valueClass=%3$s | syntax=%4$s| isBinary=%5$s | isId=%6$s | isReadOnly=%7$s | isList=%8$s | isObjectClass=%9$s",
|
||||
getName(), getField(), getValueClass(), getSyntax(), isBinary(), isId(), isReadOnly(), isCollection(), isObjectClass());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core.impl;
|
||||
|
||||
import org.springframework.ldap.UncategorizedLdapException;
|
||||
import org.springframework.ldap.odm.annotations.Attribute;
|
||||
import org.springframework.ldap.odm.annotations.DnAttribute;
|
||||
import org.springframework.ldap.odm.annotations.Id;
|
||||
import org.springframework.ldap.odm.annotations.Transient;
|
||||
|
||||
import javax.naming.Name;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/*
|
||||
* Extract attribute meta-data from the @Attribute annotation, the @Id annotation
|
||||
* and via reflection.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
/* package */ final class AttributeMetaData {
|
||||
private static final CaseIgnoreString OBJECT_CLASS_ATTRIBUTE_CI=new CaseIgnoreString("objectclass");
|
||||
|
||||
// Name of the LDAP attribute from the @Attribute annotation
|
||||
private CaseIgnoreString name;
|
||||
|
||||
// Syntax of the LDAP attribute from the @Attribute annotation
|
||||
private String syntax;
|
||||
|
||||
// Whether this attribute is binary from the @Attribute annotation
|
||||
private boolean isBinary;
|
||||
|
||||
// The Java field corresponding to this meta-data
|
||||
private final Field field;
|
||||
|
||||
// The Java class of the field corresponding to this meta data
|
||||
// This is the actual scalar type meaning that if the field is
|
||||
// List<String> then the valueClass will be String
|
||||
private Class<?> valueClass;
|
||||
|
||||
// Is this field annotated @Id
|
||||
private boolean isId;
|
||||
|
||||
// Is this field multi-valued represented by a List
|
||||
private boolean isCollection;
|
||||
|
||||
private Class<? extends Collection> collectionClass;
|
||||
|
||||
// Is this the objectClass attribute
|
||||
private boolean isObjectClass;
|
||||
|
||||
private boolean isTransient = false;
|
||||
|
||||
private boolean isReadOnly = false;
|
||||
|
||||
private String[] attributes;
|
||||
|
||||
private DnAttribute dnAttribute;
|
||||
|
||||
// Extract information from the @Attribute annotation:
|
||||
// syntax, isBinary, isObjectClass and name.
|
||||
private boolean processAttributeAnnotation(Field field) {
|
||||
// Default to no syntax specified
|
||||
syntax = "";
|
||||
|
||||
// Default to a String based attribute
|
||||
isBinary = false;
|
||||
|
||||
// Default name of attribute to the name of the field
|
||||
name = new CaseIgnoreString(field.getName());
|
||||
|
||||
// We have not yet found the @Attribute annotation
|
||||
boolean foundAnnotation=false;
|
||||
|
||||
// Grab the @Attribute annotation
|
||||
Attribute attribute = field.getAnnotation(Attribute.class);
|
||||
|
||||
List<String> attrList = new ArrayList<String>();
|
||||
// Did we find the annotation?
|
||||
if (attribute != null) {
|
||||
// Pull attribute name, syntax and whether attribute is binary
|
||||
// from the annotation
|
||||
foundAnnotation=true;
|
||||
String localAttributeName = attribute.name();
|
||||
// Would be more efficient to use !isEmpty - but that then makes us Java 6 dependent
|
||||
if (localAttributeName != null && localAttributeName.length()>0) {
|
||||
name = new CaseIgnoreString(localAttributeName);
|
||||
attrList.add(localAttributeName);
|
||||
}
|
||||
syntax = attribute.syntax();
|
||||
isBinary = attribute.type() == Attribute.Type.BINARY;
|
||||
isReadOnly = attribute.readonly();
|
||||
}
|
||||
attributes = attrList.toArray(new String[attrList.size()]);
|
||||
|
||||
isObjectClass=name.equals(OBJECT_CLASS_ATTRIBUTE_CI);
|
||||
|
||||
return foundAnnotation;
|
||||
}
|
||||
|
||||
// Extract reflection information from the field:
|
||||
// valueClass, isList
|
||||
private void determineFieldType(Field field) {
|
||||
// Determine the class of data stored in the field
|
||||
Class<?> fieldType = field.getType();
|
||||
|
||||
isCollection = Collection.class.isAssignableFrom(fieldType);
|
||||
|
||||
valueClass=null;
|
||||
if (!isCollection) {
|
||||
// It's not a list so assume its single valued - so just take the field type
|
||||
valueClass = fieldType;
|
||||
} else {
|
||||
determineCollectionClass(fieldType);
|
||||
// It's multi-valued - so we need to look at the signature in
|
||||
// the class file to find the generic type - this is supported for class file
|
||||
// format 49 and greater which corresponds to java 5 and later.
|
||||
ParameterizedType paramType;
|
||||
try {
|
||||
paramType = (ParameterizedType)field.getGenericType();
|
||||
} catch (ClassCastException e) {
|
||||
throw new MetaDataException(String.format("Can't determine destination type for field %1$s in Entry class %2$s",
|
||||
field, field.getDeclaringClass()), e);
|
||||
}
|
||||
Type[] actualParamArguments = paramType.getActualTypeArguments();
|
||||
if (actualParamArguments.length == 1) {
|
||||
if (actualParamArguments[0] instanceof Class) {
|
||||
valueClass = (Class<?>)actualParamArguments[0];
|
||||
} else {
|
||||
if (actualParamArguments[0] instanceof GenericArrayType) {
|
||||
// Deal with arrays
|
||||
Type type=((GenericArrayType)actualParamArguments[0]).getGenericComponentType();
|
||||
if (type instanceof Class) {
|
||||
valueClass=Array.newInstance((Class<?>)type, 0).getClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check we have been able to determine the value class
|
||||
if (valueClass==null) {
|
||||
throw new MetaDataException(String.format("Can't determine destination type for field %1$s in class %2$s",
|
||||
field, field.getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void determineCollectionClass(Class<?> fieldType) {
|
||||
if(fieldType.isInterface()) {
|
||||
if(Collection.class.equals(fieldType) || List.class.equals(fieldType)) {
|
||||
collectionClass = ArrayList.class;
|
||||
} else if(SortedSet.class.equals(fieldType)) {
|
||||
collectionClass = TreeSet.class;
|
||||
} else if(Set.class.isAssignableFrom(fieldType)) {
|
||||
collectionClass = LinkedHashSet.class;
|
||||
} else {
|
||||
throw new MetaDataException(String.format("Collection class %s is not supported", fieldType));
|
||||
}
|
||||
} else {
|
||||
collectionClass = (Class<? extends Collection>) fieldType;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Object> newCollectionInstance() {
|
||||
try {
|
||||
return (Collection<Object>) collectionClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new UncategorizedLdapException("Failed to instantiate collection class", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Extract information from the @Id annotation:
|
||||
// isId
|
||||
private boolean processIdAnnotation(Field field, Class<?> fieldType) {
|
||||
// Are we dealing with the Id field?
|
||||
isId=field.getAnnotation(Id.class)!=null;
|
||||
|
||||
if (isId) {
|
||||
// It must be of type Name or a subclass of that of
|
||||
if (!Name.class.isAssignableFrom(fieldType)) {
|
||||
throw new MetaDataException(
|
||||
String.format("The id field must be of type javax.naming.Name or a subclass that of in Entry class %1$s",
|
||||
field.getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
return isId;
|
||||
}
|
||||
|
||||
// Extract meta-data from the given field
|
||||
public AttributeMetaData(Field field) {
|
||||
this.field=field;
|
||||
|
||||
this.dnAttribute = field.getAnnotation(DnAttribute.class);
|
||||
if(this.dnAttribute != null && !field.getType().equals(String.class)) {
|
||||
throw new MetaDataException(String.format("%s is of type %s, but only String attributes can be declared as @DnAttributes",
|
||||
field.toString(),
|
||||
field.getType().toString()));
|
||||
}
|
||||
|
||||
Transient transientAnnotation = field.getAnnotation(Transient.class);
|
||||
if(transientAnnotation != null) {
|
||||
this.isTransient = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Reflection data
|
||||
determineFieldType(field);
|
||||
|
||||
|
||||
// Data from the @Attribute annotation
|
||||
boolean foundAttributeAnnotation=processAttributeAnnotation(field);
|
||||
|
||||
// Data from the @Id annotation
|
||||
boolean foundIdAnnoation=processIdAnnotation(field, valueClass);
|
||||
|
||||
// Check that the field has not been annotated with both @Attribute and with @Id
|
||||
if (foundAttributeAnnotation && foundIdAnnoation) {
|
||||
throw new MetaDataException(
|
||||
String.format("You may not specifiy an %1$s annoation and an %2$s annotation on the same field, error in field %3$s in Entry class %4$s",
|
||||
Id.class, Attribute.class, field.getName(), field.getDeclaringClass()));
|
||||
}
|
||||
|
||||
// If this is the objectclass attribute then it must be of type List<String>
|
||||
if (isObjectClass() && (!isCollection() || valueClass!=String.class)) {
|
||||
throw new MetaDataException(String.format("The type of the objectclass attribute must be List<String> in classs %1$s",
|
||||
field.getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
public boolean isBinary() {
|
||||
return isBinary;
|
||||
}
|
||||
|
||||
public Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public CaseIgnoreString getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isCollection() {
|
||||
return isCollection;
|
||||
}
|
||||
|
||||
public boolean isId() {
|
||||
return isId;
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return isReadOnly;
|
||||
}
|
||||
|
||||
public boolean isTransient() {
|
||||
return isTransient;
|
||||
}
|
||||
|
||||
public DnAttribute getDnAttribute() {
|
||||
return dnAttribute;
|
||||
}
|
||||
|
||||
public boolean isDnAttribute() {
|
||||
return dnAttribute != null;
|
||||
}
|
||||
|
||||
public boolean isObjectClass() {
|
||||
return isObjectClass;
|
||||
}
|
||||
|
||||
public Class<?> getValueClass() {
|
||||
return valueClass;
|
||||
}
|
||||
|
||||
public String[] getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public Class<?> getJndiClass() {
|
||||
if(isBinary()) {
|
||||
return byte[].class;
|
||||
} else if(Name.class.isAssignableFrom(valueClass)) {
|
||||
return Name.class;
|
||||
} else {
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("name=%1$s | field=%2$s | valueClass=%3$s | syntax=%4$s| isBinary=%5$s | isId=%6$s | isReadOnly=%7$s | isList=%8$s | isObjectClass=%9$s",
|
||||
getName(), getField(), getValueClass(), getSyntax(), isBinary(), isId(), isReadOnly(), isCollection(), isObjectClass());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core.impl;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
// A case independent String wrapper.
|
||||
/* package */ final class CaseIgnoreString implements Comparable<CaseIgnoreString> {
|
||||
private final String string;
|
||||
private final int hashCode;
|
||||
|
||||
public CaseIgnoreString(String string) {
|
||||
Assert.notNull(string, "string must not be null");
|
||||
this.string = string;
|
||||
hashCode = string.toUpperCase().hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof CaseIgnoreString &&
|
||||
((CaseIgnoreString)other).string.equalsIgnoreCase(string);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public int compareTo(CaseIgnoreString other) {
|
||||
CaseIgnoreString cis = other;
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(string, cis.string);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core.impl;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
// A case independent String wrapper.
|
||||
/* package */ final class CaseIgnoreString implements Comparable<CaseIgnoreString> {
|
||||
private final String string;
|
||||
private final int hashCode;
|
||||
|
||||
public CaseIgnoreString(String string) {
|
||||
Assert.notNull(string, "string must not be null");
|
||||
this.string = string;
|
||||
hashCode = string.toUpperCase().hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof CaseIgnoreString &&
|
||||
((CaseIgnoreString)other).string.equalsIgnoreCase(string);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public int compareTo(CaseIgnoreString other) {
|
||||
CaseIgnoreString cis = other;
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(string, cis.string);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core.impl;
|
||||
|
||||
import org.springframework.ldap.odm.core.OdmException;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that an instance is not suitable for persisting in the LDAP directory.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class InvalidEntryException extends OdmException {
|
||||
public InvalidEntryException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidEntryException(String message, Throwable reason) {
|
||||
super(message, reason);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.odm.core.impl;
|
||||
|
||||
import org.springframework.ldap.odm.core.OdmException;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that an instance is not suitable for persisting in the LDAP directory.
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class InvalidEntryException extends OdmException {
|
||||
public InvalidEntryException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidEntryException(String message, Throwable reason) {
|
||||
super(message, reason);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user