當前位置: 首頁>>代碼示例>>Java>>正文


Java LdapContext.close方法代碼示例

本文整理匯總了Java中javax.naming.ldap.LdapContext.close方法的典型用法代碼示例。如果您正苦於以下問題:Java LdapContext.close方法的具體用法?Java LdapContext.close怎麽用?Java LdapContext.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.naming.ldap.LdapContext的用法示例。


在下文中一共展示了LdapContext.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getGroup

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Group getGroup(String groupName) throws GroupNotFoundException {
    LdapContext ctx = null;
    try {
        String groupDN = manager.findGroupDN(groupName);
        // Load record.
        ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
        Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);

        return processGroup(ctx, attrs);
    }
    catch (Exception e) {
        Log.error(e.getMessage(), e);
        throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
    }
    finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
}
 
開發者ID:coodeer,項目名稱:g3server,代碼行數:27,代碼來源:LdapGroupProvider.java

示例2: clearLdapContext

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
private void clearLdapContext(String action) {

        try {
            loggerInfo("LDAPContext", "清空", "開始", action);

            if (ldapContexts.containsKey(action)) {
                LdapContext context = ldapContexts.get(action);
                context.close();
                context = null;
                ldapContexts.remove(action);
            }

            loggerInfo("LDAPContext", "清空", "完成", action);
        }
        catch (Exception e) {
            loggerError("LDAPContext清空", action, e);
        }

    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:20,代碼來源:GUISSOLdapClient.java

示例3: verifyPassword

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
 * Verifies that the password supplied is actually the user's password, by
 * attempting to rebind to a copy of the LDAP server context using the user's 
 * username and the supplied password.
 * 
 * @param password
 *            The password to validate.
 * @return <code>True</code> if a connection can successfully be established
 *         to the LDAP host using the user's id and the supplied password,
 *         and <code>False</code> otherwise.
 */
public boolean verifyPassword(String password) {
    boolean result = false;
    LdapContext ldapContext = null;
    try {
        ldapContext = _ldapContext.newInstance(null);
        ldapContext.addToEnvironment(Context.SECURITY_AUTHENTICATION,
                LdapConstants.SECURITY_AUTHENTICATION_SIMPLE);
        ldapContext.addToEnvironment(Context.SECURITY_PRINCIPAL, _userDN);
        ldapContext.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
        ldapContext.reconnect(null);
        result = true;
    } catch (NamingException exception) {
        // no-op
    } finally {
        if (null != ldapContext) {
            try {
                ldapContext.close();
            } catch (NamingException ex) {
                // no-op
            }
        }
    }
    return result;
}
 
開發者ID:twachan,項目名稱:James,代碼行數:36,代碼來源:ReadOnlyLDAPUser.java

示例4: getByDn

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Attributes getByDn(final String dn) throws NamingException {
    LdapContext ctx = new InitialLdapContext(env, null);
    Attributes result = ctx.getAttributes(dn);
    ctx.close();

    return result;
}
 
開發者ID:klenkes74,項目名稱:openshift-ldapsync,代碼行數:8,代碼來源:LdapServer.java

示例5: search

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public NamingEnumeration<SearchResult> search(final String baseDN, final String filter) throws NamingException {
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    LdapContext ctx = new InitialLdapContext(env, null);
    NamingEnumeration<SearchResult> result = ctx.search(baseDN, filter, searchControls);
    ctx.close();

    return result;
}
 
開發者ID:klenkes74,項目名稱:openshift-ldapsync,代碼行數:11,代碼來源:LdapServer.java

示例6: closeContext

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
private void closeContext(final LdapContext context) {
    try {
        if (context != null) {
            context.close();
        }
    } catch (final NamingException e) {
        s_logger.warn(e.getMessage(), e);
    }
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:10,代碼來源:LdapManagerImpl.java

示例7: closeContext

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
 * Closes an LDAP context, logging any errors, but not throwing
 * an exception if there is a failure.
 *
 * @param ctx the LDAP context to close.
 */
public static void closeContext(LdapContext ctx) {
    try {
        if (ctx != null) {
            ctx.close();
        }
    } catch (NamingException e) {
        log.error("Exception while closing LDAP context. ", e);
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:16,代碼來源:LdapUtils.java

示例8: getUser

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Binding getUser(long companyId, String screenName) throws Exception {

		LdapContext ctx = getContext(companyId);

		if (ctx == null) {
			return null;
		}

		String baseDN = PrefsPropsUtil.getString(companyId,
				PropsKeys.LDAP_BASE_DN);

		Properties userMappings = getUserMappings(companyId);

		StringBuilder filter = new StringBuilder();

		filter.append(StringPool.OPEN_PARENTHESIS);
		filter.append(userMappings.getProperty("screenName"));
		filter.append(StringPool.EQUAL);
		filter.append(screenName);
		filter.append(StringPool.CLOSE_PARENTHESIS);

		SearchControls cons = new SearchControls(SearchControls.SUBTREE_SCOPE,
				1, 0, null, false, false);

		NamingEnumeration<SearchResult> enu = ctx.search(baseDN,
				filter.toString(), cons);
		//System.out.println("TTTTTTTTT " + baseDN + " --------- "  + filter.toString() + "  ==== " + cons + "");
		ctx.close();

		if (enu.hasMoreElements()) {
			Binding binding = enu.nextElement();
		//	System.out.println("TTTTTTTTT " + binding);
			return binding;
		} else {
			return null;
		}
	}
 
開發者ID:openegovplatform,項目名稱:OEPv2,代碼行數:38,代碼來源:ManagerLdap.java

示例9: getUser

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public Binding getUser(LdapContext ctx, long companyId, String screenName) throws Exception {


		if (ctx == null) {
			return null;
		}

		String baseDN = PrefsPropsUtil.getString(companyId,
				PropsKeys.LDAP_BASE_DN);

		Properties userMappings = getUserMappings(companyId);

		StringBuilder filter = new StringBuilder();

		filter.append(StringPool.OPEN_PARENTHESIS);
		filter.append(userMappings.getProperty("screenName"));
		filter.append(StringPool.EQUAL);
		filter.append(screenName);
		filter.append(StringPool.CLOSE_PARENTHESIS);

		SearchControls cons = new SearchControls(SearchControls.SUBTREE_SCOPE,
				1, 0, null, false, false);

		NamingEnumeration<SearchResult> enu = ctx.search(baseDN,
				filter.toString(), cons);
		///System.out.println("TTTTTTTTT " + baseDN + " --------- "  + filter.toString() + "  ==== " + cons + "");
		ctx.close();

		if (enu.hasMoreElements()) {
			Binding binding = enu.nextElement();
		//	System.out.println("TTTTTTTTT " + binding);
			return binding;
		} else {
			return null;
		}
	}
 
開發者ID:openegovplatform,項目名稱:OEPv2,代碼行數:37,代碼來源:EmployeeExportToLdap.java

示例10: getLdapUser

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
static TPersonBean getLdapUser(String providerUrl, String bindDN, String bindPassword, String loginAttributeName, String searchStr) throws Exception {
	LdapContext ctx = null;
	try {
		ctx = getInitialContext(providerUrl, bindDN, bindPassword);
		if (ctx == null) {
			LOGGER.warn("The context is null");
		}
		// Control the search
		SearchControls ctls = new SearchControls();
		ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
		// Don't ask for more than we can handle anyways
		if (ldapMap == null || ldapMap.isEmpty()) {
			LOGGER.error("There is no LDAP mapping in quartz-jobs.xml. Please provide!");
			return null;
		}
		String firstNameAttributeName = ldapMap.get(LdapUtil.LDAP_CONFIG.FIRST_NAME);
		String lastNameAttributName = ldapMap.get(LdapUtil.LDAP_CONFIG.LAST_NAME);
		String emailAttributeName = ldapMap.get(LdapUtil.LDAP_CONFIG.EMAIL);
		String phoneAttributName = ldapMap.get(LdapUtil.LDAP_CONFIG.PHONE);
		NamingEnumeration<SearchResult> results = ctx.search("", searchStr, ctls);
		/* for each entry print out name + all attrs and values */
		while (results != null && results.hasMore()) {
			SearchResult sr = (SearchResult) results.next();
			return getPersonBean(sr, loginAttributeName, firstNameAttributeName, lastNameAttributName, emailAttributeName, phoneAttributName);
		}
	} catch (NamingException e) {
		LOGGER.warn("Searching from " + providerUrl + " by filter " + searchStr + " failed with " + e.getMessage());
		LOGGER.debug(ExceptionUtils.getStackTrace(e));
	} finally {
		if (ctx != null) {
			ctx.close();
		}
	}
	return null;
}
 
開發者ID:trackplus,項目名稱:Genji,代碼行數:36,代碼來源:LdapUtil.java

示例11: getGroup

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
@Override
public Group getGroup(String groupName) throws GroupNotFoundException {
    LdapContext ctx = null;
    try {
        String groupDN = manager.findGroupDN(groupName);
        // Load record.
        ctx = manager.getContext(manager.getGroupsBaseDN(groupName));
        Attributes attrs = ctx.getAttributes(groupDN, standardAttributes);

        return processGroup(ctx, attrs);
    }
    catch (Exception e) {
        Log.error(e.getMessage(), e);
        throw new GroupNotFoundException("Group with name " + groupName + " not found.", e);
    }
    finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
}
 
開發者ID:igniterealtime,項目名稱:Openfire,代碼行數:28,代碼來源:LdapGroupProvider.java

示例12: main

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
 * The main.
 * 
 * @param args
 * @throws NamingException
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 */
public static void main(String[] args) throws NamingException, NoSuchAlgorithmException, KeyManagementException {
    String ldapUrl = "ldap://[::1]:10389";

    if (Boolean.parseBoolean(System.getProperty("ldaptest.ssl"))) {
        SSLContext sslCtx = SSLContext.getInstance("TLS");
        sslCtx.init(null, new TrustManager[] { new NoVerificationTrustManager() }, new SecureRandom());
        SSLContext.setDefault(sslCtx);
        ldapUrl = "ldaps://[::1]:10636";
    }
    final Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ldapUrl);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    final LdapContext ctx = new InitialLdapContext(env, null);

    // ctx.setRequestControls(null);
    final SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    NamingEnumeration<?> namingEnum = ctx.search("dc=jboss,dc=org", "(uid=*)", searchControls);
    while (namingEnum.hasMore()) {
        SearchResult sr = (SearchResult) namingEnum.next();
        Attributes attrs = sr.getAttributes();
        System.out.println(attrs.get("cn"));
    }
    namingEnum.close();
    ctx.close();
}
 
開發者ID:kwart,項目名稱:ldap-server,代碼行數:38,代碼來源:LdapTest.java

示例13: main

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
 * The main.
 * 
 * @param args
 * @throws NamingException
 */
public static void main(String[] args) {
    if (args == null || args.length != 3) {
        System.err.println("Simple LDAP authenticator");
        System.err.println();
        System.err.println("Usage:");
        System.err.println("\tjava " + Authenticate.class.getName() + " <ldapURL> <userDN> <password>");
        System.err.println();
        System.err.println("Example:");
        System.err.println(
                "\tjava -cp ldap-server.jar org.jboss.test.ldap.Authenticate ldap://localhost:10389 uid=jduke,ou=Users,dc=jboss,dc=org theduke");
        System.err.println();
        System.err.println("Exit codes:");
        System.err.println("\t0\tAuthentication succeeded");
        System.err.println("\t1\tWrong parameters count");
        System.err.println("\t2\tAuthentication failed");
        System.exit(1);
    }
    final Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.PROVIDER_URL, args[0]);
    env.put(Context.SECURITY_PRINCIPAL, args[1]);
    env.put(Context.SECURITY_CREDENTIALS, args[2]);
    int exitCode = 2;
    try {
        final LdapContext ctx = new InitialLdapContext(env, null);
        System.out.println("User is authenticated");
        exitCode = 0;
        ctx.close();
    } catch (NamingException e) {
        e.printStackTrace();
    }
    System.exit(exitCode);
}
 
開發者ID:kwart,項目名稱:ldap-server,代碼行數:41,代碼來源:Authenticate.java

示例14: findRolsAmbCodi

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public List<String> findRolsAmbCodi(String codi) throws PersonesPluginException {
	List<String> roles = new ArrayList<String>();
	
	String userFilter = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.filter.user");
	String filter = new String(userFilter).replace("###", codi);
	
	String roleAtt = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.attribute.role");
	String roleName = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.attribute.role.name");
	
	if (roleAtt != null && roleName != null) {
		LdapContext ctx = null;
		
		try {
			ctx = getContext();
			SearchControls searchCtls = new SearchControls();
			searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
			NamingEnumeration<SearchResult> answer = ctx.search(
					GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.searchbase"),
					filter,
					searchCtls);
			
			if (answer.hasMoreElements()) {
				SearchResult sr = (SearchResult)answer.next();
				Attribute memberOf = sr.getAttributes().get(roleAtt);
				if (memberOf != null) {
					for (int i = 0; i < memberOf.size(); i++) {
						Attributes atts = ctx.getAttributes(memberOf.get(i).toString(), new String[] {roleName});
						Attribute att = atts.get(roleName);
						if (att.get() != null)
							roles.add(att.get().toString());
					}
				}
			}
			ctx.close();
		} catch (Exception ex) {
			throw new PersonesPluginException("No s'ha pogut trobar cap persona", ex);
		}
	}
	
	return roles;
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:42,代碼來源:PersonesPluginLdap.java

示例15: findPersonesLdap

import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
private List<DadesPersona> findPersonesLdap(String filter) throws Exception {
	String[] returnedAtts = GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.attributes").split(",");
	LdapContext ctx = getContext();
	SearchControls searchCtls = new SearchControls();
	//searchCtls.setReturningAttributes(returnedAtts);
	searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
	NamingEnumeration<SearchResult> answer = ctx.search(
			GlobalProperties.getInstance().getProperty("app.persones.plugin.ldap.search.base"),
			filter,
			searchCtls);
	List<DadesPersona> resposta = new ArrayList<DadesPersona>();
	while (answer.hasMoreElements()) {
		SearchResult sr = (SearchResult)answer.next();
		Attributes attrs = sr.getAttributes();
		String codi = (String)attrs.get(returnedAtts[0]).get();
		String nom = (String)attrs.get(returnedAtts[1]).get();
		String llinatges = null;
		if (returnedAtts.length > 2 && attrs.get(returnedAtts[2]) != null)
			llinatges = (String)attrs.get(returnedAtts[2]).get();
		String dni = null;
		if (returnedAtts.length > 3 && attrs.get(returnedAtts[3]) != null)
			dni = (String)attrs.get(returnedAtts[3]).get();
		String email = null;
		if (returnedAtts.length > 4 && attrs.get(returnedAtts[4]) != null)
			email = construirEmail((String)attrs.get(returnedAtts[4]).get());
		String contrasenya = null;
		if (returnedAtts.length > 5 && attrs.get(returnedAtts[5]) != null)
			contrasenya = new String((byte[])attrs.get(returnedAtts[5]).get());
		DadesPersona persona = new DadesPersona(
				codi,
				nom,
				llinatges,
				email,
				sexePerNom(nom));
		persona.setDni(dni);
		persona.setContrasenya(contrasenya);
		resposta.add(persona);
	}
	ctx.close();
	return resposta;
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:42,代碼來源:PersonesPluginLdap.java


注:本文中的javax.naming.ldap.LdapContext.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。