use of javax.security.auth.login.Configuration in project OpenAM by OpenRock.
the class AuthUtils method isPureJAASModulePresent.
/**
* Returns whether the auth module is or the auth chain contains pure JAAS
* module(s).
* @param configName a string of the configuratoin name.
* @return 1 for pure JAAS module; -1 for module(s) provided by IS only.
*/
public static int isPureJAASModulePresent(String configName, AMLoginContext amlc) throws AuthLoginException {
if (AuthD.isEnforceJAASThread()) {
return 1;
}
int returnValue = -1;
Configuration ISConfiguration = null;
try {
ISConfiguration = Configuration.getConfiguration();
} catch (Exception e) {
return 1;
}
AppConfigurationEntry[] entries = ISConfiguration.getAppConfigurationEntry(configName);
if (entries == null) {
throw new AuthLoginException("amAuth", AMAuthErrorCode.AUTH_CONFIG_NOT_FOUND, null);
}
// re-use the obtained configuration
amlc.setConfigEntries(entries);
for (int i = 0; i < entries.length; i++) {
String className = entries[i].getLoginModuleName();
if (utilDebug.messageEnabled()) {
utilDebug.message("config entry: " + className);
}
if (pureJAASModuleClasses.contains(className)) {
returnValue = 1;
break;
} else if (ISModuleClasses.contains(className)) {
continue;
}
try {
Object classObject = Class.forName(className, true, Thread.currentThread().getContextClassLoader()).newInstance();
if (classObject instanceof AMLoginModule) {
if (utilDebug.messageEnabled()) {
utilDebug.message(className + " is instance of AMLoginModule");
}
synchronized (ISModuleClasses) {
if (!ISModuleClasses.contains(className)) {
ISModuleClasses.add(className);
}
}
} else {
if (utilDebug.messageEnabled()) {
utilDebug.message(className + " is a pure jaas module");
}
synchronized (pureJAASModuleClasses) {
if (!pureJAASModuleClasses.contains(className)) {
pureJAASModuleClasses.add(className);
}
}
returnValue = 1;
break;
}
} catch (Exception e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("fail to instantiate class for " + className);
}
synchronized (pureJAASModuleClasses) {
if (!pureJAASModuleClasses.contains(className)) {
pureJAASModuleClasses.add(className);
}
}
returnValue = 1;
break;
}
}
return returnValue;
}
use of javax.security.auth.login.Configuration in project OpenAM by OpenRock.
the class AMLoginContext method getModuleFromAuthConfiguration.
/** This method returns a Set with is the list of
* modules for a Authentication Configuration.
* Only modules with control flag REQUIRED and
* REQUISITE are returned.
* @param moduleListSet list of configured auth module
* @return set of configured auth module with control flag REQUIRED and
* REQUISITE are returned
*/
private Set<String> getModuleFromAuthConfiguration(Set<String> moduleListSet, String orgDN) {
Configuration config = Configuration.getConfiguration();
if (configName == null) {
configName = getConfigName(indexType, indexName, orgDN, loginState.getClientType());
}
AppConfigurationEntry[] moduleList = config.getAppConfigurationEntry(configName);
if (debug.messageEnabled()) {
debug.message("configName is : " + configName);
}
String moduleName;
if (moduleList != null && moduleList.length > 0) {
if (moduleList.length == 1) {
moduleName = (String) moduleList[0].getOptions().get(ISAuthConstants.MODULE_INSTANCE_NAME);
moduleListSet.add(moduleName);
} else {
for (AppConfigurationEntry moduleListEntry : moduleList) {
LoginModuleControlFlag controlFlag = moduleListEntry.getControlFlag();
moduleName = (String) moduleListEntry.getOptions().get(ISAuthConstants.MODULE_INSTANCE_NAME);
if (isControlFlagMatchFound(controlFlag)) {
moduleListSet.add(moduleName);
}
}
}
}
if (debug.messageEnabled()) {
debug.message("ModuleSet is : " + moduleListSet);
}
return moduleListSet;
}
use of javax.security.auth.login.Configuration in project wildfly by wildfly.
the class Util method getCLMLoginContext.
/**
* Obtain a LoginContext configured for use with the ClientLoginModule.
*
* @return the configured LoginContext.
*/
public static LoginContext getCLMLoginContext(final String username, final String password) throws LoginException {
final String configurationName = "Testing";
CallbackHandler cbh = new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback current : callbacks) {
if (current instanceof NameCallback) {
((NameCallback) current).setName(username);
} else if (current instanceof PasswordCallback) {
((PasswordCallback) current).setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(current);
}
}
}
};
Configuration config = new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
if (configurationName.equals(name) == false) {
throw new IllegalArgumentException("Unexpected configuration name '" + name + "'");
}
Map<String, String> options = new HashMap<String, String>();
options.put("multi-threaded", "true");
options.put("restore-login-identity", "true");
AppConfigurationEntry clmEntry = new AppConfigurationEntry(ClientLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
return new AppConfigurationEntry[] { clmEntry };
}
};
return new LoginContext(configurationName, new Subject(), cbh, config);
}
use of javax.security.auth.login.Configuration in project OpenAM by OpenRock.
the class WindowsDesktopSSO method serviceLogin.
private synchronized void serviceLogin() throws AuthLoginException {
if (debug.messageEnabled()) {
debug.message("New Service Login ...");
}
System.setProperty("java.security.krb5.realm", kdcRealm);
System.setProperty("java.security.krb5.kdc", kdcServer);
System.setProperty("java.security.auth.login.config", "/dev/null");
try {
Configuration config = Configuration.getConfiguration();
WindowsDesktopSSOConfig wtc = null;
if (config instanceof WindowsDesktopSSOConfig) {
wtc = (WindowsDesktopSSOConfig) config;
wtc.setRefreshConfig("true");
} else {
wtc = new WindowsDesktopSSOConfig(config);
}
wtc.setPrincipalName(servicePrincipalName);
wtc.setKeyTab(keyTabFile);
Configuration.setConfiguration(wtc);
// perform service authentication using JDK Kerberos module
LoginContext lc = new LoginContext(WindowsDesktopSSOConfig.defaultAppName);
lc.login();
serviceSubject = lc.getSubject();
if (debug.messageEnabled()) {
debug.message("Service login succeeded.");
}
} catch (Exception e) {
debug.error("Service Login Error: ");
if (debug.messageEnabled()) {
debug.message("Stack trace: ", e);
}
throw new AuthLoginException(amAuthWindowsDesktopSSO, "serviceAuth", null, e);
}
}
use of javax.security.auth.login.Configuration in project camel by apache.
the class HdfsComponent method getJAASConfiguration.
static Configuration getJAASConfiguration() {
Configuration auth = null;
try {
auth = Configuration.getConfiguration();
LOG.trace("Existing JAAS Configuration {}", auth);
} catch (SecurityException e) {
LOG.trace("Cannot load existing JAAS configuration", e);
}
return auth;
}
Aggregations