Search in sources :

Example 26 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class OpenSSOIndexStore method getOrgAliasMappingResources.

static Set<String> getOrgAliasMappingResources(String realm, String applicationTypeName) throws SMSException {
    Set<String> results = new HashSet<String>();
    if (applicationTypeName.equalsIgnoreCase(ApplicationTypeManager.URL_APPLICATION_TYPE_NAME)) {
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        if (isOrgAliasMappingResourceEnabled(adminToken)) {
            OrganizationConfigManager m = new OrganizationConfigManager(adminToken, realm);
            Map<String, Set<String>> map = m.getAttributes(PolicyManager.ID_REPO_SERVICE);
            Set<String> orgAlias = map.get(PolicyManager.ORG_ALIAS);
            if ((orgAlias != null) && !orgAlias.isEmpty()) {
                for (String s : orgAlias) {
                    results.add(PolicyManager.ORG_ALIAS_URL_HTTPS_PREFIX + s.trim() + PolicyManager.ORG_ALIAS_URL_SUFFIX);
                    results.add(PolicyManager.ORG_ALIAS_URL_HTTP_PREFIX + s.trim() + PolicyManager.ORG_ALIAS_URL_SUFFIX);
                }
            }
        }
    }
    return results;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) HashSet(java.util.HashSet)

Example 27 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class EntitlementService method getParentAndPeerRealmNames.

public Set<String> getParentAndPeerRealmNames() throws EntitlementException {
    Set<String> results = new HashSet<String>();
    try {
        OrganizationConfigManager mgr = new OrganizationConfigManager(EntitlementUtils.getAdminToken(), realm);
        mgr = mgr.getParentOrgConfigManager();
        String parentRealm = DNMapper.orgNameToRealmName(mgr.getOrganizationName());
        results.add(parentRealm);
        Set<String> orgNames = mgr.getSubOrganizationNames();
        for (String o : orgNames) {
            results.add(DNMapper.orgNameToRealmName(o));
        }
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getSubRealmNames", ex);
    // realm no longer exist
    }
    return results;
}
Also used : SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) HashSet(java.util.HashSet)

Example 28 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class PolicyModelImpl method hasPolicyConfigSvcRegistered.

private boolean hasPolicyConfigSvcRegistered(String realmName) {
    try {
        OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(adminSSOToken, realmName);
        Set names = orgCfgMgr.getAssignedServices();
        return (names != null) && names.contains(AMAdminConstants.POLICY_SERVICE);
    } catch (SMSException e) {
        debug.warning("PolicyModelImpl.hasPolicyConfigSvcRegistered", e);
        return false;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager)

Example 29 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class CoreAttributesModelImpl method getAttributeValues.

/**
     * Returns attributes values.
     *
     * @return attributes values.
     */
public Map getAttributeValues() {
    Map attrs = null;
    String[] param = { currentRealm };
    logEvent("ATTEMPT_GET_AUTH_PROFILE_IN_REALM", param);
    try {
        OrganizationConfigManager scm = new OrganizationConfigManager(getUserSSOToken(), currentRealm);
        ServiceConfig config = scm.getServiceConfig(AUTH_SERVICE_NAME);
        attrs = config.getAttributes();
        if ((attrs == null) || attrs.isEmpty()) {
            debug.warning("no attributes were returned for Core Auth ...");
        }
        logEvent("SUCCEED_GET_AUTH_PROFILE_IN_REALM", param);
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, strError };
        logEvent("SMS_CONFIGURATION_EXCEPTION_GET_AUTH_PROFILE_IN_REALM", paramsEx);
        debug.error("CoreAttributesModelImpl.getAttributeValues", e);
    }
    return (attrs == null) ? Collections.EMPTY_MAP : attrs;
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Map(java.util.Map)

Example 30 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class IdServicesImpl method getServiceAttributesAscending.

/**
    * Non-javadoc, non-public methods
    * Get the service attributes of the name identity. Traverse to the global
    * configuration if necessary until all attributes are found or reached
    * the global area whichever occurs first.
    *
    * @param token is the sso token of the person performing this operation.
    * @param type is the identity type of the name parameter.
    * @param name is the identity we are interested in.
    * @param serviceName is the service we are interested in
    * @param attrNames are the name of the attributes wer are interested in.
    * @param amOrgName is the orgname.
    * @param amsdkDN is the amsdkDN.
    * @throws IdRepoException if there are repository related error conditions.
    * @throws SSOException if user's single sign on token is invalid.
    */
public Map getServiceAttributesAscending(SSOToken token, IdType type, String name, String serviceName, Set attrNames, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
    Map finalResult = new HashMap();
    Set finalAttrName = new HashSet();
    String nextName = name;
    String nextAmOrgName = amOrgName;
    String nextAmsdkDN = amsdkDN;
    IdType nextType = type;
    Set missingAttr = new HashSet(attrNames);
    do {
        // amsdkDN will change as we move up the tree.
        try {
            Map serviceResult = getServiceAttributes(token, nextType, nextName, serviceName, missingAttr, nextAmOrgName, nextAmsdkDN);
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdServicesImpl." + "getServiceAttributesAscending:" + " nextType=" + nextType + "; nextName=" + nextName + "; serviceName=" + serviceName + "; missingAttr=" + missingAttr + "; nextAmOrgName=" + nextAmOrgName + "; nextAmsdkDN=" + nextAmsdkDN);
                DEBUG.message("  getServiceAttributesAscending: " + "serviceResult=" + serviceResult);
                DEBUG.message("  getServiceAttributesAscending: " + " finalResult=" + finalResult);
                DEBUG.message("  getServiceAttributesAscending: " + " finalAttrName=" + finalAttrName);
            }
            if (serviceResult != null) {
                Set srvNameReturned = serviceResult.keySet();
                // save the newly found attrs
                // amsdk returns emptyset when attrname is not present.
                Iterator nameIt = srvNameReturned.iterator();
                while (nameIt.hasNext()) {
                    String attr = (String) nameIt.next();
                    Set attrValue = (Set) serviceResult.get(attr);
                    if (!attrValue.isEmpty()) {
                        finalResult.put(attr, attrValue);
                        finalAttrName.add(attr);
                    }
                }
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("    getServiceAttributesAscending:" + " serviceResult=" + serviceResult);
                    DEBUG.message("    getServiceAttributesAscending:" + " finalResult=" + finalResult);
                }
            }
            if (finalAttrName.containsAll(attrNames)) {
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("exit getServiceAttributesAscending:" + " finalResult=" + finalResult);
                }
                return (finalResult);
            }
            // find the missing attributes
            missingAttr.clear();
            Iterator it = attrNames.iterator();
            while (it.hasNext()) {
                String attrName = (String) it.next();
                if (!finalAttrName.contains(attrName)) {
                    missingAttr.add(attrName);
                }
            }
        } catch (IdRepoException idrepo) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("  getServiceAttributesAscending: " + "idrepoerr", idrepo);
            }
        } catch (SSOException ssoex) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("  getServiceAttributesAscending: " + "ssoex", ssoex);
            }
        }
        //  go up to the parent org
        try {
            if (nextType.equals(IdType.USER) || nextType.equals(IdType.AGENT)) {
                // try the user or agent's correct realm.
                nextAmsdkDN = nextAmOrgName;
                nextType = IdType.REALM;
            } else {
                OrganizationConfigManager ocm = new OrganizationConfigManager(token, nextAmOrgName);
                OrganizationConfigManager parentOCM = ocm.getParentOrgConfigManager();
                String parentName = parentOCM.getOrganizationName();
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("  getServiceAttributesAscending: " + "parentName=" + parentName);
                }
                nextType = IdType.REALM;
                if (nextAmOrgName.equalsIgnoreCase(parentName)) {
                    // at root.
                    nextName = null;
                } else {
                    nextAmOrgName = parentName;
                }
                nextAmOrgName = parentName;
                nextAmsdkDN = parentName;
            }
        } catch (SMSException smse) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("  getServiceAttributesAscending: " + "smserror", smse);
            }
            nextName = null;
        }
    } while (nextName != null);
    // get the rest from global.
    if (!missingAttr.isEmpty()) {
        try {
            ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
            ServiceSchema schema = ssm.getDynamicSchema();
            Map gAttrs = schema.getAttributeDefaults();
            Iterator missingIt = missingAttr.iterator();
            while (missingIt.hasNext()) {
                String missingAttrName = (String) missingIt.next();
                finalResult.put(missingAttrName, gAttrs.get(missingAttrName));
            }
        } catch (SMSException smse) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdServicesImpl(): getServiceAttributeAscending " + " Failed to get global default.", smse);
            }
        }
    }
    if (DEBUG.messageEnabled()) {
        DEBUG.message("exit end  getServiceAttributesAscending: " + " finalResult=" + finalResult);
    }
    return finalResult;
}
Also used : Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType) ServiceSchema(com.sun.identity.sm.ServiceSchema) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Aggregations

OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)144 SMSException (com.sun.identity.sm.SMSException)87 Set (java.util.Set)79 HashSet (java.util.HashSet)54 SSOException (com.iplanet.sso.SSOException)50 Map (java.util.Map)48 HashMap (java.util.HashMap)40 SSOToken (com.iplanet.sso.SSOToken)33 IdRepoException (com.sun.identity.idm.IdRepoException)32 Iterator (java.util.Iterator)28 AMIdentity (com.sun.identity.idm.AMIdentity)23 CLIException (com.sun.identity.cli.CLIException)21 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)20 ServiceConfig (com.sun.identity.sm.ServiceConfig)17 IOutput (com.sun.identity.cli.IOutput)15 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)15 List (java.util.List)10 ForbiddenException (org.forgerock.json.resource.ForbiddenException)9 BadRequestException (org.forgerock.json.resource.BadRequestException)8 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)8