use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class AMCommonNameGenerator method addFormats.
/**
* Adds format by retrieving the globalization service
* attributes to get the list of formats and add them
* accordingly.
*
* @param realm Realm Name
* @return map of locale to formats
*/
private Map addFormats(String realm) {
Set values = null;
Map map = null;
try {
AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
AMIdentity realmIdentity = repo.getRealmIdentity();
Set servicesFromIdRepo = realmIdentity.getAssignedServices();
if (servicesFromIdRepo.contains(G11N_SERVICE_NAME)) {
map = realmIdentity.getServiceAttributes(G11N_SERVICE_NAME);
} else {
OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(adminSSOToken, realm);
map = orgCfgMgr.getServiceAttributes(G11N_SERVICE_NAME);
}
} catch (SSOException e) {
debug.warning("AMCommonNameGenerator.addFormats", e);
} catch (SMSException e) {
debug.warning("AMCommonNameGenerator.addFormats", e);
} catch (IdRepoException e) {
debug.warning("AMCommonNameGenerator.addFormats", e);
}
if ((map != null) && !map.isEmpty()) {
values = (Set) map.get(G11N_SERIVCE_COMMON_NAME_FORMAT);
}
if ((values == null) || values.isEmpty()) {
if (serviceSchemaManager != null) {
try {
values = AMAdminUtils.getAttribute(serviceSchemaManager, SchemaType.ORGANIZATION, G11N_SERIVCE_COMMON_NAME_FORMAT);
} catch (SMSException e) {
debug.error("AMCommonNameGenerator.addFormats", e);
}
} else {
debug.error("AMCommonNameGenerator.addFormats: " + "formats are not added because Console cannot get " + "an instance of service schema manager.");
}
}
Map mapFormats = getFormatMap(values);
synchronized (mapRealmToFormat) {
mapRealmToFormat.put(realm, mapFormats);
}
return mapFormats;
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class OATH method getIdentity.
/**
* Gets the AMIdentity of a user with username equal to uName.
*
* @param uName username of the user to get.
* @return The AMIdentity of user with username equal to uName or null
* if error while trying to find user.
*/
private AMIdentity getIdentity(String uName) {
AMIdentity theID = null;
AMIdentityRepository amIdRepo = getAMIdentityRepository(getRequestOrg());
IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setAllReturnAttributes(true);
// search for the identity
Set<AMIdentity> results = Collections.EMPTY_SET;
try {
idsc.setMaxResults(0);
IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, uName, idsc);
if (searchResults != null) {
results = searchResults.getSearchResults();
}
if (results == null || results.isEmpty()) {
throw new IdRepoException("OATH.getIdentity : User " + userName + " is not found");
} else if (results.size() > 1) {
throw new IdRepoException("OATH.getIdentity: More than one user found for the userName: " + userName);
}
theID = results.iterator().next();
} catch (IdRepoException e) {
debug.error("OATH.getIdentity: error searching Identities with username : " + userName, e);
} catch (SSOException e) {
debug.error("OATH.getIdentity: AuthOATH module exception : ", e);
}
return theID;
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class Membership method userExists.
/** check if user exists */
private boolean userExists(String userID) throws IdRepoException, SSOException {
AMIdentityRepository amIdRepo = getAMIdentityRepository(getRequestOrg());
IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setTimeOut(0);
idsc.setAllReturnAttributes(true);
// search for the identity
Set results = Collections.EMPTY_SET;
try {
idsc.setMaxResults(0);
IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userID, idsc);
if (searchResults != null) {
results = searchResults.getSearchResults();
}
} catch (IdRepoException e) {
if (debug.messageEnabled()) {
debug.message("IdRepoException : Error searching " + " Identities with username : " + e.getMessage());
}
}
return !results.isEmpty();
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class Membership method loginUser.
private ModuleState loginUser(Callback[] callbacks) throws AuthLoginException {
String password = null;
Callback[] idCallbacks = new Callback[2];
try {
if (callbacks != null && callbacks.length == 0) {
userName = (String) sharedState.get(getUserKey());
password = (String) sharedState.get(getPwdKey());
if (userName == null || password == null) {
return ModuleState.LOGIN_START;
}
getCredentialsFromSharedState = true;
NameCallback nameCallback = new NameCallback("dummy");
nameCallback.setName(userName);
idCallbacks[0] = nameCallback;
PasswordCallback passwordCallback = new PasswordCallback("dummy", false);
passwordCallback.setPassword(password.toCharArray());
idCallbacks[1] = passwordCallback;
} else {
idCallbacks = callbacks;
//callbacks is not null
userName = ((NameCallback) callbacks[0]).getName();
password = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());
}
if (password == null || password.length() == 0) {
if (debug.messageEnabled()) {
debug.message("Membership.loginUser: Password is null/empty");
}
throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
}
//store username password both in success and failure case
storeUsernamePasswd(userName, password);
initAuthConfig();
AMIdentityRepository idrepo = getAMIdentityRepository(getRequestOrg());
boolean success = idrepo.authenticate(idCallbacks);
if (success) {
validatedUserID = userName;
return ModuleState.COMPLETE;
} else {
throw new AuthLoginException(amAuthMembership, "authFailed", null);
}
} catch (IdRepoException ex) {
if (getCredentialsFromSharedState && !isUseFirstPassEnabled()) {
getCredentialsFromSharedState = false;
return ModuleState.LOGIN_START;
}
if (debug.warningEnabled()) {
debug.warning("idRepo Exception");
}
setFailureID(userName);
throw new AuthLoginException(amAuthMembership, "authFailed", null, ex);
}
}
use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.
the class ConfigMonitoring method getAgentGroups.
private void getAgentGroups(String realm) {
String classMethod = "ConfigMonitoring.getAgentGroups: ";
/*
* given a realm, search the AMIdentityRepository for
* IdType.AGENTGROUP.
* this is similar to AgentsModelImpl.java:getAgentGroupNames(...)
*/
StringBuffer sb = new StringBuffer(classMethod);
try {
IdSearchControl isc = new IdSearchControl();
isc.setMaxResults(0);
// should use set value, but for now...
isc.setTimeOut(3000);
isc.setAllReturnAttributes(false);
AMIdentityRepository airepo = new AMIdentityRepository(ssoToken, realm);
IdSearchResults isr = airepo.searchIdentities(IdType.AGENTGROUP, "*", isc);
// set of AMIdentitys
Set results = isr.getSearchResults();
sb = new StringBuffer("AgentGroups for realm ");
sb.append(realm).append("; size = ").append(results.size()).append(":\n");
for (Iterator it = results.iterator(); it.hasNext(); ) {
AMIdentity aid = (AMIdentity) it.next();
processAgentIdentity(aid, sb);
}
debug.error(classMethod + sb.toString());
} catch (IdRepoException e) {
debug.error(classMethod + "idrepo error getting agents: " + e.getMessage());
} catch (SSOException e) {
debug.error(classMethod + "sso error getting agents: " + e.getMessage());
}
}
Aggregations