import javax.transaction.TransactionManager;
+import org.argeo.naming.LdapAttrs;
+import org.argeo.transaction.simple.SimpleTransactionManager;
import org.osgi.service.useradmin.Authorization;
import org.osgi.service.useradmin.Group;
import org.osgi.service.useradmin.Role;
import junit.framework.TestCase;
public class LdifUserAdminTest extends TestCase implements BasicTestConstants {
- private BitronixTransactionManager tm;
+ final static int TM_SIMPLE = 0;
+ final static int TM_BITRONIX = 1;
+
+ private int tmType = TM_SIMPLE;
+ private TransactionManager tm;
private URI uri;
private AbstractUserDirectory userAdmin;
private Path tempDir;
// credentials
byte[] hashedPassword = ("{SHA}" + Base64.getEncoder().encodeToString(DigestUtils.sha1("demo".getBytes())))
.getBytes();
- assertTrue(rootUser.hasCredential(LdifName.userPassword.name(), hashedPassword));
- assertTrue(demoUser.hasCredential(LdifName.userPassword.name(), hashedPassword));
+ assertTrue(rootUser.hasCredential(LdapAttrs.userPassword.name(), hashedPassword));
+ assertTrue(demoUser.hasCredential(LdapAttrs.userPassword.name(), hashedPassword));
// search
Role[] search = userAdmin.getRoles(null);
uri = ldifPath.toUri();
}
- bitronix.tm.Configuration tmConf = TransactionManagerServices.getConfiguration();
- tmConf.setServerId(UUID.randomUUID().toString());
- tmConf.setLogPart1Filename(new File(tempDir.toFile(), "btm1.tlog").getAbsolutePath());
- tmConf.setLogPart2Filename(new File(tempDir.toFile(), "btm2.tlog").getAbsolutePath());
- tm = TransactionManagerServices.getTransactionManager();
+ // Init transaction manager
+ if (TM_SIMPLE == tmType) {
+ tm = new SimpleTransactionManager();
+ } else if (TM_BITRONIX == tmType) {
+ bitronix.tm.Configuration tmConf = TransactionManagerServices.getConfiguration();
+ tmConf.setServerId(UUID.randomUUID().toString());
+ tmConf.setLogPart1Filename(new File(tempDir.toFile(), "btm1.tlog").getAbsolutePath());
+ tmConf.setLogPart2Filename(new File(tempDir.toFile(), "btm2.tlog").getAbsolutePath());
+ tm = TransactionManagerServices.getTransactionManager();
+ }
userAdmin = initUserAdmin(uri, tm);
}
userAdmin = new LdifUserAdmin(props);
userAdmin.init();
// JTA
- EhCacheXAResourceProducer.registerXAResource(UserDirectory.class.getName(), userAdmin.getXaResource());
+ if (TM_BITRONIX == tmType)
+ EhCacheXAResourceProducer.registerXAResource(UserDirectory.class.getName(), userAdmin.getXaResource());
userAdmin.setTransactionManager(tm);
return userAdmin;
}
private void persistAndRestart() {
- EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource());
+ if (TM_BITRONIX == tmType)
+ EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource());
if (userAdmin instanceof LdifUserAdmin)
((LdifUserAdmin) userAdmin).save();
userAdmin.destroy();
@Override
protected void tearDown() throws Exception {
- EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource());
- tm.shutdown();
+ if (TM_BITRONIX == tmType) {
+ EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource());
+ ((BitronixTransactionManager) tm).shutdown();
+ }
if (userAdmin != null)
userAdmin.destroy();
if (tempDir != null)