use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class ProxyPETest method createUser.
private void createUser(SSOToken adminToken) throws IdRepoException, SSOException {
AMIdentityRepository amir = new AMIdentityRepository(adminToken, "/");
Map<String, Set<String>> attrValues = new HashMap<String, Set<String>>();
Set<String> set = new HashSet<String>();
set.add(TEST_USER_NAME);
attrValues.put("givenname", set);
attrValues.put("sn", set);
attrValues.put("cn", set);
attrValues.put("userpassword", set);
testUser = amir.createIdentity(IdType.USER, TEST_USER_NAME, attrValues);
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class IdentityManager method getClientIdentity.
/**
* Gets a client's identity.
*
* @param clientName The client's name.
* @param realm The client's realm.
* @return The Clients identity.
* @throws UnauthorizedClientException If the client's identity cannot be found.
*/
public AMIdentity getClientIdentity(String clientName, String realm) throws UnauthorizedClientException {
final SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
final AMIdentity amIdentity;
try {
final AMIdentityRepository amIdRepo = new AMIdentityRepository(token, realm);
final IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setAllReturnAttributes(true);
// search for the identity
idsc.setMaxResults(0);
final IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.AGENTONLY, clientName, idsc);
final Set<AMIdentity> results = searchResults.getSearchResults();
if (results == null || results.size() != 1) {
logger.error("No client profile or more than one profile found.");
throw new UnauthorizedClientException("Not able to get client from OpenAM");
}
amIdentity = results.iterator().next();
//if the client is deactivated return null
if (amIdentity.isActive()) {
return amIdentity;
} else {
return null;
}
} catch (Exception e) {
logger.error("Unable to get client AMIdentity: ", e);
throw new UnauthorizedClientException("Not able to get client from OpenAM");
}
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class OpenAMClientDAO method read.
/**
* {@inheritDoc}
*/
public Client read(String clientId, OAuth2Request request) throws UnauthorizedClientException {
Map<String, Set<String>> clientAttributes = new HashMap<String, Set<String>>();
try {
AMIdentity theID = null;
final SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
final String realm = request.getParameter(OAuth2Constants.Custom.REALM);
AMIdentityRepository repo = idRepoFactory.create(realm, token);
IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setAllReturnAttributes(true);
// search for the identity
Set<AMIdentity> results;
idsc.setMaxResults(0);
IdSearchResults searchResults = repo.searchIdentities(IdType.AGENTONLY, clientId, idsc);
results = searchResults.getSearchResults();
if (results == null || results.size() != 1) {
logger.error("OpenAMClientDAO.read(): No client profile or more than one profile found.");
throw new UnauthorizedClientException("Not able to get client from OpenAM");
}
theID = results.iterator().next();
//if the client is deactivated return null
if (!theID.isActive()) {
theID = null;
} else {
clientAttributes = theID.getAttributes();
}
} catch (UnauthorizedClientException e) {
logger.error("OpenAMClientDAO.read(): Unable to get client AMIdentity: ", e);
throw new UnauthorizedClientException("Not able to get client from OpenAM");
} catch (SSOException e) {
logger.error("OpenAMClientDAO.read(): Unable to get client AMIdentity: ", e);
throw new UnauthorizedClientException("Not able to get client from OpenAM");
} catch (IdRepoException e) {
logger.error("OpenAMClientDAO.read(): Unable to get client AMIdentity: ", e);
throw new UnauthorizedClientException("Not able to get client from OpenAM");
}
Client client = createClient(clientAttributes);
client.setClientID(clientId);
return client;
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class AgentConfiguration method deleteAgentGroups.
/**
* Deletes agent groups.
*
* @param ssoToken Single Sign On token that is to be used for deletion.
* @param realm Realm where agent groups reside.
* @param agentGroups Set of Agent Group object.
* @throws IdRepoException if unable to delete groups.
* @throws SSOException if the Single Sign On token is invalid or has
* expired.
* @throws SMSException if there are errors in service management layers.
*/
public static void deleteAgentGroups(SSOToken ssoToken, String realm, Set agentGroups) throws IdRepoException, SSOException, SMSException {
if ((agentGroups != null) && !agentGroups.isEmpty()) {
for (Iterator i = agentGroups.iterator(); i.hasNext(); ) {
AMIdentity group = (AMIdentity) i.next();
unheritPropertyValues(group);
}
AMIdentityRepository repo = new AMIdentityRepository(ssoToken, realm);
repo.deleteIdentities(agentGroups);
}
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class RealmSetServiceAttributeValues 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();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String datafile = getStringOptionValue(IArgument.DATA_FILE);
List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
boolean bAppend = isOptionSet(OPT_APPEND);
if ((datafile == null) && (attrValues == null)) {
throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
}
Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
attributeValues = processFileAttributes(attributeValues);
try {
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity ai = repo.getRealmIdentity();
Set servicesFromIdRepo = ai.getAssignedServices();
if (servicesFromIdRepo.contains(serviceName)) {
handleDynamicAttributes(ai, realm, serviceName, attributeValues, bAppend);
} else {
handleOrganizatioAttribute(realm, serviceName, attributeValues, bAppend);
}
} catch (IdRepoException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmSetServiceAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, e.getMessage() };
debugError("RealmSetServiceAttributeValues.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations