core/cas-server-core-configuration/src/main/java/org/apereo/cas/configuration/support/Beans.java
/**
     * New connection config connection config.
     *
     * @param l the ldap properties
     * @return the connection config
     */
New connection config connection config.
@param l the ldap properties
@return the connection config
New connection config connection config . @param l the ldap properties @return the connection config
public static ConnectionConfig newConnectionConfig(final AbstractLdapProperties l) {
        final ConnectionConfig cc = new ConnectionConfig();
        cc.setLdapUrl(l.getLdapUrl());
        cc.setUseSSL(l.isUseSsl());
        cc.setUseStartTLS(l.isUseStartTls());
        cc.setConnectTimeout(newDuration(l.getConnectTimeout()));
        if (l.getTrustCertificates() != null) {
            final X509CredentialConfig cfg = new X509CredentialConfig();
            cfg.setTrustCertificates(l.getTrustCertificates());
            cc.setSslConfig(new SslConfig(cfg));
        } else if (l.getKeystore() != null) {
            final KeyStoreCredentialConfig cfg = new KeyStoreCredentialConfig();
            cfg.setKeyStore(l.getKeystore());
            cfg.setKeyStorePassword(l.getKeystorePassword());
            cfg.setKeyStoreType(l.getKeystoreType());
            cc.setSslConfig(new SslConfig(cfg));
        } else {
            cc.setSslConfig(new SslConfig());
        }
        if (l.getSaslMechanism() != null) {
            final BindConnectionInitializer bc = new BindConnectionInitializer();
            final SaslConfig sc;
            switch (l.getSaslMechanism()) {
                case DIGEST_MD5:
                    sc = new DigestMd5Config();
                    ((DigestMd5Config) sc).setRealm(l.getSaslRealm());
                    break;
                case CRAM_MD5:
                    sc = new CramMd5Config();
                    break;
                case EXTERNAL:
                    sc = new ExternalConfig();
                    break;
                case GSSAPI:
                    sc = new GssApiConfig();
                    ((GssApiConfig) sc).setRealm(l.getSaslRealm());
                    break;
                default:
                    throw new IllegalArgumentException("Unknown SASL mechanism " + l.getSaslMechanism().name());
            }
            sc.setAuthorizationId(l.getSaslAuthorizationId());
            sc.setMutualAuthentication(l.getSaslMutualAuth());
            sc.setQualityOfProtection(l.getSaslQualityOfProtection());
            sc.setSecurityStrength(l.getSaslSecurityStrength());
            bc.setBindSaslConfig(sc);
            cc.setConnectionInitializer(bc);
        } else if (StringUtils.equals(l.getBindCredential(), "*") && StringUtils.equals(l.getBindDn(), "*")) {
            cc.setConnectionInitializer(new FastBindOperation.FastBindConnectionInitializer());
        } else if (StringUtils.isNotBlank(l.getBindDn()) && StringUtils.isNotBlank(l.getBindCredential())) {
            cc.setConnectionInitializer(new BindConnectionInitializer(l.getBindDn(), new Credential(l.getBindCredential())));
        }
        return cc;
    }
public static ConnectionConfig newConnectionConfig ( final AbstractLdapProperties l ) { final ConnectionConfig cc = new ConnectionConfig ( ) ; cc . setLdapUrl ( l . getLdapUrl ( ) ) ; cc . setUseSSL ( l . isUseSsl ( ) ) ; cc . setUseStartTLS ( l . isUseStartTls ( ) ) ; cc . setConnectTimeout ( newDuration ( l . getConnectTimeout ( ) ) ) ; if ( l . getTrustCertificates ( ) != null ) { final X509CredentialConfig cfg = new X509CredentialConfig ( ) ; cfg . setTrustCertificates ( l . getTrustCertificates ( ) ) ; cc . setSslConfig ( new SslConfig ( cfg ) ) ; } else if ( l . getKeystore ( ) != null ) { final KeyStoreCredentialConfig cfg = new KeyStoreCredentialConfig ( ) ; cfg . setKeyStore ( l . getKeystore ( ) ) ; cfg . setKeyStorePassword ( l . getKeystorePassword ( ) ) ; cfg . setKeyStoreType ( l . getKeystoreType ( ) ) ; cc . setSslConfig ( new SslConfig ( cfg ) ) ; } else { cc . setSslConfig ( new SslConfig ( ) ) ; } if ( l . getSaslMechanism ( ) != null ) { final BindConnectionInitializer bc = new BindConnectionInitializer ( ) ; final SaslConfig sc ; switch ( l . getSaslMechanism ( ) ) { case DIGEST_MD5 : sc = new DigestMd5Config ( ) ; ( ( DigestMd5Config ) sc ) . setRealm ( l . getSaslRealm ( ) ) ; break ; case CRAM_MD5 : sc = new CramMd5Config ( ) ; break ; case EXTERNAL : sc = new ExternalConfig ( ) ; break ; case GSSAPI : sc = new GssApiConfig ( ) ; ( ( GssApiConfig ) sc ) . setRealm ( l . getSaslRealm ( ) ) ; break ; default : throw new IllegalArgumentException ( "Unknown SASL mechanism " + l . getSaslMechanism ( ) . name ( ) ) ; } sc . setAuthorizationId ( l . getSaslAuthorizationId ( ) ) ; sc . setMutualAuthentication ( l . getSaslMutualAuth ( ) ) ; sc . setQualityOfProtection ( l . getSaslQualityOfProtection ( ) ) ; sc . setSecurityStrength ( l . getSaslSecurityStrength ( ) ) ; bc . setBindSaslConfig ( sc ) ; cc . setConnectionInitializer ( bc ) ; } else if ( StringUtils . equals ( l . getBindCredential ( ) , "*" ) && StringUtils . equals ( l . getBindDn ( ) , "*" ) ) { cc . setConnectionInitializer ( new FastBindOperation . FastBindConnectionInitializer ( ) ) ; } else if ( StringUtils . isNotBlank ( l . getBindDn ( ) ) && StringUtils . isNotBlank ( l . getBindCredential ( ) ) ) { cc . setConnectionInitializer ( new BindConnectionInitializer ( l . getBindDn ( ) , new Credential ( l . getBindCredential ( ) ) ) ) ; } return cc ; }
New connection config connection config.
New connection config connection config .