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


Java InitialLdapContext类代码示例

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


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

示例1: getContext

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
private LdapContext getContext() throws Exception {
	Hashtable<String, String> envDC = new Hashtable<String, String>();
	envDC.put(
			Context.INITIAL_CONTEXT_FACTORY,
			"com.sun.jndi.ldap.LdapCtxFactory");
	envDC.put(
			Context.PROVIDER_URL,
			GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.url"));
	envDC.put(
			Context.SECURITY_AUTHENTICATION,
			"simple");
	envDC.put(
			Context.SECURITY_PRINCIPAL,
			GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.principal"));
	envDC.put(
			Context.SECURITY_CREDENTIALS,
			GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.credentials"));
	return new InitialLdapContext(envDC, null);
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:20,代码来源:PersonesPluginLdap.java

示例2: init

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
private void init()
        throws Exception 
{
    @SuppressWarnings("UseOfObsoleteCollectionType")
    Hashtable<String,String> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, sdsUrl);
    if (ConditionalCompilationControls.LDAPS && !ConditionalCompilationControls.OPENTEST) {
        env.put(Context.SECURITY_PROTOCOL, "ssl");
        env.put(Context.SECURITY_AUTHENTICATION, "none");
        if (ConditionalCompilationControls.LDAPOVERTLS && !ConditionalCompilationControls.OPENTEST) {
            env.put("java.naming.ldap.factory.socket", "org.warlock.spine.connection.SpineSecurityContext");
        }
    }
    ldapContext = new InitialLdapContext(env, null);
}
 
开发者ID:DamianJMurphy,项目名称:SpineTools-Java,代码行数:17,代码来源:SDSconnection.java

示例3: setSchemaContext

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
private void setSchemaContext(KdcConfiguration configuration, DirectoryService service,
                              String connectionUser)
        throws DirectoryServerException {
    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(DirectoryService.JNDI_KEY, service);
    env.put(Context.SECURITY_PRINCIPAL, connectionUser);
    env.put(Context.SECURITY_CREDENTIALS, configuration.getSystemAdminPassword());
    env.put(Context.SECURITY_AUTHENTICATION, ConfigurationConstants.SIMPLE_AUTHENTICATION);
    env.put(Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName());

    env.put(Context.PROVIDER_URL, SchemaConstants.OU_SCHEMA);

    try {
        schemaRoot = new InitialLdapContext(env, null);
    } catch (NamingException e) {
        throw new DirectoryServerException(
                "Unable to create Schema context with user " + connectionUser, e);
    }

}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:21,代码来源:ApacheKDCServer.java

示例4: bindDNReferralAuthentication

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
/**
 * This method validates absoluteName and credential against referral LDAP and returns used user DN.
 *
 * <ol>
 * <li> Parses given absoluteName to URL and DN
 * <li> creates initial LDAP context of referral LDAP to validate credential
 * <li> closes the initial context
 * </ol>
 *
 * It uses all options from login module setup except of ProviderURL.
 *
 * @param userDN - userDN which has to be used instead of parsed absoluteName (if is null, use absoluteName) - value is gained using distinguishedNameAttribute
 * @param absoluteName - absolute user DN
 * @param credential
 * @return used user DN for validation
 * @throws NamingException
 */
private String bindDNReferralAuthentication(final String userDN, String absoluteName, Object credential)
        throws NamingException
{
    URI uri;
    try {
        uri = new URI(absoluteName);
    }
    catch (URISyntaxException e)
    {
        throw PicketBoxMessages.MESSAGES.unableToParseReferralAbsoluteName(e, absoluteName);
    }
    String name = (userDN != null ? userDN : uri.getPath().substring(1));
    String namingProviderURL = uri.getScheme() + "://" + uri.getAuthority();

    Properties refEnv = constructLdapContextEnvironment(namingProviderURL, name, credential);

    InitialLdapContext refCtx = new InitialLdapContext(refEnv, null);
    refCtx.close();
 return name;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:38,代码来源:LdapExtLoginModule.java

示例5: testGetControlInstanceControl

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
/**
 * <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control)'</p>
 * <p>Here we are going to test if we can get an instance with the controls sended.</p>
 */
public void testGetControlInstanceControl() {

	try {
		
		Hashtable env = new Hashtable();
		env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
		MockControl[] cs = { new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }), 
				new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
		MockControl cs2 =  new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }); 
		InitialLdapContext ilc=new InitialLdapContext(env, cs);
		assertEquals(cs2,ControlFactory.getControlInstance(cs2,ilc,env));
		
	} catch (NamingException e) {
		
	}
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:TestControlFactoryWhiteBoxDevelopment.java

示例6: testReconnect003

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.reconnect(Control[])'
 * </p>
 * <p>
 * Here we are testing if this method correctly reconnects to the LDAP
 * server. In this case we are using a different set of controls for the
 * reconnection.
 * </p>
 * <p>
 * The expected result is a reconection with the new set of controls.
 * </p>
 */
public void testReconnect003() throws Exception {
    System
            .setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    Control[] cs = {
            new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
            new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
    Control[] cs2 = {
            new MockControl("c2", false, new byte[] { 1, 2, 3, 4 }),
            new MockControl("c2", true, new byte[] { 'a', 'b', 'c', 'd' }), };
    InitialLdapContext ilc = new InitialLdapContext(null, cs);
    ilc.reconnect(cs2);
    assertEquals(cs2, ilc.getConnectControls());
    ilc.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:30,代码来源:TestInitialLdapContext.java

示例7: testConnectControls3

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
public void testConnectControls3() throws Exception {
    // set connect controls by InitialLdapContext
    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
    InitialLdapContext initialDirContext = new InitialLdapContext(env,
            new Control[] { new SortControl("", Control.NONCRITICAL) });

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_SEARCH_RESULT_DONE,
            new EncodableLdapResult(), null) });
    LdapContext context = (LdapContext) initialDirContext.lookup("");

    Control[] controls = context.getConnectControls();
    assertNotNull(controls);
    assertEquals(1, controls.length);
    Control c = controls[0];
    assertTrue(c instanceof SortControl);
    assertEquals(Control.NONCRITICAL, c.isCritical());

}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:LdapContextServerMockedTest.java

示例8: findAccountByAccountName

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
/**
 * Find account by account name.
 *
 * @param accountName the account name
 * @return the search result
 * @throws NamingException the naming exception
 */
protected SearchResult findAccountByAccountName(String accountName) throws NamingException {
  String searchFilter = String.format(searchFilterPattern, accountName);
  SearchControls searchControls = new SearchControls();
  searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
  InitialLdapContext ctx = new InitialLdapContext(env, null);
  try {
    NamingEnumeration<SearchResult> results = ctx.search(searchBase, searchFilter, searchControls);
    if (!results.hasMoreElements()) {
      throw new UserConfigLoaderException("LDAP Search returned no accounts");
    }
    SearchResult searchResult = results.nextElement();
    if (results.hasMoreElements()) {
      throw new UserConfigLoaderException("More than one account found in ldap search");
    }
    return searchResult;
  } finally {
    ctx.close();
  }
}
 
开发者ID:apache,项目名称:lens,代码行数:27,代码来源:LDAPBackedDatabaseUserConfigLoader.java

示例9: testGetControlInstanceControl

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
/**
 * <p>Test method for 'javax.naming.ldap.ControlFactory.getControlInstance(Control)'</p>
 * <p>Here we are gonna test if we can get an instance with the controls sended.</p>
 */
public void testGetControlInstanceControl() {

	try {
		
		Hashtable env = new Hashtable();
		env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
		MockControl[] cs = { new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }), 
				new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
		MockControl cs2 =  new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }); 
		InitialLdapContext ilc=new InitialLdapContext(env, cs);
		assertEquals(cs2,ControlFactory.getControlInstance(cs2,ilc,env));
		
	} catch (NamingException e) {
		
	}
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:21,代码来源:TestControlFactoryWhiteBoxDevelopment.java

示例10: testReconnect003

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.reconnect(Control[])'
 * </p>
 * <p>
 * Here we are testing if this method reconnects to the LDAP server using
 * the supplied controls and this context's environment. In this case we are
 * sending a new set of controls to reconection.
 * </p>
 * <p>
 * The expected result is a reconection with the new set of controls.
 * </p>
 */
public void testReconnect003() throws Exception {
    System
            .setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    Control[] cs = {
            new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
            new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
    Control[] cs2 = {
            new MockControl("c2", false, new byte[] { 1, 2, 3, 4 }),
            new MockControl("c2", true, new byte[] { 'a', 'b', 'c', 'd' }), };
    InitialLdapContext ilc = new InitialLdapContext(null, cs);
    ilc.reconnect(cs2);
    assertEquals(cs2, ilc.getConnectControls());
    ilc.close();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:30,代码来源:TestInitialLdapContext.java

示例11: setUp

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
protected void setUp() throws Exception {
    super.setUp();
    configuration = new MutableServerStartupConfiguration();
    configuration.setWorkingDirectory(new File(workingDir));
    cleanWorkingDir(configuration.getWorkingDirectory());
    port = AvailablePortFinder.getNextAvailable(1024);
    configuration.setLdapPort(port);
    // configuration.setShutdownHookEnabled(false);
    serverEnv = new Hashtable<String, Object>(configuration
            .toJndiEnvironment());

    initialAuth();

    serverEnv.put(Context.INITIAL_CONTEXT_FACTORY,
            ServerContextFactory.class.getName());

    serverEnv.put(Context.PROVIDER_URL, "");
    rootDSE = new InitialLdapContext(serverEnv, null);

}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:21,代码来源:Support_LdapTest.java

示例12: getFullyQualifiedNameByUserId

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
protected String getFullyQualifiedNameByUserId(String userId) throws UnauthorizedOperationException {
	
	  env.put(Context.SECURITY_PRINCIPAL, ctxPrinciplePattern.replaceAll(userNamePattern, delegatedUserName));	
      env.put(Context.SECURITY_CREDENTIALS, delegatedUserPassword);
      try {
    	  LdapContext ctx = new InitialLdapContext(env,null);
	
    	  String searchFilter = searchFilterPattern.replaceAll(userNamePattern, userId);

    	  SearchControls searchControls = new SearchControls();
    	  searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    	  NamingEnumeration<SearchResult> results = ctx.search(ldapSearchBase,
    			  searchFilter, searchControls);

    	  SearchResult searchResult = null;
    	  if (results.hasMoreElements()) {
    		  searchResult = results.nextElement();
    		  return searchResult.getNameInNamespace();
    	  }
    	  return null;
      } catch (NamingException e) {
    	  throw new UnauthorizedOperationException(e.getMessage());
      }
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:25,代码来源:LDAPAuthenticator.java

示例13: createContext

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
public LdapContext createContext()
{
  init();
  final Hashtable<String, String> env;
  final String authentication = ldapConfig.getAuthentication();
  if ("none".equals(authentication) == false) {
    env = createEnv(ldapConfig.getManagerUser(), ldapConfig.getManagerPassword());
  } else {
    env = createEnv(null, null);
  }
  try {
    final LdapContext ctx = new InitialLdapContext(env, null);
    return ctx;
  } catch (final NamingException ex) {
    log.error("While trying to connect LDAP initally: " + ex.getMessage(), ex);
    throw new RuntimeException(ex);
  }
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:19,代码来源:LdapConnector.java

示例14: ActiveDirectory

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
public ActiveDirectory(String serverName, String username, String password,
		String domain) throws NamingException {
	if (StringUtils.isEmpty(domain))
		throw new NamingException("The domain is empty");
	Properties properties = new Properties();
	properties.put(Context.INITIAL_CONTEXT_FACTORY,
			"com.sun.jndi.ldap.LdapCtxFactory");

	domainSearchName = getDomainSearch(domain);
	String login = StringUtils.fastConcat(username, "@", domain);
	if (serverName != null) {
		properties.put(Context.PROVIDER_URL,
				StringUtils.fastConcat("ldap://", serverName, ":389"));
	}
	properties.put(Context.SECURITY_PRINCIPAL, login);
	properties.put(Context.SECURITY_CREDENTIALS, password);
	properties.put(Context.REFERRAL, "follow");
	properties.put("java.naming.ldap.attributes.binary", "objectSID");
	dirContext = new InitialLdapContext(properties, null);
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:21,代码来源:ActiveDirectory.java

示例15: getCurrentSession

import javax.naming.ldap.InitialLdapContext; //导入依赖的package包/类
/**
 * Return the session which the current thread holds. If not exist, a new
 * session will be created and bind to current thread.
 * 
 * @return
 */
@Override
public Session getCurrentSession() {
	Map.Entry<Session, InitialLdapContext> current = sessions.get();
	if (null == current) {
		try {
			InitialLdapContext ldapConnection = getContext();
			Session session = new SessionImpl(this, ldapConnection, true);
			current = new AbstractMap.SimpleEntry<Session, InitialLdapContext>(
					session, ldapConnection);
		} catch (NamingException e) {
			throw new ODMException("Cannot instantiate a session", e);
		}
	}
	return current.getKey();
}
 
开发者ID:xingyuli,项目名称:some-ldap,代码行数:22,代码来源:AbstractThreadLocalSessionFactory.java


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