use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class RealmGetServiceAttributeValues method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
IOutput outputWriter = getOutputWriter();
try {
String[] params = { realm, serviceName };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_REALM_SERVICE_ATTR_VALUES", params);
Map attributeValues = null;
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = repo.getRealmIdentity();
Set servicesFromIdRepo = ai.getAssignedServices();
if (servicesFromIdRepo.contains(serviceName)) {
attributeValues = ai.getServiceAttributes(serviceName);
} else {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
attributeValues = ocm.getServiceAttributes(serviceName);
}
if ((attributeValues != null) && !attributeValues.isEmpty()) {
outputWriter.printlnMessage(FormatUtils.printAttributeValues(getResourceString("get-service-attr-values-of-realm-result"), attributeValues, CLIUtil.getPasswordFields(serviceName)));
} else {
outputWriter.printlnMessage(getResourceString("get-service-attr-values-of-realm-no-attr"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_REALM_SERVICE_ATTR_VALUES", params);
} catch (IdRepoException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmGetServiceAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_REALM_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmGetServiceAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_REALM_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, serviceName, e.getMessage() };
debugError("RealmGetServiceAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_REALM_SERVICE_ATTR_VALUES", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class RealmUnassignService method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
IOutput outputWriter = getOutputWriter();
try {
OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
Set assignedServices = ocm.getAssignedServices();
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = amir.getRealmIdentity();
Set dynAssignedServices = ai.getAssignedServices();
String[] params = { realm, serviceName };
boolean unassigned = false;
if (assignedServices.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UNASSIGN_SERVICE_FROM_REALM", params);
ocm.unassignService(serviceName);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("unassign-service-from-realm-succeed"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UNASSIGN_SERVICE_FROM_REALM", params);
unassigned = true;
}
if (dynAssignedServices.contains(serviceName)) {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UNASSIGN_SERVICE_FROM_REALM", params);
ai.unassignService(serviceName);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("unassign-service-from-realm-succeed"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UNASSIGN_SERVICE_FROM_REALM", params);
unassigned = true;
}
if (!unassigned) {
outputWriter.printlnMessage(MessageFormat.format(getResourceString("unassign-service-from-realm-service-not-assigned"), (Object[]) params));
}
} catch (SSOException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmUnassignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UNASSIGN_SERVICE_FROM_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IdRepoException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmUnassignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UNASSIGN_SERVICE_FROM_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmUnassignService.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UNASSIGN_SERVICE_FROM_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class IsMember method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String idName = getStringOptionValue(ARGUMENT_ID_NAME);
String type = getStringOptionValue(ARGUMENT_ID_TYPE);
IdType idType = convert2IdType(type);
String memberIdName = getStringOptionValue(ARGUMENT_MEMBER_IDNAME);
String memberType = getStringOptionValue(ARGUMENT_MEMBER_IDTYPE);
IdType memberIdType = convert2IdType(memberType);
String[] params = { realm, type, idName, memberIdName, memberType };
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
Set memberOfs = memberIdType.canBeMemberOf();
if (!memberOfs.contains(idType)) {
String[] args = { type, memberType };
throw new CLIException(MessageFormat.format(getResourceString("idrepo-cannot-be-member"), (Object[]) args), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_IS_MEMBER", params);
AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
AMIdentity memberAmid = new AMIdentity(adminSSOToken, memberIdName, memberIdType, realm, null);
String[] args = { memberIdName, idName };
if (memberAmid.isMember(amid)) {
String msg = getResourceString("idrepo-ismembers-positive-result");
outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) args));
} else {
String msg = getResourceString("idrepo-ismembers-negative-result");
outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) args));
}
outputWriter.printlnMessage(MessageFormat.format(getResourceString("idrepo-get-ismember-succeed"), (Object[]) params));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_IS_MEMBER", params);
} catch (IdRepoException e) {
String[] args = { realm, type, idName, memberIdName, memberType, e.getMessage() };
debugError("IsMember.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_IS_MEMBER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, type, idName, memberIdName, memberType, e.getMessage() };
debugError("IsMember.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_IS_MEMBER", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class AMLoginModule method authenticateToDatastore.
/**
* Authenticates to the datastore using idRepo API
*
* @param callbacks Array of last submitted callbacks to the
* authentication module
* @return <code>true</code> if success. <code>false</code> if failure
* @throws <code> AuthLoginException </code>
*/
private boolean authenticateToDatastore(Callback[] callbacks) throws AuthLoginException {
boolean retval = false;
boolean needToCheck = false;
Callback[] idrepoCallbacks = new Callback[2];
String userName = null;
char[] password = null;
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nc = (NameCallback) callbacks[i];
userName = nc.getName();
if (debug.messageEnabled()) {
debug.message("AMLoginModule.authenticateToDatastore:: " + " user is : " + userName);
debug.message("AMLoginModule.authenticateToDatastore:: " + " Internal users : " + LoginState.INTERNAL_USERS);
}
if (LoginState.INTERNAL_USERS.contains(userName.toLowerCase())) {
needToCheck = true;
} else {
break;
}
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callbacks[i];
password = pc.getPassword();
}
}
if (needToCheck == false) {
return true;
}
if (debug.messageEnabled()) {
debug.message("AMLoginModule.authenticateToDatastore:: " + "Authenticating Internal user to configuration store");
}
NameCallback nameCallback = new NameCallback("NamePrompt");
nameCallback.setName(userName);
idrepoCallbacks[0] = nameCallback;
PasswordCallback passwordCallback = new PasswordCallback("PasswordPrompt", false);
passwordCallback.setPassword(password);
idrepoCallbacks[1] = passwordCallback;
try {
AMIdentityRepository idrepo = getAMIdentityRepository(getRequestOrg());
retval = idrepo.authenticate(idrepoCallbacks);
if (debug.messageEnabled()) {
debug.message("AMLoginModule.authenticateToDatastore:: " + " IDRepo authentication successful");
}
} catch (IdRepoException idrepoExp) {
if (debug.messageEnabled()) {
debug.message("AMLoginModule.authenticateToDatastore:: " + "IdRepo Exception : ", idrepoExp);
}
} catch (InvalidPasswordException ipe) {
throw new AuthLoginException(AMAuthErrorCode.AUTH_MODULE_DENIED);
}
return retval;
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class IdentityServicesImpl method searchIdentityDetails.
/**
* Searches the identity repository to find all identities that match the search criteria and returns them as a
* list of identities.
*
* @param crestQuery A CREST Query object which will contain either a _queryId or a _queryFilter.
* @param searchModifiers The search modifiers
* @param admin Your SSO token.
* @return a list of matching identities.
* @throws ResourceException
*/
public List<IdentityDetails> searchIdentityDetails(CrestQuery crestQuery, Map<String, Set<String>> searchModifiers, SSOToken admin) throws ResourceException {
try {
String realm = "/";
String objectType = "User";
if (searchModifiers != null) {
realm = attractValues("realm", searchModifiers, "/");
objectType = attractValues("objecttype", searchModifiers, "User");
}
AMIdentityRepository repo = getRepo(admin, realm);
IdType idType = getIdType(objectType);
if (idType != null) {
List<AMIdentity> identities = fetchAMIdentities(idType, crestQuery, true, repo, searchModifiers);
List<IdentityDetails> result = new ArrayList<>();
for (AMIdentity identity : identities) {
result.add(convertToIdentityDetails(identity, null));
}
return result;
}
debug.error("IdentityServicesImpl.searchIdentities unsupported IdType " + objectType);
throw new BadRequestException("searchIdentities: unsupported IdType " + objectType);
} catch (IdRepoException e) {
debug.error("IdentityServicesImpl.searchIdentities", e);
throw new InternalServerErrorException(e.getMessage());
} catch (SSOException e) {
debug.error("IdentityServicesImpl.searchIdentities", e);
throw new InternalServerErrorException(e.getMessage());
} catch (ObjectNotFound e) {
debug.error("IdentityServicesImpl.searchIdentities", e);
throw new NotFoundException(e.getMessage());
}
}
Aggregations