org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider Java Examples

The following examples show how to use org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AtlasADAuthenticationProvider.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
     }
 }
 
Example #2
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public AuthenticationProvider authenticationProvider(){
    ActiveDirectoryLdapAuthenticationProvider ap = new ActiveDirectoryLdapAuthenticationProvider(
                                                                "corp.jbcpcalendar.com",
                                                                   "ldap://corp.jbcpcalendar.com/");
    ap.setConvertSubErrorCodesToExceptions(true);
    return ap;
}
 
Example #3
Source File: AtlasADAuthenticationProvider.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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;
     }
 }
 
Example #4
Source File: RangerAuthenticationProvider.java    From ranger with Apache License 2.0 4 votes vote down vote up
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;
}