org.springframework.security.authentication.jaas.memory.InMemoryConfiguration Java Examples
The following examples show how to use
org.springframework.security.authentication.jaas.memory.InMemoryConfiguration.
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: AtlasPamAuthenticationProvider.java From incubator-atlas with Apache License 2.0 | 6 votes |
private void init() { try { AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry( loginModuleName, controlFlag, options); AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[]{appConfigurationEntry}; Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>(); appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries); Configuration configuration = new InMemoryConfiguration( appConfigurationEntriesOptions); jaasAuthenticationProvider.setConfiguration(configuration); UserAuthorityGranter authorityGranter = new UserAuthorityGranter(); UserAuthorityGranter[] authorityGranters = new UserAuthorityGranter[]{authorityGranter}; jaasAuthenticationProvider.setAuthorityGranters(authorityGranters); jaasAuthenticationProvider.afterPropertiesSet(); } catch (Exception e) { LOG.error("Failed to init PAM Authentication", e); } }
Example #2
Source File: AtlasPamAuthenticationProvider.java From atlas with Apache License 2.0 | 5 votes |
private void init() { try { AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry( loginModuleName, controlFlag, options); AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[]{appConfigurationEntry}; Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>(); appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries); Configuration configuration = new InMemoryConfiguration( appConfigurationEntriesOptions); jaasAuthenticationProvider.setConfiguration(configuration); UserAuthorityGranter authorityGranter = new UserAuthorityGranter(); UserAuthorityGranter[] authorityGranters = new UserAuthorityGranter[]{authorityGranter}; jaasAuthenticationProvider.setAuthorityGranters(authorityGranters); jaasAuthenticationProvider.afterPropertiesSet(); if(LOG.isDebugEnabled()) { LOG.debug("AtlasPAMAuthenticationProvider{" + "jaasAuthenticationProvider='" + jaasAuthenticationProvider + '\'' + ", loginModuleName='" + loginModuleName + '\'' + ", controlFlag='" + controlFlag + '\'' + ", options='" + options + '}'); } } catch (Exception e) { LOG.error("Failed to init PAM Authentication", e); } }
Example #3
Source File: RangerAuthenticationProvider.java From ranger with Apache License 2.0 | 4 votes |
public Authentication getPamAuthentication(Authentication authentication) { try { String rangerLdapDefaultRole = PropertiesUtil.getProperty( "ranger.ldap.default.role", "ROLE_USER"); DefaultJaasAuthenticationProvider jaasAuthenticationProvider = new DefaultJaasAuthenticationProvider(); String loginModuleName = "org.apache.ranger.authentication.unix.jaas.PamLoginModule"; LoginModuleControlFlag controlFlag = LoginModuleControlFlag.REQUIRED; Map<String, String> options = PropertiesUtil.getPropertiesMap(); if (!options.containsKey("ranger.pam.service")) options.put("ranger.pam.service", "ranger-admin"); AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry( loginModuleName, controlFlag, options); AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[] { appConfigurationEntry }; Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>(); appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries); Configuration configuration = new InMemoryConfiguration( appConfigurationEntriesOptions); jaasAuthenticationProvider.setConfiguration(configuration); RoleUserAuthorityGranter authorityGranter = new RoleUserAuthorityGranter(); RoleUserAuthorityGranter[] authorityGranters = new RoleUserAuthorityGranter[] { authorityGranter }; jaasAuthenticationProvider.setAuthorityGranters(authorityGranters); jaasAuthenticationProvider.afterPropertiesSet(); 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 = jaasAuthenticationProvider .authenticate(finalAuthentication); authentication=getAuthenticationWithGrantedAuthority(authentication); return authentication; } else { return authentication; } } catch (Exception e) { logger.debug("Pam Authentication Failed:", e); } return authentication; }
Example #4
Source File: RangerAuthenticationProvider.java From ranger with Apache License 2.0 | 4 votes |
public Authentication getUnixAuthentication(Authentication authentication) { try { String rangerLdapDefaultRole = PropertiesUtil.getProperty( "ranger.ldap.default.role", "ROLE_USER"); DefaultJaasAuthenticationProvider jaasAuthenticationProvider = new DefaultJaasAuthenticationProvider(); String loginModuleName = "org.apache.ranger.authentication.unix.jaas.RemoteUnixLoginModule"; LoginModuleControlFlag controlFlag = LoginModuleControlFlag.REQUIRED; Map<String, String> options = PropertiesUtil.getPropertiesMap(); AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry( loginModuleName, controlFlag, options); AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[] { appConfigurationEntry }; Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>(); appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries); Configuration configuration = new InMemoryConfiguration( appConfigurationEntriesOptions); jaasAuthenticationProvider.setConfiguration(configuration); RoleUserAuthorityGranter authorityGranter = new RoleUserAuthorityGranter(); RoleUserAuthorityGranter[] authorityGranters = new RoleUserAuthorityGranter[] { authorityGranter }; jaasAuthenticationProvider.setAuthorityGranters(authorityGranters); jaasAuthenticationProvider.afterPropertiesSet(); 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 = jaasAuthenticationProvider .authenticate(finalAuthentication); authentication=getAuthenticationWithGrantedAuthority(authentication); return authentication; } else { return authentication; } } catch (Exception e) { logger.debug("Unix Authentication Failed:", e); } return authentication; }