use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class SessionResourceTest method setUp.
@BeforeMethod
public void setUp() throws IdRepoException, SSOException {
SessionQueryManager sessionQueryManager = mock(SessionQueryManager.class);
ssoTokenManager = mock(SSOTokenManager.class);
authUtilsWrapper = mock(AuthUtilsWrapper.class);
propertyWhitelist = mock(SessionPropertyWhitelist.class);
headerResponse = null;
urlResponse = null;
cookieResponse = null;
given(mockContext.getCallerSSOToken()).willReturn(ssoToken);
realmContext = new RealmContext(mockContext);
amIdentity = new AMIdentity(DN.valueOf("id=demo,dc=example,dc=com"), null);
configureWhitelist();
sessionResource = new SessionResource(sessionQueryManager, ssoTokenManager, authUtilsWrapper, propertyWhitelist) {
@Override
AMIdentity getIdentity(SSOToken ssoToken) throws IdRepoException, SSOException {
return amIdentity;
}
@Override
String convertDNToRealm(String dn) {
return "/";
}
@Override
protected String getTokenIdFromHeader(Context context, String cookieName) {
return headerResponse;
}
@Override
protected String getTokenIdFromUrlParam(ActionRequest request) {
return urlResponse;
}
@Override
protected String getTokenIdFromCookie(Context context, String cookieName) {
return cookieResponse;
}
};
}
use of com.sun.identity.idm.AMIdentity 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.AMIdentity in project OpenAM by OpenRock.
the class AgentGroupMembersViewBean method beginDisplay.
/**
* Displays servers and sites information.
*
* @param event Display Event.
* @throws ModelControlException if unable to initialize model.
*/
public void beginDisplay(DisplayEvent event) throws ModelControlException {
super.beginDisplay(event);
AgentsModel model = (AgentsModel) getModel();
String universalId = (String) getPageSessionAttribute(UNIVERSAL_ID);
try {
Set agents = model.getAgentGroupMembers(universalId);
if ((agents == null) || agents.isEmpty()) {
setDisplayFieldValue(CHILD_MEMBERS, model.getLocalizedString("agentconfig.group.members.nomembers"));
} else {
Set ordered = new TreeSet();
Map nameToId = new HashMap(agents.size() * 2);
for (Iterator i = agents.iterator(); i.hasNext(); ) {
AMIdentity amid = (AMIdentity) i.next();
String name = amid.getName();
ordered.add(name);
nameToId.put(name, amid.getUniversalId());
}
StringBuilder buff = new StringBuilder();
for (Iterator i = ordered.iterator(); i.hasNext(); ) {
String name = (String) i.next();
buff.append(name).append(" (").append((String) nameToId.get(name)).append(")<br />");
}
setDisplayFieldValue(CHILD_MEMBERS, buff.toString());
}
} catch (AMConsoleException e) {
setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class AgentsViewBean method handleTblDataActionGroupHrefRequest.
/**
* Forwards request to edit agent group view bean.
*
* @param event Request Invocation Event.
*/
public void handleTblDataActionGroupHrefRequest(RequestInvocationEvent event) {
AgentsModel model = (AgentsModel) getModel();
String idType = getDisplayIDType();
String universalId = hexToString((String) getDisplayFieldValue(TBL_DATA_ACTION_HREF_GROUP));
setPageSessionAttribute(AgentProfileViewBean.UNIVERSAL_ID, universalId);
SSOToken ssoToken = model.getUserSSOToken();
String realm = (String) getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
StringTokenizer st = new StringTokenizer(universalId, "=,");
st.nextToken();
String agentGrpName = st.nextToken();
try {
AMIdentity amid = new AMIdentity(ssoToken, agentGrpName, IdType.AGENTGROUP, realm, null);
String vbName = (String) agentViewBeans.get(idType);
if (vbName == null) {
vbName = GENERIC_VIEW_BEAN;
}
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(vbName);
AMViewBeanBase vb = (AMViewBeanBase) getViewBean(clazz);
removePageSessionAttribute(GenericAgentProfileViewBean.PS_TABNAME);
setPageSessionAttribute(PG_SESSION_SUPERCEDE_AGENT_TYPE, model.getAgentType(amid));
passPgSessionMap(vb);
vb.forwardTo(getRequestContext());
} catch (AMConsoleException e) {
setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", model.getErrorString(e));
forwardTo();
} catch (ClassNotFoundException e) {
setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", model.getErrorString(e));
forwardTo();
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class WindowsDesktopSSO method searchUserAccount.
/**
* Searches for an account with user Id userID in the organization organization
* @param attributeValue The attributeValue to compare when searching for an
* identity in the organization
* @param organization organization or the organization name where the identity will be
* looked up
* @return the attribute value for the identity searched. Empty string if not found or
* null if an error occurs
*/
private String searchUserAccount(String attributeValue, String organization) throws AuthLoginException {
String classMethod = "WindowsDesktopSSO.searchUserAccount: ";
if (organization.isEmpty()) {
organization = "/";
}
if (debug.messageEnabled()) {
debug.message(classMethod + " searching for user " + attributeValue + " in the organization =" + organization);
}
// And the search criteria
IdSearchControl searchControl = new IdSearchControl();
searchControl.setMaxResults(1);
searchControl.setTimeOut(3000);
searchControl.setSearchModifiers(IdSearchOpModifier.OR, buildSearchControl(attributeValue));
searchControl.setAllReturnAttributes(false);
try {
AMIdentityRepository amirepo = new AMIdentityRepository(getSSOSession(), organization);
IdSearchResults searchResults = amirepo.searchIdentities(IdType.USER, "*", searchControl);
if (searchResults.getErrorCode() == IdSearchResults.SUCCESS && searchResults != null) {
Set<AMIdentity> results = searchResults.getSearchResults();
if (!results.isEmpty()) {
if (debug.messageEnabled()) {
debug.message(classMethod + results.size() + " result(s) obtained");
}
AMIdentity userDNId = results.iterator().next();
if (userDNId != null) {
if (debug.messageEnabled()) {
debug.message(classMethod + "user = " + userDNId.getUniversalId());
debug.message(classMethod + "attrs =" + userDNId.getAttributes(getUserAliasList()));
}
return attributeValue.trim();
}
}
}
} catch (IdRepoException idrepoex) {
String[] data = { attributeValue, organization };
throw new AuthLoginException(amAuthWindowsDesktopSSO, "idRepoSearch", data, idrepoex);
} catch (SSOException ssoe) {
String[] data = { attributeValue, organization };
throw new AuthLoginException(amAuthWindowsDesktopSSO, "ssoSearch", data, ssoe);
}
if (debug.messageEnabled()) {
debug.message(classMethod + " No results were found !");
}
return null;
}
Aggregations