Search in sources :

Example 1 with ServiceSchemaManager

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

the class AMIdentity method getServiceAttributesName.

private Set getServiceAttributesName(String serviceName) throws IdRepoException, SSOException {
    Set attrNames = Collections.EMPTY_SET;
    try {
        // Get attribute names for USER type only, so plugin knows
        // what attributes to remove.
        attrNames = new HashSet();
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        ServiceSchema uss = ssm.getSchema(type.getName());
        if (uss != null) {
            attrNames = uss.getAttributeSchemaNames();
        }
        // realm, need to add dynamic attributes also
        if (!(type.equals(IdType.ROLE) || type.equals(IdType.REALM) || type.equals(IdType.FILTEREDROLE))) {
            uss = ssm.getDynamicSchema();
            if (uss != null) {
                if (attrNames == Collections.EMPTY_SET) {
                    attrNames = uss.getAttributeSchemaNames();
                } else {
                    attrNames.addAll(uss.getAttributeSchemaNames());
                }
            }
        } else {
            // Add COS priority attribute
            attrNames.add(COS_PRIORITY);
        }
    } catch (SMSException smse) {
        if (debug.messageEnabled()) {
            debug.message("AMIdentity.getServiceAttributes: Caught SM exception", smse);
        }
    // just returned whatever we find or empty set
    // if services is not found.
    }
    return attrNames;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 2 with ServiceSchemaManager

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

the class AMIdentity method unassignService.

/**
     * Removes a service from the identity.
     *
     * This method is only valid for AMIdentity object of type User.
     *
     * @param serviceName
     *            Name of service to be removed.
     * @throws IdRepoException
     *             If there are repository related error conditions.
     * @throws SSOException
     *             If user's single sign on token is invalid.
     * @supported.api
     */
public void unassignService(String serviceName) throws IdRepoException, SSOException {
    IdServices idServices = IdServicesFactory.getDataStoreServices();
    Set OCs = getServiceOCs(token, serviceName);
    Map tMap = new HashMap();
    tMap.put(serviceName, OCs);
    Set assignedServices = idServices.getAssignedServices(token, type, name, tMap, orgName, univDN);
    if (!assignedServices.contains(serviceName)) {
        Object[] args = { serviceName };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
    }
    Map attrMap = new HashMap();
    Set objectclasses = getAttribute("objectclass");
    if (objectclasses != null && !objectclasses.isEmpty()) {
        Set removeOCs = AMCommonUtils.updateAndGetRemovableOCs(objectclasses, OCs);
        try {
            // Get attribute names for USER type only, so plugin knows
            // what attributes to remove.
            Set attrNames = new HashSet();
            ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
            ServiceSchema uss = ssm.getSchema(type.getName());
            if (uss != null) {
                attrNames = uss.getAttributeSchemaNames();
            }
            Iterator it = attrNames.iterator();
            while (it.hasNext()) {
                String a = (String) it.next();
                attrMap.put(a, Collections.EMPTY_SET);
            }
        } catch (SMSException smse) {
        /*
                 * debug.error( "AMIdentity.unassignService: Caught SM
                 * exception", smse); do nothing
                 */
        }
        attrMap.put("objectclass", removeOCs);
    // The protocol is to pass service Name and Map of objectclasses
    // to be removed from entry.
    }
    idServices.unassignService(token, type, name, serviceName, attrMap, orgName, univDN);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) ServiceSchema(com.sun.identity.sm.ServiceSchema) Iterator(java.util.Iterator) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 3 with ServiceSchemaManager

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

the class AMIdentity method getServiceConfig.

/**
     * Get service default config from SMS
     *
     * @param token
     *            SSOToken a valid SSOToken
     * @param serviceName
     *            the service name
     * @param type
     *            service schema type (Dynamic, Policy etc)
     * @return returns a Map of Default Configuration values for the specified
     *         service.
     */
private Map getServiceConfig(SSOToken token, String serviceName, SchemaType type) throws SMSException, SSOException {
    // Map of attribute/value pairs
    Map attrMap = null;
    if (type != SchemaType.POLICY) {
        ServiceSchemaManager scm = new ServiceSchemaManager(serviceName, token);
        ServiceSchema gsc = scm.getSchema(type);
        attrMap = gsc.getAttributeDefaults();
    }
    return attrMap;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 4 with ServiceSchemaManager

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

the class AMIdentity method modifyService.

/**
     * Set attributes related to a specific service. The assumption is that the
     * service is already assigned to the identity. The attributes for the
     * service are validated against the service schema.
     *
     * This method is only valid for AMIdentity object of type User.
     *
     * @param serviceName
     *            Name of the service.
     * @param attrMap
     *            Map of attribute-values.
     * @throws IdRepoException
     *             If there are repository related error conditions.
     * @throws SSOException
     *             If user's single sign on token is invalid.
     * @supported.api
     */
public void modifyService(String serviceName, Map attrMap) throws IdRepoException, SSOException {
    IdServices idServices = IdServicesFactory.getDataStoreServices();
    Set OCs = getServiceOCs(token, serviceName);
    SchemaType stype;
    Map tMap = new HashMap();
    tMap.put(serviceName, OCs);
    Set assignedServices = idServices.getAssignedServices(token, type, name, tMap, orgName, univDN);
    if (!assignedServices.contains(serviceName)) {
        Object[] args = { serviceName };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
    }
    // Check if attrMap has cos priority attribute
    // If present, remove it for validating the attributes
    boolean hasCosPriority = (new CaseInsensitiveHashSet(attrMap.keySet()).contains(COS_PRIORITY));
    Object values = null;
    if (hasCosPriority) {
        attrMap = new CaseInsensitiveHashMap(attrMap);
        values = attrMap.remove(COS_PRIORITY);
    }
    // Validate the attributes
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        ServiceSchema ss = ssm.getSchema(type.getName());
        if (ss != null) {
            attrMap = ss.validateAndInheritDefaults(attrMap, false);
            stype = ss.getServiceType();
        } else if ((ss = ssm.getSchema(SchemaType.DYNAMIC)) != null) {
            attrMap = ss.validateAndInheritDefaults(attrMap, false);
            stype = SchemaType.DYNAMIC;
        } else {
            Object[] args = { serviceName };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, args);
        }
    } catch (SMSException smse) {
        // debug.error
        Object[] args = { serviceName };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.DATA_INVALID_FOR_SERVICE, args);
    }
    // Add COS priority if present
    if (hasCosPriority) {
        attrMap.put(COS_PRIORITY, values);
    }
    // modify service attrs
    if (debug.messageEnabled()) {
        debug.message("AMIdentity.modifyService befre idService " + "serviceName=" + serviceName + ";  attrMap=" + attrMap);
    }
    idServices.modifyService(token, type, name, serviceName, stype, attrMap, orgName, univDN);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) SchemaType(com.sun.identity.sm.SchemaType) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) ServiceSchema(com.sun.identity.sm.ServiceSchema) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 5 with ServiceSchemaManager

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

the class AMIdentity method serviceHasSubSchema.

/**
     * Returns true if the service has the subSchema. False otherwise.
     *
     * @param token
     *            SSOToken a valid SSOToken
     * @param serviceName
     *            the service name
     * @param schemaType
     *            service schema type (Dynamic, Policy etc)
     * @return true if the service has the subSchema.
     */
private boolean serviceHasSubSchema(SSOToken token, String serviceName, SchemaType schemaType) throws SMSException, SSOException {
    boolean schemaTypeFlg = false;
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        Set types = ssm.getSchemaTypes();
        if (debug.messageEnabled()) {
            debug.message("AMServiceUtils.serviceHasSubSchema() " + "SchemaTypes types for " + serviceName + " are: " + types);
        }
        schemaTypeFlg = types.contains(schemaType);
    } catch (ServiceNotFoundException ex) {
        if (debug.warningEnabled()) {
            debug.warning("AMServiceUtils.serviceHasSubSchema() " + "Service does not exist : " + serviceName);
        }
    }
    return (schemaTypeFlg);
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Aggregations

ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)209 SMSException (com.sun.identity.sm.SMSException)146 ServiceSchema (com.sun.identity.sm.ServiceSchema)131 SSOException (com.iplanet.sso.SSOException)119 Set (java.util.Set)87 HashSet (java.util.HashSet)60 Map (java.util.Map)56 HashMap (java.util.HashMap)49 AttributeSchema (com.sun.identity.sm.AttributeSchema)46 SSOToken (com.iplanet.sso.SSOToken)43 Iterator (java.util.Iterator)40 CLIException (com.sun.identity.cli.CLIException)33 BeforeTest (org.testng.annotations.BeforeTest)27 AfterTest (org.testng.annotations.AfterTest)26 Test (org.testng.annotations.Test)26 CLIRequest (com.sun.identity.cli.CLIRequest)25 Parameters (org.testng.annotations.Parameters)18 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)15 TreeSet (java.util.TreeSet)12 ByteString (org.forgerock.opendj.ldap.ByteString)11