List of usage examples for org.apache.shiro.realm.ldap DefaultLdapContextFactory setUrl
public void setUrl(String url)
From source file:org.apache.zeppelin.realm.ActiveDirectoryGroupRealm.java
License:Apache License
public LdapContextFactory getLdapContextFactory() { if (this.ldapContextFactory == null) { if (log.isDebugEnabled()) { log.debug("No LdapContextFactory specified - creating a default instance."); }/*w ww.j av a 2 s . c o m*/ DefaultLdapContextFactory defaultFactory = new DefaultLdapContextFactory(); defaultFactory.setPrincipalSuffix(this.principalSuffix); defaultFactory.setSearchBase(this.searchBase); defaultFactory.setUrl(this.url); defaultFactory.setSystemUsername(this.systemUsername); defaultFactory.setSystemPassword(getSystemPassword()); this.ldapContextFactory = defaultFactory; } return this.ldapContextFactory; }
From source file:org.sonatype.nexus.ldap.internal.realms.LdapConnectionUtils.java
License:Open Source License
public static LdapContextFactory getLdapContextFactory(final LdapConfiguration configuration, final TrustStore trustStore) throws LdapDAOException { if (configuration == null) { throw new LdapDAOException("Ldap connection is not configured."); }// ww w .j a v a 2 s .c o m DefaultLdapContextFactory defaultLdapContextFactory = new DefaultLdapContextFactory(); Connection connInfo = configuration.getConnection(); Host host = connInfo.getHost(); String url; try { url = new LdapURL(host.getProtocol().name(), host.getHostName(), host.getPort(), connInfo.getSearchBase()).toString(); } catch (MalformedURLException e) { // log an error, because the user could still log in and fix the config. log.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<>(); connectionProperties.put("com.sun.jndi.ldap.connect.timeout", Integer.toString(connInfo.getConnectionTimeout() * 1000)); // and the realm if (connInfo.getSaslRealm() != null) { connectionProperties.put("java.naming.security.sasl.realm", connInfo.getSaslRealm()); } defaultLdapContextFactory.setAdditionalEnvironment(connectionProperties); if (host.getProtocol() == Connection.Protocol.ldaps && connInfo.getUseTrustStore()) { SSLContext sslContext = trustStore.getSSLContext(); log.debug("Using Nexus SSL Trust Store for accessing {}:{}", host.getHostName(), host.getPort()); return new SSLLdapContextFactory(sslContext, defaultLdapContextFactory); } log.debug("Using JVM Trust Store for accessing {}:{}", host.getHostName(), host.getPort()); return defaultLdapContextFactory; }
From source file:org.sonatype.security.ldap.realms.SimpleLdapManager.java
License:Open Source License
protected LdapContextFactory getLdapContextFactory() throws LdapDAOException { DefaultLdapContextFactory defaultLdapContextFactory = new DefaultLdapContextFactory(); if (this.getLdapConfiguration() == null || this.getLdapConfiguration().readConnectionInfo() == null) { throw new LdapDAOException("Ldap connection is not configured."); }//from w ww.ja va 2s.co m CConnectionInfo connInfo = this.getLdapConfiguration().readConnectionInfo(); String url; try { 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. this.log.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()); return defaultLdapContextFactory; }
From source file:org.sonatype.security.realms.ldap.internal.realms.LdapConnectionUtils.java
License:Open Source License
public static DefaultLdapContextFactory getLdapContextFactory(LdapConfiguration ldapServer, boolean useBackupUrl) throws LdapDAOException { DefaultLdapContextFactory defaultLdapContextFactory = new DefaultLdapContextFactory(); if (ldapServer == null) { throw new LdapDAOException("Ldap connection is not configured."); }//from ww w .j a va 2 s.c o m Connection connInfo = ldapServer.getConnection(); String url; try { if (useBackupUrl) { url = new LdapURL(connInfo.getBackupHost().getProtocol().name(), connInfo.getBackupHost().getHostName(), connInfo.getBackupHost().getPort(), connInfo.getSearchBase()).toString(); } else { url = new LdapURL(connInfo.getHost().getProtocol().name(), connInfo.getHost().getHostName(), connInfo.getHost().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.getConnection().getConnectionTimeout() * 1000)); // and the realm if (connInfo.getSaslRealm() != null) { connectionProperties.put("java.naming.security.sasl.realm", connInfo.getSaslRealm()); } defaultLdapContextFactory.setAdditionalEnvironment(connectionProperties); return defaultLdapContextFactory; }