Search in sources :

Example 6 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class OpenSSOGroupSubject method getSearchIndexAttributes.

/**
     * Returns search index attributes.
     *
     * @return search index attributes.
     */
@Override
public Map<String, Set<String>> getSearchIndexAttributes() {
    SubjectAttributesManager sam = getSubjectAttributesManager();
    if (sam != null) {
        Map<String, Set<String>> map = new HashMap<String, Set<String>>(4);
        if (sam.isGroupMembershipSearchIndexEnabled()) {
            Set<String> set = new HashSet<String>();
            String uuid = getID();
            SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
            try {
                AMIdentity amid = IdUtils.getIdentity(adminToken, uuid);
                set.add(OpenSSOSubjectAttributesCollector.getIDWithoutOrgName(amid));
            } catch (IdRepoException ex) {
                if (PrivilegeManager.debug.messageEnabled()) {
                    PrivilegeManager.debug.message("OpenSSOGroupSubject.getSearchIndexAttributes", ex);
                }
                set.add(uuid);
            }
            map.put(SubjectAttributesCollector.NAMESPACE_MEMBERSHIP + IdType.GROUP.getName(), set);
        } else {
            Set<String> set = new HashSet<String>();
            set.add(SubjectAttributesCollector.ATTR_NAME_ALL_ENTITIES);
            map.put(SubjectAttributesCollector.NAMESPACE_IDENTITY, set);
        }
        return map;
    } else {
        return super.getSearchIndexAttributes();
    }
}
Also used : SubjectAttributesManager(com.sun.identity.entitlement.SubjectAttributesManager) Set(java.util.Set) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) HashSet(java.util.HashSet)

Example 7 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class OpenSSOSubjectAttributesCollector method hasAttribute.

/**
     * Returns <code>true</code> if attribute value for the given user
     * represented by <class>Subject</class> object is present.
     *
     * @param subject identity of the user
     * @param attrName attribute name to check
     * @param attrValue attribute value to check
     * @return <code>true</code> if attribute value for the given user
     * represented by <class>Subject</class> object is present.
     * @throws com.sun.identity.entitlement.EntitlementException if this
     * operation failed.
     */
public boolean hasAttribute(Subject subject, String attrName, String attrValue) throws EntitlementException {
    String uuid = SubjectUtils.getPrincipalId(subject);
    try {
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        AMIdentity amid = new AMIdentity(adminToken, uuid);
        if (attrName.startsWith(NAMESPACE_ATTR)) {
            Set<String> values = amid.getAttribute(attrName.substring(NAMESPACE_ATTR.length()));
            return (values != null) ? values.contains(attrValue) : false;
        } else if (attrName.startsWith(NAMESPACE_MEMBERSHIP)) {
            IdType type = IdUtils.getType(attrName.substring(NAMESPACE_MEMBERSHIP.length()));
            if (type != null) {
                AMIdentity parent = new AMIdentity(adminToken, attrValue);
                if (parent.getType().equals(type)) {
                    Set<String> members = parent.getMembers(IdType.USER);
                    return members.contains(amid.getUniversalId());
                }
            }
        }
        return false;
    } catch (IdRepoException e) {
        Object[] params = { uuid };
        throw new EntitlementException(601, params, e);
    } catch (SSOException e) {
        Object[] params = { uuid };
        throw new EntitlementException(601, params, e);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) HashSet(java.util.HashSet) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType)

Example 8 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class OpenSSOSubjectAttributesCollector method getUserAttributes.

/**
     * Returns the attribute values of the given user represented by
     * <class>Subject</class> object.
     *
     * @param subject identity of the user.
     * @param attrNames requested attribute names.
     * @return a map of attribute names and their values
     * @throws com.sun.identity.entitlement.EntitlementException if this
     * operation failed.
     */
public Map<String, Set<String>> getUserAttributes(Subject subject, Set<String> attrNames) throws EntitlementException {
    String uuid = SubjectUtils.getPrincipalId(subject);
    try {
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        AMIdentity amid = new AMIdentity(adminToken, uuid);
        return amid.getAttributes(attrNames);
    } catch (IdRepoException e) {
        Object[] params = { uuid };
        throw new EntitlementException(601, params, e);
    } catch (SSOException e) {
        Object[] params = { uuid };
        throw new EntitlementException(601, params, e);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 9 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class DefaultOpenIdConnectTokenClaimMapper method getCustomClaims.

@Override
public Map<String, String> getCustomClaims(SSOToken token, Map<String, String> claimMap) throws TokenCreationException {
    try {
        final AMIdentity amIdentity = IdUtils.getIdentity(token);
        final HashSet<String> attributeNames = new HashSet<>(claimMap.size());
        attributeNames.addAll(claimMap.values());
        Map<String, String> joinedMappings = joinMultiValues(amIdentity.getAttributes(attributeNames));
        /*
             At this point, the key entries joinedMappings will be the attribute name, and the value will be the
             corresponding value pulled from the user data store. Because I need to return a Map where the keys are the
             claim names, as in the claimMap parameter, I need to create a new map, whose keys correspond to the
             keys in the claimMap parameter, and whose value correspond to the joinedMappings value.
             */
        Map<String, String> adjustedMap = new HashMap<>(joinedMappings.size());
        for (Map.Entry<String, String> claimMapEntry : claimMap.entrySet()) {
            if (!StringUtils.isEmpty(joinedMappings.get(claimMapEntry.getValue()))) {
                adjustedMap.put(claimMapEntry.getKey(), joinedMappings.get(claimMapEntry.getValue()));
            }
        }
        return adjustedMap;
    } catch (IdRepoException | SSOException e) {
        throw new TokenCreationException(ResourceException.INTERNAL_ERROR, "Exception encountered in claim attribute lookup: " + e, e);
    }
}
Also used : HashMap(java.util.HashMap) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map) TokenCreationException(org.forgerock.openam.sts.TokenCreationException) HashSet(java.util.HashSet)

Example 10 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class DelegationPolicyImpl method getSubjects.

/**
     * Returns a set of selected subjects of specified types matching the
     * pattern in the given realm. The pattern accepts "*" as the wild card for
     * searching subjects. For example, "a*c" matches with any subject starting
     * with a and ending with c.
     * 
     * @param token The <code>SSOToken</code> of the requesting user
     * @param orgName The name of the realm from which the subjects are fetched.
     * @param types a set of subject types. e.g. ROLE, GROUP.
     * @param pattern a filter used to select the subjects.
     * 
     * @return a set of subjects associated with the realm.
     * 
     * @throws SSOException invalid or expired single-sign-on token
     * @throws DelegationException for any abnormal condition
     *
     * @return <code>Set</code> of universal Ids of the subjects associated 
     *         with the realm.
     *
     * @throws SSOException invalid or expired single-sign-on token
     * @throws DelegationException for any abnormal condition
     */
public Set getSubjects(SSOToken token, String orgName, Set types, String pattern) throws SSOException, DelegationException {
    Set results = new HashSet();
    // All Authenticated Users would be returned only if pattern is *
    if ((pattern != null) && pattern.equals("*")) {
        results.add(AUTHN_USERS_ID);
    }
    if (DelegationManager.debug.messageEnabled()) {
        DelegationManager.debug.message("DelegationPolicyImpl.getSubjects(): types=" + types);
    }
    try {
        AMIdentityRepository idRepo = new AMIdentityRepository(appToken, orgName);
        Set supportedTypes = idRepo.getSupportedIdTypes();
        if (DelegationManager.debug.messageEnabled()) {
            DelegationManager.debug.message("DelegationPolicyImpl.getSubjects(): " + "supported subject types=" + supportedTypes);
        }
        if ((supportedTypes != null) && (!supportedTypes.isEmpty()) && (types != null) && (!types.isEmpty())) {
            Iterator it = types.iterator();
            while (it.hasNext()) {
                IdType idType = IdUtils.getType((String) it.next());
                if (supportedTypes.contains(idType)) {
                    IdSearchControl ctrl = new IdSearchControl();
                    ctrl.setRecursive(true);
                    ctrl.setMaxResults(-1);
                    ctrl.setTimeOut(-1);
                    IdSearchResults idsr = idRepo.searchIdentities(idType, pattern, ctrl);
                    if (idsr != null) {
                        Set searchRes = idsr.getSearchResults();
                        if ((searchRes != null) && (!searchRes.isEmpty())) {
                            Iterator iter = searchRes.iterator();
                            while (iter.hasNext()) {
                                AMIdentity id = (AMIdentity) iter.next();
                                results.add(IdUtils.getUniversalId(id));
                            }
                        }
                    }
                }
            }
        }
        return results;
    } catch (IdRepoException ide) {
        throw new DelegationException(ide);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) IdSearchControl(com.sun.identity.idm.IdSearchControl) IdRepoException(com.sun.identity.idm.IdRepoException) DelegationException(com.sun.identity.delegation.DelegationException) HashSet(java.util.HashSet) IdType(com.sun.identity.idm.IdType)

Aggregations

IdRepoException (com.sun.identity.idm.IdRepoException)403 SSOException (com.iplanet.sso.SSOException)275 Set (java.util.Set)224 AMIdentity (com.sun.identity.idm.AMIdentity)221 HashSet (java.util.HashSet)183 Map (java.util.Map)121 Iterator (java.util.Iterator)118 SSOToken (com.iplanet.sso.SSOToken)112 HashMap (java.util.HashMap)110 SMSException (com.sun.identity.sm.SMSException)103 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)96 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)67 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)58 IdType (com.sun.identity.idm.IdType)57 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)51 CLIException (com.sun.identity.cli.CLIException)48 IOutput (com.sun.identity.cli.IOutput)45 IdSearchResults (com.sun.identity.idm.IdSearchResults)44 IdSearchControl (com.sun.identity.idm.IdSearchControl)39 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)35