use of org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider in project atlas by apache.
the class AtlasADAuthenticationProvider method getADAuthentication.
private Authentication getADAuthentication(Authentication authentication) {
try {
String userName = authentication.getName();
String userPassword = "";
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
ActiveDirectoryLdapAuthenticationProvider adAuthenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(adDomain, adURL);
adAuthenticationProvider.setConvertSubErrorCodesToExceptions(true);
adAuthenticationProvider.setUseAuthenticationRequestCredentials(true);
adAuthenticationProvider.setSearchFilter(adUserSearchFilter);
if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
final UserDetails principal = new User(userName, userPassword, grantedAuths);
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
authentication = adAuthenticationProvider.authenticate(finalAuthentication);
if (groupsFromUGI) {
authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
}
return authentication;
} else {
LOG.error("AD Authentication Failed userName or userPassword is null or empty");
return null;
}
} catch (Exception e) {
LOG.error("AD Authentication Failed:", e);
return null;
}
}
use of org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider in project incubator-atlas by apache.
the class AtlasADAuthenticationProvider method getADAuthentication.
private Authentication getADAuthentication(Authentication authentication) {
try {
String userName = authentication.getName();
String userPassword = "";
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
ActiveDirectoryLdapAuthenticationProvider adAuthenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(adDomain, adURL);
adAuthenticationProvider.setConvertSubErrorCodesToExceptions(true);
adAuthenticationProvider.setUseAuthenticationRequestCredentials(true);
if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
final UserDetails principal = new User(userName, userPassword, grantedAuths);
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
authentication = adAuthenticationProvider.authenticate(finalAuthentication);
if (groupsFromUGI) {
authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
}
return authentication;
} else {
LOG.error("AD Authentication Failed userName or userPassword is null or empty");
return null;
}
} catch (Exception e) {
LOG.error("AD Authentication Failed:", e);
return null;
}
}
use of org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider in project service-authorization by reportportal.
the class ActiveDirectoryAuthProvider method getDelegate.
@Override
protected AuthenticationProvider getDelegate() {
Integration integration = integrationRepository.findAllByTypeIn(AuthIntegrationType.ACTIVE_DIRECTORY.getName()).stream().findFirst().orElseThrow(() -> new BadCredentialsException("Active Directory is not configured"));
ActiveDirectoryLdapAuthenticationProvider adAuth = new ActiveDirectoryLdapAuthenticationProvider(LdapParameter.DOMAIN.getParameter(integration).orElse(null), LdapParameter.URL.getRequiredParameter(integration), LdapParameter.BASE_DN.getRequiredParameter(integration));
adAuth.setAuthoritiesMapper(new NullAuthoritiesMapper());
adAuth.setUserDetailsContextMapper(detailsContextMapper);
LdapParameter.SEARCH_FILTER_REMOVE_NOT_PRESENT.getParameter(integration).ifPresent(adAuth::setSearchFilter);
return adAuth;
}
use of org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider in project ranger by apache.
the class RangerAuthenticationProvider method getADAuthentication.
public Authentication getADAuthentication(Authentication authentication) {
try {
String rangerADURL = PropertiesUtil.getProperty("ranger.ldap.ad.url", "");
String rangerADDomain = PropertiesUtil.getProperty("ranger.ldap.ad.domain", "");
String rangerLdapDefaultRole = PropertiesUtil.getProperty("ranger.ldap.default.role", "ROLE_USER");
String rangerLdapUserSearchFilter = PropertiesUtil.getProperty("ranger.ldap.ad.user.searchfilter", "(sAMAccountName={0})");
ActiveDirectoryLdapAuthenticationProvider adAuthenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(rangerADDomain, rangerADURL);
adAuthenticationProvider.setConvertSubErrorCodesToExceptions(true);
adAuthenticationProvider.setUseAuthenticationRequestCredentials(true);
adAuthenticationProvider.setSearchFilter(rangerLdapUserSearchFilter);
// Grab the user-name and password out of the authentication object.
String userName = authentication.getName();
String userPassword = "";
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
// getting user authenticated
if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
final List<GrantedAuthority> grantedAuths = new ArrayList<>();
grantedAuths.add(new SimpleGrantedAuthority(rangerLdapDefaultRole));
final UserDetails principal = new User(userName, userPassword, grantedAuths);
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
authentication = adAuthenticationProvider.authenticate(finalAuthentication);
return authentication;
} else {
return authentication;
}
} catch (Exception e) {
logger.debug("AD Authentication Failed:", e);
}
return authentication;
}
Aggregations