Moved everything from mvn-build to trunk root.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
/**
|
||||
* Dummy bean to be used in the LdapTemplate integration tests.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class Person {
|
||||
private String fullname;
|
||||
|
||||
private String lastname;
|
||||
|
||||
private String description;
|
||||
|
||||
private String phone;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getFullname() {
|
||||
return fullname;
|
||||
}
|
||||
|
||||
public void setFullname(String fullname) {
|
||||
this.fullname = fullname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
|
||||
|
||||
/**
|
||||
* Dummy implementation of AttributesMapper for use in integration tests.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*
|
||||
*/
|
||||
public 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.setPhone((String) attributes.get("telephoneNumber").get());
|
||||
person.setDescription((String) attributes.get("description").get());
|
||||
return person;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
|
||||
/**
|
||||
* Dummy implemention of ContextMapper for use in the integration tests and for
|
||||
* illustration purposes.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class PersonContextMapper extends AbstractContextMapper {
|
||||
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
Person person = new Person();
|
||||
person.setFullname(ctx.getStringAttribute("cn"));
|
||||
person.setLastname(ctx.getStringAttribute("sn"));
|
||||
person.setPhone(ctx.getStringAttribute("telephoneNumber"));
|
||||
person.setDescription(ctx.getStringAttribute("description"));
|
||||
|
||||
return person;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.core;
|
||||
|
||||
/**
|
||||
* Dummy implementation of a class that has a {@link DistinguishedName} setter,
|
||||
* used for testing purposes.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class DummyDistinguishedNameConsumer {
|
||||
private DistinguishedName distinguishedName;
|
||||
|
||||
public DistinguishedName getDistinguishedName() {
|
||||
return distinguishedName;
|
||||
}
|
||||
|
||||
public void setDistinguishedName(DistinguishedName distinguishedName) {
|
||||
this.distinguishedName = distinguishedName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
/**
|
||||
* Dummy implementation of {@link BaseLdapPathAware}.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class DummyBaseLdapPathAware implements BaseLdapPathAware {
|
||||
|
||||
private DistinguishedName base;
|
||||
|
||||
public void setBaseLdapPath(DistinguishedName baseLdapPath) {
|
||||
this.base = baseLdapPath;
|
||||
}
|
||||
|
||||
public DistinguishedName getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2005-2008 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.filter;
|
||||
|
||||
/**
|
||||
* Dummy class to test Filter property editor.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyFilterConsumer {
|
||||
|
||||
private Filter filter;
|
||||
|
||||
public Filter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(Filter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.transaction.compensating.manager;
|
||||
|
||||
public interface DummyDao {
|
||||
void createWithException(String country, String company, String fullname,
|
||||
String lastname, String description);
|
||||
|
||||
void create(String country, String company, String fullname,
|
||||
String lastname, String description);
|
||||
|
||||
void update(String dn, String fullname, String lastname, String description);
|
||||
|
||||
void updateWithException(String dn, String fullname, String lastname,
|
||||
String description);
|
||||
|
||||
void updateAndRename(String dn, String newDn, String description);
|
||||
|
||||
void updateAndRenameWithException(String dn, String newDn,
|
||||
String description);
|
||||
|
||||
void modifyAttributes(String dn, String lastName, String description);
|
||||
|
||||
void modifyAttributesWithException(String dn, String lastName,
|
||||
String description);
|
||||
|
||||
void unbind(String dn, String fullname);
|
||||
|
||||
void unbindWithException(String dn, String fullname);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.transaction.compensating.manager;
|
||||
|
||||
public class DummyException extends RuntimeException {
|
||||
public DummyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.transaction.compensating.manager;
|
||||
|
||||
public class DummyServiceImpl {
|
||||
private DummyDao dummyDaoImpl;
|
||||
|
||||
public void setDummyDaoImpl(DummyDao dummyDaoImpl) {
|
||||
this.dummyDaoImpl = dummyDaoImpl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.transaction.compensating.manager;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
|
||||
public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setLdapTemplate(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createWithException(String country, String company, String fullname, String lastname, String description) {
|
||||
create(country, company, fullname, lastname, description);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void create(String country, String company, String fullname, String lastname, String description) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("c", country);
|
||||
dn.add("ou", company);
|
||||
dn.add("cn", fullname);
|
||||
|
||||
DirContextAdapter ctx = new DirContextAdapter();
|
||||
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
ctx.setAttributeValue("cn", fullname);
|
||||
ctx.setAttributeValue("sn", lastname);
|
||||
ctx.setAttributeValue("description", description);
|
||||
ldapTemplate.bind(dn, ctx, null);
|
||||
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { fullname, lastname, description });
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void update(String dn, String fullname, String lastname, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("sn", lastname);
|
||||
ctx.setAttributeValue("description", description);
|
||||
ctx.update();
|
||||
|
||||
ldapTemplate.rebind(dn, ctx, null);
|
||||
jdbcTemplate.update("update PERSON set lastname=?, description = ? where fullname = ?", new Object[] {
|
||||
lastname, description, fullname });
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateWithException(String dn, String fullname, String lastname, String description) {
|
||||
update(dn, fullname, lastname, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRename(String dn, String newDn, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("description", description);
|
||||
ctx.update();
|
||||
|
||||
ldapTemplate.rebind(dn, ctx, null);
|
||||
ldapTemplate.rename(dn, newDn);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRenameWithException(String dn, String newDn, String description) {
|
||||
updateAndRename(dn, newDn, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributes(String dn, String lastName, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("sn", lastName);
|
||||
ctx.setAttributeValue("description", description);
|
||||
|
||||
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributesWithException(String dn, String lastName, String description) {
|
||||
modifyAttributes(dn, lastName, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
|
||||
*/
|
||||
public void unbind(String dn, String fullname) {
|
||||
ldapTemplate.unbind(dn);
|
||||
jdbcTemplate.update("delete from PERSON where fullname=?", new Object[] { fullname });
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
|
||||
*/
|
||||
public void unbindWithException(String dn, String fullname) {
|
||||
unbind(dn, fullname);
|
||||
throw new DummyException("This operation failed.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.transaction.compensating.manager;
|
||||
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
|
||||
public class LdapDummyDaoImpl implements DummyDao {
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
public void setLdapTemplate(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String,
|
||||
* java.lang.String)
|
||||
*/
|
||||
public void createWithException(String country, String company,
|
||||
String fullname, String lastname, String description) {
|
||||
create(country, company, fullname, lastname, description);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String,
|
||||
* java.lang.String)
|
||||
*/
|
||||
public void create(String country, String company, String fullname,
|
||||
String lastname, String description) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("c", country);
|
||||
dn.add("ou", company);
|
||||
dn.add("cn", fullname);
|
||||
|
||||
DirContextAdapter ctx = new DirContextAdapter();
|
||||
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
ctx.setAttributeValue("cn", fullname);
|
||||
ctx.setAttributeValue("sn", lastname);
|
||||
ctx.setAttributeValue("description", description);
|
||||
ldapTemplate.bind(dn, ctx, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void update(String dn, String fullname, String lastname,
|
||||
String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("sn", lastname);
|
||||
ctx.setAttributeValue("description", description);
|
||||
ctx.update();
|
||||
|
||||
ldapTemplate.rebind(dn, ctx, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateWithException(String dn, String fullname,
|
||||
String lastname, String description) {
|
||||
update(dn, fullname, lastname, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRename(String dn, String newDn, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("description", description);
|
||||
ctx.update();
|
||||
|
||||
ldapTemplate.rebind(dn, ctx, null);
|
||||
ldapTemplate.rename(dn, newDn);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRenameWithException(String dn, String newDn,
|
||||
String description) {
|
||||
updateAndRename(dn, newDn, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributes(String dn, String lastName, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("sn", lastName);
|
||||
ctx.setAttributeValue("description", description);
|
||||
|
||||
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributesWithException(String dn, String lastName,
|
||||
String description) {
|
||||
modifyAttributes(dn, lastName, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
|
||||
*/
|
||||
public void unbind(String dn, String fullname) {
|
||||
ldapTemplate.unbind(dn);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
|
||||
*/
|
||||
public void unbindWithException(String dn, String fullname) {
|
||||
unbind(dn, fullname);
|
||||
throw new DummyException("This operation failed.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package org.springframework.ldap.transaction.compensating.manager.hibernate;
|
||||
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
/**
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements OrgPersonDao {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
public void create(OrgPerson person) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("c", person.getCountry());
|
||||
dn.add("ou", person.getCompany());
|
||||
dn.add("cn", person.getFullname());
|
||||
|
||||
DirContextAdapter ctx = new DirContextAdapter();
|
||||
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
ctx.setAttributeValue("cn", person.getFullname());
|
||||
ctx.setAttributeValue("sn", person.getLastname());
|
||||
ctx.setAttributeValue("description", person.getDescription());
|
||||
ldapTemplate.bind(dn, ctx, null);
|
||||
this.getHibernateTemplate().saveOrUpdate(person);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void createWithException(OrgPerson person) {
|
||||
this.create(person);
|
||||
throw new DummyException("This method failed");
|
||||
|
||||
}
|
||||
|
||||
public void modifyAttributes(String dn, String lastName, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("sn", lastName);
|
||||
ctx.setAttributeValue("description", description);
|
||||
|
||||
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
|
||||
}
|
||||
|
||||
public void modifyAttributesWithException(String dn, String lastName,
|
||||
String description) {
|
||||
modifyAttributes(dn, lastName, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
public void unbind(OrgPerson person) {
|
||||
String dn = prepareDn(person);
|
||||
ldapTemplate.unbind(dn);
|
||||
this.getHibernateTemplate().delete(person);
|
||||
|
||||
}
|
||||
|
||||
public void unbindWithException(OrgPerson person) {
|
||||
this.unbind(person);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
public void update(OrgPerson person) {
|
||||
String dn = prepareDn(person);
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("sn", person.getLastname());
|
||||
ctx.setAttributeValue("description", person.getDescription());
|
||||
ctx.update();
|
||||
|
||||
ldapTemplate.rebind(dn, ctx, null);
|
||||
this.getHibernateTemplate().saveOrUpdate(person);
|
||||
|
||||
}
|
||||
|
||||
public void updateWithException(OrgPerson person) {
|
||||
this.update(person);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
public void updateAndRename(String dn, String newDn, String updatedDescription) {
|
||||
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("description", updatedDescription);
|
||||
ctx.update();
|
||||
|
||||
ldapTemplate.rebind(dn, ctx, null);
|
||||
ldapTemplate.rename(dn, newDn);
|
||||
|
||||
}
|
||||
|
||||
public void updateAndRenameWithException(String dn, String newDn, String updatedDescription) {
|
||||
this.updateAndRename(dn, newDn, updatedDescription);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLdapTemplate(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
private String prepareDn(OrgPerson person){
|
||||
return "cn=" + person.getFullname() + ",ou=" + person.getCompany() + ",c=" + person.getCountry();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package org.springframework.ldap.transaction.compensating.manager.hibernate;
|
||||
|
||||
/**
|
||||
* Pojo for use with the ContextSourceAndHibernateTransactionManager integration tests
|
||||
* @author Hans Westerbeek
|
||||
*
|
||||
*/
|
||||
public class OrgPerson{
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String fullname;
|
||||
|
||||
private String lastname;
|
||||
|
||||
private String company;
|
||||
|
||||
private String country;
|
||||
|
||||
private String description;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFullname() {
|
||||
return fullname;
|
||||
}
|
||||
|
||||
public void setFullname(String fullname) {
|
||||
this.fullname = fullname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((company == null) ? 0 : company.hashCode());
|
||||
result = prime * result + ((country == null) ? 0 : country.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((fullname == null) ? 0 : fullname.hashCode());
|
||||
result = prime * result + ((lastname == null) ? 0 : lastname.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final OrgPerson other = (OrgPerson) obj;
|
||||
if (company == null) {
|
||||
if (other.company != null)
|
||||
return false;
|
||||
}
|
||||
else if (!company.equals(other.company))
|
||||
return false;
|
||||
if (country == null) {
|
||||
if (other.country != null)
|
||||
return false;
|
||||
}
|
||||
else if (!country.equals(other.country))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
}
|
||||
else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (fullname == null) {
|
||||
if (other.fullname != null)
|
||||
return false;
|
||||
}
|
||||
else if (!fullname.equals(other.fullname))
|
||||
return false;
|
||||
if (lastname == null) {
|
||||
if (other.lastname != null)
|
||||
return false;
|
||||
}
|
||||
else if (!lastname.equals(other.lastname))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springframework.ldap.transaction.compensating.manager.hibernate;
|
||||
|
||||
public interface OrgPersonDao {
|
||||
void createWithException(OrgPerson person);
|
||||
|
||||
void create(OrgPerson person);
|
||||
|
||||
void update(OrgPerson person);
|
||||
|
||||
void updateWithException(OrgPerson person);
|
||||
|
||||
void updateAndRename(String dn, String newDn, String updatedDescription);
|
||||
|
||||
void updateAndRenameWithException(String dn, String newDn, String updatedDescription);
|
||||
|
||||
void modifyAttributes(String dn, String lastName, String description);
|
||||
|
||||
void modifyAttributesWithException(String dn, String lastName, String description);
|
||||
|
||||
void unbind(OrgPerson person);
|
||||
|
||||
void unbindWithException(OrgPerson person);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.test.LdapTestUtils;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
public abstract class AbstractLdapTemplateIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
private static final ClassPathResource LDIF_FILE_RESOURCE = new ClassPathResource("setup_data.ldif");
|
||||
|
||||
@Autowired
|
||||
@Qualifier("contextSource")
|
||||
private ContextSource contextSource;
|
||||
|
||||
@Before
|
||||
public void cleanAndSetup() throws NamingException, IOException {
|
||||
LdapTestUtils.cleanAndSetup(contextSource, getRoot(), LDIF_FILE_RESOURCE);
|
||||
}
|
||||
|
||||
protected DistinguishedName getRoot() {
|
||||
return DistinguishedName.EMPTY_PATH;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.CompositeName;
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the rename methods of LdapTemplate.
|
||||
*
|
||||
* We rely on that the bind, unbind and lookup methods work as they should -
|
||||
* that should be ok, since that is verified in a separate test class. *
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class InvalidBackslashITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static DistinguishedName DN = new DistinguishedName("cn=Some\\\\Person6,ou=company1,c=Sweden");
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some\\Person6");
|
||||
adapter.setAttributeValue("sn", "Person6");
|
||||
adapter.setAttributeValue("description", "Some description");
|
||||
|
||||
tested.unbind(DN);
|
||||
tested.bind(DN, adapter, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
tested.unbind(DN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for LDAP-109, LDAP-50. When an entry has a distinguished name
|
||||
* including a backslach ('\') the Name supplied to DefaultDirObjectFactory
|
||||
* will be invalid.
|
||||
* <p>
|
||||
* E.g. the distinguished name "cn=Some\\Person6,ou=company1,c=Sweden"
|
||||
* (indicating that the cn value is 'Some\Person'), will be represented by a
|
||||
* <code>CompositeName</code> with the string representation
|
||||
* "cn=Some\\\Person6,ou=company1,c=Sweden", which is in fact an invalid DN.
|
||||
* This will be supplied to <code>DistinguishedName</code> for parsing,
|
||||
* causing it to fail. This test makes sure that Spring LDAP properly works
|
||||
* around this bug.
|
||||
* </p>
|
||||
* <p>
|
||||
* What happens under the covers is (in the Java LDAP Provider code):
|
||||
*
|
||||
* <pre>
|
||||
* LdapName ldapname = new LdapName("cn=Some\\\\Person6,ou=company1,c=Sweden");
|
||||
* compositeName compositeName = new CompositeName();
|
||||
* compositeName.add(ldapname.get(ldapname.size() - 1)); // for some odd reason
|
||||
* </pre>
|
||||
* <code>CompositeName#add()</code> cannot handle this and the result is
|
||||
* the spoiled DN.
|
||||
* </p>
|
||||
* @throws InvalidNameException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchForDnSpoiledByCompositeName() throws InvalidNameException {
|
||||
List result = tested.search("", "(sn=Person6)", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
DistinguishedName dn = (DistinguishedName) ctx.getDn();
|
||||
assertEquals("cn=Some\\\\Person6, ou=company1, c=Sweden", dn.toString());
|
||||
assertEquals("Some\\Person6", dn.getLdapRdn("cn").getValue());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the attributes mapper search method.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateIntegrationTest {
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributeMapper() throws Exception {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
List result = tested.search("ou=company1,c=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
Person person = (Person) result.get(0);
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertEquals("Person2", person.getLastname());
|
||||
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrates how to retrieve all values of a multi-value attribute.
|
||||
*
|
||||
* @see LdapTemplateContextMapperITest#testSearch_ContextMapper_MultiValue()
|
||||
*/
|
||||
@Test
|
||||
public void testSearch_AttributesMapper_MultiValue() throws Exception {
|
||||
AttributesMapper mapper = new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
LinkedList list = new LinkedList();
|
||||
NamingEnumeration enumeration = attributes.get("uniqueMember").getAll();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
String value = (String) enumeration.nextElement();
|
||||
list.add(value);
|
||||
}
|
||||
String[] members = (String[]) list.toArray(new String[0]);
|
||||
return members;
|
||||
}
|
||||
};
|
||||
List result = tested.search("ou=groups", "(objectclass=groupOfUniqueNames)", mapper);
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(1, ((String[]) result.get(0)).length);
|
||||
assertEquals(5, ((String[]) result.get(1)).length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the bind and unbind methods of LdapTemplate. The test methods in this
|
||||
* class tests a little too much, but we need to clean up after binding, so the
|
||||
* most efficient way to test is to do it all in one test method. Also, the
|
||||
* methods in this class relies on that the lookup method works as it should -
|
||||
* that should be ok, since that is verified in a separate test class. NOTE: if
|
||||
* any of the tests in this class fails, it may be necessary to run the cleanup
|
||||
* script as described in README.txt under /src/iutest/.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateBindUnbindITest extends AbstractLdapTemplateIntegrationTest {
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static String DN = "cn=Some Person4,ou=company1,c=Sweden";
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbind_Attributes_Plain() {
|
||||
Attributes attributes = setupAttributes();
|
||||
tested.bind(DN, null, attributes);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(DN);
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbind_Attributes_DIstinguishedName() {
|
||||
Attributes attributes = setupAttributes();
|
||||
tested.bind(new DistinguishedName(DN), null, attributes);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(new DistinguishedName(DN));
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbind_DirContextAdapter_Plain() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(DN, adapter, null);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(DN);
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbind_DirContextAdapter_DIstinguishedName() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(new DistinguishedName(DN), adapter, null);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(new DistinguishedName(DN));
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
private Attributes setupAttributes() {
|
||||
Attributes attributes = new BasicAttributes();
|
||||
BasicAttribute ocattr = new BasicAttribute("objectclass");
|
||||
ocattr.add("top");
|
||||
ocattr.add("person");
|
||||
attributes.put(ocattr);
|
||||
attributes.put("cn", "Some Person4");
|
||||
attributes.put("sn", "Person4");
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private void verifyBoundCorrectData() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(DN);
|
||||
assertEquals("Some Person4", result.getStringAttribute("cn"));
|
||||
assertEquals("Person4", result.getStringAttribute("sn"));
|
||||
}
|
||||
|
||||
private void verifyCleanup() {
|
||||
try {
|
||||
tested.lookup(DN);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.ContextExecutor;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's context executor methods.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateContextExecutorTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
public void testLookupLink() {
|
||||
ContextExecutor executor = new ContextExecutor() {
|
||||
public Object executeWithContext(DirContext ctx) throws NamingException {
|
||||
return ctx.lookupLink("cn=Some Person,ou=company1,c=Sweden");
|
||||
}
|
||||
};
|
||||
|
||||
Object object = tested.executeReadOnly(executor);
|
||||
assertTrue("Should be a DirContextAdapter", object instanceof DirContextAdapter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.ContextMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the ContextMapper search method. In its way this method also
|
||||
* demonstrates the use of DirContextAdapter and the DirObjectFactory.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateContextMapperITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testSearch_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
List result = tested.search("ou=company1,c=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
Person person = (Person) result.get(0);
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertEquals("Person2", person.getLastname());
|
||||
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrates how to retrieve all values of a multi-value attribute.
|
||||
*
|
||||
* @see LdapTemplateAttributesMapperITest#testSearch_AttributesMapper_MultiValue()
|
||||
*/
|
||||
@Test
|
||||
public void testSearch_ContextMapper_MultiValue() throws Exception {
|
||||
ContextMapper mapper = new ContextMapper() {
|
||||
public Object mapFromContext(Object ctx) {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx;
|
||||
String[] members = adapter.getStringAttributes("uniqueMember");
|
||||
return members;
|
||||
}
|
||||
};
|
||||
List result = tested.search("ou=groups", "(objectclass=groupOfUniqueNames)", mapper);
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(1, ((String[]) result.get(0)).length);
|
||||
assertEquals(5, ((String[]) result.get(1)).length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's list methods.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private AttributeCheckContextMapper contextMapper;
|
||||
|
||||
private static final String BASE_STRING = "";
|
||||
|
||||
private static final DistinguishedName BASE_NAME = new DistinguishedName(BASE_STRING);
|
||||
|
||||
private static final String[] ALL_ATTRIBUTES = { "cn", "sn", "description", "telephoneNumber" };
|
||||
|
||||
private static final String[] ALL_VALUES = { "Some Person", "Person", "Sweden, Company2, Some Person",
|
||||
"+46 555-456321" };
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
contextMapper = new AttributeCheckContextMapper();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
contextMapper = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.listBindings("ou=company2,c=Sweden" + BASE_STRING, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
DistinguishedName dn = new DistinguishedName("ou=company2,c=Sweden");
|
||||
dn.append(BASE_NAME);
|
||||
List list = tested.listBindings(dn, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_ContextMapper_MapToPersons() {
|
||||
DistinguishedName dn = new DistinguishedName("ou=company1,c=Sweden");
|
||||
dn.append(BASE_NAME);
|
||||
List list = tested.listBindings(dn, new PersonContextMapper());
|
||||
assertEquals(3, list.size());
|
||||
String personClass = "org.springframework.ldap.Person";
|
||||
assertEquals(personClass, list.get(0).getClass().getName());
|
||||
assertEquals(personClass, list.get(1).getClass().getName());
|
||||
assertEquals(personClass, list.get(2).getClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList() {
|
||||
List list = tested.list(BASE_STRING);
|
||||
assertEquals(3, list.size());
|
||||
assertTrue(list.contains("ou=groups"));
|
||||
assertTrue(list.contains("c=Norway"));
|
||||
assertTrue(list.contains("c=Sweden"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Name() {
|
||||
List list = tested.list(BASE_NAME);
|
||||
assertEquals(3, list.size());
|
||||
assertTrue(list.contains("ou=groups"));
|
||||
assertTrue(list.contains("c=Norway"));
|
||||
assertTrue(list.contains("c=Sweden"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.list(BASE_STRING, handler);
|
||||
assertEquals(3, handler.getNoOfRows());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Name_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.list(BASE_NAME, handler);
|
||||
assertEquals(3, handler.getNoOfRows());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings() {
|
||||
List list = tested.listBindings(BASE_STRING);
|
||||
assertEquals(3, list.size());
|
||||
assertTrue(list.contains("ou=groups"));
|
||||
assertTrue(list.contains("c=Norway"));
|
||||
assertTrue(list.contains("c=Sweden"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Name() {
|
||||
List list = tested.listBindings(BASE_NAME);
|
||||
assertEquals(3, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.listBindings(BASE_STRING, handler);
|
||||
assertEquals(3, handler.getNoOfRows());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Name_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.listBindings(BASE_NAME, handler);
|
||||
assertEquals(3, handler.getNoOfRows());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.ldap.core.support.AbstractContextSource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_Plain() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person2, ou=company1,c=Sweden");
|
||||
|
||||
assertEquals("Some Person2", result.getStringAttribute("cn"));
|
||||
assertEquals("Person2", result.getStringAttribute("sn"));
|
||||
assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_AttributesMapper() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,c=Sweden", mapper);
|
||||
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertEquals("Person2", person.getLastname());
|
||||
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_AttributesMapper_DistinguishedName() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(new DistinguishedName("cn=Some Person2, ou=company1,c=Sweden"), mapper);
|
||||
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertEquals("Person2", person.getLastname());
|
||||
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
assertNull("sn should be null", attributes.get("sn"));
|
||||
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.
|
||||
*/
|
||||
@Test
|
||||
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);
|
||||
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertNull("lastName should not be set", person.getLastname());
|
||||
assertNull("description should not be set", person.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Test
|
||||
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);
|
||||
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertNull("lastName should not be set", person.getLastname());
|
||||
assertNull("description should not be set", person.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,c=Sweden", mapper);
|
||||
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertEquals("Person2", person.getLastname());
|
||||
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
*/
|
||||
@Test
|
||||
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);
|
||||
|
||||
assertEquals("Some Person2", person.getFullname());
|
||||
assertNull("lastName should not be set", person.getLastname());
|
||||
assertNull("description should not be set", 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.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enable test when ApacheDS supports multi-valued rdns")
|
||||
public void DISABLED_testLookup_MultiValuedRdn() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway", mapper);
|
||||
|
||||
assertEquals("Some Person", person.getFullname());
|
||||
assertEquals("Person", person.getLastname());
|
||||
assertEquals("Norway, Company1, Some Person2", 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.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enable test when ApacheDS supports multi-valued rdns")
|
||||
public void DISABLED_testLookup_MultiValuedRdn_DirContextAdapter() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
|
||||
|
||||
assertEquals("Some Person", result.getStringAttribute("cn"));
|
||||
assertEquals("Person", result.getStringAttribute("sn"));
|
||||
assertEquals("Norway, Company1, Some Person", result.getStringAttribute("description"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_GetNameInNamespace_Plain() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person2, ou=company1,c=Sweden");
|
||||
|
||||
assertEquals("cn=Some Person2, ou=company1, c=Sweden", result.getDn().toString());
|
||||
assertEquals("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se", result.getNameInNamespace());
|
||||
}
|
||||
|
||||
@Test
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests bind and lookup with Java objects where the ContextSource already
|
||||
* has a DirObjectFactory configured.
|
||||
*/
|
||||
@Test
|
||||
public void testBindJavaObject() throws Exception {
|
||||
AbstractContextSource contextSource = (AbstractContextSource) tested.getContextSource();
|
||||
Class originalObjectFactory = contextSource.getDirObjectFactory();
|
||||
try {
|
||||
contextSource.setDirObjectFactory(null);
|
||||
contextSource.afterPropertiesSet();
|
||||
tested.bind("cn=myRandomInt", new Integer(54321), null);
|
||||
Integer result = (Integer) tested.lookup("cn=myRandomInt");
|
||||
assertEquals(54321, result.intValue());
|
||||
}
|
||||
finally {
|
||||
// reset the DirObjectFactory so as not to disturb other tests
|
||||
tested.unbind("cn=myRandomInt");
|
||||
contextSource.setDirObjectFactory(originalObjectFactory);
|
||||
contextSource.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.ModificationItem;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the modification methods (rebind and modifyAttributes) of LdapTemplate.
|
||||
* It also illustrates the use of DirContextAdapter as a means of getting
|
||||
* ModificationItems, in order to avoid doing a full rebind and use
|
||||
* modifyAttributes() instead. We rely on that the bind, unbind and lookup
|
||||
* methods work as they should - that should be ok, since that is verified in a
|
||||
* separate test class. NOTE: if any of the tests in this class fails, it may be
|
||||
* necessary to run the cleanup script as described in README.txt under
|
||||
* /src/iutest/.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static String PERSON4_DN = "cn=Some Person4,ou=company1,c=Sweden";
|
||||
|
||||
private static String PERSON5_DN = "cn=Some Person5,ou=company1,c=Sweden";
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
adapter.setAttributeValue("description", "Some description");
|
||||
|
||||
tested.bind(PERSON4_DN, adapter, null);
|
||||
|
||||
adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person5");
|
||||
adapter.setAttributeValue("sn", "Person5");
|
||||
adapter.setAttributeValues("description", new String[] { "qwe", "123", "rty", "uio" });
|
||||
|
||||
tested.bind(PERSON5_DN, adapter, null);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
tested.unbind(PERSON4_DN);
|
||||
tested.unbind(PERSON5_DN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRebind_Attributes_Plain() {
|
||||
Attributes attributes = setupAttributes();
|
||||
|
||||
tested.rebind(PERSON4_DN, null, attributes);
|
||||
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRebind_Attributes_DistinguishedName() {
|
||||
Attributes attributes = setupAttributes();
|
||||
|
||||
tested.rebind(new DistinguishedName(PERSON4_DN), null, attributes);
|
||||
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_MultiValueReplace() {
|
||||
BasicAttribute attr = new BasicAttribute("description", "Some other description");
|
||||
attr.add("Another description");
|
||||
ModificationItem[] mods = new ModificationItem[1];
|
||||
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
|
||||
|
||||
tested.modifyAttributes(PERSON4_DN, mods);
|
||||
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
|
||||
String[] attributes = result.getStringAttributes("description");
|
||||
assertEquals(2, attributes.length);
|
||||
assertEquals("Some other description", attributes[0]);
|
||||
assertEquals("Another description", attributes[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_MultiValueAdd() {
|
||||
BasicAttribute attr = new BasicAttribute("description", "Some other description");
|
||||
attr.add("Another description");
|
||||
ModificationItem[] mods = new ModificationItem[1];
|
||||
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
|
||||
|
||||
tested.modifyAttributes(PERSON4_DN, mods);
|
||||
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
|
||||
String[] attributes = result.getStringAttributes("description");
|
||||
assertEquals(3, attributes.length);
|
||||
assertEquals("Some description", attributes[0]);
|
||||
assertEquals("Some other description", attributes[1]);
|
||||
assertEquals("Another description", attributes[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_MultiValueAddDuplicateToUnordered() {
|
||||
BasicAttribute attr = new BasicAttribute("description", "Some description");
|
||||
ModificationItem[] mods = new ModificationItem[1];
|
||||
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
|
||||
|
||||
try {
|
||||
tested.modifyAttributes(PERSON4_DN, mods);
|
||||
fail("AttributeInUseException expected");
|
||||
}
|
||||
catch (AttributeInUseException expected) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test written originally to verify that duplicates are allowed on ordered
|
||||
* attributes, but had to be changed since Apache DS seems to disallow
|
||||
* duplicates even for ordered attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testModifyAttributes_MultiValueAddDuplicateToOrdered() {
|
||||
BasicAttribute attr = new BasicAttribute("description", "Some other description", true); // ordered
|
||||
attr.add("Another description");
|
||||
// Commented out duplicate to make test work for Apache DS
|
||||
// attr.add("Some description");
|
||||
ModificationItem[] mods = new ModificationItem[1];
|
||||
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
|
||||
|
||||
tested.modifyAttributes(PERSON4_DN, mods);
|
||||
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
|
||||
String[] attributes = result.getStringAttributes("description");
|
||||
assertEquals(3, attributes.length);
|
||||
assertEquals("Some description", attributes[0]);
|
||||
assertEquals("Some other description", attributes[1]);
|
||||
assertEquals("Another description", attributes[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_Plain() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
|
||||
tested.modifyAttributes(PERSON4_DN, new ModificationItem[] { item });
|
||||
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_DistinguishedName() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
|
||||
tested.modifyAttributes(new DistinguishedName(PERSON4_DN), new ModificationItem[] { item });
|
||||
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_DirContextAdapter_MultiAttributes() {
|
||||
DirContextAdapter adapter = (DirContextAdapter) tested.lookup(PERSON5_DN);
|
||||
adapter.setAttributeValues("description", new String[] { "qwe", "123", "klytt", "kalle" });
|
||||
|
||||
tested.modifyAttributes(PERSON5_DN, adapter.getModificationItems());
|
||||
|
||||
// Verify
|
||||
adapter = (DirContextAdapter) tested.lookup(PERSON5_DN);
|
||||
String[] attributes = adapter.getStringAttributes("description");
|
||||
assertEquals(4, attributes.length);
|
||||
assertEquals("qwe", attributes[0]);
|
||||
assertEquals("123", attributes[1]);
|
||||
assertEquals("klytt", attributes[2]);
|
||||
assertEquals("kalle", attributes[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrates how the DirContextAdapter can be used to automatically keep
|
||||
* track of changes of the attributes and deliver ModificationItems to use
|
||||
* in moifyAttributes().
|
||||
*/
|
||||
@Test
|
||||
public void testModifyAttributes_DirContextAdapter() throws Exception {
|
||||
DirContextAdapter adapter = (DirContextAdapter) tested.lookup(PERSON4_DN);
|
||||
|
||||
adapter.setAttributeValue("description", "Some other description");
|
||||
|
||||
ModificationItem[] modificationItems = adapter.getModificationItems();
|
||||
tested.modifyAttributes(PERSON4_DN, modificationItems);
|
||||
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
private Attributes setupAttributes() {
|
||||
Attributes attributes = new BasicAttributes();
|
||||
BasicAttribute ocattr = new BasicAttribute("objectclass");
|
||||
ocattr.add("top");
|
||||
ocattr.add("person");
|
||||
attributes.put(ocattr);
|
||||
attributes.put("cn", "Some Person4");
|
||||
attributes.put("sn", "Person4");
|
||||
attributes.put("description", "Some other description");
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private void verifyBoundCorrectData() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
|
||||
assertEquals("Some Person4", result.getStringAttribute("cn"));
|
||||
assertEquals("Person4", result.getStringAttribute("sn"));
|
||||
assertEquals("Some other description", result.getStringAttribute("description"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests to verify that not setting a base suffix on the ContextSource (as
|
||||
* defined in ldapTemplateNoBaseSuffixTestContext.xml) works as expected.
|
||||
*
|
||||
* NOTE: This test will not work under Java 1.4.1 or earlier.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateNoBaseSuffixTestContext.xml" })
|
||||
public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Override
|
||||
protected DistinguishedName getRoot() {
|
||||
return new DistinguishedName("dc=jayway,dc=se");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_Plain() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se");
|
||||
|
||||
assertEquals("Some Person2", result.getStringAttribute("cn"));
|
||||
assertEquals("Person2", result.getStringAttribute("sn"));
|
||||
assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description"));
|
||||
assertEquals("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se", result.getDn().toString());
|
||||
assertEquals("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se", result.getNameInNamespace());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_Plain() {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
|
||||
tested.search("dc=jayway, dc=se", "(objectclass=person)", handler);
|
||||
assertEquals(5, handler.getNoOfRows());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbind_Plain() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
tested.bind("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se", adapter, null);
|
||||
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se");
|
||||
|
||||
assertEquals("Some Person4", result.getStringAttribute("cn"));
|
||||
assertEquals("Person4", result.getStringAttribute("sn"));
|
||||
assertEquals("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se", result.getDn().toString());
|
||||
|
||||
tested.unbind("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se");
|
||||
try {
|
||||
tested.lookup("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se");
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextSource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests bind and lookup with Java objects where the ContextSource has a
|
||||
* <code>null</code> DirObjectFactory configured.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateObjectBindTestContext.xml" })
|
||||
public class LdapTemplateObjectBindIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
public void testBindJavaObject() throws Exception {
|
||||
String dn = "cn=myRandomInt";
|
||||
tested.bind(dn, new Integer(54321), null);
|
||||
|
||||
Integer result = (Integer) tested.lookup(dn);
|
||||
assertEquals(54321, result.intValue());
|
||||
tested.unbind(dn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindLinkedList() {
|
||||
LinkedList list = new LinkedList();
|
||||
list.add(new Integer(54321));
|
||||
list.add(new Integer(67890));
|
||||
|
||||
String dn = "cn=myRandomList";
|
||||
tested.bind(dn, list, null);
|
||||
|
||||
LinkedList result = (LinkedList) tested.lookup(dn);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(54321, ((Integer) result.get(0)).intValue());
|
||||
assertEquals(67890, ((Integer) result.get(1)).intValue());
|
||||
tested.unbind(dn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindNonSerializableJavaObjectShouldFail() throws Exception {
|
||||
NonSerializablePojo pojo = new NonSerializablePojo();
|
||||
pojo.setName("A Name");
|
||||
|
||||
try {
|
||||
tested.bind("cn=myRandomObject", pojo, null);
|
||||
fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("can only bind Referenceable, Serializable, DirContext", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom non-serializable class used for demonstrating bind and lookup of
|
||||
* Java objects.
|
||||
*/
|
||||
public static class NonSerializablePojo {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindSerializableJavaObjectShouldSucceed() throws Exception {
|
||||
SerializablePojo pojo = new SerializablePojo();
|
||||
pojo.setName("A Name");
|
||||
|
||||
tested.bind("cn=myRandomObject", pojo, null);
|
||||
|
||||
SerializablePojo result = (SerializablePojo) tested.lookup("cn=myRandomObject");
|
||||
assertEquals("A Name", result.getName());
|
||||
tested.unbind("cn=myRandomObject");
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom serializable class used for demonstrating bind and lookup of Java
|
||||
* objects.
|
||||
*/
|
||||
public static class SerializablePojo implements Serializable {
|
||||
private static final long serialVersionUID = 3655768927093734908L;
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test demonstrates that it's fully possible to perform plain JNDI
|
||||
* operations from Spring LDAP.
|
||||
*/
|
||||
@Test
|
||||
public void testPlainJndiBindJavaObject() throws Exception {
|
||||
AbstractContextSource contextSource = (AbstractContextSource) tested.getContextSource();
|
||||
DirContext ctx = contextSource.getReadWriteContext();
|
||||
|
||||
ctx.bind("cn=myRandomInt", new Integer(28420));
|
||||
|
||||
Integer result = (Integer) ctx.lookup("cn=myRandomInt");
|
||||
assertEquals(28420, result.intValue());
|
||||
tested.unbind("cn=myRandomInt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the recursive modification methods (unbind and the protected delete
|
||||
* methods) of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static DistinguishedName DN = new DistinguishedName("cn=Some Person5,ou=company1,c=Sweden");
|
||||
|
||||
private DistinguishedName firstSubDn;
|
||||
|
||||
private DistinguishedName secondSubDn;
|
||||
|
||||
private DistinguishedName leafDn;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person5");
|
||||
adapter.setAttributeValue("sn", "Person5");
|
||||
adapter.setAttributeValue("description", "Some description");
|
||||
tested.bind(DN, adapter, null);
|
||||
|
||||
firstSubDn = new DistinguishedName("cn=subPerson");
|
||||
firstSubDn.prepend(DN);
|
||||
adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "subPerson");
|
||||
adapter.setAttributeValue("sn", "subPerson");
|
||||
adapter.setAttributeValue("description", "Should be recursively deleted");
|
||||
tested.bind(firstSubDn, adapter, null);
|
||||
secondSubDn = new DistinguishedName("cn=subPerson2");
|
||||
secondSubDn.prepend(DN);
|
||||
adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "subPerson2");
|
||||
adapter.setAttributeValue("sn", "subPerson2");
|
||||
adapter.setAttributeValue("description", "Should be recursively deleted");
|
||||
tested.bind(secondSubDn, adapter, null);
|
||||
|
||||
leafDn = new DistinguishedName("cn=subSubPerson");
|
||||
leafDn.prepend(firstSubDn);
|
||||
adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "subSubPerson");
|
||||
adapter.setAttributeValue("sn", "subSubPerson");
|
||||
adapter.setAttributeValue("description", "Should be recursively deleted");
|
||||
tested.bind(leafDn, adapter, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
try {
|
||||
tested.unbind(DN, true);
|
||||
}
|
||||
catch (NameNotFoundException ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveUnbind() {
|
||||
tested.unbind(DN, true);
|
||||
|
||||
verifyDeleted(DN);
|
||||
verifyDeleted(firstSubDn);
|
||||
verifyDeleted(secondSubDn);
|
||||
verifyDeleted(leafDn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveUnbindOnLeaf() {
|
||||
tested.unbind(leafDn, true);
|
||||
verifyDeleted(leafDn);
|
||||
}
|
||||
|
||||
private void verifyDeleted(Name dn) {
|
||||
try {
|
||||
tested.lookup(dn);
|
||||
fail("Expected entry '" + dn + "' to be non-existent");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests the rename methods of LdapTemplate.
|
||||
*
|
||||
* We rely on that the bind, unbind and lookup methods work as they should -
|
||||
* that should be ok, since that is verified in a separate test class. *
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateRenameITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static String DN = "cn=Some Person6,ou=company1,c=Sweden";
|
||||
|
||||
private static String NEWDN = "cn=Some Person6,ou=company2,c=Sweden";
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person6");
|
||||
adapter.setAttributeValue("sn", "Person6");
|
||||
adapter.setAttributeValue("description", "Some description");
|
||||
|
||||
tested.bind(DN, adapter, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
tested.unbind(NEWDN);
|
||||
tested.unbind(DN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRename() {
|
||||
tested.rename(DN, NEWDN);
|
||||
|
||||
verifyDeleted(new DistinguishedName(DN));
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRename_DistinguishedName() throws Exception {
|
||||
Name oldDn = new DistinguishedName(DN);
|
||||
Name newDn = new DistinguishedName(NEWDN);
|
||||
tested.rename(oldDn, newDn);
|
||||
|
||||
verifyDeleted(oldDn);
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
private void verifyDeleted(Name dn) {
|
||||
try {
|
||||
tested.lookup(dn);
|
||||
fail("Expected entry '" + dn + "' to be non-existent");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyBoundCorrectData() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(NEWDN);
|
||||
assertEquals("Some Person6", result.getStringAttribute("cn"));
|
||||
assertEquals("Person6", result.getStringAttribute("sn"));
|
||||
assertEquals("Some description", result.getStringAttribute("description"));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.directory.SearchControls;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's search methods. This test class tests all the
|
||||
* different versions of the search methods except the generic ones covered in
|
||||
* other tests.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private AttributeCheckAttributesMapper attributesMapper;
|
||||
|
||||
private AttributeCheckContextMapper contextMapper;
|
||||
|
||||
private static final String[] ALL_ATTRIBUTES = { "cn", "sn", "description", "telephoneNumber" };
|
||||
|
||||
private static final String[] CN_SN_ATTRS = { "cn", "sn" };
|
||||
|
||||
private static final String[] ABSENT_ATTRIBUTES = { "description", "telephoneNumber" };
|
||||
|
||||
private static final String[] CN_SN_VALUES = { "Some Person2", "Person2" };
|
||||
|
||||
private static final String[] ALL_VALUES = { "Some Person2", "Person2", "Sweden, Company1, Some Person2",
|
||||
"+46 555-654321" };
|
||||
|
||||
private static final String BASE_STRING = "";
|
||||
|
||||
private static final String FILTER_STRING = "(&(objectclass=person)(sn=Person2))";
|
||||
|
||||
private static final Name BASE_NAME = new DistinguishedName(BASE_STRING);
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
attributesMapper = new AttributeCheckAttributesMapper();
|
||||
contextMapper = new AttributeCheckContextMapper();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
attributesMapper = null;
|
||||
contextMapper = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, attributesMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
attributesMapper.setExpectedValues(CN_SN_VALUES);
|
||||
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
|
||||
attributesMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
attributesMapper.setExpectedValues(CN_SN_VALUES);
|
||||
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List list = tested
|
||||
.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_LimitedAttrs_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
contextMapper.setExpectedValues(CN_SN_VALUES);
|
||||
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_SearchScope_LimitedAttrs_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
contextMapper.setExpectedValues(CN_SN_VALUES);
|
||||
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithInvalidSearchBaseShouldByDefaultThrowException() {
|
||||
try {
|
||||
tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
|
||||
contextMapper);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithInvalidSearchBaseCanBeConfiguredToSwallowException() {
|
||||
tested.setIgnoreNameNotFoundException(true);
|
||||
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
contextMapper.setExpectedValues(CN_SN_VALUES);
|
||||
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List list = tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
|
||||
contextMapper);
|
||||
assertEquals(0, list.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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.control;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
|
||||
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.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Provides tests that verify that the server supports certain controls.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/rootContextSourceTestContext.xml" })
|
||||
public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest {
|
||||
/** must use a context source that has no base set */
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static final String SUPPORTED_CONTROL = "supportedcontrol";
|
||||
|
||||
@Override
|
||||
protected DistinguishedName getRoot() {
|
||||
return new DistinguishedName("dc=jayway,dc=se");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpectedControlsSupported() throws Exception {
|
||||
/**
|
||||
* Maps the 'supportedcontrol' attribute to a string array.
|
||||
*/
|
||||
ContextMapper mapper = new ContextMapper() {
|
||||
|
||||
public Object mapFromContext(Object ctx) {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx;
|
||||
return adapter.getStringAttributes(SUPPORTED_CONTROL);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
String[] controls = (String[]) tested.lookup("", new String[] { SUPPORTED_CONTROL }, mapper);
|
||||
System.out.println(Arrays.toString(controls));
|
||||
assertEquals("Persistent Search LDAPv3 control,", "2.16.840.1.113730.3.4.3", controls[0]);
|
||||
assertEquals("Entry Change Notification LDAPv3 control,", "2.16.840.1.113730.3.4.7", controls[1]);
|
||||
assertEquals("Subentries Control,", "1.3.6.1.4.1.4203.1.10.1", controls[2]);
|
||||
assertEquals("Manage DSA IT LDAPv3 control,", "2.16.840.1.113730.3.4.2", controls[3]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.core;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link DistinguishedNameEditor}.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/distinguishedNameEditorTestContext.xml" })
|
||||
public class DistinguishedNameEditorITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private DummyDistinguishedNameConsumer distinguishedNameConsumer;
|
||||
|
||||
@Test
|
||||
public void testDistinguishedNameEditor() throws Exception {
|
||||
assertNotNull(distinguishedNameConsumer);
|
||||
DistinguishedName name = distinguishedNameConsumer.getDistinguishedName();
|
||||
assertEquals(new DistinguishedName("dc=jayway, dc=se"), name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Performance test for the {@link DistinguishedName} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class DnParsePerformanceITest {
|
||||
|
||||
/**
|
||||
* Tests parsing and toString.
|
||||
*/
|
||||
@Test
|
||||
public void testContains() {
|
||||
StopWatch stopWatch = new StopWatch("Dn Parse Performance");
|
||||
stopWatch.start();
|
||||
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
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");
|
||||
}
|
||||
|
||||
stopWatch.stop();
|
||||
System.out.println(stopWatch.prettyPrint());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.core.simple;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@ContextConfiguration(locations = { "/conf/simpleLdapTemplateTestContext.xml" })
|
||||
public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private SimpleLdapTemplate ldapTemplate;
|
||||
|
||||
@Test
|
||||
public void testLookup() {
|
||||
String result = ldapTemplate.lookup("cn=Some Person,ou=company1,c=Sweden", new CnContextMapper());
|
||||
assertEquals("Some Person", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch() {
|
||||
List<String> cns = ldapTemplate.search("", "(&(objectclass=person)(sn=Person3))", new CnContextMapper());
|
||||
|
||||
assertEquals(1, cns.size());
|
||||
assertEquals("Some Person3", cns.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes() {
|
||||
DirContextOperations ctx = ldapTemplate.lookupContext("cn=Some Person,ou=company1,c=Sweden");
|
||||
|
||||
ctx.setAttributeValue("description", "updated description");
|
||||
ctx.setAttributeValue("telephoneNumber", "0000001");
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
|
||||
// verify that the data was properly updated.
|
||||
ldapTemplate.lookup("cn=Some Person,ou=company1,c=Sweden", new ParameterizedContextMapper<Object>() {
|
||||
public Object mapFromContext(Object ctx) {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx;
|
||||
assertEquals("updated description", adapter.getStringAttribute("description"));
|
||||
assertEquals("0000001", adapter.getStringAttribute("telephoneNumber"));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class CnContextMapper implements ParameterizedContextMapper<String> {
|
||||
|
||||
public String mapFromContext(Object ctx) {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx;
|
||||
|
||||
return adapter.getStringAttribute("cn");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class BaseLdapPathBeanPostprocessorITest {
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitialization() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertNotNull(base);
|
||||
assertEquals(new DistinguishedName("dc=jayway,dc=se"), base);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationMultipleContextSources() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorMultiContextSourceTestContext.xml");
|
||||
fail("BeanCreationException expected");
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
Throwable cause = expected.getCause();
|
||||
assertTrue(cause instanceof NoSuchBeanDefinitionException);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationMultipleContextSourcesOneSpecified() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorMultiContextSourceOneSpecTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertNotNull(base);
|
||||
assertEquals(new DistinguishedName("cn=john doe,dc=jayway,dc=se"), base);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationNoContextSource() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorNoContextSourceTestContext.xml");
|
||||
fail("BeanCreationException expected");
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
Throwable cause = expected.getCause();
|
||||
assertTrue(cause instanceof NoSuchBeanDefinitionException);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationBaseSetInProperty() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorPropertyOverrideTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertNotNull(base);
|
||||
assertEquals(new DistinguishedName("cn=john doe"), base);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationTransactionProxy() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorTransactionTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertNotNull(base);
|
||||
assertEquals(new DistinguishedName("dc=jayway,dc=se"), base);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Integration tests for ContextSourceImpl.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapContextSourcelITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ContextSource tested;
|
||||
|
||||
@Test
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContext() throws NamingException {
|
||||
DirContext ctx = null;
|
||||
try {
|
||||
String expectedPrincipal = "cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se";
|
||||
String expectedCredentials = "password";
|
||||
ctx = tested.getContext(expectedPrincipal, expectedCredentials);
|
||||
assertNotNull(ctx);
|
||||
// Double check to see that we are authenticated.
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertEquals(expectedPrincipal, environment.get(Context.SECURITY_PRINCIPAL));
|
||||
assertEquals(expectedCredentials, environment.get(Context.SECURITY_CREDENTIALS));
|
||||
}
|
||||
finally {
|
||||
// Always clean up.
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.core.support;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
/**
|
||||
* Integration tests for ContextSourceImpl.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapContextSourceTestContext.xml" })
|
||||
public class LdapContextSourcelMultiServerITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapContextSource tested;
|
||||
|
||||
@Test
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2005-2008 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.filter;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/hardcodedFilterTestContext.xml" })
|
||||
public class HardcodedFilterIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private DummyFilterConsumer dummyFilterConsumer;
|
||||
|
||||
@Test
|
||||
public void verifyThatFilterEditorWorks() {
|
||||
Filter filter = dummyFilterConsumer.getFilter();
|
||||
assertTrue(filter instanceof HardcodedFilter);
|
||||
assertEquals("(&(objectclass=person)(!(objectclass=computer))", filter.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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.transaction.compensating.manager;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ContextSourceAndDataSourceTransactionManager}.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapAndJdbcTransactionTestContext.xml" })
|
||||
public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Log log = LogFactory.getLog(ContextSourceAndDataSourceTransactionManagerIntegrationTest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
private DummyDao dummyDao;
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
|
||||
jdbcTemplate.execute("drop table PERSON if exists");
|
||||
jdbcTemplate.execute("create table PERSON(fullname VARCHAR, lastname VARCHAR, description VARCHAR)");
|
||||
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { "Some Person", "Person",
|
||||
"Sweden, Company1, Some Person" });
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
jdbcTemplate.execute("drop table PERSON if exists");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithException() {
|
||||
try {
|
||||
dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
log.debug("Verifying result");
|
||||
|
||||
// Verify that no entry was created
|
||||
try {
|
||||
ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
try {
|
||||
jdbcTemplate.queryForObject("select * from PERSON where fullname='some testperson'", new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
fail("EmptyResultDataAccessException expected");
|
||||
}
|
||||
catch (EmptyResultDataAccessException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");
|
||||
|
||||
log.debug("Verifying result");
|
||||
Object ldapResult = ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
|
||||
Object dbResult = jdbcTemplate.queryForObject("select * from PERSON where fullname='some testperson'",
|
||||
new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
assertNotNull(ldapResult);
|
||||
assertNotNull(dbResult);
|
||||
|
||||
ldapTemplate.unbind("cn=some testperson, ou=company1, c=Sweden");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
try {
|
||||
dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
log.debug("Verifying result");
|
||||
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Person", attributes.get("sn").get());
|
||||
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?",
|
||||
new Object[] { "Some Person" }, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
assertEquals("Person", rs.getString("lastname"));
|
||||
assertEquals("Sweden, Company1, Some Person", rs.getString("description"));
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
assertNotNull(jdbcResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
dummyDao.update(dn, "Some Person", "Updated Person", "Updated description");
|
||||
|
||||
log.debug("Verifying result");
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated Person", attributes.get("sn").get());
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?",
|
||||
new Object[] { "Some Person" }, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
assertEquals("Updated Person", rs.getString("lastname"));
|
||||
assertEquals("Updated description", rs.getString("description"));
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
assertNotNull(jdbcResult);
|
||||
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAndRenameWithException() {
|
||||
String dn = "cn=Some Person2,ou=company1,c=Sweden";
|
||||
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify that entry was not moved.
|
||||
try {
|
||||
ldapTemplate.lookup(newDn);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify that original entry was not updated.
|
||||
Object object = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
assertNotNull(object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAndRename() {
|
||||
String dn = "cn=Some Person2,ou=company1,c=Sweden";
|
||||
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.updateAndRename(dn, newDn, "Updated description");
|
||||
|
||||
// Verify that entry was moved and updated.
|
||||
Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(object);
|
||||
dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributesWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify result - check that the operation was properly rolled back
|
||||
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Person", attributes.get("sn").get());
|
||||
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");
|
||||
|
||||
// Verify result - check that the operation was not rolled back
|
||||
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated lastname", attributes.get("sn").get());
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(result);
|
||||
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnbindWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.unbindWithException(dn, "Some Person");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify result - check that the operation was properly rolled back
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
// Just verify that the entry still exists.
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?",
|
||||
new Object[] { "Some Person" }, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
// Just verify that the entry still exists.
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
assertNotNull(jdbcResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnbind() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.unbind(dn, "Some Person");
|
||||
|
||||
try {
|
||||
// Verify result - check that the operation was not rolled back
|
||||
ldapTemplate.lookup(dn);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
try {
|
||||
jdbcTemplate.queryForObject("select * from PERSON where fullname=?", new Object[] { "Some Person" },
|
||||
new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
fail("EmptyResultDataAccessException expected");
|
||||
}
|
||||
catch (EmptyResultDataAccessException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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.transaction.compensating.manager;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ContextSourceAndDataSourceTransactionManager}.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTransactionTestContext.xml" })
|
||||
public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Log log = LogFactory.getLog(ContextSourceTransactionManagerIntegrationTest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
private DummyDao dummyDao;
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithException() {
|
||||
try {
|
||||
dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
log.debug("Verifying result");
|
||||
|
||||
// Verify that no entry was created
|
||||
try {
|
||||
ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");
|
||||
|
||||
log.debug("Verifying result");
|
||||
String expectedDn = "cn=some testperson, ou=company1, c=Sweden";
|
||||
Object ldapResult = ldapTemplate.lookup(expectedDn);
|
||||
assertNotNull(ldapResult);
|
||||
|
||||
ldapTemplate.unbind(expectedDn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
try {
|
||||
dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
log.debug("Verifying result");
|
||||
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Person", attributes.get("sn").get());
|
||||
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
dummyDao.update(dn, "Some Person", "Updated Person", "Updated description");
|
||||
|
||||
log.debug("Verifying result");
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated Person", attributes.get("sn").get());
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
|
||||
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAndRenameWithException() {
|
||||
String dn = "cn=Some Person2,ou=company1,c=Sweden";
|
||||
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify that entry was not moved.
|
||||
try {
|
||||
ldapTemplate.lookup(newDn);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify that original entry was not updated.
|
||||
Object object = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
assertNotNull(object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAndRename() {
|
||||
String dn = "cn=Some Person2,ou=company1,c=Sweden";
|
||||
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.updateAndRename(dn, newDn, "Updated description");
|
||||
|
||||
// Verify that entry was moved and updated.
|
||||
Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(object);
|
||||
dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributesWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify result - check that the operation was properly rolled back
|
||||
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Person", attributes.get("sn").get());
|
||||
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");
|
||||
|
||||
// Verify result - check that the operation was not rolled back
|
||||
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated lastname", attributes.get("sn").get());
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnbindWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.unbindWithException(dn, "Some Person");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify result - check that the operation was properly rolled back
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
// Just verify that the entry still exists.
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnbind() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.unbind(dn, "Some Person");
|
||||
|
||||
try {
|
||||
// Verify result - check that the operation was not rolled back
|
||||
ldapTemplate.lookup(dn);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* Copyright 2005-2007 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.transaction.compensating.manager.hibernate;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager;
|
||||
import org.springframework.ldap.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.orm.hibernate3.HibernateTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ContextSourceAndHibernateTransactionManager}.
|
||||
*
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/conf/ldapAndHibernateTransactionTestContext.xml" })
|
||||
public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Log log = LogFactory.getLog(ContextSourceAndHibernateTransactionManagerIntegrationTest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
private OrgPersonDao dummyDao;
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@Autowired
|
||||
private HibernateTemplate hibernateTemplate;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Before
|
||||
public void prepareTest() throws Exception {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
|
||||
OrgPerson person = new OrgPerson();
|
||||
person.setId(new Integer(1));
|
||||
person.setLastname("Person");
|
||||
person.setFullname("Some Person");
|
||||
person.setDescription("Sweden, Company1, Some Person");
|
||||
person.setCountry("Sweden");
|
||||
person.setCompany("Company1");
|
||||
// "Some Person", "Person", "Sweden, Company1, Some Person"
|
||||
// avoid the transaction manager we have configured, do it manually
|
||||
Session session = this.sessionFactory.openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.saveOrUpdate(person);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
// probably the wrong idea, this will use the thing i am trying to
|
||||
// test..
|
||||
|
||||
Session session = this.sessionFactory.openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
Query query = session.createQuery("delete from OrgPerson");
|
||||
query.executeUpdate();
|
||||
tx.commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithException() {
|
||||
OrgPerson person = new OrgPerson();
|
||||
|
||||
person.setId(new Integer(2));
|
||||
person.setDescription("some description");
|
||||
person.setFullname("Some testperson");
|
||||
person.setLastname("testperson");
|
||||
person.setCountry("Sweden");
|
||||
person.setCompany("company1");
|
||||
|
||||
try {
|
||||
dummyDao.createWithException(person);
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
log.debug("Verifying result");
|
||||
|
||||
// Verify that no entry was created in ldap or hibernate db
|
||||
try {
|
||||
ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
List result = hibernateTemplate.findByNamedParam("from OrgPerson person where person.lastname = :lastname",
|
||||
"lastname", person.getLastname());
|
||||
assertTrue(result.size() == 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
OrgPerson person = new OrgPerson();
|
||||
|
||||
person.setId(new Integer(2));
|
||||
person.setDescription("some description");
|
||||
person.setFullname("Some testperson");
|
||||
person.setLastname("testperson");
|
||||
person.setCountry("Sweden");
|
||||
person.setCompany("company1");
|
||||
// dummyDao.create("Sweden", "company1", "some testperson",
|
||||
// "testperson", "some description");
|
||||
|
||||
this.dummyDao.create(person);
|
||||
person = null;
|
||||
log.debug("Verifying result");
|
||||
Object ldapResult = ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
|
||||
OrgPerson fromDb = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(2));
|
||||
assertNotNull(ldapResult);
|
||||
assertNotNull(fromDb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
OrgPerson originalPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
|
||||
originalPerson.setLastname("fooo");
|
||||
try {
|
||||
dummyDao.updateWithException(originalPerson);
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
log.debug("Verifying result");
|
||||
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertNotNull("Person", attributes.get("sn").get());
|
||||
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
OrgPerson notUpdatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
|
||||
assertEquals("Person", notUpdatedPerson.getLastname());
|
||||
assertEquals("Sweden, Company1, Some Person", notUpdatedPerson.getDescription());
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
// no need to assert if notUpdatedPerson exists
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
|
||||
person.setLastname("Updated Person");
|
||||
person.setDescription("Updated description");
|
||||
|
||||
dummyDao.update(person);
|
||||
|
||||
log.debug("Verifying result");
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated Person", attributes.get("sn").get());
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
|
||||
assertEquals("Updated Person", updatedPerson.getLastname());
|
||||
assertEquals("Updated description", updatedPerson.getDescription());
|
||||
assertNotNull(ldapResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAndRenameWithException() {
|
||||
String dn = "cn=Some Person2,ou=company1,c=Sweden";
|
||||
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
|
||||
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
|
||||
person.setLastname("Updated Person");
|
||||
person.setDescription("Updated description");
|
||||
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify that entry was not moved.
|
||||
try {
|
||||
ldapTemplate.lookup(newDn);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify that original entry was not updated.
|
||||
Object object = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
assertNotNull(object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAndRename() {
|
||||
String dn = "cn=Some Person2,ou=company1,c=Sweden";
|
||||
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.updateAndRename(dn, newDn, "Updated description");
|
||||
|
||||
// Verify that entry was moved and updated.
|
||||
Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributesWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Verify result - check that the operation was properly rolled back
|
||||
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Person", attributes.get("sn").get());
|
||||
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
// Perform test
|
||||
dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");
|
||||
|
||||
// Verify result - check that the operation was not rolled back
|
||||
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
assertEquals("Updated lastname", attributes.get("sn").get());
|
||||
assertEquals("Updated description", attributes.get("description").get());
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnbindWithException() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
|
||||
|
||||
try {
|
||||
// Perform test
|
||||
dummyDao.unbindWithException(person);
|
||||
fail("DummyException expected");
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
person = null;
|
||||
// Verify result - check that the operation was properly rolled back
|
||||
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
// Just verify that the entry still exists.
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); // will
|
||||
// throw
|
||||
// exception
|
||||
// of
|
||||
// person
|
||||
// does
|
||||
// not
|
||||
// exist
|
||||
|
||||
assertNotNull(ldapResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnbind() {
|
||||
String dn = "cn=Some Person,ou=company1,c=Sweden";
|
||||
// Perform test
|
||||
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
|
||||
dummyDao.unbind(person);
|
||||
|
||||
try {
|
||||
// Verify result - check that the operation was not rolled back
|
||||
ldapTemplate.lookup(dn);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1));
|
||||
assertNull(person);
|
||||
}
|
||||
}
|
||||
110
test/integration-tests/src/test/java/setup_data.ldif
Normal file
110
test/integration-tests/src/test/java/setup_data.ldif
Normal file
@@ -0,0 +1,110 @@
|
||||
dn: ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: groups
|
||||
|
||||
dn: cn=ROLE_USER,ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: groupOfUniqueNames
|
||||
cn: ROLE_USER
|
||||
uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person,ou=company1,c=Norway,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person,ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
|
||||
dn: cn=ROLE_ADMIN,ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: groupOfUniqueNames
|
||||
cn: ROLE_ADMIN
|
||||
uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
|
||||
dn: c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Sweden
|
||||
description: The country of Sweden
|
||||
|
||||
dn: c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Norway
|
||||
description: The country of Norway
|
||||
|
||||
dn: ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Sweden
|
||||
|
||||
dn: ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company2
|
||||
description: Second company in Sweden
|
||||
|
||||
dn: ou=company1,c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Norway
|
||||
|
||||
dn: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company1, Some Person
|
||||
telephoneNumber: +46 555-123456
|
||||
|
||||
dn: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person2
|
||||
userPassword: password
|
||||
cn: Some Person2
|
||||
sn: Person2
|
||||
description: Sweden, Company1, Some Person2
|
||||
telephoneNumber: +46 555-654321
|
||||
|
||||
dn: cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person3
|
||||
userPassword: password
|
||||
cn: Some Person3
|
||||
sn: Person3
|
||||
description: Sweden, Company1, Some Person3
|
||||
telephoneNumber: +46 555-123654
|
||||
|
||||
dn: cn=Some Person,ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person4
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company2, Some Person
|
||||
telephoneNumber: +46 555-456321
|
||||
|
||||
dn: cn=Some Person+sn=Person,ou=company1,c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.norwegian
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Norway, Company1, Some Person+Person
|
||||
telephoneNumber: +45 555-654123
|
||||
5
test/integration-tests/src/test/java/teardown_data.ldif
Normal file
5
test/integration-tests/src/test/java/teardown_data.ldif
Normal file
@@ -0,0 +1,5 @@
|
||||
ou=groups,dc=jayway,dc=se
|
||||
|
||||
c=Sweden,dc=jayway,dc=se
|
||||
|
||||
c=Norway,dc=jayway,dc=se
|
||||
16
test/integration-tests/src/test/resources/conf/OrgPerson.hbm.xml
Executable file
16
test/integration-tests/src/test/resources/conf/OrgPerson.hbm.xml
Executable file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping auto-import="true" default-lazy="false">
|
||||
|
||||
<class name="org.springframework.ldap.transaction.compensating.manager.hibernate.OrgPerson" table="PERSON">
|
||||
<id name="id" column="id">
|
||||
<generator class="assigned"/>
|
||||
</id>
|
||||
<property name="fullname" column="fullname"/>
|
||||
<property name="lastname" column="lastname"/>
|
||||
<property name="company" column="company"/>
|
||||
<property name="country" column="country"/>
|
||||
<property name="description" column="description"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
This context automatically starts the Apache Directory Server
|
||||
and sets up the test data
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<!-- Used mainly to enable injecting base into LdapServerManager -->
|
||||
<bean
|
||||
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
|
||||
|
||||
<!-- JNDI environment variable -->
|
||||
<bean id="environment"
|
||||
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<props>
|
||||
<prop key="java.naming.security.authentication">
|
||||
simple
|
||||
</prop>
|
||||
<prop key="java.naming.security.principal">
|
||||
${userDn}
|
||||
</prop>
|
||||
<prop key="java.naming.security.credentials">
|
||||
${password}
|
||||
</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Note the non-standard port, in order to leave 389 unused, thus
|
||||
making it easier for the integration tests requiring OpenLDAP.
|
||||
-->
|
||||
<bean id="configuration" class="org.apache.directory.server.configuration.MutableServerStartupConfiguration">
|
||||
<property name="ldapPort" value="3900" />
|
||||
<property name="contextPartitionConfigurations">
|
||||
<set>
|
||||
<ref bean="jaywayPartitionConfiguration"/>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jaywayPartitionConfiguration"
|
||||
class="org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration">
|
||||
<property name="name" value="jayway" />
|
||||
<property name="suffix" value="dc=jayway,dc=se" />
|
||||
<property name="contextEntry">
|
||||
<value>
|
||||
objectClass: top
|
||||
objectClass: domain
|
||||
objectClass: extensibleObject
|
||||
dc: jayway
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="configEnvHelper" class="org.springframework.ldap.ConfigEnvHelper">
|
||||
<constructor-arg ref="environment" />
|
||||
<constructor-arg ref="configuration" />
|
||||
</bean>
|
||||
|
||||
<bean name="serverContext" class="javax.naming.InitialContext">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
|
||||
<property name="targetObject" ref="configEnvHelper" />
|
||||
<property name="propertyPath" value="env" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean name="ldapServerManager" class="org.springframework.ldap.LdapServerManager">
|
||||
<property name="contextSource" ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<!-- Custom editors required to launch ApacheDS -->
|
||||
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
<map>
|
||||
<entry key="javax.naming.directory.Attributes">
|
||||
<bean class="org.apache.directory.server.core.configuration.AttributesPropertyEditor"/>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.core.support.LdapContextSource">
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="${base}" />
|
||||
<property name="dirObjectFactory"
|
||||
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="contextSource2"
|
||||
class="org.springframework.ldap.core.support.LdapContextSource">
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="cn=john doe, ${base}" />
|
||||
<property name="dirObjectFactory"
|
||||
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="dummyBaseContextAware"
|
||||
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor">
|
||||
<property name="baseLdapPathSourceName" value="contextSource2" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.core.support.LdapContextSource">
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="${base}" />
|
||||
<property name="dirObjectFactory"
|
||||
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="contextSource2"
|
||||
class="org.springframework.ldap.core.support.LdapContextSource">
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="${base}" />
|
||||
<property name="dirObjectFactory"
|
||||
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="dummyBaseContextAware"
|
||||
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="dummyBaseContextAware"
|
||||
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
|
||||
</beans>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.core.support.LdapContextSource">
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="${base}" />
|
||||
<property name="dirObjectFactory"
|
||||
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="dummyBaseContextAware"
|
||||
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor">
|
||||
<property name="basePath" value="cn=john doe"/>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.core.support.LdapContextSource">
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="${base}" />
|
||||
<property name="dirObjectFactory"
|
||||
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="dummyBaseContextAware"
|
||||
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
|
||||
</beans>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.core.support.LdapContextSource">
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="${base}" />
|
||||
<property name="dirObjectFactory"
|
||||
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="contextSourceProxy"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="dummyBaseContextAware"
|
||||
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
|
||||
</beans>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<!--
|
||||
This context configuration file defines common beans,
|
||||
minimizing duplication in the various test context files.
|
||||
-->
|
||||
|
||||
<bean id="placeholderConfig"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:/conf/ldap.properties" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="distinguishedNameConsumer"
|
||||
class="org.springframework.ldap.core.DummyDistinguishedNameConsumer">
|
||||
<property name="distinguishedName" value="dc=jayway, dc=se" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean class="org.springframework.ldap.filter.DummyFilterConsumer">
|
||||
<property name="filter"
|
||||
value="(&(objectclass=person)(!(objectclass=computer))" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,4 @@
|
||||
urls=ldap://127.0.0.1:3900
|
||||
userDn=uid=admin,ou=system
|
||||
password=secret
|
||||
base=dc=jayway,dc=se
|
||||
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
<property name="pooled" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
|
||||
<property name="url" value="jdbc:hsqldb:mem:aname" />
|
||||
<property name="username" value="sa" />
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactedContextSource"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
<value>conf/OrgPerson.hbm.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="hibernateProperties">
|
||||
<value>
|
||||
hibernate.dialect=org.hibernate.dialect.HSQLDialect
|
||||
hibernate.hbm2ddl.auto=create
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean name="dummyDaoTarget"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.hibernate.DummyDaoLdapAndHibernateImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"
|
||||
ref="transactionManager" />
|
||||
<property name="target" ref="dummyDaoTarget" />
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
<property name="pooled" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
|
||||
<property name="url" value="jdbc:hsqldb:mem:aname" />
|
||||
<property name="username" value="sa" />
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactedContextSource"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate"
|
||||
class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean name="dummyDaoTarget"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.LdapAndJdbcDummyDaoImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"
|
||||
ref="transactionManager" />
|
||||
<property name="target" ref="dummyDaoTarget" />
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<bean id="contextSource2" class="org.springframework.ldap.core.support.LdapContextSource" >
|
||||
<property name="urls" value="ldap://127.0.0.1:389,ldap://127.0.0.2:389" />
|
||||
<property name="userDn" value="cn=dummy" />
|
||||
<property name="password" value="dummy" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/conf/commonTestContext.xml" />
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
<property name="authenticationSource">
|
||||
<bean
|
||||
class="org.springframework.ldap.authentication.AcegiAuthenticationSource" />
|
||||
</property>
|
||||
<property name="baseOnTarget" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="initialDirContextFactory"
|
||||
class="org.acegisecurity.ldap.DefaultInitialDirContextFactory">
|
||||
<constructor-arg value="${urls}/${base}" />
|
||||
<property name="managerDn" value="${userDn}" />
|
||||
<property name="managerPassword" value="${password}" />
|
||||
</bean>
|
||||
|
||||
<bean id="userSearch"
|
||||
class="org.acegisecurity.ldap.search.FilterBasedLdapUserSearch">
|
||||
<constructor-arg index="0">
|
||||
<value></value>
|
||||
</constructor-arg>
|
||||
<constructor-arg index="1"
|
||||
value="(&(cn={0})(objectclass=person))" />
|
||||
<constructor-arg index="2" ref="initialDirContextFactory" />
|
||||
<property name="searchSubtree" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapAuthProvider"
|
||||
class="org.acegisecurity.providers.ldap.LdapAuthenticationProvider">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.acegisecurity.providers.ldap.authenticator.BindAuthenticator">
|
||||
<constructor-arg ref="initialDirContextFactory" />
|
||||
<property name="userSearch" ref="userSearch" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator">
|
||||
<constructor-arg ref="initialDirContextFactory" />
|
||||
<constructor-arg value="c=Sweden" />
|
||||
<property name="groupRoleAttribute" value="ou" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
<property name="baseOnTarget" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
|
||||
-->
|
||||
</beans>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
<property name="dirObjectFactory"><null/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml" />
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
|
||||
-->
|
||||
</beans>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/conf/commonTestContext.xml"/>
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
<property name="pooled" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactedContextSource"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
|
||||
<property name="contextSource" ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean name="dummyDaoTarget"
|
||||
class="org.springframework.ldap.transaction.compensating.manager.LdapDummyDaoImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean name="dummyDao"
|
||||
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"
|
||||
ref="transactionManager" />
|
||||
<property name="target" ref="dummyDaoTarget" />
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml" />
|
||||
|
||||
<!-- note that this has no base set, since we want to get at the root entry -->
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
<property name="baseOnTarget" value="false" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml" />
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
</bean>
|
||||
|
||||
<bean id="simpleLdapTemplate"
|
||||
class="org.springframework.ldap.core.simple.SimpleLdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
|
||||
-->
|
||||
</beans>
|
||||
@@ -0,0 +1,9 @@
|
||||
log4j.rootCategory=WARN, stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout.ConversionPattern=%r [%t] %-5p\: %-15c{2} - %m%n
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
|
||||
# Enable info on Spring LDAP
|
||||
#log4j.logger.org.springframework.ldap=INFO
|
||||
|
||||
log4j.logger.org.apache.directory.server.schema.registries.DefaultSyntaxRegistry=WARN
|
||||
110
test/integration-tests/src/test/resources/setup_data.ldif
Normal file
110
test/integration-tests/src/test/resources/setup_data.ldif
Normal file
@@ -0,0 +1,110 @@
|
||||
dn: ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: groups
|
||||
|
||||
dn: cn=ROLE_USER,ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: groupOfUniqueNames
|
||||
cn: ROLE_USER
|
||||
uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person,ou=company1,c=Norway,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person,ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
|
||||
dn: cn=ROLE_ADMIN,ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: groupOfUniqueNames
|
||||
cn: ROLE_ADMIN
|
||||
uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
|
||||
dn: c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Sweden
|
||||
description: The country of Sweden
|
||||
|
||||
dn: c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Norway
|
||||
description: The country of Norway
|
||||
|
||||
dn: ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Sweden
|
||||
|
||||
dn: ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company2
|
||||
description: Second company in Sweden
|
||||
|
||||
dn: ou=company1,c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Norway
|
||||
|
||||
dn: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company1, Some Person
|
||||
telephoneNumber: +46 555-123456
|
||||
|
||||
dn: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person2
|
||||
userPassword: password
|
||||
cn: Some Person2
|
||||
sn: Person2
|
||||
description: Sweden, Company1, Some Person2
|
||||
telephoneNumber: +46 555-654321
|
||||
|
||||
dn: cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person3
|
||||
userPassword: password
|
||||
cn: Some Person3
|
||||
sn: Person3
|
||||
description: Sweden, Company1, Some Person3
|
||||
telephoneNumber: +46 555-123654
|
||||
|
||||
dn: cn=Some Person,ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person4
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company2, Some Person
|
||||
telephoneNumber: +46 555-456321
|
||||
|
||||
dn: cn=Some Person+sn=Person,ou=company1,c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.norwegian
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Norway, Company1, Some Person+Person
|
||||
telephoneNumber: +45 555-654123
|
||||
Reference in New Issue
Block a user