Java 8 InitialLdapContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 InitialLdapContext class.

This code example shows how to use the following methods:
 
    // if want to use explicitly ApacheDS and not the Sun supplied ones 
    // env.put( Context.PROVIDER_URL, "o=sonatype" ); 
    // env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.directory.server.jndi.ServerContextFactory" ); 
 
    InitialLdapContext initialContext = new InitialLdapContext(new Hashtable<String, Object>(env), null);
 
    LdapAuthConfiguration configuration = new LdapAuthConfiguration();
    configuration.setUserBaseDn("ou=people");
    configuration.setGroupBaseDn("ou=groups");
    configuration.setGroupObjectClass("groupOfUniqueNames");
    configuration.setGroupMemberAttribute("uniqueMember");
    configuration.setGroupMemberFormat(groupMemberFormat);
    configuration.setLdapGroupsAsRoles(true);
    configuration.setUserMemberOfAttribute("");
 
    LdapGroupDAO lgm = (LdapGroupDAO) lookup(LdapGroupDAO.class.getName());
 
    Set<String> groups = lgm.getGroupMembership("cstamas", initialContext, configuration);
    assertTrue(groups.contains("public"));

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    // if want to use explicitly ApacheDS and not the Sun supplied ones 
    // env.put( Context.PROVIDER_URL, "o=sonatype" ); 
    // env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.directory.server.jndi.ServerContextFactory" ); 
 
    InitialLdapContext initialContext = new InitialLdapContext(new Hashtable<String, Object>(env), null);
 
    LdapAuthConfiguration configuration = new LdapAuthConfiguration();
    configuration.setUserBaseDn("ou=people");
    configuration.setGroupBaseDn("ou=groups");
    configuration.setGroupObjectClass("groupOfUniqueNames");
    configuration.setGroupMemberAttribute("uniqueMember");
    configuration.setUserRealNameAttribute("cn");
 
    LdapUserDAO lum = (LdapUserDAO) lookup(LdapUserDAO.class.getName());
 
    LdapUser user = lum.getUser("cstamas", initialContext, configuration);
    assertEquals("cstamas", user.getUsername());
    // assertEquals( "Tamas Cservenak", user.getRealName() ); 
    assertEquals("cstamas123", user.getPassword());

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    // if want to use explicitly ApacheDS and not the Sun supplied ones 
    // env.put( Context.PROVIDER_URL, "o=sonatype" ); 
    // env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.directory.server.jndi.ServerContextFactory" ); 
 
    InitialLdapContext initialContext = new InitialLdapContext(new Hashtable<String, Object>(env), null);
 
    LdapAuthConfiguration configuration = new LdapAuthConfiguration();
    configuration.setUserBaseDn("ou=people");
    // configuration.setGroupBaseDn( "ou=groups" ); 
    // configuration.setGroupObjectClass( "groupOfUniqueNames" ); 
    // configuration.setGroupMemberAttribute( "uniqueMember" ); 
    configuration.setUserRealNameAttribute("cn");
    configuration.setUserMemberOfAttribute("businesscategory");
    configuration.setLdapGroupsAsRoles(true);
 
    LdapUserDAO lum = (LdapUserDAO) lookup(LdapUserDAO.class.getName());
 
    LdapUser user = lum.getUser("cstamas", initialContext, configuration);
    assertEquals("cstamas", user.getUsername());

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        this.convertSubErrorCodesToExceptions = convertSubErrorCodesToExceptions;
    } 
 
    static class ContextFactory { 
        DirContext createContext(Hashtable<?,?> env) throws NamingException {
            return new InitialLdapContext(env, null);
        } 
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
            logger.debug("Authentication {}", this.config.getProperty(Context.SECURITY_AUTHENTICATION));
            logger.debug("Protocol {}",  this.config.getProperty(Context.SECURITY_PROTOCOL));
            logger.debug("Provider URL {}",  this.config.getProperty(Context.PROVIDER_URL));
        } 
         
        return new InitialLdapContext(this.config, null);
    } 
     
	protected int parseSearchScope(String searchScope) {
		logger.debug("Search scope: {}", searchScope);
		if ("OBJECT_SCOPE".equals(searchScope))
			return 0; 
		else if ("ONELEVEL_SCOPE".equals(searchScope))
			return 1; 
		else if ("SUBTREE_SCOPE".equals(searchScope))
			return 2; 
 
		// Default set to ONELEVEL_SCOPE 
		return 1; 
	} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
            logger.debug("Authentication {}", this.config.getProperty(Context.SECURITY_AUTHENTICATION));
            logger.debug("Protocol {}",  this.config.getProperty(Context.SECURITY_PROTOCOL));
            logger.debug("Provider URL {}",  this.config.getProperty(Context.PROVIDER_URL));
        } 
         
        return new InitialLdapContext(this.config, null);
    } 
     
    protected String searchLdap(String context, String filter, String attrId, OrganizationalEntity entity) {
        InitialLdapContext ctx = null;
        String result = null;
        try { 
            ctx = buildInitialLdapContext();
            String entityId =  entity.getId();
            if (Boolean.parseBoolean(this.config.getProperty(IS_ENTITY_ID_DN, "false"))) {
                entityId = extractUserId(entityId, entity);
            } 
            filter = filter.replaceAll("\\{0\\}",entityId);
             
            SearchControls constraints = new SearchControls();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getSchema
	public Control[] getResponseControls() throws NamingException {
		return initCtx.getResponseControls();
	} 
 
	public DirContext getSchema(Name name) throws NamingException {
		return initCtx.getSchema(name);
	} 
 
	public DirContext getSchema(String name) throws NamingException {
		return initCtx.getSchema(name);
	} 
 
	public DirContext getSchemaClassDefinition(Name name)
			throws NamingException {
		return initCtx.getSchemaClassDefinition(name);
	} 
 
	public DirContext getSchemaClassDefinition(String name)
			throws NamingException {
		return initCtx.getSchemaClassDefinition(name);
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:destroySubcontext, createSubcontext, setRequestControls
        env.put( "java.naming.ldap.version", "3" ); 
        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
        env.put( Context.SECURITY_CREDENTIALS, "secret" );
        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
        InitialLdapContext ctx = new InitialLdapContext( env, null );
 
        Attributes user = new BasicAttributes( "cn", "Kate Bush", true );
        Attribute oc = new BasicAttribute( "objectClass" );
        oc.add( "top" );
        oc.add( "person" );
        oc.add( "organizationalPerson" );
        oc.add( "inetOrgPerson" );
        user.put( oc );
        user.put( "sn", "Bush" );
        user.put( "userPassword", "Aerial" );
        ctx.setRequestControls( JndiUtils.toJndiControls( getLdapServer().getDirectoryService().getLdapCodecService(),
            new Control[] 
                { unsupported } ) ); 
 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        if (ldapLoginPassword != null && ldapLoginPassword.length() > 0) {
            env.put(Context.SECURITY_CREDENTIALS, ldapLoginPassword);
        } 
        env.put(Context.PROVIDER_URL, ldapUrl);
        try { 
            ctx = new InitialLdapContext(env, null);
        } catch (NamingException e) {
            throw new NamingException("Instantiation of Ldap Context failed");
        } 
        return ctx;
    } 
 
    /** 
     * Converts a binary SID to a string 
     */ 
    private static String binaryToStringSID(byte[] sidBytes) {
        StringBuilder sidString = new StringBuilder();
        sidString.append("S-");
        // Add SID revision 
        sidString.append(Byte.toString(sidBytes[0]));
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    private LdapContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext)
        throws NamingException, IOException {
        Hashtable<String, String> environment = getEnvironment(principal, password, providerUrl, isSystemContext);
        s_logger.debug("initializing ldap with provider url: " + environment.get(Context.PROVIDER_URL));
        return new InitialLdapContext(environment, null);
    } 
 
    public LdapContext createUserContext(final String principal, final String password) throws NamingException, IOException {
        return createInitialDirContext(principal, password, false);
    } 
 
    private void enableSSL(final Hashtable<String, String> environment) {
        final boolean sslStatus = _ldapConfiguration.getSSLStatus();
 
        if (sslStatus) {
            s_logger.info("LDAP SSL enabled."); 
            environment.put(Context.SECURITY_PROTOCOL, "ssl");
            System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore());
            System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword());
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 InitialLdapContext Methods: