Package org.sonatype.security.ldap.realms

Examples of org.sonatype.security.ldap.realms.DefaultLdapContextFactory


  public static DefaultLdapContextFactory getLdapContextFactory(CLdapServerConfiguration ldapServer,
                                                                boolean useBackupUrl)
      throws LdapDAOException
  {
    DefaultLdapContextFactory defaultLdapContextFactory = new DefaultLdapContextFactory();

    if (ldapServer == null) {
      throw new LdapDAOException("Ldap connection is not configured.");
    }

    CConnectionInfo connInfo = ldapServer.getConnectionInfo();

    String url;
    try {
      if (useBackupUrl) {
        url = new LdapURL(connInfo.getBackupMirrorProtocol(), connInfo.getBackupMirrorHost(), connInfo
            .getBackupMirrorPort(), connInfo.getSearchBase()).toString();
      }
      else {
        url = new LdapURL(connInfo.getProtocol(), connInfo.getHost(), connInfo.getPort(), connInfo
            .getSearchBase()).toString();
      }
    }
    catch (MalformedURLException e) {
      // log an error, because the user could still log in and fix the config.
      logger.error("LDAP Configuration is Invalid.");
      throw new LdapDAOException("Invalid LDAP URL: " + e.getMessage());
    }

    defaultLdapContextFactory.setUsePooling(true);
    defaultLdapContextFactory.setUrl(url);
    defaultLdapContextFactory.setSystemUsername(connInfo.getSystemUsername());
    defaultLdapContextFactory.setSystemPassword(connInfo.getSystemPassword());
    defaultLdapContextFactory.setSearchBase(connInfo.getSearchBase());
    defaultLdapContextFactory.setAuthentication(connInfo.getAuthScheme());

    // get the timeout
    Map<String, String> connectionProperties = new HashMap<String, String>();
    connectionProperties.put("com.sun.jndi.ldap.connect.timeout",
        Integer.toString(ldapServer.getConnectionInfo().getConnectionTimeout() * 1000));

    // and the realm
    if (connInfo.getRealm() != null) {
      connectionProperties.put("java.naming.security.sasl.realm", connInfo.getRealm());
    }
    defaultLdapContextFactory.setAdditionalEnvironment(connectionProperties);

    return defaultLdapContextFactory;
  }
View Full Code Here


  }

  private LdapContextFactory getLdapContextFactory(CLdapServerConfiguration ldapServer, boolean useBackupUrl)
      throws LdapDAOException
  {
    final DefaultLdapContextFactory ldapContextFactory = LdapConnectionUtils.getLdapContextFactory(
        ldapServer, useBackupUrl
    );
    final TrustStoreKey key = ldapTrustStoreKey(ldapServer.getId() == null ? "<unknown>" : ldapServer.getId());
    if ("ldaps".equals(ldapServer.getConnectionInfo().getProtocol())) {
      final SSLContext sslContext = trustStore.getSSLContextFor(key);
View Full Code Here

  protected LdapContextFactory buildDefaultLdapContextFactory(final String ldapServerId,
                                                              final CConnectionInfo connectionDto)
      throws MalformedURLException
  {
    DefaultLdapContextFactory ldapContextFactory = new DefaultLdapContextFactory();
    ldapContextFactory.setAuthentication(connectionDto.getAuthScheme());
    ldapContextFactory.setSearchBase(connectionDto.getSearchBase());
    ldapContextFactory.setSystemPassword(connectionDto.getSystemPassword());
    ldapContextFactory.setSystemUsername(connectionDto.getSystemUsername());
    ldapContextFactory.setUrl(new LdapURL(connectionDto.getProtocol(), connectionDto.getHost(), connectionDto
        .getPort(), connectionDto.getSearchBase()).toString());
    ldapContextFactory.setAuthentication(connectionDto.getAuthScheme());

    final TrustStoreKey key = ldapTrustStoreKey(ldapServerId == null ? "<unknown>" : ldapServerId);
    if ("ldaps".equals(connectionDto.getProtocol())) {
      final SSLContext sslContext = trustStore.getSSLContextFor(key);
      if (sslContext != null) {
View Full Code Here

TOP

Related Classes of org.sonatype.security.ldap.realms.DefaultLdapContextFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.