当前位置: 首页>>代码示例>>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;未经允许,请勿转载。