use of javax.security.auth.login.Configuration in project polymap4-core by Polymap4.
the class SpnegoFilterConfig method moduleExists.
private boolean moduleExists(final String side, final String moduleName) {
// confirm that runtime loaded the login file
final Configuration config = Configuration.getConfiguration();
// we only expect one entry
final AppConfigurationEntry[] entry = config.getAppConfigurationEntry(moduleName);
// confirm that the module name exists in the file
if (null == entry) {
throw new IllegalArgumentException("The " + side + " module name " + "was not found in the login file: " + moduleName);
}
// confirm that the login module class was defined
if (0 == entry.length) {
throw new IllegalArgumentException("The " + side + " module name " + "exists but login module class not defined: " + moduleName);
}
// confirm that only one login module class specified
if (entry.length > 1) {
throw new IllegalArgumentException("Only one login module class " + "is supported for the " + side + " module: " + entry.length);
}
// confirm class name is "com.sun.security.auth.module.Krb5LoginModule"
if (!entry[0].getLoginModuleName().equals("com.sun.security.auth.module.Krb5LoginModule")) {
throw new UnsupportedOperationException("Login module class not " + "supported: " + entry[0].getLoginModuleName());
}
// confirm Control Flag is specified as REQUIRED
if (!entry[0].getControlFlag().equals(AppConfigurationEntry.LoginModuleControlFlag.REQUIRED)) {
throw new UnsupportedOperationException("Control Flag must " + "have a value of REQUIRED: " + entry[0].getControlFlag());
}
return true;
}
use of javax.security.auth.login.Configuration in project ranger by apache.
the class DbToSolrMigrationUtil method registerSolrClientJAAS.
private void registerSolrClientJAAS() {
logger.info("==> createSolrClient.registerSolrClientJAAS()");
Properties props = PropertiesUtil.getProps();
try {
// Refer InMemoryJAASConfiguration doc for JAAS Configuration
if (System.getProperty(PROP_JAVA_SECURITY_AUTH_LOGIN_CONFIG) == null) {
System.setProperty(PROP_JAVA_SECURITY_AUTH_LOGIN_CONFIG, "/dev/null");
}
logger.info("Loading SolrClient JAAS config from Ranger audit config if present...");
Configuration conf = InMemoryJAASConfiguration.init(props);
if (conf != null) {
Configuration.setConfiguration(conf);
}
} catch (Exception e) {
logger.error("ERROR: Unable to load SolrClient JAAS config from ranger admin config file. Audit migration to Secure Solr will fail...", e);
}
logger.info("<==createSolrClient.registerSolrClientJAAS()");
}
use of javax.security.auth.login.Configuration in project ranger by apache.
the class RangerAuthenticationProvider method getUnixAuthentication.
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;
}
use of javax.security.auth.login.Configuration in project ranger by apache.
the class RangerAuthenticationProvider method getPamAuthentication.
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;
}
use of javax.security.auth.login.Configuration in project calcite-avatica by apache.
the class KerberosConnectionTest method previousContextLoggedOut.
@Test
public void previousContextLoggedOut() throws Exception {
KerberosConnection krbUtil = mock(KerberosConnection.class);
Subject subject = new Subject();
Subject loggedInSubject = new Subject();
Configuration conf = mock(Configuration.class);
LoginContext originalContext = mock(LoginContext.class);
LoginContext context = mock(LoginContext.class);
// Call the real login(LoginContext, Configuration, Subject) method
when(krbUtil.login(any(LoginContext.class), any(Configuration.class), any(Subject.class))).thenCallRealMethod();
// Return a fake LoginContext
when(krbUtil.createLoginContext(conf)).thenReturn(context);
// Return a fake Subject from that fake LoginContext
when(context.getSubject()).thenReturn(loggedInSubject);
Entry<LoginContext, Subject> pair = krbUtil.login(originalContext, conf, subject);
// Verify we get the fake LoginContext and Subject
assertEquals(context, pair.getKey());
assertEquals(loggedInSubject, pair.getValue());
verify(originalContext).logout();
// login should be called on the LoginContext
verify(context).login();
}
Aggregations