use of com.sun.identity.authentication.config.AMAuthenticationInstance in project OpenAM by OpenRock.
the class PolicyModelImpl method getAuthInstances.
/**
* Returns authentication instances configured for the realm.
*
* @param realmName Name of realm.
* @return authentication instances configured for the realm.
*/
public Set getAuthInstances(String realmName) {
Set instances = null;
try {
AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realmName);
Set inst = mgr.getAuthenticationInstances();
if ((inst != null) && !inst.isEmpty()) {
instances = new HashSet(inst.size() * 2);
for (Iterator iter = inst.iterator(); iter.hasNext(); ) {
AMAuthenticationInstance i = (AMAuthenticationInstance) iter.next();
instances.add(i.getName());
}
}
} catch (AMConfigurationException e) {
debug.warning("PolicyModelImpl.getAuthInstances", e);
}
return (instances == null) ? Collections.EMPTY_SET : instances;
}
use of com.sun.identity.authentication.config.AMAuthenticationInstance 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.AMAuthenticationInstance in project OpenAM by OpenRock.
the class ConfigMonitoring method getAllRealms.
private void getAllRealms(String startRealm) {
String classMethod = "ConfigMonitoring.getAllRealms: ";
StringBuilder sb = new StringBuilder(classMethod);
if (debug.messageEnabled()) {
sb.append("orgnames starting from ").append(startRealm).append(":\n").append(" ").append(startRealm).append("\n");
}
try {
OrganizationConfigManager orgMgr = new OrganizationConfigManager(ssoToken, startRealm);
Set orgs = orgMgr.getSubOrganizationNames("*", true);
/*
* the orgs Set of realms seems to have some sort of
* ordering to it, going through each of "/"'s realms.
* don't know that we need to count on it, but it's
* nice.
*/
// do the top-level realm first
HashMap authHM = getRealmAuthMods("/");
/*
* get agent information... just for info, not processing
*/
if (debug.messageEnabled()) {
getAgentTypes();
}
SSOServerRealmInfo srInfo = new SSOServerRealmInfo.SSOServerRealmInfoBuilder("/").authModules(authHM).build();
int i = Agent.realmConfigMonitoringAgent(srInfo);
/*
* if realmConfigMonitoringAgent() had a problem with
* this realm, there's not much point in processing its
* subrealms...
*/
if (i != 0) {
debug.error(classMethod + "error processing root realm; " + "skip subrealms.");
return;
}
// then all the subrealms; they have leading "/"
for (Iterator it = orgs.iterator(); it.hasNext(); ) {
String ss = "/" + (String) it.next();
if (debug.messageEnabled()) {
sb.append(" ").append(ss).append("\n");
}
/* get this realm's auth modules */
try {
AMIdentityRepository idRepo = new AMIdentityRepository(ssoToken, ss);
AMIdentity thisRealmAMId = idRepo.getRealmIdentity();
String currentRealmAMIdName = thisRealmAMId.getRealm();
Set s1 = getAuthModules(currentRealmAMIdName);
authHM = new HashMap();
if (!s1.isEmpty()) {
for (Iterator it2 = s1.iterator(); it2.hasNext(); ) {
AMAuthenticationInstance ai = (AMAuthenticationInstance) it2.next();
String stname = ai.getName();
String sttype = ai.getType();
authHM.put(stname, sttype);
}
/*
* all get an "Application" instance/type by default
*/
authHM.put("Application", "Application");
}
/*
* get agent information
* don't need with the *Specific versions... just
* needed to see what attributes there were (and values)
*/
srInfo = new SSOServerRealmInfo.SSOServerRealmInfoBuilder(ss).authModules(authHM).build();
i = Agent.realmConfigMonitoringAgent(srInfo);
/*
* problem with this subrealm, but at least the
* root realm was added. just output error and do next
* subrealm.
*/
if (i != 0) {
debug.error(classMethod + "error processing realm " + ss);
}
} catch (IdRepoException ire) {
debug.error(classMethod + "IdRepoException getting AMIdentityRepository" + " object for realm: " + ss + ": " + ire.getMessage());
} catch (SSOException ssoe) {
debug.error(classMethod + "SSOException getting info for realm " + ss + ": " + ssoe.getMessage());
}
}
if (debug.messageEnabled()) {
debug.message(sb.toString());
}
} catch (SMSException e) {
debug.error(classMethod + "SMSException getting OrgConfigMgr: " + e.getMessage());
}
}
use of com.sun.identity.authentication.config.AMAuthenticationInstance 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.AMAuthenticationInstance in project OpenAM by OpenRock.
the class ConfigMonitoring method doSubRealms.
/*
* recursively process subrealms.
* gather per-realm configuration items:
* authentication modules
* 2.2 agents
* J2EE agents
* J2EE agent groups
* Web agents
* Web agent groups
* COTs
* each COT's members
* IDPs
* SPs
*/
private void doSubRealms(String realm) {
String classMethod = "ConfigMonitoring.doSubRealms: ";
try {
// get this realm's identity
AMIdentityRepository idRepo = new AMIdentityRepository(ssoToken, realm);
AMIdentity thisRealmAMId = idRepo.getRealmIdentity();
String currentRealmAMIdName = thisRealmAMId.getRealm();
String currentAMIdName = thisRealmAMId.getName();
// currentRealmAMIdName is fql; currentAMIdName is just realmname
if (debug.messageEnabled()) {
debug.message(classMethod + "this realm name = '" + currentRealmAMIdName + "', name = '" + currentAMIdName + "'");
}
// get this realm's subrealms
Set subRealms = (idRepo.searchIdentities(IdType.REALM, "*", new IdSearchControl())).getSearchResults();
if (subRealms.isEmpty()) {
if (debug.messageEnabled()) {
debug.message(classMethod + currentAMIdName + " has no subrealms");
}
} else {
if (debug.messageEnabled()) {
debug.message(classMethod + currentAMIdName + " has " + subRealms.size() + " subrealms");
}
int num = 0;
for (Iterator it = subRealms.iterator(); it.hasNext(); ) {
AMIdentity amid = (AMIdentity) it.next();
String ss = amid.getName();
// get assigned services
Set svcs = amid.getAssignedServices();
StringBuffer sb2 = new StringBuffer(ss);
if (debug.messageEnabled()) {
sb2.append(" has ").append(svcs.size()).append(" assigned services:\n");
for (Iterator it3 = svcs.iterator(); it3.hasNext(); ) {
sb2.append(" ").append(it3.next()).append("\n");
}
debug.message(classMethod + sb2.toString());
}
// get auth modules
Set insts = getAuthModules(currentRealmAMIdName);
if (debug.messageEnabled()) {
StringBuilder sb3 = new StringBuilder(ss);
sb3.append(" has ").append(insts.size()).append(" auth modules:\n");
for (Iterator it4 = insts.iterator(); it4.hasNext(); ) {
AMAuthenticationInstance ai = (AMAuthenticationInstance) it4.next();
sb3.append(" ").append(ai.getName()).append("\n");
}
debug.message(classMethod + sb3.toString());
}
insts = getSupportedEntityTypes(currentRealmAMIdName);
if (debug.messageEnabled()) {
sb2 = new StringBuffer("Supported Entity types for ");
sb2.append(currentAMIdName).append(":\n");
for (Iterator it4 = insts.iterator(); it4.hasNext(); ) {
IdType type = (IdType) it4.next();
String stype = type.getName();
sb2.append(" ").append(stype);
}
debug.message(classMethod + sb2.toString());
debug.message(classMethod + currentAMIdName + "'s subrealm #" + num++ + " is " + ss);
}
doSubRealms(amid.getRealm());
}
}
} catch (IdRepoException ire) {
debug.error(classMethod + "IdRepoException getting AMIdentityRepository" + " object for root realm: " + ire.getMessage());
} catch (SSOException ssoe) {
debug.error(classMethod + "SSOException getting subrealms for root realm: " + ssoe.getMessage());
}
return;
}
Aggregations