當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。