org.springframework.ldap.core.ContextSource Java Examples
The following examples show how to use
org.springframework.ldap.core.ContextSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void verifyParseWithDefaultTransactions() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-transactional-defaults.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class); assertThat(outerContextSource).isNotNull(); assertThat(transactionManager).isNotNull(); assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(transactionManager instanceof ContextSourceTransactionManager).isTrue(); Object delegate = getInternalState(transactionManager, "delegate"); assertThat(contextSource).isSameAs(getInternalState(delegate, "contextSource")); TempEntryRenamingStrategy renamingStrategy = (TempEntryRenamingStrategy) getInternalState(delegate, "renamingStrategy"); assertThat(renamingStrategy instanceof DefaultTempEntryRenamingStrategy).isTrue(); assertThat("_temp").isEqualTo(getInternalState(renamingStrategy, "tempSuffix")); }
Example #2
Source File: ContextSourceTransactionManagerTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { if (TransactionSynchronizationManager.isSynchronizationActive()) { TransactionSynchronizationManager.clearSynchronization(); } contextSourceMock = mock(ContextSource.class); contextMock = mock(DirContext.class); transactionDefinitionMock = mock(TransactionDefinition.class); transactionDataManagerMock = mock(CompensatingTransactionOperationManager.class); renamingStrategyMock = mock(TempEntryRenamingStrategy.class); tested = new ContextSourceTransactionManager(); tested.setContextSource(contextSourceMock); tested.setRenamingStrategy(renamingStrategyMock); }
Example #3
Source File: AuthoritiesPopulator.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
/** * @param contextSource * @param groupSearchBase */ public AuthoritiesPopulator(ContextSource contextSource, String groupSearchBase, String adminRole, String defaultRole) { super(contextSource, groupSearchBase); this.adminRoleAsAuthority = new SimpleGrantedAuthority(adminRole.toUpperCase(Locale.ROOT)); // spring will // convert group names to uppercase by default String[] defaultRoles = StringUtils.split(defaultRole, ","); if (ArrayUtils.contains(defaultRoles, Constant.ROLE_MODELER)) { this.defaultAuthorities.add(modelerAuthority); this.defaultAuthorities.add(analystAuthority); } if (ArrayUtils.contains(defaultRoles, Constant.ROLE_ANALYST)) this.defaultAuthorities.add(analystAuthority); }
Example #4
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void verifyParsePoolWithPlaceholders() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-config-with-placeholders.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(pooledContextSource).isNotNull(); GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10); assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20); assertThat(objectPool.getMaxWait()).isEqualTo(10); assertThat(objectPool.getMaxTotal()).isEqualTo(11); assertThat(objectPool.getMaxActive()).isEqualTo(15); assertThat(objectPool.getMinIdle()).isEqualTo(16); assertThat(objectPool.getMaxIdle()).isEqualTo(17); assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18); }
Example #5
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void verifyParsePoolingSizeSet() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-configured-poolsize.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(pooledContextSource).isNotNull(); GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); assertThat(objectPool.getMaxActive()).isEqualTo(10); assertThat(objectPool.getMaxTotal()).isEqualTo(12); assertThat(objectPool.getMaxIdle()).isEqualTo(11); assertThat(objectPool.getMaxWait()).isEqualTo(13); assertThat(objectPool.getMinIdle()).isEqualTo(14); assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)0); }
Example #6
Source File: SpringLdapExternalUidTranslation.java From unitime with Apache License 2.0 | 6 votes |
public String uid2ext(String uid) { String externalIdAttribute = ApplicationProperty.AuthenticationLdapIdAttribute.value(); if ("uid".equals(externalIdAttribute)) return uid; // Nothing to translate try { ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource"); String query = ApplicationProperty.AuthenticationLdapLogin2UserId.value(); SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source); DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", uid), new String[] {externalIdAttribute}); return user == null ? null : user.getStringAttribute(externalIdAttribute); } catch (Exception e) { sLog.warn("Unable to translate uid to " + externalIdAttribute + ": " + e.getMessage()); } return null; }
Example #7
Source File: SpringLdapExternalUidTranslation.java From unitime with Apache License 2.0 | 6 votes |
public String ext2uid(String externalUserId) { String externalIdAttribute = ApplicationProperty.AuthenticationLdapIdAttribute.value(); if ("uid".equals(externalIdAttribute)) return externalUserId; // Nothing to translate try { ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource"); String query = ApplicationProperty.AuthenticationLdapUserId2Login.value().replace("%", externalIdAttribute); SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source); DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", externalIdAttribute), new String[] {"uid"}); return user == null ? null : user.getStringAttribute("uid"); } catch (Exception e) { sLog.warn("Unable to translate " + externalIdAttribute + " to uid: " + e.getMessage()); } return null; }
Example #8
Source File: AuthoritiesPopulator.java From kylin with Apache License 2.0 | 6 votes |
/** * @param contextSource * @param groupSearchBase */ public AuthoritiesPopulator(ContextSource contextSource, String groupSearchBase, String adminRole, String defaultRole) { super(contextSource, groupSearchBase); this.adminRoleAsAuthority = new SimpleGrantedAuthority(adminRole.toUpperCase(Locale.ROOT)); // spring will // convert group names to uppercase by default String[] defaultRoles = StringUtils.split(defaultRole, ","); if (ArrayUtils.contains(defaultRoles, Constant.ROLE_MODELER)) { this.defaultAuthorities.add(modelerAuthority); this.defaultAuthorities.add(analystAuthority); } if (ArrayUtils.contains(defaultRoles, Constant.ROLE_ANALYST)) this.defaultAuthorities.add(analystAuthority); }
Example #9
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void verifyParsePool2WithPlaceholders() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-config-with-placeholders.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(pooledContextSource).isNotNull(); org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10); assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20); assertThat(objectPool.getMaxWaitMillis()).isEqualTo(10); assertThat(objectPool.getMaxTotal()).isEqualTo(11); assertThat(objectPool.getMinIdlePerKey()).isEqualTo(12); assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(13); assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(14); assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18); }
Example #10
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void verifyReferences() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-references.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); AuthenticationSource authenticationSource = ctx.getBean(AuthenticationSource.class); DirContextAuthenticationStrategy authenticationStrategy = ctx.getBean(DirContextAuthenticationStrategy.class); Object baseEnv = ctx.getBean("baseEnvProps"); assertThat(outerContextSource).isNotNull(); assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(authenticationSource).isSameAs(getInternalState(contextSource, "authenticationSource")); assertThat(authenticationStrategy).isSameAs(getInternalState(contextSource, "authenticationStrategy")); assertThat(baseEnv).isEqualTo(getInternalState(contextSource, "baseEnv")); }
Example #11
Source File: ContextSourceTransactionManagerDelegate.java From spring-ldap with Apache License 2.0 | 6 votes |
/** * Set the ContextSource to work on. Even though the actual ContextSource * sent to the LdapTemplate instance should be a * {@link TransactionAwareContextSourceProxy}, the one sent to this method * should be the target of that proxy. If it is not, the target will be * extracted and used instead. * * @param contextSource * the ContextSource to work on. */ public void setContextSource(ContextSource contextSource) { if (contextSource instanceof TransactionAwareContextSourceProxy) { TransactionAwareContextSourceProxy proxy = (TransactionAwareContextSourceProxy) contextSource; this.contextSource = proxy.getTarget(); } else { this.contextSource = contextSource; } if (contextSource instanceof AbstractContextSource) { AbstractContextSource abstractContextSource = (AbstractContextSource) contextSource; if(abstractContextSource.isAnonymousReadOnly()) { throw new IllegalArgumentException( "Compensating LDAP transactions cannot be used when context-source is anonymous-read-only"); } } }
Example #12
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 6 votes |
@Test public void supportsSpel() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-spel.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); assertThat(outerContextSource).isNotNull(); assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(LdapUtils.newLdapName("dc=261consulting,dc=com")).isEqualTo(getInternalState(contextSource, "base")); assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn")); assertThat("apassword").isEqualTo(getInternalState(contextSource, "password")); assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls")); }
Example #13
Source File: SingleContextSource.java From spring-ldap with Apache License 2.0 | 6 votes |
/** * Construct a SingleContextSource and execute the LdapOperationsCallback using the created instance. * This makes sure the same connection will be used for all operations inside the LdapOperationsCallback, * which is particularly useful when working with e.g. Paged Results as these typically require the exact * same connection to be used for all requests involving the same cookie.. * The SingleContextSource instance will be properly disposed of once the operation has been completed. * * @param contextSource The target ContextSource to retrieve a DirContext from * @param callback the callback to perform the Ldap operations * @param useReadOnly if <code>true</code>, use the {@link org.springframework.ldap.core.ContextSource#getReadOnlyContext()} * method on the target ContextSource to get the actual DirContext instance, if <code>false</code>, * use {@link org.springframework.ldap.core.ContextSource#getReadWriteContext()}. * @param ignorePartialResultException Used for populating this property on the created LdapTemplate instance. * @param ignoreNameNotFoundException Used for populating this property on the created LdapTemplate instance. * @return the result returned from the callback. * @since 2.0 */ public static <T> T doWithSingleContext(ContextSource contextSource, LdapOperationsCallback<T> callback, boolean useReadOnly, boolean ignorePartialResultException, boolean ignoreNameNotFoundException) { SingleContextSource singleContextSource; if (useReadOnly) { singleContextSource = new SingleContextSource(contextSource.getReadOnlyContext()); } else { singleContextSource = new SingleContextSource(contextSource.getReadWriteContext()); } LdapTemplate ldapTemplate = new LdapTemplate(singleContextSource); ldapTemplate.setIgnorePartialResultException(ignorePartialResultException); ldapTemplate.setIgnoreNameNotFoundException(ignoreNameNotFoundException); try { return callback.doWithLdapOperations(ldapTemplate); } finally { singleContextSource.destroy(); } }
Example #14
Source File: AuthoritiesPopulator.java From Kylin with Apache License 2.0 | 5 votes |
/** * @param contextSource * @param groupSearchBase */ public AuthoritiesPopulator(ContextSource contextSource, String groupSearchBase, String adminRole, String defaultRole) { super(contextSource, groupSearchBase); this.adminRole = adminRole; this.adminRoleAsAuthority = new SimpleGrantedAuthority(adminRole); if (defaultRole.contains(Constant.ROLE_MODELER)) this.defaultAuthorities.add(modelerAuthority); if (defaultRole.contains(Constant.ROLE_ANALYST)) this.defaultAuthorities.add(analystAuthority); }
Example #15
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void verifyParsePoolingDefaults() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-defaults.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); assertThat(outerContextSource).isNotNull(); assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(pooledContextSource).isNotNull(); assertThat(pooledContextSource instanceof PoolingContextSource).isTrue(); Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory"); assertThat(getInternalState(objectFactory, "contextSource")).isNotNull(); assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull(); Set<Class<? extends Throwable>> nonTransientExceptions = (Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions"); assertThat(nonTransientExceptions).hasSize(1); assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue(); GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); assertThat(objectPool.getMaxActive()).isEqualTo(8); assertThat(objectPool.getMaxTotal()).isEqualTo(-1); assertThat(objectPool.getMaxIdle()).isEqualTo(8); assertThat(objectPool.getMaxWait()).isEqualTo(-1); assertThat(objectPool.getMinIdle()).isEqualTo(0); assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)1); }
Example #16
Source File: TransactionAwareContextSourceProxyTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { contextSourceMock = mock(ContextSource.class); ldapContextMock = mock(LdapContext.class); dirContextMock = mock(DirContext.class); tested = new TransactionAwareContextSourceProxy(contextSourceMock); }
Example #17
Source File: SpringLdapExternalUidLookup.java From unitime with Apache License 2.0 | 5 votes |
@Override public UserInfo doLookup(String uid) throws Exception { try { ContextSource source = (ContextSource)SpringApplicationContextHolder.getBean("unitimeLdapContextSource"); String query = ApplicationProperty.AuthenticationLdapIdentify.value(); String idAttributeName = ApplicationProperty.AuthenticationLdapIdAttribute.value(); SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(source); DirContextOperations user = template.retrieveEntry(query.replaceAll("\\{0\\}", uid), new String[] {"uid", idAttributeName, "cn", "givenName", "sn", "mail"}); if (user == null || user.getStringAttribute(idAttributeName) == null) return null; UserInfo info = new UserInfo(); info.setExternalId(user.getStringAttribute(idAttributeName)); info.setUserName(user.getStringAttribute("uid")); if (info.getUserName() == null) info.setUserName(uid); info.setName(user.getStringAttribute("cn")); info.setFirstName(user.getStringAttribute("givenName")); info.setLastName(user.getStringAttribute("sn")); info.setEmail(user.getStringAttribute("mail")); if (info.getEmail() == null) { String email = info.getUserName() + "@"; for (String x: user.getNameInNamespace().split(",")) if (x.startsWith("dc=")) email += (email.endsWith("@") ? "" : ".") + x.substring(3); if (!email.endsWith("@")) info.setEmail(email); } return info; } catch (Exception e) { sLog.warn("Lookup for " + uid + " failed: " + e.getMessage()); } return null; }
Example #18
Source File: DirContextPoolableObjectFactory.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * @param contextSource * the contextSource to set */ public void setContextSource(ContextSource contextSource) { if (contextSource == null) { throw new IllegalArgumentException("contextSource may not be null"); } this.contextSource = contextSource; }
Example #19
Source File: AuthConfiguration.java From apollo with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public ContextSource ldapContextSource() { LdapContextSource source = new LdapContextSource(); source.setUserDn(this.properties.getUsername()); source.setPassword(this.properties.getPassword()); source.setAnonymousReadOnly(this.properties.getAnonymousReadOnly()); source.setBase(this.properties.getBase()); source.setUrls(this.properties.determineUrls(this.environment)); source.setBaseEnvironmentProperties( Collections.unmodifiableMap(this.properties.getBaseEnvironment())); return source; }
Example #20
Source File: LdapTestUtils.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * Clear the directory sub-tree starting with the node represented by the * supplied distinguished name. * * @param contextSource the ContextSource to use for getting a DirContext. * @param name the distinguished name of the root node. * @throws NamingException if anything goes wrong removing the sub-tree. */ public static void clearSubContexts(ContextSource contextSource, Name name) throws NamingException { DirContext ctx = null; try { ctx = contextSource.getReadWriteContext(); clearSubContexts(ctx, name); } finally { try { ctx.close(); } catch (Exception e) { // Never mind this } } }
Example #21
Source File: TransactionAwareDirContextInvocationHandler.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * Close the supplied context, but only if it is not associated with the * current transaction. * * @param context * the DirContext to close. * @param contextSource * the ContextSource bound to the transaction. * @throws NamingException */ void doCloseConnection(DirContext context, ContextSource contextSource) throws javax.naming.NamingException { DirContextHolder transactionContextHolder = (DirContextHolder) TransactionSynchronizationManager .getResource(contextSource); if (transactionContextHolder == null || transactionContextHolder.getCtx() != context) { log.debug("Closing context"); // This is not the transactional context or the transaction is // no longer active - we should close it. context.close(); } else { log.debug("Leaving transactional context open"); } }
Example #22
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void supportsMultipleUrls() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-multiurls.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); assertThat(outerContextSource).isNotNull(); assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" }, (Object[]) getInternalState(contextSource, "urls")); }
Example #23
Source File: TransactionAwareContextSourceProxy.java From spring-ldap with Apache License 2.0 | 5 votes |
private DirContext getTransactionAwareDirContextProxy(DirContext context, ContextSource target) { return (DirContext) Proxy .newProxyInstance(DirContextProxy.class.getClassLoader(), new Class[] { LdapUtils .getActualTargetClass(context), DirContextProxy.class }, new TransactionAwareDirContextInvocationHandler( context, target)); }
Example #24
Source File: TransactionAwareDirContextInvocationHandlerTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { dirContextMock = mock(DirContext.class); contextSourceMock = mock(ContextSource.class); holder = new DirContextHolder(null, dirContextMock); tested = new TransactionAwareDirContextInvocationHandler(null, null); }
Example #25
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void verifyParseWithCustomValues() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-values.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class); DirContextAuthenticationStrategy authenticationStrategy = ctx.getBean(DirContextAuthenticationStrategy.class); assertThat(outerContextSource).isNotNull(); assertThat(ldapTemplate).isNotNull(); assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(LdapUtils.newLdapName("dc=261consulting,dc=com")).isEqualTo(getInternalState(contextSource, "base")); assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn")); assertThat("apassword").isEqualTo(getInternalState(contextSource, "password")); assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls")); assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "pooled")); assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly")); assertThat("follow").isEqualTo(getInternalState(contextSource, "referral")); assertThat(authenticationStrategy).isSameAs(getInternalState(contextSource, "authenticationStrategy")); assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource")); assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException")); assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignoreNameNotFoundException")); assertThat(100).isEqualTo(getInternalState(ldapTemplate, "defaultCountLimit")); assertThat(200).isEqualTo(getInternalState(ldapTemplate, "defaultTimeLimit")); assertThat(SearchControls.OBJECT_SCOPE).isEqualTo(getInternalState(ldapTemplate, "defaultSearchScope")); }
Example #26
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void verifyThatAnonymousReadOnlyContextWillNotBeWrappedInProxy() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-anonymous-read-only.xml"); ContextSource contextSource = ctx.getBean(ContextSource.class); assertThat(contextSource).isNotNull(); assertThat(contextSource instanceof LdapContextSource).isTrue(); assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly")); }
Example #27
Source File: LdapTemplateNamespaceHandlerTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void verifyParseWithDefaultValues() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-defaults.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class); assertThat(outerContextSource).isNotNull(); assertThat(ldapTemplate).isNotNull(); assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(LdapUtils.emptyLdapName()).isEqualTo(getInternalState(contextSource, "base")); assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn")); assertThat("apassword").isEqualTo(getInternalState(contextSource, "password")); assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls")); assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "pooled")); assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly")); assertThat(getInternalState(contextSource, "referral")).isNull(); assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource")); assertThat(Boolean.FALSE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException")); assertThat(Boolean.FALSE).isEqualTo(getInternalState(ldapTemplate, "ignoreNameNotFoundException")); assertThat(0).isEqualTo(getInternalState(ldapTemplate, "defaultCountLimit")); assertThat(0).isEqualTo(getInternalState(ldapTemplate, "defaultTimeLimit")); assertThat(SearchControls.SUBTREE_SCOPE).isEqualTo(getInternalState(ldapTemplate, "defaultSearchScope")); }
Example #28
Source File: AbstractPoolTestCase.java From spring-ldap with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { contextMock = mock(Context.class); dirContextMock = mock(DirContext.class); ldapContextMock = mock(LdapContext.class); keyedObjectPoolMock = mock(KeyedObjectPool.class); contextSourceMock = mock(ContextSource.class); dirContextValidatorMock = mock(DirContextValidator.class); }
Example #29
Source File: ContextSourceTransactionManagerTest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testSetContextSource_Proxy() { TransactionAwareContextSourceProxy proxy = new TransactionAwareContextSourceProxy(contextSourceMock); // Perform test tested.setContextSource(proxy); ContextSource result = tested.getContextSource(); // Verify result assertThat(result).isSameAs(contextSourceMock); }
Example #30
Source File: DirContextPoolableObjectFactory.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * @param contextSource * the contextSource to set */ public void setContextSource(ContextSource contextSource) { if (contextSource == null) { throw new IllegalArgumentException("contextSource may not be null"); } this.contextSource = contextSource; }