Search in sources :

Example 91 with AMIdentity

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;
        }
    };
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) RootContext(org.forgerock.services.context.RootContext) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SessionContext(org.forgerock.http.session.SessionContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) AttributesContext(org.forgerock.services.context.AttributesContext) SecurityContext(org.forgerock.services.context.SecurityContext) Context(org.forgerock.services.context.Context) SSOToken(com.iplanet.sso.SSOToken) RealmContext(org.forgerock.openam.rest.RealmContext) SessionResource(org.forgerock.openam.core.rest.session.SessionResource) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) SessionQueryManager(org.forgerock.openam.core.rest.session.query.SessionQueryManager) AuthUtilsWrapper(org.forgerock.openam.authentication.service.AuthUtilsWrapper) AMIdentity(com.sun.identity.idm.AMIdentity) SessionPropertyWhitelist(org.forgerock.openam.session.SessionPropertyWhitelist) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 92 with AMIdentity

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;
}
Also used : IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 93 with AMIdentity

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());
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) AMIdentity(com.sun.identity.idm.AMIdentity) Iterator(java.util.Iterator) AgentsModel(com.sun.identity.console.agentconfig.model.AgentsModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 94 with AMIdentity

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();
    }
}
Also used : AMViewBeanBase(com.sun.identity.console.base.AMViewBeanBase) StringTokenizer(java.util.StringTokenizer) SSOToken(com.iplanet.sso.SSOToken) AMIdentity(com.sun.identity.idm.AMIdentity) AgentsModel(com.sun.identity.console.agentconfig.model.AgentsModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 95 with AMIdentity

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;
}
Also used : IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) IdSearchControl(com.sun.identity.idm.IdSearchControl) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException)

Aggregations

AMIdentity (com.sun.identity.idm.AMIdentity)373 IdRepoException (com.sun.identity.idm.IdRepoException)243 SSOException (com.iplanet.sso.SSOException)215 Set (java.util.Set)170 HashSet (java.util.HashSet)150 SSOToken (com.iplanet.sso.SSOToken)112 Iterator (java.util.Iterator)91 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)85 Map (java.util.Map)83 HashMap (java.util.HashMap)78 IdType (com.sun.identity.idm.IdType)52 SMSException (com.sun.identity.sm.SMSException)52 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)44 CLIException (com.sun.identity.cli.CLIException)43 IOutput (com.sun.identity.cli.IOutput)42 IdSearchResults (com.sun.identity.idm.IdSearchResults)39 IdSearchControl (com.sun.identity.idm.IdSearchControl)35 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)23 Test (org.testng.annotations.Test)23 List (java.util.List)22