public Hashtable getEnvironment()

in redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/DefaultLdapConnection.java [134:236]


    public Hashtable<Object, Object> getEnvironment()
        throws LdapException
    {
        Properties env = new Properties();

        env.putAll( config.getExtraProperties() );

        config.check();

        env.put( Context.INITIAL_CONTEXT_FACTORY, config.getContextFactory() );

        // REDBACK-289/MRM-1488
        // enable connection pooling when using Sun's LDAP context factory
        if ( config.getContextFactory().equals( "com.sun.jndi.ldap.LdapCtxFactory" ) )
        {
            env.put( "com.sun.jndi.ldap.connect.pool", "true" );

            env.put( "com.sun.jndi.ldap.connect.pool.timeout", "3600" );
        }

        if ( config.getHostname() != null )
        {
            String protocol = "ldap";// config.isSsl() ? "ldaps" : "ldap";
            if ( config.getPort() != 0 )
            {
                env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + ":" + config.getPort() + "/" );
            }
            else
            {
                env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + "/" );
            }
        }

        if ( config.isSsl() )
        {
            env.put( Context.SECURITY_PROTOCOL, "ssl" );
        }

        if ( config.getAuthenticationMethod() != null )
        {
            env.put( Context.SECURITY_AUTHENTICATION, config.getAuthenticationMethod() );
        }

        if ( config.getBindDn() != null )
        {
            env.put( Context.SECURITY_PRINCIPAL, config.getBindDn().toString() );
        }

        if ( config.getPassword() != null )
        {
            env.put( Context.SECURITY_CREDENTIALS, config.getPassword() );
        }

        // ----------------------------------------------------------------------
        // Object Factories
        // ----------------------------------------------------------------------

        String objectFactories = null;

        for ( Class<?> objectFactoryClass : config.getObjectFactories() )
        {
            if ( objectFactories == null )
            {
                objectFactories = objectFactoryClass.getName();
            }
            else
            {
                objectFactories += ":" + objectFactoryClass.getName();
            }
        }

        if ( objectFactories != null )
        {
            env.setProperty( Context.OBJECT_FACTORIES, objectFactories );
        }

        // ----------------------------------------------------------------------
        // State Factories
        // ----------------------------------------------------------------------

        String stateFactories = null;

        for ( Class<?> stateFactoryClass : config.getStateFactories() )
        {
            if ( stateFactories == null )
            {
                stateFactories = stateFactoryClass.getName();
            }
            else
            {
                stateFactories += ":" + stateFactoryClass.getName();
            }
        }

        if ( stateFactories != null )
        {
            env.setProperty( Context.STATE_FACTORIES, stateFactories );
        }

        log.debug( "env properties: {}", env );

        return env;
    }