final AbstractTlsDirContextAuthenticationStrategy tlsAuthenticationStrategy = new DefaultTlsDirContextAuthenticationStrategy();
@Override protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException { super.applyAuthentication(ctx, userDn, password); ctx.reconnect(ctx.getConnectControls()); } }
void setTls(LdapContextSource ldapContextSource) { // set tls logger.debug("Ldap TLS enabled."); DefaultTlsDirContextAuthenticationStrategy tls = new DefaultTlsDirContextAuthenticationStrategy(); tls.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); tls.setSslSocketFactory(new DummySSLSocketFactory()); ldapContextSource.setAuthenticationStrategy(tls); }
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) { DefaultTlsDirContextAuthenticationStrategy authenticationStrategy = new DefaultTlsDirContextAuthenticationStrategy(); authenticationStrategy.setHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return hostname.equals(dnsName); } }); ctx.setAuthenticationStrategy(authenticationStrategy); ctx.setPooled(false); } }
/** * Creates an LdapContext from a configuration object. * * @param ldapConfig */ public static LdapContextSource createLdapContext(LDAPBaseSecurityServiceConfig ldapConfig) { LdapContextSource ldapContext = new DefaultSpringSecurityContextSource(ldapConfig.getServerURL()); ldapContext.setCacheEnvironmentProperties(false); ldapContext.setAuthenticationSource(new SpringSecurityAuthenticationSource()); if (ldapConfig.isUseTLS()) { // TLS does not play nicely with pooled connections ldapContext.setPooled(false); DefaultTlsDirContextAuthenticationStrategy tls = new DefaultTlsDirContextAuthenticationStrategy(); tls.setHostnameVerifier( new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); ldapContext.setAuthenticationStrategy(tls); } return ldapContext; }
final AbstractTlsDirContextAuthenticationStrategy tlsAuthenticationStrategy = new DefaultTlsDirContextAuthenticationStrategy();
@Test public void applyAuthenticationThenReconnectInvoked() throws Exception { this.strategy.applyAuthentication(this.context, "username", "password"); verify(this.context).reconnect(null); } }
final AbstractTlsDirContextAuthenticationStrategy tlsAuthenticationStrategy = new DefaultTlsDirContextAuthenticationStrategy();
final AbstractTlsDirContextAuthenticationStrategy tlsAuthenticationStrategy = new DefaultTlsDirContextAuthenticationStrategy();