当前位置: 首页>>代码示例>>Java>>正文


Java LdapContextSource类代码示例

本文整理汇总了Java中org.springframework.ldap.core.support.LdapContextSource的典型用法代码示例。如果您正苦于以下问题:Java LdapContextSource类的具体用法?Java LdapContextSource怎么用?Java LdapContextSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LdapContextSource类属于org.springframework.ldap.core.support包,在下文中一共展示了LdapContextSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startLDAPServer

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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_________");
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:18,代码来源:LDAPIdentityServiceImplTest.java

示例2: loadData

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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"));
}
 
开发者ID:geoserver,项目名称:geofence,代码行数:19,代码来源:BaseDAOTest.java

示例3: buildContextTemplate

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:17,代码来源:Spring_Ldap.java

示例4: createUserSearch

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的package包/类
/**
 * Creates LDAP User search
 * @param properties Properties POJO
 * @return LDAP User search
 */
public static LdapUserSearch createUserSearch(LdapProperties properties, LdapContextSource source) {
    UserProperties userProperties = properties.getUser();

    switch (userProperties.getType()) {
        case kerberos:
            return ldapKerberosUserSearch(userProperties, source);
        case filter:
            return ldapFilteredUserSearch(userProperties, source);
        case dn:
            return ldapFullDnUserSearch(source);
        default:
            log.warn("Failed to create LDAP User search with type {}.", userProperties.getType());
            return null;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:21,代码来源:LdapFactory.java

示例5: createAuthoritiesPopulator

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的package包/类
/**
 * Creates LDAP authorities populator
 * @param properties Properties POJO
 * @return LDAP authorities populator
 */
public static UasAuthoritiesPopulator createAuthoritiesPopulator(LdapProperties properties, LdapContextSource source) {
    GroupProperties groupProperties = properties.getGroup();

    UasAuthoritiesPopulator populator;
    switch (groupProperties.getType()) {
        case ad:
            populator = ldapADAuthoritiesPopulator(groupProperties);
            break;
        case other:
            populator = ldapOtherAuthoritiesPopulator(groupProperties, source);
            break;
        default:
            log.warn("Failed to create LDAP Authorities populator with type {}.", groupProperties.getType());
            return null;
    }

    Map<String, String> permissionMap = groupProperties.getPermissionMap();
    if (permissionMap != null && !permissionMap.isEmpty()) {
        return new RewriteAuthoritiesPopulator(populator, permissionMap);
    } else {
        return populator;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:29,代码来源:LdapFactory.java

示例6: init

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:LdapLoginProvider.java

示例7: init

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:18,代码来源:LdapAuthProvider.java

示例8: supports

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:29,代码来源:LdapUserGroupAccessor.java

示例9: createInstance

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的package包/类
@Override
protected LdapContextSource createInstance() throws Exception {
    ContextSourceBuilder contextSourceBuilder = new ContextSourceBuilder();

    contextSourceBuilder
            .root(environment.getProperty("context-source-base"));

    // set up embedded mode
    if (environment.getProperty("embedded", boolean.class, false)) {
        contextSourceBuilder.ldif("classpath:/ldap/gravitee-io-management-rest-api-ldap-test.ldif");
    } else {
        contextSourceBuilder
                .managerDn(environment.getProperty("context-source-username"))
                .managerPassword(environment.getProperty("context-source-password"))
                .url(environment.getProperty("context-source-url"));
    }

    ldapContextSource = contextSourceBuilder.build();
    return ldapContextSource;
}
 
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:21,代码来源:LdapContextSourceFactory.java

示例10: init

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的package包/类
public void init(LdapContextSource contextSource, LdapSetting ldapSetting) {
    Assert.notNull(contextSource, "contextSource must not be null.");
    this.contextSource = contextSource;
    boolean hasDnPattern = StringUtils.hasText(ldapSetting.getUserDnPattern());
    SearchPattern search = ldapSetting.getSearch();
    boolean hasSearch = search != null && StringUtils.hasText(search.getSearchFilter());
    Assert.isTrue(hasDnPattern || hasSearch,
            "An Authentication pattern should provide a userDnPattern or a searchFilter (or both)");

    if (hasDnPattern) {
        setUserDnPatterns(new String[]{ldapSetting.getUserDnPattern()});
    }

    if (hasSearch) {
        this.userSearches = getLdapGroupAddon().getLdapUserSearches(contextSource, ldapSetting);
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:18,代码来源:ArtifactoryBindAuthenticator.java

示例11: SimpleLDAPAuthenticationProvider

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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();
}
 
开发者ID:mcraken,项目名称:spring-scaffy,代码行数:20,代码来源:SimpleLDAPAuthenticationProvider.java

示例12: LdapCredentialsAuthenticator

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的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);
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:25,代码来源:LdapCredentialsAuthenticator.java

示例13: buildDB

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的package包/类
@Before @Override
  public void buildDB() throws Exception {
  	super.buildDB ();

  	
// Bind to the LDAP directory:
final LdapContextSource contextSource = new LdapContextSource ();
contextSource.setUrl ("ldap://127.0.0.1:" + PORT + "/dc=inspire,dc=idgis,dc=eu");
contextSource.setUserDn (PRINCIPAL);
contextSource.setPassword (CREDENTIALS);
contextSource.setPooled (false);
contextSource.afterPropertiesSet ();

// Create an LDAP template:
ldapTemplate = new LdapTemplate (contextSource);

LdapTestUtils.cleanAndSetup (ldapTemplate.getContextSource (), new DistinguishedName (), new ClassPathResource ("nl/ipo/cds/dao/testdata.ldif"));

((ManagerDaoImpl)managerDao).setLdapTemplate (ldapTemplate);

      entityManager.flush ();
  }
 
开发者ID:CDS-INSPIRE,项目名称:InSpider,代码行数:23,代码来源:BaseLdapManagerDaoTest.java

示例14: init

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的package包/类
public void init() throws Exception {
    if (!useLdapAuth()) {
        return;
    }
    LdapContextSource contextSource = new DefaultSpringSecurityContextSource(ldapHost);
    contextSource.setUserDn(ldapUsername);
    contextSource.setPassword(ldapPassword);
    contextSource.afterPropertiesSet();

    DefaultLdapAuthoritiesPopulator ldapAuthoritiesPopulator =
            new DefaultLdapAuthoritiesPopulator(contextSource, ldapGroupSearchBase);
    ldapAuthoritiesPopulator.setGroupRoleAttribute(ldapGroupRoleAttribute);
    ldapAuthoritiesPopulator.setGroupSearchFilter(ldapGroupSearchFilter);

    ldapBindAuthenticator = new SimpleBindAunthenticator(contextSource, gizmoGroup);
    ldapBindAuthenticator.setUserDnPatterns(new String[]{userDnPattern});
}
 
开发者ID:Evolveum,项目名称:gizmo-v3,代码行数:18,代码来源:GizmoAuthProvider.java

示例15: testGetReadOnlyContext

import org.springframework.ldap.core.support.LdapContextSource; //导入依赖的package包/类
@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
			}
		}
	}
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:25,代码来源:LdapContextSourceIntegrationTest.java


注:本文中的org.springframework.ldap.core.support.LdapContextSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。