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


Java InitialLdapContext.close方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: createLdapInitContext

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * Bind to the LDAP server for authentication
 */
private boolean createLdapInitContext(String username, Object credential) throws Exception
{
   // Get the admin context for searching
   InitialLdapContext ctx = null;
   ClassLoader currentTCCL = SecurityActions.getContextClassLoader();
   try
   {
      if (currentTCCL != null)
         SecurityActions.setContextClassLoader(null);
      ctx = constructInitialLdapContext(bindDN, bindCredential);
      // Validate the user by binding against the userDN
      bindDNAuthentication(ctx, username, credential, baseDN, baseFilter);
   }
   catch(Exception e)
   {
 	  throw e;
   }
finally
   {
      if (ctx != null)
         ctx.close();
      if (currentTCCL != null)
         SecurityActions.setContextClassLoader(currentTCCL);
   }
   return true;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:30,代码来源:LdapUsersLoginModule.java

示例5: safeClose

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
protected void safeClose(InitialLdapContext ic)
{
	if(ic != null)
	{
		try
		{
			ic.close();
		}
		catch (NamingException e)
		{
		}
	}
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:14,代码来源:LdapCallbackHandler.java

示例6: testNewInstance002

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.newInstance(Control[])'
 * </p>
 * <p>
 * Here we are testing if this method correctly creates a new
 * InitialLdapContext instance. In this case we are using a non-null
 * parameter.
 * </p>
 * <p>
 * The expected result is a non-null InitialLdapContext.
 * </p>
 */
public void testNewInstance002() throws Exception {
    Hashtable env = new Hashtable();
    env.put(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' }), };
    InitialLdapContext x = new InitialLdapContext(env, null);
    InitialLdapContext t = (InitialLdapContext) x.newInstance(cs);
    assertNotNull(x);
    assertNotSame(x, t);
    x.close();
    t.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:TestInitialLdapContext.java

示例7: bindDNAuthentication

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
protected String bindDNAuthentication(InitialLdapContext ctx, String user, Object credential, String baseDN,
      String filter) throws NamingException
{
   SearchControls constraints = new SearchControls();
   constraints.setSearchScope(searchScope);
   constraints.setTimeLimit(searchTimeLimit);
   String attrList[] = {distinguishedNameAttribute};
   constraints.setReturningAttributes(attrList);

   NamingEnumeration<SearchResult> results = null;

   Object[] filterArgs = {user};
   results = ctx.search(baseDN, filter, filterArgs, constraints);
   if (!results.hasMore())
   {
      results.close();
      throw PicketBoxMessages.MESSAGES.failedToFindBaseContextDN(baseDN);
   }

   SearchResult sr = results.next();
   String name = sr.getName();
   String userDN = null;
   Attributes attrs = sr.getAttributes();
   if (attrs != null)
   {
      Attribute dn = attrs.get(distinguishedNameAttribute);
      if (dn != null)
      {
         userDN = (String) dn.get();
      }
   }
   if (userDN == null)
   {
      if (sr.isRelative())
         userDN = name + ("".equals(baseDN) ? "" : "," + baseDN);
      else
         throw PicketBoxMessages.MESSAGES.unableToFollowReferralForAuth(name);
   }

   results.close();
   results = null;
   // Bind as the user dn to authenticate the user
   InitialLdapContext userCtx = constructInitialLdapContext(userDN, credential);
   userCtx.close();

   return userDN;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:48,代码来源:LdapUsersLoginModule.java

示例8: testInitialLdapContextHashtableOfQQControlArray001

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.InitialLdapContext(Hashtable<?,
 * ?>, Control[])'
 * </p>
 * <p>
 * Here we are testing the constructor with two null arguments.
 * </p>
 * <p>
 * The expected result is an instance of this class.</p<
 */
public void testInitialLdapContextHashtableOfQQControlArray001()
        throws Exception {

    InitialLdapContext ilc = new InitialLdapContext(null, null);
    ilc.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:TestInitialLdapContext.java

示例9: testInitialLdapContextHashtableOfQQControlArray002

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.InitialLdapContext(Hashtable<?,
 * ?>, Control[])'
 * </p>
 * <p>
 * Here we are testing the constructor with two non-null arguments.
 * </p>
 * <p>
 * The expected result is an instance of this class.
 * </p>
 */
public void testInitialLdapContextHashtableOfQQControlArray002()
        throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    Control[] cs = { new MockControl("c1", false, new byte[4]),
            new MockControl("c1", true, new byte[4]) };

    InitialLdapContext ilc = new InitialLdapContext(env, cs);
    ilc.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:24,代码来源:TestInitialLdapContext.java

示例10: testInitialLdapContextHashtableOfQQControlArray004

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.InitialLdapContext(Hashtable<?,
 * ?>, Control[])'
 * </p>
 * <p>
 * Here we are testing the constructor with the INITIAL_CONTEXT_FACTORY
 * constant set to reference a correct class, but with no controls.
 * </p>
 * <p>
 * The expected result is an exception.
 * </p>
 */
public void testInitialLdapContextHashtableOfQQControlArray004()
        throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    Control[] cs = null;

    InitialLdapContext x = new InitialLdapContext(env, cs);
    assertNotNull(x);
    x.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:25,代码来源:TestInitialLdapContext.java

示例11: testInitialLdapContextHashtableOfQQControlArray005

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.InitialLdapContext(Hashtable<?,
 * ?>, Control[])'
 * </p>
 * <p>
 * Here we are testing the constructor with two non-null arguments. In this
 * case the hashtable is empty.
 * </p>
 * <p>
 * The expected result is a new InitialLdapContext instance.
 * </p>
 */
public void testInitialLdapContextHashtableOfQQControlArray005()
        throws Exception {
    Hashtable env = new Hashtable();
    Control[] cs = {
            new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
            new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };

    InitialLdapContext x = new InitialLdapContext(env, cs);
    x.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:25,代码来源:TestInitialLdapContext.java

示例12: testInitialLdapContextHashtableOfQQControlArray006

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.InitialLdapContext(Hashtable<?,
 * ?>, Control[])'
 * </p>
 * <p>
 * Here we are testing the constructor with two non-null arguments, and here
 * the hashtable is not empty but contains unsuitable data, and the Control
 * array is not empty.
 * </p>
 * <p>
 * The expected result is a new InitialLdapContext instance.
 * </p>
 */
public void testInitialLdapContextHashtableOfQQControlArray006()
        throws Exception {
    Control[] cf = {
            new MockControl("c1", false, new byte[] { 1, 2, 3, 4 }),
            new MockControl("c1", true, new byte[] { 'a', 'b', 'c', 'd' }), };
    Hashtable ht = new Hashtable();
    ht.put("one", new Integer(1));
    ht.put("two", new Integer(2));
    ht.put("three", new Integer(3));

    InitialLdapContext ilc = new InitialLdapContext(ht, cf);
    assertNotNull(ilc);
    ilc.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:30,代码来源:TestInitialLdapContext.java

示例13: testInitialLdapContextHashtableOfQQControlArray007

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.InitialLdapContext(Hashtable<?,
 * ?>, Control[])'
 * </p>
 * <p>
 * Here we are testing the constructor with two non-null arguments, and here
 * the hashtable is not empty but contains unsuitable data.
 * </p>
 * <p>
 * The expected result is a new InitialLdapContext instance.
 * </p>
 */
public void testInitialLdapContextHashtableOfQQControlArray007()
        throws Exception {
    Control[] cf = null;
    Hashtable ht = new Hashtable();
    ht.put("one", new Integer(1));
    ht.put("two", new Integer(2));
    ht.put("three", new Integer(3));

    InitialLdapContext ilc = new InitialLdapContext(ht, cf);
    assertNotNull(ilc);
    ilc.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:27,代码来源:TestInitialLdapContext.java

示例14: testExtendedOperation002

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.extendedOperation(ExtendedRequest)'
 * </p>
 * <p>
 * Here we are testing if this method correctly executes the given
 * operation. Here we send a non-null ExtendedRequest.
 * </p>
 * <p>
 * The expected result is an ExtendedResponse.
 * </p>
 */
public void testExtendedOperation002() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    InitialLdapContext x = new InitialLdapContext();
    StartTlsResponse f = (StartTlsResponse)x.extendedOperation(new StartTlsRequest());
    assertNotNull(f);
    x.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:TestInitialLdapContext.java

示例15: testNewInstance001

import javax.naming.ldap.InitialLdapContext; //导入方法依赖的package包/类
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.newInstance(Control[])'
 * </p>
 * <p>
 * Here we are testing if this method correctly creates a new
 * InitialLdapContext instance. In this case we are using null as a
 * parameter.
 * </p>
 * <p>
 * The expected result is a non-null InitialLdapContext.
 * </p>
 */
public void testNewInstance001() throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    InitialLdapContext x = new InitialLdapContext(env, null);
    InitialLdapContext t = (InitialLdapContext) x.newInstance(null);
    assertNotNull(t);
    assertNotSame(x, t);
    x.close();
    t.close();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:TestInitialLdapContext.java


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