List of usage examples for javax.naming.directory InitialDirContext lookup
public Object lookup(String name) throws NamingException
From source file:org.apache.syncope.core.rest.AbstractTest.java
@SuppressWarnings({ "unchecked", "rawtypes", "UseOfObsoleteCollectionType" }) protected Object getLdapRemoteObject(final String bindDn, final String bindPwd, final String objectDn) { ResourceTO ldapRes = resourceService.read(RESOURCE_NAME_LDAP); final Map<String, ConnConfProperty> ldapConnConf = connectorService.read(ldapRes.getConnectorId()) .getConfigurationMap();//from ww w. j a va 2 s . co m Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://" + ldapConnConf.get("host").getValues().get(0) + ":" + ldapConnConf.get("port").getValues().get(0) + "/"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, bindDn == null ? ldapConnConf.get("principal").getValues().get(0) : bindDn); env.put(Context.SECURITY_CREDENTIALS, bindPwd == null ? ldapConnConf.get("credentials").getValues().get(0) : bindPwd); try { final InitialDirContext ctx = new InitialDirContext(env); return ctx.lookup(objectDn); } catch (Exception e) { return null; } }
From source file:org.apache.syncope.fit.AbstractITCase.java
protected Object getLdapRemoteObject(final String bindDn, final String bindPwd, final String objectDn) { InitialDirContext ctx = null; try {/* w w w . ja v a 2s . c o m*/ ctx = getLdapResourceDirContext(bindDn, bindPwd); return ctx.lookup(objectDn); } catch (Exception e) { return null; } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { // ignore } } } }