Convert to Linux Line Endings
This commit is contained in:
@@ -1,72 +1,72 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Dummy bean to be used in the LdapTemplate integration tests.
|
||||
*
|
||||
* @author Mattias Hellborg 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Dummy bean to be used in the LdapTemplate integration tests.
|
||||
*
|
||||
* @author Mattias Hellborg 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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 Hellborg 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;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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 Hellborg 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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 Hellborg 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;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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 Hellborg 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core;
|
||||
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
/**
|
||||
* Dummy implementation of a class that has a {@link DistinguishedName} setter,
|
||||
* used for testing purposes.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyDistinguishedNameConsumer {
|
||||
private DistinguishedName distinguishedName;
|
||||
|
||||
public DistinguishedName getDistinguishedName() {
|
||||
return distinguishedName;
|
||||
}
|
||||
|
||||
public void setDistinguishedName(DistinguishedName distinguishedName) {
|
||||
this.distinguishedName = distinguishedName;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core;
|
||||
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
/**
|
||||
* Dummy implementation of a class that has a {@link DistinguishedName} setter,
|
||||
* used for testing purposes.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyDistinguishedNameConsumer {
|
||||
private DistinguishedName distinguishedName;
|
||||
|
||||
public DistinguishedName getDistinguishedName() {
|
||||
return distinguishedName;
|
||||
}
|
||||
|
||||
public void setDistinguishedName(DistinguishedName distinguishedName) {
|
||||
this.distinguishedName = distinguishedName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.support.BaseLdapPathAware;
|
||||
|
||||
/**
|
||||
* Dummy implementation of {@link BaseLdapPathAware}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyBaseLdapPathAware implements BaseLdapPathAware {
|
||||
|
||||
private DistinguishedName base;
|
||||
|
||||
public void setBaseLdapPath(DistinguishedName baseLdapPath) {
|
||||
this.base = baseLdapPath;
|
||||
}
|
||||
|
||||
public DistinguishedName getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.support.BaseLdapPathAware;
|
||||
|
||||
/**
|
||||
* Dummy implementation of {@link BaseLdapPathAware}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyBaseLdapPathAware implements BaseLdapPathAware {
|
||||
|
||||
private DistinguishedName base;
|
||||
|
||||
public void setBaseLdapPath(DistinguishedName baseLdapPath) {
|
||||
this.base = baseLdapPath;
|
||||
}
|
||||
|
||||
public DistinguishedName getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.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);
|
||||
|
||||
void deleteRecursively(String dn);
|
||||
|
||||
void deleteRecursivelyWithException(String dn);
|
||||
|
||||
void createRecursivelyAndUnbindSubnode();
|
||||
|
||||
void createRecursivelyAndUnbindSubnodeWithException();
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.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);
|
||||
|
||||
void deleteRecursively(String dn);
|
||||
|
||||
void deleteRecursivelyWithException(String dn);
|
||||
|
||||
void createRecursivelyAndUnbindSubnode();
|
||||
|
||||
void createRecursivelyAndUnbindSubnodeWithException();
|
||||
}
|
||||
|
||||
@@ -1,22 +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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
public class DummyException extends RuntimeException {
|
||||
public DummyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
public class DummyException extends RuntimeException {
|
||||
public DummyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
public class DummyServiceImpl {
|
||||
private DummyDao dummyDaoImpl;
|
||||
|
||||
public void setDummyDaoImpl(DummyDao dummyDaoImpl) {
|
||||
this.dummyDaoImpl = dummyDaoImpl;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
public class DummyServiceImpl {
|
||||
private DummyDao dummyDaoImpl;
|
||||
|
||||
public void setDummyDaoImpl(DummyDao dummyDaoImpl) {
|
||||
this.dummyDaoImpl = dummyDaoImpl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,187 +1,187 @@
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.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;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
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("ou", 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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursively(String dn) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursivelyWithException(String dn) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnode() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnodeWithException() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.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;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
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("ou", 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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursively(String dn) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursivelyWithException(String dn) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnode() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnodeWithException() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,195 +1,195 @@
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
public class LdapDummyDaoImpl implements DummyDao {
|
||||
private static final boolean RECURSIVE = true;
|
||||
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("ou", 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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* (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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursively(String dn) {
|
||||
ldapTemplate.unbind(dn, RECURSIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursivelyWithException(String dn) {
|
||||
deleteRecursively(dn);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnode() {
|
||||
DirContextAdapter ctx = new DirContextAdapter();
|
||||
ctx.setAttributeValues("objectclass", new String[]{"top", "organizationalUnit"});
|
||||
ctx.setAttributeValue("ou", "dummy");
|
||||
ctx.setAttributeValue("description", "dummy description");
|
||||
|
||||
ldapTemplate.bind("ou=dummy", ctx, null);
|
||||
ldapTemplate.bind("ou=dummy,ou=dummy", ctx, null);
|
||||
ldapTemplate.unbind("ou=dummy,ou=dummy");
|
||||
ldapTemplate.unbind("ou=dummy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnodeWithException() {
|
||||
createRecursivelyAndUnbindSubnode();
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
public class LdapDummyDaoImpl implements DummyDao {
|
||||
private static final boolean RECURSIVE = true;
|
||||
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("ou", 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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* (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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursively(String dn) {
|
||||
ldapTemplate.unbind(dn, RECURSIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecursivelyWithException(String dn) {
|
||||
deleteRecursively(dn);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnode() {
|
||||
DirContextAdapter ctx = new DirContextAdapter();
|
||||
ctx.setAttributeValues("objectclass", new String[]{"top", "organizationalUnit"});
|
||||
ctx.setAttributeValue("ou", "dummy");
|
||||
ctx.setAttributeValue("description", "dummy description");
|
||||
|
||||
ldapTemplate.bind("ou=dummy", ctx, null);
|
||||
ldapTemplate.bind("ou=dummy,ou=dummy", ctx, null);
|
||||
ldapTemplate.unbind("ou=dummy,ou=dummy");
|
||||
ldapTemplate.unbind("ou=dummy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnodeWithException() {
|
||||
createRecursivelyAndUnbindSubnode();
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
package org.springframework.ldap.itest.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.itest.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@Transactional
|
||||
public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements OrgPersonDao {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
public void create(OrgPerson person) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("ou", 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());
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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() + ",ou=" + person.getCountry();
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.ldap.itest.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.itest.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@Transactional
|
||||
public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements OrgPersonDao {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
public void create(OrgPerson person) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("ou", 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());
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
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() + ",ou=" + person.getCountry();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
package org.springframework.ldap.itest.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;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.ldap.itest.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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.springframework.ldap.itest.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);
|
||||
}
|
||||
package org.springframework.ldap.itest.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);
|
||||
}
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ldap.LdapConditionallyFilteredTestRunner;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.LdapTestUtils;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
|
||||
@DirtiesContext
|
||||
@RunWith(LdapConditionallyFilteredTestRunner.class)
|
||||
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
public abstract class AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private final static String DEFAULT_BASE = "dc=261consulting,dc=com";
|
||||
|
||||
@Autowired
|
||||
@Qualifier("contextSource")
|
||||
protected ContextSource contextSource;
|
||||
|
||||
@Value("${base}")
|
||||
protected String base;
|
||||
|
||||
@Before
|
||||
public void cleanAndSetup() throws NamingException, IOException {
|
||||
Resource ldifResource = getLdifFileResource();
|
||||
if(!LdapUtils.newLdapName(base).equals(LdapUtils.newLdapName(DEFAULT_BASE))) {
|
||||
List<String> lines = IOUtils.readLines(ldifResource.getInputStream());
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(sw);
|
||||
for (String line : lines) {
|
||||
writer.println(StringUtils.replace(line, DEFAULT_BASE, base));
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
ldifResource = new ByteArrayResource(sw.toString().getBytes("UTF8"));
|
||||
}
|
||||
|
||||
LdapTestUtils.cleanAndSetup(contextSource, getRoot(), ldifResource);
|
||||
}
|
||||
|
||||
protected Resource getLdifFileResource() {
|
||||
return new ClassPathResource("/setup_data.ldif");
|
||||
}
|
||||
|
||||
protected Name getRoot() {
|
||||
return LdapUtils.emptyLdapName();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ldap.LdapConditionallyFilteredTestRunner;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.LdapTestUtils;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
|
||||
@DirtiesContext
|
||||
@RunWith(LdapConditionallyFilteredTestRunner.class)
|
||||
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
public abstract class AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private final static String DEFAULT_BASE = "dc=261consulting,dc=com";
|
||||
|
||||
@Autowired
|
||||
@Qualifier("contextSource")
|
||||
protected ContextSource contextSource;
|
||||
|
||||
@Value("${base}")
|
||||
protected String base;
|
||||
|
||||
@Before
|
||||
public void cleanAndSetup() throws NamingException, IOException {
|
||||
Resource ldifResource = getLdifFileResource();
|
||||
if(!LdapUtils.newLdapName(base).equals(LdapUtils.newLdapName(DEFAULT_BASE))) {
|
||||
List<String> lines = IOUtils.readLines(ldifResource.getInputStream());
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(sw);
|
||||
for (String line : lines) {
|
||||
writer.println(StringUtils.replace(line, DEFAULT_BASE, base));
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
ldifResource = new ByteArrayResource(sw.toString().getBytes("UTF8"));
|
||||
}
|
||||
|
||||
LdapTestUtils.cleanAndSetup(contextSource, getRoot(), ldifResource);
|
||||
}
|
||||
|
||||
protected Resource getLdifFileResource() {
|
||||
return new ClassPathResource("/setup_data.ldif");
|
||||
}
|
||||
|
||||
protected Name getRoot() {
|
||||
return LdapUtils.emptyLdapName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,110 +1,110 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for verifying that issues LDAP-50 and LDAP-109 are solved.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class InvalidBackslashITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static LdapName DN = LdapUtils.newLdapName("cn=Some\\\\Person6,ou=company1,ou=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,ou=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,ou=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,ou=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
|
||||
@Category(NoAdTest.class)
|
||||
public void testSearchForDnSpoiledByCompositeName() throws InvalidNameException {
|
||||
List result = tested.search("", "(sn=Person6)", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
LdapName dn = (LdapName) ctx.getDn();
|
||||
Rdn rdn = LdapUtils.getRdn(dn, "cn");
|
||||
assertThat(dn.toString()).isEqualTo("cn=Some\\\\Person6,ou=company1,ou=Sweden");
|
||||
assertThat(rdn.getValue()).isEqualTo("Some\\Person6");
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for verifying that issues LDAP-50 and LDAP-109 are solved.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class InvalidBackslashITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static LdapName DN = LdapUtils.newLdapName("cn=Some\\\\Person6,ou=company1,ou=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,ou=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,ou=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,ou=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
|
||||
@Category(NoAdTest.class)
|
||||
public void testSearchForDnSpoiledByCompositeName() throws InvalidNameException {
|
||||
List result = tested.search("", "(sn=Person6)", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
LdapName dn = (LdapName) ctx.getDn();
|
||||
Rdn rdn = LdapUtils.getRdn(dn, "cn");
|
||||
assertThat(dn.toString()).isEqualTo("cn=Some\\\\Person6,ou=company1,ou=Sweden");
|
||||
assertThat(rdn.getValue()).isEqualTo("Some\\Person6");
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the attributes mapper search method.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateIntegrationTest {
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributeMapper() throws Exception {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
List result = tested.search("ou=company1,ou=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
Person person = (Person) result.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)(cn=ROLE_USER))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
|
||||
assertThat(((String[]) result.get(0)).length).isEqualTo(4);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the attributes mapper search method.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateIntegrationTest {
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributeMapper() throws Exception {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
List result = tested.search("ou=company1,ou=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
Person person = (Person) result.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)(cn=ROLE_USER))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
|
||||
assertThat(((String[]) result.get(0)).length).isEqualTo(4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,171 +1,171 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.AuthenticationException;
|
||||
import org.springframework.ldap.core.AuthenticatedLdapEntryContextCallback;
|
||||
import org.springframework.ldap.core.CollectingAuthenticationErrorCallback;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapEntryIdentification;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.LookupAttemptingCallback;
|
||||
import org.springframework.ldap.filter.AndFilter;
|
||||
import org.springframework.ldap.filter.EqualsFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* Tests the authenticate methods of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticate() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
assertThat(tested.authenticate("", filter.toString(), "password")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQuery() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"password");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithInvalidPassword() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
assertThat(tested.authenticate("", filter.toString(), "invalidpassword")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndInvalidPassword() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"invalidpassword");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLookupOperationPerformedOnAuthenticatedContext() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
AuthenticatedLdapEntryContextCallback contextCallback = new AuthenticatedLdapEntryContextCallback() {
|
||||
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
try {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx.lookup(ldapEntryIdentification.getRelativeDn());
|
||||
assertThat(adapter.getStringAttribute("cn")).isEqualTo("Some Person3");
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw new RuntimeException("Failed to lookup " + ldapEntryIdentification.getRelativeDn(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
assertThat(tested.authenticate("", filter.toString(), "password", contextCallback)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapper() {
|
||||
DirContextOperations ctx = tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"password",
|
||||
new LookupAttemptingCallback());
|
||||
|
||||
assertThat(ctx).isNotNull();
|
||||
assertThat(ctx.getStringAttribute("uid")).isEqualTo("some.person3");
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapperAndInvalidPassword() {
|
||||
DirContextOperations ctx = tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"invalidpassword",
|
||||
new LookupAttemptingCallback());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithInvalidPasswordAndCollectedException() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
final CollectingAuthenticationErrorCallback errorCallback = new CollectingAuthenticationErrorCallback();
|
||||
assertThat(tested.authenticate("", filter.toString(), "invalidpassword", errorCallback)).isFalse();
|
||||
final Exception error = errorCallback.getError();
|
||||
assertThat(error).as("collected error should not be null").isNotNull();
|
||||
assertThat(error instanceof AuthenticationException).as("expected org.springframework.ldap.AuthenticationException").isTrue();
|
||||
assertThat(error.getCause() instanceof javax.naming.AuthenticationException).as("expected javax.naming.AuthenticationException").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithFilterThatDoesNotMatchAnything() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(
|
||||
new EqualsFilter("uid", "some.person.that.isnt.there"));
|
||||
assertThat(tested.authenticate("", filter.toString(), "password")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected=IncorrectResultSizeDataAccessException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithFilterThatMatchesSeveralEntries() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", "Some Person"));
|
||||
tested.authenticate("", filter.toString(), "password");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookupAttemptingCallback() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
LookupAttemptingCallback callback = new LookupAttemptingCallback();
|
||||
assertThat(tested.authenticate("", filter.encode(), "password", callback)).isTrue();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.AuthenticationException;
|
||||
import org.springframework.ldap.core.AuthenticatedLdapEntryContextCallback;
|
||||
import org.springframework.ldap.core.CollectingAuthenticationErrorCallback;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapEntryIdentification;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.LookupAttemptingCallback;
|
||||
import org.springframework.ldap.filter.AndFilter;
|
||||
import org.springframework.ldap.filter.EqualsFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* Tests the authenticate methods of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticate() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
assertThat(tested.authenticate("", filter.toString(), "password")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQuery() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"password");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithInvalidPassword() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
assertThat(tested.authenticate("", filter.toString(), "invalidpassword")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndInvalidPassword() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"invalidpassword");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLookupOperationPerformedOnAuthenticatedContext() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
AuthenticatedLdapEntryContextCallback contextCallback = new AuthenticatedLdapEntryContextCallback() {
|
||||
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
try {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx.lookup(ldapEntryIdentification.getRelativeDn());
|
||||
assertThat(adapter.getStringAttribute("cn")).isEqualTo("Some Person3");
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw new RuntimeException("Failed to lookup " + ldapEntryIdentification.getRelativeDn(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
assertThat(tested.authenticate("", filter.toString(), "password", contextCallback)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapper() {
|
||||
DirContextOperations ctx = tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"password",
|
||||
new LookupAttemptingCallback());
|
||||
|
||||
assertThat(ctx).isNotNull();
|
||||
assertThat(ctx.getStringAttribute("uid")).isEqualTo("some.person3");
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapperAndInvalidPassword() {
|
||||
DirContextOperations ctx = tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"invalidpassword",
|
||||
new LookupAttemptingCallback());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithInvalidPasswordAndCollectedException() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
final CollectingAuthenticationErrorCallback errorCallback = new CollectingAuthenticationErrorCallback();
|
||||
assertThat(tested.authenticate("", filter.toString(), "invalidpassword", errorCallback)).isFalse();
|
||||
final Exception error = errorCallback.getError();
|
||||
assertThat(error).as("collected error should not be null").isNotNull();
|
||||
assertThat(error instanceof AuthenticationException).as("expected org.springframework.ldap.AuthenticationException").isTrue();
|
||||
assertThat(error.getCause() instanceof javax.naming.AuthenticationException).as("expected javax.naming.AuthenticationException").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithFilterThatDoesNotMatchAnything() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(
|
||||
new EqualsFilter("uid", "some.person.that.isnt.there"));
|
||||
assertThat(tested.authenticate("", filter.toString(), "password")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected=IncorrectResultSizeDataAccessException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithFilterThatMatchesSeveralEntries() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", "Some Person"));
|
||||
tested.authenticate("", filter.toString(), "password");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookupAttemptingCallback() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
LookupAttemptingCallback callback = new LookupAttemptingCallback();
|
||||
assertThat(tested.authenticate("", filter.encode(), "password", callback)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,170 +1,170 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateBindUnbindITest extends
|
||||
AbstractLdapTemplateIntegrationTest {
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static String DN = "cn=Some Person4,ou=company1,ou=Sweden";
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithAttributes() {
|
||||
Attributes attributes = setupAttributes();
|
||||
tested.bind(DN, null, attributes);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(DN);
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindGroupOfUniqueNamesWithNameValues() {
|
||||
DirContextAdapter ctx = new DirContextAdapter(LdapUtils.newLdapName("cn=TEST,ou=groups"));
|
||||
ctx.addAttributeValue("cn", "TEST");
|
||||
ctx.addAttributeValue("objectclass", "top");
|
||||
ctx.addAttributeValue("objectclass", "groupOfUniqueNames");
|
||||
ctx.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base));
|
||||
tested.bind(ctx);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithAttributesUsingLdapName() {
|
||||
Attributes attributes = setupAttributes();
|
||||
tested.bind(LdapUtils.newLdapName(DN), null, attributes);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(LdapUtils.newLdapName(DN));
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapter() {
|
||||
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 testBindAndUnbindWithDirContextAdapterUsingLdapName() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(LdapUtils.newLdapName(DN), adapter, null);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(LdapUtils.newLdapName(DN));
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(adapter);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(DN);
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndRebindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(adapter);
|
||||
verifyBoundCorrectData();
|
||||
adapter.setAttributeValue("sn", "Person4.Changed");
|
||||
tested.rebind(adapter);
|
||||
verifyReboundCorrectData();
|
||||
tested.unbind(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);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
}
|
||||
|
||||
private void verifyReboundCorrectData() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(DN);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4.Changed");
|
||||
}
|
||||
|
||||
private void verifyCleanup() {
|
||||
try {
|
||||
tested.lookup(DN);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateBindUnbindITest extends
|
||||
AbstractLdapTemplateIntegrationTest {
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static String DN = "cn=Some Person4,ou=company1,ou=Sweden";
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithAttributes() {
|
||||
Attributes attributes = setupAttributes();
|
||||
tested.bind(DN, null, attributes);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(DN);
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindGroupOfUniqueNamesWithNameValues() {
|
||||
DirContextAdapter ctx = new DirContextAdapter(LdapUtils.newLdapName("cn=TEST,ou=groups"));
|
||||
ctx.addAttributeValue("cn", "TEST");
|
||||
ctx.addAttributeValue("objectclass", "top");
|
||||
ctx.addAttributeValue("objectclass", "groupOfUniqueNames");
|
||||
ctx.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base));
|
||||
tested.bind(ctx);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithAttributesUsingLdapName() {
|
||||
Attributes attributes = setupAttributes();
|
||||
tested.bind(LdapUtils.newLdapName(DN), null, attributes);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(LdapUtils.newLdapName(DN));
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapter() {
|
||||
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 testBindAndUnbindWithDirContextAdapterUsingLdapName() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(LdapUtils.newLdapName(DN), adapter, null);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(LdapUtils.newLdapName(DN));
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(adapter);
|
||||
verifyBoundCorrectData();
|
||||
tested.unbind(DN);
|
||||
verifyCleanup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindAndRebindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
tested.bind(adapter);
|
||||
verifyBoundCorrectData();
|
||||
adapter.setAttributeValue("sn", "Person4.Changed");
|
||||
tested.rebind(adapter);
|
||||
verifyReboundCorrectData();
|
||||
tested.unbind(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);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
}
|
||||
|
||||
private void verifyReboundCorrectData() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(DN);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4.Changed");
|
||||
}
|
||||
|
||||
private void verifyCleanup() {
|
||||
try {
|
||||
tested.lookup(DN);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's context executor methods.
|
||||
*
|
||||
* @author Mattias Hellborg 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,ou=Sweden");
|
||||
}
|
||||
};
|
||||
|
||||
Object object = tested.executeReadOnly(executor);
|
||||
assertThat(object instanceof DirContextAdapter).as("Should be a DirContextAdapter").isTrue();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's context executor methods.
|
||||
*
|
||||
* @author Mattias Hellborg 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,ou=Sweden");
|
||||
}
|
||||
};
|
||||
|
||||
Object object = tested.executeReadOnly(executor);
|
||||
assertThat(object instanceof DirContextAdapter).as("Should be a DirContextAdapter").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the ContextMapper search method. In its way this method also
|
||||
* demonstrates the use of DirContextAdapter and the DirObjectFactory.
|
||||
*
|
||||
* @author Mattias Hellborg 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,ou=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
Person person = (Person) result.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)(cn=ROLE_USER))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(((String[]) result.get(0)).length).isEqualTo(4);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the ContextMapper search method. In its way this method also
|
||||
* demonstrates the use of DirContextAdapter and the DirObjectFactory.
|
||||
*
|
||||
* @author Mattias Hellborg 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,ou=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
Person person = (Person) result.get(0);
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)(cn=ROLE_USER))", mapper);
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(((String[]) result.get(0)).length).isEqualTo(4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,160 +1,160 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.ldap.LdapName;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 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 LdapName BASE_NAME = LdapUtils.newLdapName(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,ou=Sweden" + BASE_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
LdapName dn = LdapUtils.newLdapName("ou=company2,ou=Sweden");
|
||||
List list = tested.listBindings(dn, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_ContextMapper_MapToPersons() {
|
||||
LdapName dn = LdapUtils.newLdapName("ou=company1,ou=Sweden");
|
||||
List list = tested.listBindings(dn, new PersonContextMapper());
|
||||
assertThat(list).hasSize(3);
|
||||
String personClass = "org.springframework.ldap.itest.Person";
|
||||
assertThat(list.get(0).getClass().getName()).isEqualTo(personClass);
|
||||
assertThat(list.get(1).getClass().getName()).isEqualTo(personClass);
|
||||
assertThat(list.get(2).getClass().getName()).isEqualTo(personClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList() {
|
||||
List<String> list = tested.list(BASE_STRING);
|
||||
assertThat(list).hasSize(3);
|
||||
verifyBindings(list);
|
||||
}
|
||||
|
||||
private void verifyBindings(List<String> list) {
|
||||
LinkedList<LdapName> transformed = new LinkedList<LdapName>();
|
||||
|
||||
for (String s : list) {
|
||||
transformed.add(LdapUtils.newLdapName(s));
|
||||
}
|
||||
|
||||
assertThat(transformed.contains(LdapUtils.newLdapName("ou=groups"))).isTrue();
|
||||
assertThat(transformed.contains(LdapUtils.newLdapName("ou=Norway"))).isTrue();
|
||||
assertThat(transformed.contains(LdapUtils.newLdapName("ou=Sweden"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Name() {
|
||||
List<String> list = tested.list(BASE_NAME);
|
||||
assertThat(list).hasSize(3);
|
||||
verifyBindings(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.list(BASE_STRING, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Name_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.list(BASE_NAME, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings() {
|
||||
List<String> list = tested.listBindings(BASE_STRING);
|
||||
assertThat(list).hasSize(3);
|
||||
verifyBindings(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Name() {
|
||||
List list = tested.listBindings(BASE_NAME);
|
||||
assertThat(list).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.listBindings(BASE_STRING, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Name_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.listBindings(BASE_NAME, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.ldap.LdapName;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 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 LdapName BASE_NAME = LdapUtils.newLdapName(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,ou=Sweden" + BASE_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
LdapName dn = LdapUtils.newLdapName("ou=company2,ou=Sweden");
|
||||
List list = tested.listBindings(dn, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_ContextMapper_MapToPersons() {
|
||||
LdapName dn = LdapUtils.newLdapName("ou=company1,ou=Sweden");
|
||||
List list = tested.listBindings(dn, new PersonContextMapper());
|
||||
assertThat(list).hasSize(3);
|
||||
String personClass = "org.springframework.ldap.itest.Person";
|
||||
assertThat(list.get(0).getClass().getName()).isEqualTo(personClass);
|
||||
assertThat(list.get(1).getClass().getName()).isEqualTo(personClass);
|
||||
assertThat(list.get(2).getClass().getName()).isEqualTo(personClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList() {
|
||||
List<String> list = tested.list(BASE_STRING);
|
||||
assertThat(list).hasSize(3);
|
||||
verifyBindings(list);
|
||||
}
|
||||
|
||||
private void verifyBindings(List<String> list) {
|
||||
LinkedList<LdapName> transformed = new LinkedList<LdapName>();
|
||||
|
||||
for (String s : list) {
|
||||
transformed.add(LdapUtils.newLdapName(s));
|
||||
}
|
||||
|
||||
assertThat(transformed.contains(LdapUtils.newLdapName("ou=groups"))).isTrue();
|
||||
assertThat(transformed.contains(LdapUtils.newLdapName("ou=Norway"))).isTrue();
|
||||
assertThat(transformed.contains(LdapUtils.newLdapName("ou=Sweden"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Name() {
|
||||
List<String> list = tested.list(BASE_NAME);
|
||||
assertThat(list).hasSize(3);
|
||||
verifyBindings(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.list(BASE_STRING, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList_Name_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.list(BASE_NAME, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings() {
|
||||
List<String> list = tested.listBindings(BASE_STRING);
|
||||
assertThat(list).hasSize(3);
|
||||
verifyBindings(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Name() {
|
||||
List list = tested.listBindings(BASE_NAME);
|
||||
assertThat(list).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.listBindings(BASE_STRING, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListBindings_Name_Handler() throws Exception {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
tested.listBindings(BASE_NAME, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,186 +1,186 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg 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,ou=Sweden");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookupContextRoot() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("");
|
||||
|
||||
assertThat(result.getDn().toString()).isEqualTo("");
|
||||
assertThat(result.getNameInNamespace()).isEqualTo(base);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_AttributesMapper() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_AttributesMapper_LdapName() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"), mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributesMapper} that only maps a subset of the full
|
||||
* attributes list. Used in tests where the return attributes list has been
|
||||
* limited.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
private final class SubsetPersonAttributesMapper implements AttributesMapper {
|
||||
/**
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object. Also
|
||||
* verifies that the other attributes haven't been set.
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullname((String) attributes.get("cn").get());
|
||||
assertThat(attributes.get("sn")).as("sn should be null").isNull();
|
||||
assertThat(attributes.get("description")).as("description should be null").isNull();
|
||||
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,ou=Sweden", new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes. Uses LdapName instead
|
||||
* of plain string as name.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_AttributesMapper_LdapName() {
|
||||
AttributesMapper mapper = new SubsetPersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"),
|
||||
new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_GetNameInNamespace_Plain() {
|
||||
String expectedDn = "cn=Some Person2, ou=company1,ou=Sweden";
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn);
|
||||
|
||||
LdapName expectedName = LdapUtils.newLdapName(expectedDn);
|
||||
assertThat(result.getDn()).isEqualTo(expectedName);
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
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.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg 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,ou=Sweden");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookupContextRoot() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("");
|
||||
|
||||
assertThat(result.getDn().toString()).isEqualTo("");
|
||||
assertThat(result.getNameInNamespace()).isEqualTo(base);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_AttributesMapper() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_AttributesMapper_LdapName() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"), mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributesMapper} that only maps a subset of the full
|
||||
* attributes list. Used in tests where the return attributes list has been
|
||||
* limited.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
private final class SubsetPersonAttributesMapper implements AttributesMapper {
|
||||
/**
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object. Also
|
||||
* verifies that the other attributes haven't been set.
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullname((String) attributes.get("cn").get());
|
||||
assertThat(attributes.get("sn")).as("sn should be null").isNull();
|
||||
assertThat(attributes.get("description")).as("description should be null").isNull();
|
||||
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,ou=Sweden", new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes. Uses LdapName instead
|
||||
* of plain string as name.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_AttributesMapper_LdapName() {
|
||||
AttributesMapper mapper = new SubsetPersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"),
|
||||
new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_ContextMapper() {
|
||||
ContextMapper mapper = new PersonContextMapper();
|
||||
|
||||
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
assertThat(person.getDescription()).as("description should not be set").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup_GetNameInNamespace_Plain() {
|
||||
String expectedDn = "cn=Some Person2, ou=company1,ou=Sweden";
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn);
|
||||
|
||||
LdapName expectedName = LdapUtils.newLdapName(expectedDn);
|
||||
assertThat(result.getDn()).isEqualTo(expectedName);
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
protected Resource getLdifFileResource() {
|
||||
return new ClassPathResource("/setup_data_multi_rdn.ldif");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookup_MultiValuedRdn() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getLastname()).isEqualTo("Person");
|
||||
assertThat(person.getDescription()).isEqualTo("Norway, Company1, Some Person+Person");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookup_MultiValuedRdn_DirContextAdapter() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Norway, Company1, Some Person+Person");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookup_GetNameInNamespace_MultiRdn() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person,ou=company1,ou=Norway");
|
||||
|
||||
assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway");
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
protected Resource getLdifFileResource() {
|
||||
return new ClassPathResource("/setup_data_multi_rdn.ldif");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookup_MultiValuedRdn() {
|
||||
AttributesMapper mapper = new PersonAttributesMapper();
|
||||
Person person = (Person) tested.lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway", mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person");
|
||||
assertThat(person.getLastname()).isEqualTo("Person");
|
||||
assertThat(person.getDescription()).isEqualTo("Norway, Company1, Some Person+Person");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookup_MultiValuedRdn_DirContextAdapter() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway");
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Norway, Company1, Some Person+Person");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testLookup_GetNameInNamespace_MultiRdn() {
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person,ou=company1,ou=Norway");
|
||||
|
||||
assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway");
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,284 +1,284 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.AttributeInUseException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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 Hellborg 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,ou=Sweden";
|
||||
|
||||
private static String PERSON5_DN = "cn=Some Person5,ou=company1,ou=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_LdapName() {
|
||||
Attributes attributes = setupAttributes();
|
||||
|
||||
tested.rebind(LdapUtils.newLdapName(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);
|
||||
List<String> attributes = Arrays.asList(result.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(2);
|
||||
assertThat(attributes.contains("Some other description")).isTrue();
|
||||
assertThat(attributes.contains("Another description")).isTrue();
|
||||
}
|
||||
|
||||
@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);
|
||||
List<String> attributes = Arrays.asList(result.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(3);
|
||||
assertThat(attributes.contains("Some other description")).isTrue();
|
||||
assertThat(attributes.contains("Another description")).isTrue();
|
||||
assertThat(attributes.contains("Some description")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_AddAttributeValueWithExistingValue() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.addAttributeValue("uniqueMember", "cn=Some Person,ou=company1,ou=Norway," + base);
|
||||
tested.modifyAttributes(ctx);
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
@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);
|
||||
List<String> attributes = Arrays.asList(result.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(3);
|
||||
assertThat(attributes.contains("Some other description")).isTrue();
|
||||
assertThat(attributes.contains("Another description")).isTrue();
|
||||
assertThat(attributes.contains("Some description")).isTrue();
|
||||
}
|
||||
|
||||
@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_LdapName() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
|
||||
tested.modifyAttributes(LdapUtils.newLdapName(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);
|
||||
List<String> attributes = Arrays.asList(adapter.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(4);
|
||||
assertThat(attributes.contains("qwe")).isTrue();
|
||||
assertThat(attributes.contains("123")).isTrue();
|
||||
assertThat(attributes.contains("klytt")).isTrue();
|
||||
assertThat(attributes.contains("kalle")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyCompleteReplacementOfUniqueMemberAttribute_Ldap119Workaround() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.setAttributeValues("uniqueMember",
|
||||
new String[]{"cn=Some Person,ou=company1,ou=Norway," + base},
|
||||
true);
|
||||
ctx.getModificationItems();
|
||||
|
||||
tested.modifyAttributes(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test originally failed on ApacheDS complaining that the uniqueMember attribute
|
||||
* was emptied.
|
||||
*/
|
||||
@Test
|
||||
public void verifyCompleteReplacementOfUniqueMemberAttribute_Ldap119() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.setAttributeValues("uniqueMember",
|
||||
new String[]{"cn=Some Person,ou=company1,ou=Norway," + base});
|
||||
ctx.getModificationItems();
|
||||
|
||||
tested.modifyAttributes(ctx);
|
||||
}
|
||||
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);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some other description");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.AttributeInUseException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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 Hellborg 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,ou=Sweden";
|
||||
|
||||
private static String PERSON5_DN = "cn=Some Person5,ou=company1,ou=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_LdapName() {
|
||||
Attributes attributes = setupAttributes();
|
||||
|
||||
tested.rebind(LdapUtils.newLdapName(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);
|
||||
List<String> attributes = Arrays.asList(result.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(2);
|
||||
assertThat(attributes.contains("Some other description")).isTrue();
|
||||
assertThat(attributes.contains("Another description")).isTrue();
|
||||
}
|
||||
|
||||
@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);
|
||||
List<String> attributes = Arrays.asList(result.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(3);
|
||||
assertThat(attributes.contains("Some other description")).isTrue();
|
||||
assertThat(attributes.contains("Another description")).isTrue();
|
||||
assertThat(attributes.contains("Some description")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_AddAttributeValueWithExistingValue() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.addAttributeValue("uniqueMember", "cn=Some Person,ou=company1,ou=Norway," + base);
|
||||
tested.modifyAttributes(ctx);
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
@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);
|
||||
List<String> attributes = Arrays.asList(result.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(3);
|
||||
assertThat(attributes.contains("Some other description")).isTrue();
|
||||
assertThat(attributes.contains("Another description")).isTrue();
|
||||
assertThat(attributes.contains("Some description")).isTrue();
|
||||
}
|
||||
|
||||
@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_LdapName() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
|
||||
tested.modifyAttributes(LdapUtils.newLdapName(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);
|
||||
List<String> attributes = Arrays.asList(adapter.getStringAttributes("description"));
|
||||
assertThat(attributes).hasSize(4);
|
||||
assertThat(attributes.contains("qwe")).isTrue();
|
||||
assertThat(attributes.contains("123")).isTrue();
|
||||
assertThat(attributes.contains("klytt")).isTrue();
|
||||
assertThat(attributes.contains("kalle")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyCompleteReplacementOfUniqueMemberAttribute_Ldap119Workaround() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.setAttributeValues("uniqueMember",
|
||||
new String[]{"cn=Some Person,ou=company1,ou=Norway," + base},
|
||||
true);
|
||||
ctx.getModificationItems();
|
||||
|
||||
tested.modifyAttributes(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test originally failed on ApacheDS complaining that the uniqueMember attribute
|
||||
* was emptied.
|
||||
*/
|
||||
@Test
|
||||
public void verifyCompleteReplacementOfUniqueMemberAttribute_Ldap119() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.setAttributeValues("uniqueMember",
|
||||
new String[]{"cn=Some Person,ou=company1,ou=Norway," + base});
|
||||
ctx.getModificationItems();
|
||||
|
||||
tested.modifyAttributes(ctx);
|
||||
}
|
||||
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);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some other description");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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 Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateNoBaseSuffixTestContext.xml"})
|
||||
public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Override
|
||||
protected Name getRoot() {
|
||||
return LdapUtils.newLdapName(base);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_Plain() {
|
||||
String expectedDn = "cn=Some Person2, ou=company1, ou=Sweden," + base;
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn);
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2");
|
||||
|
||||
LdapName expectedName = LdapUtils.newLdapName(expectedDn);
|
||||
assertThat(result.getDn()).isEqualTo(expectedName);
|
||||
assertThat(result.getNameInNamespace()).isEqualTo(expectedDn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_Plain() {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
|
||||
tested.search(base, "(objectclass=person)", handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@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, ou=Sweden," + base, adapter, null);
|
||||
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
assertThat(result.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person4,ou=company1,ou=Sweden," + base));
|
||||
|
||||
tested.unbind("cn=Some Person4,ou=company1,ou=Sweden," + base);
|
||||
try {
|
||||
tested.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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 Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateNoBaseSuffixTestContext.xml"})
|
||||
public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Override
|
||||
protected Name getRoot() {
|
||||
return LdapUtils.newLdapName(base);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_Plain() {
|
||||
String expectedDn = "cn=Some Person2, ou=company1, ou=Sweden," + base;
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn);
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2");
|
||||
|
||||
LdapName expectedName = LdapUtils.newLdapName(expectedDn);
|
||||
assertThat(result.getDn()).isEqualTo(expectedName);
|
||||
assertThat(result.getNameInNamespace()).isEqualTo(expectedDn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_Plain() {
|
||||
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
|
||||
|
||||
tested.search(base, "(objectclass=person)", handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@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, ou=Sweden," + base, adapter, null);
|
||||
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
assertThat(result.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person4,ou=company1,ou=Sweden," + base));
|
||||
|
||||
tested.unbind("cn=Some Person4,ou=company1,ou=Sweden," + base);
|
||||
try {
|
||||
tested.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.LdapTestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* This test only works against in-process Apache DS server, regardless of configured profile.
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplatePooledTestContext.xml"})
|
||||
public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Autowired
|
||||
private ContextSource contextSource;
|
||||
|
||||
@Value("${base}")
|
||||
protected String base;
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
LdapTestUtils.shutdownEmbeddedServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void verifyThatInvalidConnectionIsAutomaticallyPurged() throws Exception {
|
||||
LdapTestUtils.startEmbeddedServer(1888, "dc=261consulting,dc=com", "jayway");
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
|
||||
|
||||
DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2");
|
||||
|
||||
// Shutdown server and kill all existing connections
|
||||
LdapTestUtils.shutdownEmbeddedServer();
|
||||
LdapTestUtils.startEmbeddedServer(1888, "dc=261consulting,dc=com", "jayway");
|
||||
|
||||
try {
|
||||
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
fail("Exception expected");
|
||||
} catch (Exception expected) {
|
||||
// This should fail because the target connection was closed
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
|
||||
// But this should be OK, because the dirty connection should have been automatically purged.
|
||||
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.LdapTestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* This test only works against in-process Apache DS server, regardless of configured profile.
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplatePooledTestContext.xml"})
|
||||
public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Autowired
|
||||
private ContextSource contextSource;
|
||||
|
||||
@Value("${base}")
|
||||
protected String base;
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
LdapTestUtils.shutdownEmbeddedServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void verifyThatInvalidConnectionIsAutomaticallyPurged() throws Exception {
|
||||
LdapTestUtils.startEmbeddedServer(1888, "dc=261consulting,dc=com", "jayway");
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
|
||||
|
||||
DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2");
|
||||
|
||||
// Shutdown server and kill all existing connections
|
||||
LdapTestUtils.shutdownEmbeddedServer();
|
||||
LdapTestUtils.startEmbeddedServer(1888, "dc=261consulting,dc=com", "jayway");
|
||||
|
||||
try {
|
||||
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
fail("Exception expected");
|
||||
} catch (Exception expected) {
|
||||
// This should fail because the target connection was closed
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
|
||||
// But this should be OK, because the dirty connection should have been automatically purged.
|
||||
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +1,132 @@
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests the recursive modification methods (unbind and the protected delete
|
||||
* methods) of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static LdapName DN = LdapUtils.newLdapName("cn=Some Person5,ou=company1,ou=Sweden");
|
||||
|
||||
private LdapName firstSubDn;
|
||||
|
||||
private LdapName secondSubDn;
|
||||
|
||||
private LdapName 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 = LdapUtils.newLdapName("cn=subPerson");
|
||||
firstSubDn = LdapUtils.prepend(firstSubDn, 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 = LdapUtils.newLdapName("cn=subPerson2");
|
||||
secondSubDn = LdapUtils.prepend(secondSubDn, 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 = LdapUtils.newLdapName("cn=subSubPerson");
|
||||
leafDn = LdapUtils.prepend(leafDn, DN);
|
||||
|
||||
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
|
||||
@Category(NoAdTest.class)
|
||||
public void testRecursiveUnbind() {
|
||||
tested.unbind(DN, true);
|
||||
|
||||
verifyDeleted(DN);
|
||||
verifyDeleted(firstSubDn);
|
||||
verifyDeleted(secondSubDn);
|
||||
verifyDeleted(leafDn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests the recursive modification methods (unbind and the protected delete
|
||||
* methods) of LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
private static LdapName DN = LdapUtils.newLdapName("cn=Some Person5,ou=company1,ou=Sweden");
|
||||
|
||||
private LdapName firstSubDn;
|
||||
|
||||
private LdapName secondSubDn;
|
||||
|
||||
private LdapName 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 = LdapUtils.newLdapName("cn=subPerson");
|
||||
firstSubDn = LdapUtils.prepend(firstSubDn, 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 = LdapUtils.newLdapName("cn=subPerson2");
|
||||
secondSubDn = LdapUtils.prepend(secondSubDn, 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 = LdapUtils.newLdapName("cn=subSubPerson");
|
||||
leafDn = LdapUtils.prepend(leafDn, DN);
|
||||
|
||||
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
|
||||
@Category(NoAdTest.class)
|
||||
public void testRecursiveUnbind() {
|
||||
tested.unbind(DN, true);
|
||||
|
||||
verifyDeleted(DN);
|
||||
verifyDeleted(firstSubDn);
|
||||
verifyDeleted(secondSubDn);
|
||||
verifyDeleted(leafDn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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,ou=Sweden";
|
||||
|
||||
private static String NEWDN = "cn=Some Person6,ou=company2,ou=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(LdapUtils.newLdapName(DN));
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRename_LdapName() throws Exception {
|
||||
Name oldDn = LdapUtils.newLdapName(DN);
|
||||
Name newDn = LdapUtils.newLdapName(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);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person6");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person6");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some description");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* 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,ou=Sweden";
|
||||
|
||||
private static String NEWDN = "cn=Some Person6,ou=company2,ou=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(LdapUtils.newLdapName(DN));
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRename_LdapName() throws Exception {
|
||||
Name oldDn = LdapUtils.newLdapName(DN);
|
||||
Name newDn = LdapUtils.newLdapName(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);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person6");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person6");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some description");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,422 +1,422 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.SizeLimitExceededException;
|
||||
import org.springframework.ldap.core.ContextMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.query.SearchScope;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* 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 Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
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 = LdapUtils.newLdapName(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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope_CorrectBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_NoBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_DifferentBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForObject() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.searchForObject(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = IncorrectResultSizeDataAccessException.class)
|
||||
public void testSearchForObjectWithMultipleHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=*))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForObjectNoHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery() {
|
||||
DirContextOperations result = tested.searchForContext(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() {
|
||||
DirContextOperations result =
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyThatSearchWithCountLimitReturnsTheEntriesFoundSoFar() {
|
||||
List<Object> result = tested.search(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person"), new ContextMapper<Object>() {
|
||||
@Override
|
||||
public Object mapFromContext(Object ctx) throws NamingException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(result).hasSize(3);
|
||||
}
|
||||
|
||||
@Test(expected = SizeLimitExceededException.class)
|
||||
public void verifyThatSearchWithCountLimitWithFlagToFalseThrowsException() {
|
||||
tested.setIgnoreSizeLimitExceededException(false);
|
||||
tested.search(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person"), new ContextMapper<Object>() {
|
||||
@Override
|
||||
public Object mapFromContext(Object ctx) throws NamingException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.SizeLimitExceededException;
|
||||
import org.springframework.ldap.core.ContextMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.query.SearchScope;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* 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 Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
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 = LdapUtils.newLdapName(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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope_CorrectBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_NoBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_DifferentBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForObject() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.searchForObject(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = IncorrectResultSizeDataAccessException.class)
|
||||
public void testSearchForObjectWithMultipleHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=*))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForObjectNoHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery() {
|
||||
DirContextOperations result = tested.searchForContext(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() {
|
||||
DirContextOperations result =
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyThatSearchWithCountLimitReturnsTheEntriesFoundSoFar() {
|
||||
List<Object> result = tested.search(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person"), new ContextMapper<Object>() {
|
||||
@Override
|
||||
public Object mapFromContext(Object ctx) throws NamingException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(result).hasSize(3);
|
||||
}
|
||||
|
||||
@Test(expected = SizeLimitExceededException.class)
|
||||
public void verifyThatSearchWithCountLimitWithFlagToFalseThrowsException() {
|
||||
tested.setIgnoreSizeLimitExceededException(false);
|
||||
tested.search(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person"), new ContextMapper<Object>() {
|
||||
@Override
|
||||
public Object mapFromContext(Object ctx) throws NamingException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,392 +1,392 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.query.SearchScope;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* 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 Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTestContext.xml"})
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class LdapTemplateSearchResultNamespaceConfigITest 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 = LdapUtils.newLdapName(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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope_CorrectBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_NoBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_DifferentBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForObject() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.searchForObject(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = IncorrectResultSizeDataAccessException.class)
|
||||
public void testSearchForObjectWithMultipleHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=*))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForObjectNoHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery() {
|
||||
DirContextOperations result = tested.searchForContext(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() {
|
||||
DirContextOperations result =
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.query.SearchScope;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
|
||||
import org.springframework.ldap.test.AttributeCheckContextMapper;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* 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 Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTestContext.xml"})
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class LdapTemplateSearchResultNamespaceConfigITest 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 = LdapUtils.newLdapName(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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_SearchScope_CorrectBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_NoBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_DifferentBase() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForObject() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.searchForObject(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = IncorrectResultSizeDataAccessException.class)
|
||||
public void testSearchForObjectWithMultipleHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=*))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForObjectNoHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery() {
|
||||
DirContextOperations result = tested.searchForContext(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() {
|
||||
DirContextOperations result =
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@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) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.control;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
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.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.NoAdTest;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 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 Name getRoot() {
|
||||
return LdapUtils.newLdapName(base);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
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));
|
||||
|
||||
HashSet<String> controlsSet = new HashSet<String>(Arrays.asList(controls));
|
||||
|
||||
assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Entry Change Notification LDAPv3 control,").isTrue();
|
||||
assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Subentries Control,").isTrue();
|
||||
assertThat(controlsSet.contains("2.16.840.1.113730.3.4.2")).as("Manage DSA IT LDAPv3 control,").isTrue();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.control;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
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.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.NoAdTest;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 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 Name getRoot() {
|
||||
return LdapUtils.newLdapName(base);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
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));
|
||||
|
||||
HashSet<String> controlsSet = new HashSet<String>(Arrays.asList(controls));
|
||||
|
||||
assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Entry Change Notification LDAPv3 control,").isTrue();
|
||||
assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Subentries Control,").isTrue();
|
||||
assertThat(controlsSet.contains("2.16.840.1.113730.3.4.2")).as("Manage DSA IT LDAPv3 control,").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.DistinguishedNameEditor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/distinguishedNameEditorTestContext.xml"})
|
||||
public class DistinguishedNameEditorITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private DummyDistinguishedNameConsumer distinguishedNameConsumer;
|
||||
|
||||
@Test
|
||||
public void testDistinguishedNameEditor() throws Exception {
|
||||
assertThat(distinguishedNameConsumer).isNotNull();
|
||||
DistinguishedName name = distinguishedNameConsumer.getDistinguishedName();
|
||||
assertThat(name).isEqualTo(new DistinguishedName("dc=jayway, dc=se"));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.DistinguishedNameEditor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/distinguishedNameEditorTestContext.xml"})
|
||||
public class DistinguishedNameEditorITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private DummyDistinguishedNameConsumer distinguishedNameConsumer;
|
||||
|
||||
@Test
|
||||
public void testDistinguishedNameEditor() throws Exception {
|
||||
assertThat(distinguishedNameConsumer).isNotNull();
|
||||
DistinguishedName name = distinguishedNameConsumer.getDistinguishedName();
|
||||
assertThat(name).isEqualTo(new DistinguishedName("dc=jayway, dc=se"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Performance test for the {@link DistinguishedName} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class DnParsePerformanceITest {
|
||||
|
||||
@Test
|
||||
public void testCreateFromString() {
|
||||
StopWatch stopWatch = new StopWatch("Create from String");
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFromDistinguishedName() {
|
||||
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 stopWatch = new StopWatch("Create from DistinguishedName");
|
||||
stopWatch.start();
|
||||
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
migpath = new DistinguishedName(migpath);
|
||||
path1 = new DistinguishedName(path1);
|
||||
path2 = new DistinguishedName(path2);
|
||||
path3 = new DistinguishedName(path3);
|
||||
path4 = new DistinguishedName(path4);
|
||||
|
||||
pathE1 = new DistinguishedName(pathE1);
|
||||
pathE2 = new DistinguishedName(pathE2);
|
||||
}
|
||||
|
||||
stopWatch.stop();
|
||||
System.out.println(stopWatch.prettyPrint());
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Performance test for the {@link DistinguishedName} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class DnParsePerformanceITest {
|
||||
|
||||
@Test
|
||||
public void testCreateFromString() {
|
||||
StopWatch stopWatch = new StopWatch("Create from String");
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFromDistinguishedName() {
|
||||
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 stopWatch = new StopWatch("Create from DistinguishedName");
|
||||
stopWatch.start();
|
||||
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
migpath = new DistinguishedName(migpath);
|
||||
path1 = new DistinguishedName(path1);
|
||||
path2 = new DistinguishedName(path2);
|
||||
path3 = new DistinguishedName(path3);
|
||||
path4 = new DistinguishedName(path4);
|
||||
|
||||
pathE1 = new DistinguishedName(pathE1);
|
||||
pathE2 = new DistinguishedName(pathE2);
|
||||
}
|
||||
|
||||
stopWatch.stop();
|
||||
System.out.println(stopWatch.prettyPrint());
|
||||
}
|
||||
}
|
||||
@@ -1,106 +1,106 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
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;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BaseLdapPathBeanPostprocessorITest {
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitialization() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class);
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=261consulting,dc=com"));
|
||||
|
||||
DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class);
|
||||
assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=261consulting,dc=com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationMultipleContextSources() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorMultiContextSourceTestContext.xml");
|
||||
fail("BeanCreationException expected");
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
Throwable cause = expected.getCause();
|
||||
assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationMultipleContextSourcesOneSpecified() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorMultiContextSourceOneSpecTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("cn=john doe,dc=261consulting,dc=com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationNoContextSource() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorNoContextSourceTestContext.xml");
|
||||
fail("BeanCreationException expected");
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
Throwable cause = expected.getCause();
|
||||
assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationBaseSetInProperty() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorPropertyOverrideTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("cn=john doe"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationTransactionProxy() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorTransactionTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=261consulting,dc=com"));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
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;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BaseLdapPathBeanPostprocessorITest {
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitialization() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class);
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=261consulting,dc=com"));
|
||||
|
||||
DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class);
|
||||
assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=261consulting,dc=com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationMultipleContextSources() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorMultiContextSourceTestContext.xml");
|
||||
fail("BeanCreationException expected");
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
Throwable cause = expected.getCause();
|
||||
assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationMultipleContextSourcesOneSpecified() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorMultiContextSourceOneSpecTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("cn=john doe,dc=261consulting,dc=com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationNoContextSource() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorNoContextSourceTestContext.xml");
|
||||
fail("BeanCreationException expected");
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
Throwable cause = expected.getCause();
|
||||
assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationBaseSetInProperty() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorPropertyOverrideTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("cn=john doe"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationTransactionProxy() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorTransactionTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=261consulting,dc=com"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BaseLdapPathBeanPostprocessorNamespaceConfigITest {
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationWithNamespaceConfig() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorNamespaceTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class);
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=jayway,dc=se"));
|
||||
|
||||
DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class);
|
||||
assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=jayway,dc=se"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationWithNamespaceConfigAndPooling() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorPoolingNamespaceTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class);
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=jayway,dc=se"));
|
||||
|
||||
DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class);
|
||||
assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=jayway,dc=se"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BaseLdapPathBeanPostprocessorNamespaceConfigITest {
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationWithNamespaceConfig() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorNamespaceTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class);
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=jayway,dc=se"));
|
||||
|
||||
DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class);
|
||||
assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=jayway,dc=se"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessBeforeInitializationWithNamespaceConfigAndPooling() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/conf/baseLdapPathPostProcessorPoolingNamespaceTestContext.xml");
|
||||
DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class);
|
||||
|
||||
DistinguishedName base = tested.getBase();
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=jayway,dc=se"));
|
||||
|
||||
DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class);
|
||||
assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=jayway,dc=se"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,168 +1,168 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.core.support.LdapContextSource;
|
||||
import org.springframework.ldap.filter.EqualsFilter;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.NoAdTest;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for LdapContextSource.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("contextSource")
|
||||
private ContextSource tested;
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@Test
|
||||
public void testGetReadOnlyContext() throws NamingException {
|
||||
DirContext ctx = null;
|
||||
|
||||
try {
|
||||
ctx = tested.getReadOnlyContext();
|
||||
assertThat(ctx).isNotNull();
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse();
|
||||
assertThat(environment.containsKey(Context.SECURITY_PRINCIPAL)).isTrue();
|
||||
assertThat(environment.containsKey(Context.SECURITY_CREDENTIALS)).isTrue();
|
||||
}
|
||||
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();
|
||||
assertThat(ctx).isNotNull();
|
||||
// Double check to see that we are authenticated.
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse();
|
||||
assertThat(environment.containsKey(Context.SECURITY_PRINCIPAL)).isTrue();
|
||||
assertThat(environment.containsKey(Context.SECURITY_CREDENTIALS)).isTrue();
|
||||
}
|
||||
finally {
|
||||
// Always clean up.
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testGetContext() throws NamingException {
|
||||
DirContext ctx = null;
|
||||
try {
|
||||
String expectedPrincipal = "cn=Some Person,ou=company1,ou=Sweden," + base;
|
||||
String expectedCredentials = "password";
|
||||
ctx = tested.getContext(expectedPrincipal, expectedCredentials);
|
||||
assertThat(ctx).isNotNull();
|
||||
// Double check to see that we are authenticated, and that we did not receive
|
||||
// a connection eligible for connection pooling.
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse();
|
||||
assertThat(environment.get(Context.SECURITY_PRINCIPAL)).isEqualTo(expectedPrincipal);
|
||||
assertThat(environment.get(Context.SECURITY_CREDENTIALS)).isEqualTo(expectedCredentials);
|
||||
}
|
||||
finally {
|
||||
// Always clean up.
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void verifyAuthenticate() {
|
||||
EqualsFilter filter = new EqualsFilter("cn", "Some Person2");
|
||||
List<String> results = ldapTemplate.search("", filter.toString(), new DnContextMapper());
|
||||
if (results.size() != 1) {
|
||||
throw new IncorrectResultSizeDataAccessException(1, results.size());
|
||||
}
|
||||
|
||||
DirContext ctx = null;
|
||||
try {
|
||||
ctx = tested.getContext(results.get(0), "password");
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Authentication failed");
|
||||
}
|
||||
finally {
|
||||
LdapUtils.closeContext(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final static class DnContextMapper extends AbstractContextMapper<String> {
|
||||
@Override
|
||||
protected String doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx.getNameInNamespace();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
import org.springframework.ldap.core.support.LdapContextSource;
|
||||
import org.springframework.ldap.filter.EqualsFilter;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.NoAdTest;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for LdapContextSource.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("contextSource")
|
||||
private ContextSource tested;
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@Test
|
||||
public void testGetReadOnlyContext() throws NamingException {
|
||||
DirContext ctx = null;
|
||||
|
||||
try {
|
||||
ctx = tested.getReadOnlyContext();
|
||||
assertThat(ctx).isNotNull();
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse();
|
||||
assertThat(environment.containsKey(Context.SECURITY_PRINCIPAL)).isTrue();
|
||||
assertThat(environment.containsKey(Context.SECURITY_CREDENTIALS)).isTrue();
|
||||
}
|
||||
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();
|
||||
assertThat(ctx).isNotNull();
|
||||
// Double check to see that we are authenticated.
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse();
|
||||
assertThat(environment.containsKey(Context.SECURITY_PRINCIPAL)).isTrue();
|
||||
assertThat(environment.containsKey(Context.SECURITY_CREDENTIALS)).isTrue();
|
||||
}
|
||||
finally {
|
||||
// Always clean up.
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testGetContext() throws NamingException {
|
||||
DirContext ctx = null;
|
||||
try {
|
||||
String expectedPrincipal = "cn=Some Person,ou=company1,ou=Sweden," + base;
|
||||
String expectedCredentials = "password";
|
||||
ctx = tested.getContext(expectedPrincipal, expectedCredentials);
|
||||
assertThat(ctx).isNotNull();
|
||||
// Double check to see that we are authenticated, and that we did not receive
|
||||
// a connection eligible for connection pooling.
|
||||
Hashtable environment = ctx.getEnvironment();
|
||||
assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse();
|
||||
assertThat(environment.get(Context.SECURITY_PRINCIPAL)).isEqualTo(expectedPrincipal);
|
||||
assertThat(environment.get(Context.SECURITY_CREDENTIALS)).isEqualTo(expectedCredentials);
|
||||
}
|
||||
finally {
|
||||
// Always clean up.
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void verifyAuthenticate() {
|
||||
EqualsFilter filter = new EqualsFilter("cn", "Some Person2");
|
||||
List<String> results = ldapTemplate.search("", filter.toString(), new DnContextMapper());
|
||||
if (results.size() != 1) {
|
||||
throw new IncorrectResultSizeDataAccessException(1, results.size());
|
||||
}
|
||||
|
||||
DirContext ctx = null;
|
||||
try {
|
||||
ctx = tested.getContext(results.get(0), "password");
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Authentication failed");
|
||||
}
|
||||
finally {
|
||||
LdapUtils.closeContext(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private final static class DnContextMapper extends AbstractContextMapper<String> {
|
||||
@Override
|
||||
protected String doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx.getNameInNamespace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.support.LdapContextSource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Advanced integration tests for LdapContextSource.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapContextSourceTestContext.xml"})
|
||||
public class LdapContextSourceMultiServerIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapContextSource tested;
|
||||
|
||||
@Test
|
||||
public void testUrls() throws NamingException {
|
||||
String[] urls = tested.getUrls();
|
||||
String string = tested.assembleProviderUrlString(urls);
|
||||
|
||||
assertThat(string).isEqualTo("ldap://127.0.0.1:389 ldap://127.0.0.2:389");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.itest.core.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.support.LdapContextSource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Advanced integration tests for LdapContextSource.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapContextSourceTestContext.xml"})
|
||||
public class LdapContextSourceMultiServerIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapContextSource tested;
|
||||
|
||||
@Test
|
||||
public void testUrls() throws NamingException {
|
||||
String[] urls = tested.getUrls();
|
||||
String string = tested.assembleProviderUrlString(urls);
|
||||
|
||||
assertThat(string).isEqualTo("ldap://127.0.0.1:389 ldap://127.0.0.2:389");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.integration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.LdapGroupDao;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for https://jira.springsource.org/browse/LDAP-247.
|
||||
* Thanks to Jürgen Failenschmid for spotting the problem and providing the code for testing this.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldap-247-testContext.xml"})
|
||||
public class JiraLdap247ITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapGroupDao ldapGroupDao;
|
||||
|
||||
@Test
|
||||
public void verifyThatBasePathIsProperlyPopulated() {
|
||||
assertThat(ldapGroupDao).isNotNull();
|
||||
|
||||
// The base path should be automatically populated by BaseLdapPathBeanPostProcessor,
|
||||
// but it doesn't unless it implements Ordered, which caused the assertion below to fail.
|
||||
assertThat(ldapGroupDao.getBasePath()).isNotNull();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.integration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.LdapGroupDao;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for https://jira.springsource.org/browse/LDAP-247.
|
||||
* Thanks to Jürgen Failenschmid for spotting the problem and providing the code for testing this.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldap-247-testContext.xml"})
|
||||
public class JiraLdap247ITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapGroupDao ldapGroupDao;
|
||||
|
||||
@Test
|
||||
public void verifyThatBasePathIsProperlyPopulated() {
|
||||
assertThat(ldapGroupDao).isNotNull();
|
||||
|
||||
// The base path should be automatically populated by BaseLdapPathBeanPostProcessor,
|
||||
// but it doesn't unless it implements Ordered, which caused the assertion below to fail.
|
||||
assertThat(ldapGroupDao.getBasePath()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,102 +1,102 @@
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.manager;
|
||||
|
||||
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.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.DummyDao;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}
|
||||
* that tests unbind/rebind of recursive entries.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTransactionSubtreeTestContext.xml"})
|
||||
public class ContextSourceTransactionManagerSubtreeIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
private DummyDao dummyDao;
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
}
|
||||
|
||||
protected Resource getLdifFileResource() {
|
||||
return new ClassPathResource("/setup_data_subtree.ldif");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap168DeleteRecursively() {
|
||||
dummyDao.deleteRecursively("ou=company1,ou=Sweden");
|
||||
|
||||
try {
|
||||
ldapTemplate.lookup("ou=company1,ou=Sweden");
|
||||
fail("NameNotFoundException expected");
|
||||
} catch (NameNotFoundException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap168DeleteWithException() {
|
||||
try {
|
||||
dummyDao.deleteRecursivelyWithException("ou=company1,ou=Sweden");
|
||||
fail("DummyException expected");
|
||||
} catch (DummyException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
// Entry should have been restored
|
||||
ldapTemplate.lookup("ou=company1,ou=Sweden");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap244CreateRecursively() {
|
||||
dummyDao.createRecursivelyAndUnbindSubnode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap244CreateRecursivelyWithException() {
|
||||
try {
|
||||
dummyDao.createRecursivelyAndUnbindSubnodeWithException();
|
||||
fail("DummyException expected");
|
||||
} catch (DummyException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.itest.manager;
|
||||
|
||||
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.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.DummyDao;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}
|
||||
* that tests unbind/rebind of recursive entries.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTransactionSubtreeTestContext.xml"})
|
||||
public class ContextSourceTransactionManagerSubtreeIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
private DummyDao dummyDao;
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() throws Exception {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
}
|
||||
|
||||
protected Resource getLdifFileResource() {
|
||||
return new ClassPathResource("/setup_data_subtree.ldif");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap168DeleteRecursively() {
|
||||
dummyDao.deleteRecursively("ou=company1,ou=Sweden");
|
||||
|
||||
try {
|
||||
ldapTemplate.lookup("ou=company1,ou=Sweden");
|
||||
fail("NameNotFoundException expected");
|
||||
} catch (NameNotFoundException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap168DeleteWithException() {
|
||||
try {
|
||||
dummyDao.deleteRecursivelyWithException("ou=company1,ou=Sweden");
|
||||
fail("DummyException expected");
|
||||
} catch (DummyException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
// Entry should have been restored
|
||||
ldapTemplate.lookup("ou=company1,ou=Sweden");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap244CreateRecursively() {
|
||||
dummyDao.createRecursivelyAndUnbindSubnode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdap244CreateRecursivelyWithException() {
|
||||
try {
|
||||
dummyDao.createRecursivelyAndUnbindSubnodeWithException();
|
||||
fail("DummyException expected");
|
||||
} catch (DummyException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user