use of com.sun.identity.authentication.config.AMAuthenticationInstance in project OpenAM by OpenRock.
the class ScriptedAuthModulesStep method captureScriptedModuleData.
private void captureScriptedModuleData(String realm) throws AMConfigurationException, ScriptException {
Set<ScriptData> scriptDataSet = new HashSet<>();
AMAuthenticationManager authManager = new AMAuthenticationManager(getAdminToken(), realm);
Set<AMAuthenticationInstance> instances = authManager.getAuthenticationInstances();
for (AMAuthenticationInstance instance : instances) {
String moduleType = instance.getType();
if ("Scripted".equalsIgnoreCase(moduleType) || "DeviceIdMatch".equalsIgnoreCase(moduleType)) {
DEBUG.message("Found Scripted Module called {}, in realm {}", instance.getName(), realm);
@SuppressWarnings("unchecked") Map<String, Set<String>> attributes = instance.getAttributeValues();
if (attributes.containsKey(SCRIPT_TYPE)) {
scriptDataSet.add(getScriptData(instance.getName(), attributes));
moduleCount++;
}
}
}
if (!scriptDataSet.isEmpty()) {
scriptsToMove.put(realm, scriptDataSet);
}
}
use of com.sun.identity.authentication.config.AMAuthenticationInstance in project OpenAM by OpenRock.
the class ScriptedAuthModulesStep method upgradeScriptedAuthModules.
private void upgradeScriptedAuthModules(String realm, Set<ScriptData> scriptDataSet) throws AMConfigurationException, ScriptException, SSOException, SMSException {
ScriptingService service = serviceFactory.create(getAdminSubject(), realm);
AMAuthenticationManager authManager = new AMAuthenticationManager(getAdminToken(), realm);
for (ScriptData scriptData : scriptDataSet) {
Map<String, Set<String>> attributes = new HashMap<>();
UpgradeProgress.reportStart("upgrade.scripted.auth.server.script.start", scriptData.serverSideScript.getName(), realm);
service.create(scriptData.serverSideScript);
attributes.put(SERVER_SCRIPT, Collections.singleton(scriptData.serverSideScript.getId()));
UpgradeProgress.reportEnd("upgrade.success");
if (scriptData.clientSideScript != null) {
UpgradeProgress.reportStart("upgrade.scripted.auth.client.script.start", scriptData.clientSideScript.getName(), realm);
service.create(scriptData.clientSideScript);
attributes.put(CLIENT_SCRIPT, Collections.singleton(scriptData.clientSideScript.getId()));
UpgradeProgress.reportEnd("upgrade.success");
} else {
attributes.put(CLIENT_SCRIPT, Collections.singleton(EMPTY_SCRIPT_SELECTION));
}
UpgradeProgress.reportStart("upgrade.scripted.auth.module.script.start", scriptData.moduleName, realm);
AMAuthenticationInstance instance = authManager.getAuthenticationInstance(scriptData.moduleName);
if (instance != null) {
instance.setAttributeValues(attributes);
UpgradeProgress.reportEnd("upgrade.success");
} else {
DEBUG.error("Scripted module {} in realm {} could not be found", scriptData.moduleName, realm);
UpgradeProgress.reportEnd("upgrade.failed");
}
}
}
use of com.sun.identity.authentication.config.AMAuthenticationInstance in project OpenAM by OpenRock.
the class UpgradeLDAPAuthModulesStep method initialize.
@Override
public void initialize() throws UpgradeException {
String realmName = null;
String authInstanceName = null;
try {
for (final String realm : getRealmNames()) {
realmName = realm;
final AMAuthenticationManager mgr = new AMAuthenticationManager(getAdminToken(), realm);
final Set<AMAuthenticationInstance> moduleInstances = mgr.getAuthenticationInstances();
if (moduleInstances != null) {
for (final AMAuthenticationInstance moduleInstance : moduleInstances) {
if (moduleInstance.getType().equalsIgnoreCase("LDAP") || moduleInstance.getType().equalsIgnoreCase("AD")) {
authInstanceName = moduleInstance.getName();
if (DEBUG.messageEnabled()) {
DEBUG.message("ldap/ad auth module configuration found under realm: " + realm + " : " + authInstanceName);
}
final Map<String, Set<String>> configProperties = moduleInstance.getAttributeValues(asSet(SSL_ENABLED_PROPERTY));
if (configProperties != null && !configProperties.isEmpty()) {
final String sslEnabledProp = CollectionHelper.getMapAttr(configProperties, SSL_ENABLED_PROPERTY);
if (sslEnabledProp != null) {
if (DEBUG.messageEnabled()) {
DEBUG.message("ldap/ad auth module config " + authInstanceName + " in realm: " + realm + " " + SSL_ENABLED_PROPERTY + ":" + sslEnabledProp);
}
Map<String, Boolean> instanceMap = instances.get(realm);
if (instanceMap == null) {
instanceMap = new HashMap<String, Boolean>();
instances.put(realm, instanceMap);
}
instanceMap.put(authInstanceName, Boolean.parseBoolean(sslEnabledProp));
}
}
}
}
}
}
} catch (final Exception ex) {
DEBUG.error("Unable to identify the configuration for the old ldap/ad auth module instance " + authInstanceName + " in realm " + realmName, ex);
throw new UpgradeException("An error occurred while trying to identify the configuration for the old " + "ldap/ad auth module instance " + authInstanceName + " in realm " + realmName, ex);
}
}
use of com.sun.identity.authentication.config.AMAuthenticationInstance in project OpenAM by OpenRock.
the class AuthPropertiesModelImpl method getServiceName.
/**
* To get the service name from the instance name:
* 1) get a handle to the AMAuthenicationInstance object
* 2) from the AuthInstance object get the type of instance
* 3) Use the instance type to get the schema for that type
* 4) from the schema get the service name
*/
public String getServiceName(String instance) {
String name = null;
try {
AMAuthenticationManager mgr = new AMAuthenticationManager(getUserSSOToken(), currentRealm);
AMAuthenticationInstance inst = mgr.getAuthenticationInstance(instance);
if (inst != null) {
AMAuthenticationSchema schema = mgr.getAuthenticationSchema(inst.getType());
name = schema.getServiceName();
} else {
if (debug.warningEnabled()) {
debug.warning("AuthPropertiesModel.getServiceName, " + " the requested instance " + instance + " does not exist.");
}
}
} catch (AMConfigurationException ace) {
if (debug.warningEnabled()) {
debug.warning("problem getting service name for " + instance, ace);
}
}
return name;
}
use of com.sun.identity.authentication.config.AMAuthenticationInstance in project OpenAM by OpenRock.
the class GetAuthInstance method handleRequest.
/**
* Handles request.
*
* @param rc Request Context.
* @throws CLIException if request cannot be processed.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String instanceName = getStringOptionValue(AuthOptions.AUTH_INSTANCE_NAME);
String[] params = { realm, instanceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_AUTH_INSTANCE", params);
try {
AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
AMAuthenticationInstance ai = mgr.getAuthenticationInstance(instanceName);
if (ai != null) {
IOutput outputWriter = getOutputWriter();
Map attributeValues = ai.getAttributeValues();
if ((attributeValues != null) && !attributeValues.isEmpty()) {
AMAuthenticationSchema schema = mgr.getAuthenticationSchema(ai.getType());
String serviceName = schema.getServiceName();
outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-succeeded"));
outputWriter.printlnMessage(FormatUtils.printAttributeValues(getResourceString("authentication-get-auth-instance-result"), attributeValues, CLIUtil.getPasswordFields(serviceName)));
} else {
outputWriter.printlnMessage(getResourceString("authentication-get-auth-instance-no-values"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_GET_AUTH_INSTANCE", params);
} else {
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(getResourceString("authentication-get-auth-instance-not-found"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} catch (SSOException e) {
debugError("GetAuthInstance.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
debugError("GetAuthInstance.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (AMConfigurationException e) {
debugError("GetAuthInstance.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_INSTANCE", params);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations