use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.
the class AuthenticationModuleTypeHandler method handleQuery.
/**
* Returns the list of configured authentication module instances for the current realm.
*
* {@inheritDoc}
*/
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
if (!"true".equals(request.getQueryFilter().toString())) {
return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
}
if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
return new NotSupportedException("Query paging not currently supported").asPromise();
}
try {
SSOToken ssoToken = context.asContext(SSOTokenContext.class).getCallerSSOToken();
String realm = context.asContext(RealmContext.class).getResolvedRealm();
AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realm);
Set<String> authenticationServiceNames = AMAuthenticationManager.getAuthenticationServiceNames();
for (String serviceName : authenticationServiceNames) {
ServiceSchemaManager schemaManager = new ServiceSchemaManager(serviceName, adminToken);
String resourceId = schemaManager.getResourceName();
String typeI18N = getI18NValue(schemaManager, resourceId, debug);
JsonValue result = json(object(field(ResourceResponse.FIELD_CONTENT_ID, resourceId), field("name", typeI18N)));
handler.handleResource(newResourceResponse(resourceId, String.valueOf(result.hashCode()), result));
}
return newResultPromise(newQueryResponse());
} catch (AMConfigurationException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: AMConfigurationException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: SSOException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: SMSException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
}
}
use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.
the class AuthenticationModuleCollectionHandler method handleQuery.
/**
* Returns the list of configured authentication module instances for the current realm.
*
* {@inheritDoc}
*/
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
String searchForId;
try {
searchForId = request.getQueryFilter().accept(new AuthenticationModuleQueryFilterVisitor(), null);
} catch (UnsupportedOperationException e) {
return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
}
if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
return new NotSupportedException("Query paging not currently supported").asPromise();
}
try {
SSOToken ssoToken = context.asContext(SSOTokenContext.class).getCallerSSOToken();
String realm = context.asContext(RealmContext.class).getResolvedRealm();
AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realm);
Set<AMAuthenticationInstance> moduleInstances = mgr.getAuthenticationInstances();
List<ResourceResponse> resourceResponses = new ArrayList<>();
for (AMAuthenticationInstance instance : moduleInstances) {
String name = instance.getName();
if (searchForId == null || searchForId.equalsIgnoreCase(name)) {
try {
ServiceSchemaManager schemaManager = getSchemaManager(instance.getType());
String type = schemaManager.getResourceName();
String typeDescription = getI18NValue(schemaManager, instance.getType(), debug);
JsonValue result = json(object(field(ResourceResponse.FIELD_CONTENT_ID, name), field("typeDescription", typeDescription), field("type", type)));
resourceResponses.add(newResourceResponse(name, String.valueOf(result.hashCode()), result));
} catch (AMConfigurationException ex) {
debug.error("AuthenticationModuleCollectionHandler.handleQuery(): Invalid auth module " + "instance configuration: {}", name);
if (debug.messageEnabled()) {
debug.message("AuthenticationModuleCollectionHandler.handleQuery(): Configuration exception: {}", name, ex);
}
}
}
}
return QueryResponsePresentation.perform(handler, request, resourceResponses);
} catch (AMConfigurationException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: AMConfigurationException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: SSOException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: SMSException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
}
}
use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.
the class AllConfiguredModuleInstances method getChoiceValues.
/**
* Returns the map of choice values for given environment params.
* @param envParams to get the map of choice values
* @return the map of choice values for given environment params.
*/
public Map getChoiceValues(Map envParams) {
String orgDN = null;
if (envParams != null) {
orgDN = (String) envParams.get(Constants.ORGANIZATION_NAME);
}
if (orgDN == null || orgDN.length() == 0) {
orgDN = SMSEntry.getRootSuffix();
}
Map<String, String> answer = new HashMap<String, String>();
try {
SSOToken adminToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
AMAuthenticationManager amAM = new AMAuthenticationManager(adminToken, orgDN);
Set<String> instanceNames = amAM.getAllowedModuleNames();
for (String config : instanceNames) {
answer.put(config, config);
}
} catch (Exception e) {
// do nothing as instanceNames will be empty.
}
return answer;
}
use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.
the class ConfigMonitoring method getRealmAuthMods.
HashMap getRealmAuthMods(String realmName) {
String classMethod = "ConfigMonitoring.getRealmAuthMods: ";
HashMap aMods = new HashMap();
try {
AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realmName);
Set insts = mgr.getAuthenticationInstances();
for (Iterator it = insts.iterator(); it.hasNext(); ) {
AMAuthenticationInstance ai = (AMAuthenticationInstance) it.next();
String stname = ai.getName();
String sttype = ai.getType();
aMods.put(stname, sttype);
}
/*
* all get an "Application" instance/type by default
*/
aMods.put("Application", "Application");
} catch (AMConfigurationException e) {
debug.error(classMethod + "getting auth instances; " + e.getMessage());
}
return aMods;
}
use of com.sun.identity.authentication.config.AMAuthenticationManager in project OpenAM by OpenRock.
the class UpgradeLDAPAuthModulesStep method updateAttributes.
private void updateAttributes(final String realm, final Map<String, Boolean> instanceMap) throws SMSException, AMConfigurationException, SSOException {
final AMAuthenticationManager mgr = new AMAuthenticationManager(getAdminToken(), realm);
for (final Map.Entry<String, Boolean> instance : instanceMap.entrySet()) {
final String instanceName = instance.getKey();
final String newValue = getNewValue(instance.getValue());
final AMAuthenticationInstance authModuleInstance = mgr.getAuthenticationInstance(instanceName);
final Map<String, Set<String>> moduleSettings = authModuleInstance.getAttributeValues();
final ServiceConfig moduleConfig = authModuleInstance.getServiceConfig();
Set<String> attributeValues = moduleSettings.get(SSL_ENABLED_PROPERTY);
if (attributeValues != null && !attributeValues.isEmpty()) {
if (DEBUG.messageEnabled()) {
DEBUG.message("Removing attribute " + SSL_ENABLED_PROPERTY + " from ldap/ad auth module instance <" + instanceName + "> in realm: " + realm);
}
moduleConfig.removeAttribute(SSL_ENABLED_PROPERTY);
}
attributeValues = moduleSettings.get(CONNECTION_MODE_PROPERTY);
if (attributeValues != null && !attributeValues.isEmpty()) {
if (DEBUG.messageEnabled()) {
DEBUG.message("Upgrading attribute " + CONNECTION_MODE_PROPERTY + " for ldap/ad auth module instance <" + instanceName + "> to <" + newValue + "> in realm: " + realm);
}
final Map<String, Set<String>> newConnectionModeValues = new HashMap<String, Set<String>>();
newConnectionModeValues.put(CONNECTION_MODE_PROPERTY, asSet(newValue));
moduleConfig.setAttributes(newConnectionModeValues);
}
}
}
Aggregations