IN PROGRESS - issue LDAP-33: Remove package dependency cycle between ldap.core and ldap.support
http://opensource.atlassian.com/projects/spring/browse/LDAP-33 Remove package dependency cycle
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.support;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.clarkware.junitperf.LoadTest;
|
||||
|
||||
/**
|
||||
* Performance test for the {@link DistinguishedName} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class DnParsePerformanceITest extends TestCase {
|
||||
|
||||
public DnParsePerformanceITest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests parsing and toString.
|
||||
*/
|
||||
public void testContains() {
|
||||
|
||||
DistinguishedName migpath = new DistinguishedName("OU=G,OU=I,OU=M");
|
||||
DistinguishedName path1 = new DistinguishedName(
|
||||
"cn=john.doe, OU=Users,OU=SE,OU=G,OU=I,OU=M");
|
||||
DistinguishedName path2 = new DistinguishedName(
|
||||
"cn=john.doe, OU=Users,OU=SE,ou=G,OU=i,OU=M, ou=foo");
|
||||
DistinguishedName path3 = new DistinguishedName(
|
||||
"ou=G,OU=i,OU=M, ou=foo");
|
||||
DistinguishedName path4 = new DistinguishedName("ou=G,OU=i,ou=m");
|
||||
|
||||
DistinguishedName pathE1 = new DistinguishedName(
|
||||
"cn=john.doe, OU=Users,OU=SE,ou=G,OU=L,OU=M, ou=foo");
|
||||
DistinguishedName pathE2 = new DistinguishedName(
|
||||
"cn=john.doe, OU=Users,OU=SE");
|
||||
|
||||
assertTrue("Contains MIG", path1.contains(migpath));
|
||||
assertTrue("Contains MIG", path2.contains(migpath));
|
||||
assertTrue("Contains MIG", path3.contains(migpath));
|
||||
assertTrue("Contains MIG", path4.contains(migpath));
|
||||
|
||||
assertFalse("Does not contain MIG", pathE1.contains(migpath));
|
||||
assertFalse("Does not contain MIG", pathE2.contains(migpath));
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
int users = 2000;
|
||||
Test testCase = new DnParsePerformanceITest("testContains");
|
||||
Test loadTest = new LoadTest(testCase, users);
|
||||
return loadTest;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.support;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.springframework.ldap.support.LdapContextSource;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Integration tests for ContextSourceImpl.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class LdapContextSourcelITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private LdapContextSource tested;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext.xml" };
|
||||
}
|
||||
|
||||
public void testGetReadOnlyContext() throws NamingException {
|
||||
DirContext ctx = null;
|
||||
|
||||
try {
|
||||
ctx = tested.getReadOnlyContext();
|
||||
assertNotNull(ctx);
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertTrue(environment
|
||||
.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG));
|
||||
assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL));
|
||||
assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS));
|
||||
} finally {
|
||||
// Always clean up.
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetReadWriteContext() throws NamingException {
|
||||
DirContext ctx = null;
|
||||
|
||||
try {
|
||||
ctx = tested.getReadWriteContext();
|
||||
assertNotNull(ctx);
|
||||
// Double check to see that we are authenticated.
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL));
|
||||
assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS));
|
||||
} finally {
|
||||
// Always clean up.
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTested(LdapContextSource tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.support;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Integration tests for ContextSourceImpl.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class LdapContextSourcelMultiServerITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private LdapContextSource tested;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapContextSourceTestContext.xml" };
|
||||
}
|
||||
|
||||
public void testUrls() throws NamingException {
|
||||
String[] urls = tested.getUrls();
|
||||
String string = tested.assembleProviderUrlString(urls);
|
||||
|
||||
assertEquals("ldap://127.0.0.1:389 ldap://127.0.0.2:389", string);
|
||||
}
|
||||
|
||||
public void setTested(LdapContextSource tested) {
|
||||
this.tested = tested;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.support.authentication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
|
||||
import org.acegisecurity.Authentication;
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.acegisecurity.providers.ldap.LdapAuthenticationProvider;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.authentication.AcegiAuthenticationSource;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
public class AcegiAuthenticationSourceITest extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private LdapAuthenticationProvider ldapAuthProvider;
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateAcegiTestContext.xml" };
|
||||
}
|
||||
|
||||
public void setLdapAuthProvider(LdapAuthenticationProvider ldapAuthProvider) {
|
||||
this.ldapAuthProvider = ldapAuthProvider;
|
||||
}
|
||||
|
||||
public void setLdapTemplate(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
public void testGetPrincipalAndCredentials() {
|
||||
Authentication authentication = ldapAuthProvider
|
||||
.authenticate(new UsernamePasswordAuthenticationToken(
|
||||
"Some Person3", "password"));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
AcegiAuthenticationSource tested = new AcegiAuthenticationSource();
|
||||
assertEquals("cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se",
|
||||
tested.getPrincipal());
|
||||
assertEquals("password", tested.getCredentials());
|
||||
}
|
||||
|
||||
public void testSearchIndiviualAuthentication() {
|
||||
Authentication authentication = ldapAuthProvider
|
||||
.authenticate(new UsernamePasswordAuthenticationToken(
|
||||
"Some Person3", "password"));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
List result = ldapTemplate.search("dc=jayway,dc=se",
|
||||
"(objectclass=person)", new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes)
|
||||
throws NamingException {
|
||||
return attributes.get("cn");
|
||||
}
|
||||
});
|
||||
assertEquals(5, result.size());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user