本文整理匯總了Java中org.springframework.ldap.core.LdapTemplate類的典型用法代碼示例。如果您正苦於以下問題:Java LdapTemplate類的具體用法?Java LdapTemplate怎麽用?Java LdapTemplate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LdapTemplate類屬於org.springframework.ldap.core包,在下文中一共展示了LdapTemplate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startLDAPServer
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
@BeforeClass
public static void startLDAPServer() throws Exception {
LdapTestUtils.startApacheDirectoryServer(PORT, baseName.toString(), "test", PRINCIPAL, CREDENTIALS, null);
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://127.0.0.1:" + PORT);
contextSource.setUserDn("");
contextSource.setPassword("");
contextSource.setPooled(false);
contextSource.afterPropertiesSet();
// Create the Sprint LDAP template
LdapTemplate template = new LdapTemplate(contextSource);
// Clear out any old data - and load the test data
LdapTestUtils.cleanAndSetup(template.getContextSource(), baseName, new ClassPathResource("ldap/testdata.ldif"));
System.out.println("____________Started LDAP_________");
}
示例2: loadData
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
protected static void loadData() throws Exception
{
// Bind to the directory
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://127.0.0.1:10389");
contextSource.setUserDn("uid=admin,ou=system");
contextSource.setPassword("secret");
contextSource.setPooled(false);
//contextSource.setDirObjectFactory(null);
contextSource.afterPropertiesSet();
// Create the Sprint LDAP template
LdapTemplate template = new LdapTemplate(contextSource);
// Clear out any old data - and load the test data
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("dc=example,dc=com"));
LdapTestUtils.loadLdif(contextSource, new ClassPathResource("data.ldif"));
}
示例3: removeUserSchema
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
/**
* Mock a managed LDAP schema violation
*/
@Test
public void removeUserSchema() {
thrown.expect(ValidationJsonException.class);
thrown.expect(MatcherUtil.validationMatcher("groups", "last-member-of-group"));
final GroupLdapRepository groupRepository = new GroupLdapRepository() {
@Override
public GroupOrg findById(final String name) {
// The group has only the user user we want to remove
return new GroupOrg("dc=" + name, name, Collections.singleton("flast1"));
}
};
groupRepository.setLdapCacheRepository(Mockito.mock(LdapCacheRepository.class));
final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
groupRepository.setTemplate(ldapTemplate);
Mockito.doThrow(new org.springframework.ldap.SchemaViolationException(new SchemaViolationException("any"))).when(ldapTemplate)
.modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());
removeUser(groupRepository);
}
示例4: buildContextTemplate
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
private LdapTemplate buildContextTemplate ()
throws Exception {
LdapTemplate ldapSpringTemplate = new LdapTemplate();
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUserDn( ldapUser );
contextSource.setPassword( ldapPass );
contextSource.setUrl( ldapUrl );
// Critical: Spring beans must be initialized, and JavaConfig requires
// explicity calls
contextSource.afterPropertiesSet();
ldapSpringTemplate.setContextSource( contextSource );
ldapSpringTemplate.afterPropertiesSet();
return ldapSpringTemplate;
}
示例5: addUser
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
@Test
public void addUser() {
final Set<String> users = new HashSet<>();
final GroupLdapRepository groupRepository = new GroupLdapRepository() {
@Override
public GroupOrg findById(final String name) {
return new GroupOrg("dc=" + name, name, users);
}
};
final LdapCacheRepository cacheRepository = Mockito.mock(LdapCacheRepository.class);
groupRepository.setLdapCacheRepository(cacheRepository);
final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
groupRepository.setTemplate(ldapTemplate);
addUser(groupRepository);
Mockito.verify(cacheRepository, VerificationModeFactory.times(1)).addUserToGroup(ArgumentMatchers.any(UserOrg.class),
ArgumentMatchers.any(GroupOrg.class));
}
示例6: addUserAlreadyMember
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
@Test
public void addUserAlreadyMember() {
final Set<String> users = new HashSet<>();
users.add("flast1");
final GroupLdapRepository groupRepository = new GroupLdapRepository() {
@Override
public GroupOrg findById(final String name) {
return new GroupOrg("dc=" + name, name, users);
}
};
final LdapCacheRepository cacheRepository = Mockito.mock(LdapCacheRepository.class);
groupRepository.setLdapCacheRepository(cacheRepository);
final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
groupRepository.setTemplate(ldapTemplate);
addUser(groupRepository);
Assert.assertEquals(1, users.size());
Assert.assertTrue(users.contains("flast1"));
}
示例7: removeUserSync
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
/**
* Mock a managed LDAP desynchronization
*/
@Test
public void removeUserSync() {
final GroupLdapRepository groupRepository = new GroupLdapRepository() {
@Override
public GroupOrg findById(final String name) {
// The group has only the user user we want to remove
return new GroupOrg("dc=" + name, name, Collections.singleton("flast1"));
}
};
groupRepository.setLdapCacheRepository(Mockito.mock(LdapCacheRepository.class));
final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
groupRepository.setTemplate(ldapTemplate);
Mockito.doThrow(new org.springframework.ldap.AttributeInUseException(new AttributeInUseException("any"))).when(ldapTemplate)
.modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());
removeUser(groupRepository);
}
示例8: queryVulnerableToInjection
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
public void queryVulnerableToInjection(LdapTemplate template, String jndiInjectMe, SearchControls searchControls, DirContextProcessor dirContextProcessor) throws NamingException {
template.list(jndiInjectMe);
template.list(jndiInjectMe, new DefaultNameClassPairMapper());
template.list(jndiInjectMe, new CountNameClassPairCallbackHandler());
template.lookup(jndiInjectMe);
template.lookup(jndiInjectMe, new DefaultIncrementalAttributesMapper());
template.lookup(jndiInjectMe, new LdapEntryIdentificationContextMapper());
template.search(jndiInjectMe,"dn=1",searchControls,new CountNameClassPairCallbackHandler());
template.search(jndiInjectMe,"dn=1",searchControls,new DefaultIncrementalAttributesMapper(), dirContextProcessor);
template.search(jndiInjectMe,"dn=1",searchControls,new LdapEntryIdentificationContextMapper(),dirContextProcessor);
template.search(jndiInjectMe,"dn=1",searchControls,new CountNameClassPairCallbackHandler(),dirContextProcessor);
template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,true,new CountNameClassPairCallbackHandler());
template.search(jndiInjectMe,"dn=1",new CountNameClassPairCallbackHandler());
template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new String[0],new DefaultIncrementalAttributesMapper());
template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new DefaultIncrementalAttributesMapper());
template.search(jndiInjectMe,"dn=1",new DefaultIncrementalAttributesMapper());
template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new String[0],new LdapEntryIdentificationContextMapper());
template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new LdapEntryIdentificationContextMapper());
template.search(jndiInjectMe,"dn=1",new LdapEntryIdentificationContextMapper());
template.search(jndiInjectMe,"dn=1",searchControls,new LdapEntryIdentificationContextMapper());
template.search(jndiInjectMe,"dn=1",searchControls, new DefaultIncrementalAttributesMapper());
}
示例9: init
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
@PostConstruct
protected void init() {
if (webLdapConfig.getLdapEnabled()) {
ldapContextSource = new LdapContextSource();
checkRequiredConfigProperties(webLdapConfig);
ldapContextSource.setBase(webLdapConfig.getLdapBase());
List<String> ldapUrls = webLdapConfig.getLdapUrls();
ldapContextSource.setUrls(ldapUrls.toArray(new String[ldapUrls.size()]));
ldapContextSource.setUserDn(webLdapConfig.getLdapUser());
ldapContextSource.setPassword(webLdapConfig.getLdapPassword());
ldapContextSource.afterPropertiesSet();
ldapTemplate = new LdapTemplate(ldapContextSource);
ldapTemplate.setIgnorePartialResultException(true);
}
}
示例10: init
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ldapContextSource = new LdapContextSource();
checkRequiredConfigProperties(webLdapConfig);
ldapContextSource.setBase(webLdapConfig.getLdapBase());
List<String> ldapUrls = webLdapConfig.getLdapUrls();
ldapContextSource.setUrls(ldapUrls.toArray(new String[ldapUrls.size()]));
ldapContextSource.setUserDn(webLdapConfig.getLdapUser());
ldapContextSource.setPassword(webLdapConfig.getLdapPassword());
ldapContextSource.afterPropertiesSet();
ldapTemplate = new LdapTemplate(ldapContextSource);
ldapTemplate.setIgnorePartialResultException(true);
}
示例11: supports
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public boolean supports(ExternalSystemConfiguration externalConfiguration) {
if (!(externalConfiguration instanceof LdapConfiguration)) {
return false;
}
try {
ldapConfiguration = (LdapConfiguration) externalConfiguration;
groupSearch = new LdapGroupSearch(ldapConfiguration);
LdapGroupAttributesMapper ldapGroupAttributesMapper = new LdapGroupAttributesMapper(
ldapConfiguration.getGroupSyncConfig()
.getGroupSearch().getPropertyMapping(),
ldapConfiguration.getSystemId(),
ldapConfiguration
.getGroupSyncConfig().isGroupIdentifierIsBinary());
retriever = new MemberAndNonMemberModeVisitingRetriever(null, ldapConfiguration,
timeout, pagingSize, -1, isPagingAllowed, ldapGroupAttributesMapper);
LdapContextSource context = LdapSearchUtils.createLdapContext(ldapConfiguration,
ldapGroupAttributesMapper);
groupRetrievalLdapTemplate = new LdapTemplate(context);
return true;
} catch (Exception e) {
LOGGER.error("There was an error initializing the LDAP group search.", e);
}
return false;
}
示例12: updateLdapUidToLdapDn
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
private void updateLdapUidToLdapDn() {
if(!isLdapServerExist()){
return;
}
if(!isBindingExist()){
return;
}
try {
LdapTemplateContextSource ldapTemplateContextSource = readLdapServerConfiguration();
LdapTemplate ldapTemplate = ldapTemplateContextSource.getLdapTemplate();
List<LdapAccountRefVO> refs = Q.New(LdapAccountRefVO.class).list();
for(LdapAccountRefVO ref : refs){
update(ldapTemplate, ref);
}
}catch (Throwable t){
logger.error("update ldapUid to ldapDn An error occurred", t);
}
}
示例13: getDnFromUserName
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
@Override
@SuppressWarnings({"unchecked"})
public LdapUser getDnFromUserName(LdapSetting ldapSetting, String userName) {
if (ldapSetting == null) {
log.warn("Cannot find user '{}' in LDAP: No LDAP settings defined.", userName);
return null;
}
if (!ldapSetting.isEnabled()) {
log.warn("Cannot find user '{}' in LDAP: LDAP settings not enabled.", userName);
return null;
}
if (ldapSetting.getSearch() == null || isBlank(ldapSetting.getSearch().getSearchFilter())) {
log.warn("Cannot find user '{}' in LDAP: No search filter defined.", userName);
return null;
}
LdapTemplate ldapTemplate = createLdapTemplate(ldapSetting);
return getUserFromLdapSearch(ldapTemplate, userName, ldapSetting);
}
示例14: SimpleLDAPAuthenticationProvider
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
public SimpleLDAPAuthenticationProvider(EntityManager entityManager,
String ldapUrl, String ldapUserDn, String ldapPassword,
String ldapBase, String ldapUid) throws Exception {
this.entityManager = entityManager;
this.ldapBase = ldapBase;
this.ldapUid = ldapUid;
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl(ldapUrl);
contextSource.setUserDn(ldapUserDn);
contextSource.setPassword(ldapPassword);
contextSource.afterPropertiesSet();
ldapTemplate = new LdapTemplate(contextSource);
ldapTemplate.afterPropertiesSet();
}
示例15: LdapCredentialsAuthenticator
import org.springframework.ldap.core.LdapTemplate; //導入依賴的package包/類
/**
* This constructor creates a LdapCredentialsAuthenticator that authenticates against an LDAP server
* that supports anonymous requests
*
* @param ldapHost the LDAP server host
* @param ldapPort the LDAP server port
* @param usersOuPath the path for the organizational unit under which users are found
*/
public LdapCredentialsAuthenticator(final String ldapHost,
final int ldapPort,
final String usersOuPath) {
Assert.hasText(ldapHost, "Invalid ldapHost");
Assert.isTrue(ldapPort > 0);
Assert.hasText(usersOuPath, "Invalid usersOuPath");
final LdapContextSource contextSource = new LdapContextSource();
contextSource.setAnonymousReadOnly(true);
contextSource.setUrl("ldap://" + ldapHost + ":" + ldapPort);
contextSource.setBase(usersOuPath);
contextSource.afterPropertiesSet();
ldapTemplate = new LdapTemplate(contextSource);
this.id = calculateId(ldapHost, ldapPort, usersOuPath);
}