@Override public Authentication authenticate(Authentication authentication) { LDAPAuthentication auth = (LDAPAuthentication) authentication; if (auth != null && supports(authentication.getClass())) { Map<String, String> ldapSettings = auth.getLdapSettings(); if (!ldapSettings.isEmpty()) { String adDomain = ldapSettings.get("security.ldap.active_directory_domain"); // set this to enable AD String ldapServerURL = ldapSettings.get("security.ldap.server_url"); String searchFilter = ldapSettings.get("security.ldap.user_search_filter"); AbstractLdapAuthenticationProvider ldapProvider; if (StringUtils.isBlank(adDomain)) { ldapProvider = new LdapAuthenticationProvider(new LDAPAuthenticator(ldapSettings)); } else { ldapProvider = new ActiveDirectoryLdapAuthenticationProvider(adDomain, ldapServerURL); ((ActiveDirectoryLdapAuthenticationProvider) ldapProvider).setConvertSubErrorCodesToExceptions(true); if (!StringUtils.isBlank(searchFilter)) { ((ActiveDirectoryLdapAuthenticationProvider) ldapProvider).setSearchFilter(searchFilter); } } ldapProvider.setUserDetailsContextMapper(new InetOrgPersonContextMapper()); return ldapProvider.authenticate(authentication); } else { throw new AuthenticationServiceException("LDAP configuration is missing."); } } else { throw new AuthenticationServiceException("Unsupported authentication type."); } }
@Override public Authentication authenticate(Authentication authentication) { LDAPAuthentication auth = (LDAPAuthentication) authentication; if (auth != null && supports(authentication.getClass())) { Map<String, String> ldapSettings = auth.getLdapSettings(); if (!ldapSettings.isEmpty()) { String adDomain = ldapSettings.get("security.ldap.active_directory_domain"); // set this to enable AD String ldapServerURL = ldapSettings.get("security.ldap.server_url"); String searchFilter = ldapSettings.get("security.ldap.user_search_filter"); AbstractLdapAuthenticationProvider ldapProvider; if (StringUtils.isBlank(adDomain)) { ldapProvider = new LdapAuthenticationProvider(new LDAPAuthenticator(ldapSettings)); } else { ldapProvider = new ActiveDirectoryLdapAuthenticationProvider(adDomain, ldapServerURL); ((ActiveDirectoryLdapAuthenticationProvider) ldapProvider).setConvertSubErrorCodesToExceptions(true); if (!StringUtils.isBlank(searchFilter)) { ((ActiveDirectoryLdapAuthenticationProvider) ldapProvider).setSearchFilter(searchFilter); } } ldapProvider.setUserDetailsContextMapper(new InetOrgPersonContextMapper()); return ldapProvider.authenticate(authentication); } else { throw new AuthenticationServiceException("LDAP configuration is missing."); } } else { throw new AuthenticationServiceException("Unsupported authentication type."); } }