Work with Spring 5
Fixes gh-415
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.ldap.core.support;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.ldap.UncategorizedLdapException;
|
||||
import org.springframework.ldap.core.AuthenticationSource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
@@ -63,12 +62,12 @@ import java.util.Map;
|
||||
* <b>Note:</b> When using implementations of this class outside of a Spring
|
||||
* Context it is necessary to call {@link #afterPropertiesSet()} when all
|
||||
* properties are set, in order to finish up initialization.
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.core.LdapTemplate
|
||||
* @see org.springframework.ldap.core.support.DefaultDirObjectFactory
|
||||
* @see org.springframework.ldap.core.support.LdapContextSource
|
||||
* @see org.springframework.ldap.core.support.DirContextSource
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Adam Skogman
|
||||
* @author Ulrik Sandberg
|
||||
@@ -168,7 +167,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.core.ContextSource#getReadWriteContext()
|
||||
*/
|
||||
public DirContext getReadWriteContext() {
|
||||
@@ -183,7 +182,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* This method should typically NOT be overridden; any customization to the
|
||||
* authentication mechanism should be managed by setting a different
|
||||
* {@link DirContextAuthenticationStrategy} on this instance.
|
||||
*
|
||||
*
|
||||
* @param env the environment to modify.
|
||||
* @param principal the principal to authenticate with.
|
||||
* @param credentials the credentials to authenticate with.
|
||||
@@ -201,7 +200,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Close the context and swallow any exceptions.
|
||||
*
|
||||
*
|
||||
* @param ctx the DirContext to close.
|
||||
*/
|
||||
private void closeContext(DirContext ctx) {
|
||||
@@ -218,7 +217,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Assemble a valid url String from all registered urls to add as
|
||||
* <code>PROVIDER_URL</code> to the environment.
|
||||
*
|
||||
*
|
||||
* @param ldapUrls all individual url Strings.
|
||||
* @return the full url String
|
||||
*/
|
||||
@@ -300,7 +299,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* Set the base suffix from which all operations should origin. If a base
|
||||
* suffix is set, you will not have to (and, indeed, must not) specify the
|
||||
* full distinguished names in any operations performed.
|
||||
*
|
||||
*
|
||||
* @param base the base suffix.
|
||||
*/
|
||||
public void setBase(String base) {
|
||||
@@ -331,7 +330,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Create a DirContext using the supplied environment.
|
||||
*
|
||||
*
|
||||
* @param environment the LDAP environment to use when creating the
|
||||
* <code>DirContext</code>.
|
||||
* @return a new DirContext implementation initialized with the supplied
|
||||
@@ -359,7 +358,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Set the context factory. Default is com.sun.jndi.ldap.LdapCtxFactory.
|
||||
*
|
||||
*
|
||||
* @param contextFactory the context factory used when creating Contexts.
|
||||
*/
|
||||
public void setContextFactory(Class<?> contextFactory) {
|
||||
@@ -368,7 +367,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Get the context factory.
|
||||
*
|
||||
*
|
||||
* @return the context factory used when creating Contexts.
|
||||
*/
|
||||
public Class<?> getContextFactory() {
|
||||
@@ -381,7 +380,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* implementation of javax.naming.spi.DirObjectFactory. <b>Note: </b>Setting
|
||||
* this value to null may have cause connection leaks when using
|
||||
* ContextMapper methods in LdapTemplate.
|
||||
*
|
||||
*
|
||||
* @param dirObjectFactory the DirObjectFactory to be used. Null means that
|
||||
* no DirObjectFactory will be used.
|
||||
*/
|
||||
@@ -391,7 +390,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Get the DirObjectFactory to use.
|
||||
*
|
||||
*
|
||||
* @return the DirObjectFactory to be used. <code>null</code> means that no
|
||||
* DirObjectFactory will be used.
|
||||
*/
|
||||
@@ -410,10 +409,6 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
throw new IllegalArgumentException("At least one server url must be set");
|
||||
}
|
||||
|
||||
if (!base.isEmpty() && getJdkVersion().compareTo(JDK_142) < 0) {
|
||||
throw new IllegalArgumentException("Base path is not supported for JDK versions < 1.4.2");
|
||||
}
|
||||
|
||||
if (authenticationSource == null) {
|
||||
LOG.debug("AuthenticationSource not set - " + "using default implementation");
|
||||
if (!StringUtils.hasText(userDn)) {
|
||||
@@ -466,7 +461,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Set the password (credentials) to use for getting authenticated contexts.
|
||||
*
|
||||
*
|
||||
* @param password the password.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
@@ -484,7 +479,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Set the user distinguished name (principal) to use for getting
|
||||
* authenticated contexts.
|
||||
*
|
||||
*
|
||||
* @param userDn the user distinguished name.
|
||||
*/
|
||||
public void setUserDn(String userDn) {
|
||||
@@ -494,7 +489,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Gets the user distinguished name (principal) to use for getting
|
||||
* authenticated contexts.
|
||||
*
|
||||
*
|
||||
* @return the user distinguished name.
|
||||
*/
|
||||
public String getUserDn() {
|
||||
@@ -504,7 +499,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Set the urls of the LDAP servers. Use this method if several servers are
|
||||
* required.
|
||||
*
|
||||
*
|
||||
* @param urls the urls of all servers.
|
||||
*/
|
||||
public void setUrls(String[] urls) {
|
||||
@@ -513,7 +508,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Get the urls of the LDAP servers.
|
||||
*
|
||||
*
|
||||
* @return the urls of all servers.
|
||||
*/
|
||||
public String[] getUrls() {
|
||||
@@ -523,7 +518,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Set the url of the LDAP server. Utility method if only one server is
|
||||
* used.
|
||||
*
|
||||
*
|
||||
* @param url the url of the LDAP server.
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
@@ -545,7 +540,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* each individually authenticated connection will be pooled separately.
|
||||
* This means that LDAP pooling will be most efficient using anonymous
|
||||
* connections or connections authenticated using one single system user.
|
||||
*
|
||||
*
|
||||
* @param pooled whether Contexts should be pooled.
|
||||
*/
|
||||
public void setPooled(boolean pooled) {
|
||||
@@ -554,7 +549,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Get whether the pooling flag should be set.
|
||||
*
|
||||
*
|
||||
* @return whether Contexts should be pooled.
|
||||
*/
|
||||
public boolean isPooled() {
|
||||
@@ -564,7 +559,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* If any custom environment properties are needed, these can be set using
|
||||
* this method.
|
||||
*
|
||||
*
|
||||
* @param baseEnvironmentProperties the base environment properties that should always be used when
|
||||
* creating new Context instances.
|
||||
*/
|
||||
@@ -572,10 +567,6 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
this.baseEnv = new Hashtable<String, Object>(baseEnvironmentProperties);
|
||||
}
|
||||
|
||||
String getJdkVersion() {
|
||||
return JdkVersion.getJavaVersion();
|
||||
}
|
||||
|
||||
protected Hashtable<String, Object> getAnonymousEnv() {
|
||||
if (cacheEnvironmentProperties) {
|
||||
return anonymousEnv;
|
||||
@@ -595,7 +586,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Set the authentication source to use when retrieving user principal and
|
||||
* credentials.
|
||||
*
|
||||
*
|
||||
* @param authenticationSource the {@link AuthenticationSource} that will
|
||||
* provide user info.
|
||||
*/
|
||||
@@ -605,7 +596,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
/**
|
||||
* Get the authentication source.
|
||||
*
|
||||
*
|
||||
* @return the {@link AuthenticationSource} that will provide user info.
|
||||
*/
|
||||
public AuthenticationSource getAuthenticationSource() {
|
||||
@@ -618,7 +609,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
* property to <code>false</code> causes the environment Hashmap to be
|
||||
* rebuilt from the current property settings of this instance between each
|
||||
* request for an anonymous environment.
|
||||
*
|
||||
*
|
||||
* @param cacheEnvironmentProperties <code>true</code> causes that the
|
||||
* anonymous environment properties should be cached, <code>false</code>
|
||||
* causes the Hashmap to be rebuilt for each request.
|
||||
@@ -630,7 +621,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Set whether an anonymous environment should be used for read-only
|
||||
* operations. Default is <code>false</code>.
|
||||
*
|
||||
*
|
||||
* @param anonymousReadOnly <code>true</code> if an anonymous environment
|
||||
* should be used for read-only operations, <code>false</code> otherwise.
|
||||
*/
|
||||
@@ -641,7 +632,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Get whether an anonymous environment should be used for read-only
|
||||
* operations.
|
||||
*
|
||||
*
|
||||
* @return <code>true</code> if an anonymous environment should be used for
|
||||
* read-only operations, <code>false</code> otherwise.
|
||||
*/
|
||||
@@ -652,7 +643,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Set the {@link DirContextAuthenticationStrategy} to use for preparing the
|
||||
* environment and processing the created <code>DirContext</code> instances.
|
||||
*
|
||||
*
|
||||
* @param authenticationStrategy the
|
||||
* {@link DirContextAuthenticationStrategy} to use; default is
|
||||
* {@link SimpleDirContextAuthenticationStrategy}.
|
||||
@@ -678,7 +669,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
/**
|
||||
* Implement in subclass to create a DirContext of the desired type (e.g.
|
||||
* InitialDirContext or InitialLdapContext).
|
||||
*
|
||||
*
|
||||
* @param environment the environment to use when creating the instance.
|
||||
* @return a new DirContext instance.
|
||||
* @throws NamingException if one is encountered when creating the instance.
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.ldap.core.support;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.ldap.transaction.compensating.manager;
|
||||
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.transaction.compensating.TempEntryRenamingStrategy;
|
||||
import org.springframework.orm.hibernate3.HibernateTransactionManager;
|
||||
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionSuspensionNotSupportedException;
|
||||
@@ -28,10 +28,10 @@ import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
* transaction. Note that even though the same logical transaction is used, this
|
||||
* is <b>not</b> a JTA XA transaction; no two-phase commit will be performed,
|
||||
* and thus commit and rollback may yield unexpected results.<br>
|
||||
* This Transaction Manager is as good as it gets when you are using in LDAP in
|
||||
* This Transaction Manager is as good as it gets when you are using in LDAP in
|
||||
* combination with a Hibernate 3 and unable to use XA transactions because LDAP
|
||||
* is not transactional by design to begin with.<br>
|
||||
*
|
||||
*
|
||||
* Furthermore, this manager <b>does not support nested transactions</b>
|
||||
* @author Hans Westerbeek
|
||||
* @since 1.2.2
|
||||
@@ -41,14 +41,14 @@ import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
public class ContextSourceAndHibernateTransactionManager extends HibernateTransactionManager {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ContextSourceTransactionManagerDelegate ldapManagerDelegate = new ContextSourceTransactionManagerDelegate();
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#isExistingTransaction(java.lang.Object)
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#isExistingTransaction(java.lang.Object)
|
||||
*/
|
||||
protected boolean isExistingTransaction(Object transaction) {
|
||||
ContextSourceAndHibernateTransactionObject actualTransactionObject = (ContextSourceAndHibernateTransactionObject) transaction;
|
||||
@@ -58,7 +58,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#doGetTransaction()
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#doGetTransaction()
|
||||
*/
|
||||
protected Object doGetTransaction() {
|
||||
Object dataSourceTransactionObject = super.doGetTransaction();
|
||||
@@ -70,7 +70,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#doBegin(java.lang.Object,
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#doBegin(java.lang.Object,
|
||||
* org.springframework.transaction.TransactionDefinition)
|
||||
*/
|
||||
protected void doBegin(Object transaction, TransactionDefinition definition) {
|
||||
@@ -89,7 +89,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#doCleanupAfterCompletion(java.lang.Object)
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#doCleanupAfterCompletion(java.lang.Object)
|
||||
*/
|
||||
protected void doCleanupAfterCompletion(Object transaction) {
|
||||
ContextSourceAndHibernateTransactionObject actualTransactionObject = (ContextSourceAndHibernateTransactionObject) transaction;
|
||||
@@ -101,7 +101,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#doCommit(org.springframework.transaction.support.DefaultTransactionStatus)
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#doCommit(org.springframework.transaction.support.DefaultTransactionStatus)
|
||||
*/
|
||||
protected void doCommit(DefaultTransactionStatus status) {
|
||||
|
||||
@@ -135,7 +135,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#doRollback(org.springframework.transaction.support.DefaultTransactionStatus)
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#doRollback(org.springframework.transaction.support.DefaultTransactionStatus)
|
||||
*/
|
||||
protected void doRollback(DefaultTransactionStatus status) {
|
||||
ContextSourceAndHibernateTransactionObject actualTransactionObject = (ContextSourceAndHibernateTransactionObject) status
|
||||
@@ -186,7 +186,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#doSuspend(java.lang.Object)
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#doSuspend(java.lang.Object)
|
||||
*/
|
||||
protected Object doSuspend(Object transaction) {
|
||||
throw new TransactionSuspensionNotSupportedException(
|
||||
@@ -195,7 +195,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.orm.hibernate3.HibernateTransactionManager#doResume(java.lang.Object,
|
||||
* @see org.springframework.orm.hibernate5.HibernateTransactionManager#doResume(java.lang.Object,
|
||||
* java.lang.Object)
|
||||
*/
|
||||
protected void doResume(Object transaction, Object suspendedResources) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for the LdapContextSource class.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@@ -46,19 +46,6 @@ public class LdapContextSourceTest {
|
||||
tested.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSet_BaseAndTooEarlyJdk() throws Exception {
|
||||
tested = new LdapContextSource() {
|
||||
String getJdkVersion() {
|
||||
return "1.4.1_03";
|
||||
}
|
||||
};
|
||||
|
||||
tested.setUrl("http://ldap.example.com:389");
|
||||
tested.setBase("dc=jayway,dc=se");
|
||||
tested.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAnonymousEnv() throws Exception {
|
||||
tested.setBase("dc=some example,dc=se");
|
||||
@@ -138,49 +125,6 @@ public class LdapContextSourceTest {
|
||||
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOldJdkWithNoBaseSetShouldWork() throws Exception {
|
||||
tested = new LdapContextSource() {
|
||||
String getJdkVersion() {
|
||||
return "1.3";
|
||||
}
|
||||
};
|
||||
tested.setUrl("ldap://ldap.example.com:389");
|
||||
tested.afterPropertiesSet();
|
||||
|
||||
// check that base was not added to environment
|
||||
Hashtable env = tested.getAnonymousEnv();
|
||||
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testOldJdkWithBaseSetShouldNotWork() throws Exception {
|
||||
tested = new LdapContextSource() {
|
||||
String getJdkVersion() {
|
||||
return "1.3";
|
||||
}
|
||||
};
|
||||
tested.setUrl("ldap://ldap.example.com:389");
|
||||
tested.setBase("dc=example,dc=com");
|
||||
tested.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOldJdkWithBaseSetToEmptyPathShouldWork() throws Exception {
|
||||
tested = new LdapContextSource() {
|
||||
String getJdkVersion() {
|
||||
return "1.3";
|
||||
}
|
||||
};
|
||||
tested.setUrl("ldap://ldap.example.com:389");
|
||||
tested.setBase(null);
|
||||
tested.afterPropertiesSet();
|
||||
|
||||
// check that base was not added to environment
|
||||
Hashtable env = tested.getAnonymousEnv();
|
||||
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthenticatedEnv() throws Exception {
|
||||
tested.setBase("dc=example,dc=se");
|
||||
|
||||
@@ -5,11 +5,11 @@ sourceCompatibility = '1.6'
|
||||
targetCompatibility = '1.6'
|
||||
|
||||
ext.apacheDsVersion = '1.5.5'
|
||||
ext.springVersion = '4.2.5.RELEASE'
|
||||
ext.springVersion = '5.0.0.BUILD-SNAPSHOT'
|
||||
ext.springDataVersion = '1.12.1.RELEASE'
|
||||
ext.springDataSpring3Version = '1.10.2.RELEASE'
|
||||
ext.springBatchVersion = '2.0.4.RELEASE'
|
||||
ext.junitVersion = '4.11'
|
||||
ext.junitVersion = '4.12'
|
||||
ext.commonsIoVersion = '2.4'
|
||||
ext.commonsPoolVersion = '1.6'
|
||||
ext.commonsLangVersion = '2.6'
|
||||
@@ -22,6 +22,7 @@ ext.slf4jVersion = '1.7.12'
|
||||
ext.powerMockVersion = '1.6.2'
|
||||
ext.commonsPool2Version = '2.4.2'
|
||||
ext.assertjVersion= '2.3.0'
|
||||
ext.hibernateVersion = '5.2.2.Final'
|
||||
|
||||
ext.powerMockDependencies = [
|
||||
"org.powermock:powermock-core:$powerMockVersion",
|
||||
|
||||
@@ -50,7 +50,7 @@ dependencies {
|
||||
testCompile "org.springframework:spring-test:$springVersion",
|
||||
"org.springframework:spring-aop:$springVersion",
|
||||
"org.springframework:spring-expression:$springVersion",
|
||||
"org.hibernate:hibernate-core:3.3.2.GA",
|
||||
"org.hibernate:hibernate-core:$hibernateVersion",
|
||||
"aspectj:aspectjrt:1.5.3",
|
||||
"aspectj:aspectjweaver:1.5.3",
|
||||
"hsqldb:hsqldb:1.8.0.7",
|
||||
|
||||
@@ -4,7 +4,7 @@ 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.hibernate3.support.HibernateDaoSupport;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.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());
|
||||
@@ -28,14 +28,14 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
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) {
|
||||
@@ -45,7 +45,7 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
|
||||
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
|
||||
}
|
||||
|
||||
|
||||
public void modifyAttributesWithException(String dn, String lastName,
|
||||
String description) {
|
||||
modifyAttributes(dn, lastName, description);
|
||||
@@ -56,7 +56,7 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
String dn = prepareDn(person);
|
||||
ldapTemplate.unbind(dn);
|
||||
this.getHibernateTemplate().delete(person);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void unbindWithException(OrgPerson person) {
|
||||
@@ -72,22 +72,22 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
|
||||
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) {
|
||||
@@ -95,12 +95,12 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class LdapConditionallyFilteredTestRunner extends SpringJUnit4ClassRunner
|
||||
String noadtest = System.getProperty("adtest");
|
||||
if (noadtest != null) {
|
||||
try {
|
||||
filter(new Categories.CategoryFilter(null, NoAdTest.class));
|
||||
filter(Categories.CategoryFilter.exclude(NoAdTest.class));
|
||||
} catch (NoTestsRemainException e) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
@@ -32,8 +32,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:ldap321.xml")
|
||||
@TransactionConfiguration(transactionManager = "txManager",defaultRollback = true)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class Ldap321Test{
|
||||
@Autowired
|
||||
private RoleRepo roleRepo;
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.ldap.itest.transaction.compensating.manager.DummyExce
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.hibernate.OrgPerson;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.hibernate.OrgPersonDao;
|
||||
import org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager;
|
||||
import org.springframework.orm.hibernate3.HibernateTemplate;
|
||||
import org.springframework.orm.hibernate5.HibernateTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
@@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ContextSourceAndHibernateTransactionManager}.
|
||||
*
|
||||
*
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapAndHibernateTransactionTestContext.xml"})
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.DummyException;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.hibernate.OrgPerson;
|
||||
import org.springframework.ldap.itest.transaction.compensating.manager.hibernate.OrgPersonDao;
|
||||
import org.springframework.orm.hibernate3.HibernateTemplate;
|
||||
import org.springframework.orm.hibernate5.HibernateTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
<constructor-arg ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
|
||||
@@ -32,11 +32,11 @@
|
||||
<constructor-arg ref="transactedContextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
|
||||
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
|
||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
|
||||
Reference in New Issue
Block a user