Search in sources :

Example 11 with SchemaType

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

the class AMIdentity method assignService.

/**
     * Assigns the service and service related attributes to the identity.
     *
     * This method is only valid for AMIdentity object of type User.
     *
     * @param serviceName
     *            Name of service to be assigned.
     * @param attributes
     *            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 assignService(String serviceName, Map attributes) 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, type.getName() };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_ALREADY_ASSIGNED, args);
    }
    // Validate the service attributes
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        ServiceSchema ss = ssm.getSchema(type.getName());
        if (ss != null) {
            // Check if attrMap has cos priority attribute
            // If present, remove it for validating the attributes
            Set cosPriority = (attributes != null) ? (Set) attributes.remove(COS_PRIORITY) : null;
            attributes = ss.validateAndInheritDefaults(attributes, orgName, true);
            if (cosPriority != null) {
                attributes.put(COS_PRIORITY, cosPriority);
            }
            attributes = AMCommonUtils.removeEmptyValues(attributes);
            stype = ss.getServiceType();
        } else {
            ss = ssm.getSchema(SchemaType.DYNAMIC);
            if (ss == null) {
                Object[] args = { serviceName };
                throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, args);
            }
            if (attributes == null) {
                try {
                    attributes = getServiceConfig(token, serviceName, SchemaType.DYNAMIC);
                } catch (SMSException smsex) {
                    Object[] args = { serviceName, type.getName() };
                    throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, "451", args);
                }
            } else {
                attributes = ss.validateAndInheritDefaults(attributes, orgName, true);
            }
            attributes = AMCommonUtils.removeEmptyValues(attributes);
            stype = SchemaType.DYNAMIC;
        }
        // TODO: Remove this dependency of AMCrypt
        attributes = AMCrypt.encryptPasswords(attributes, ss);
    } catch (SMSException smse) {
        // debug.error here
        Object[] args = { serviceName };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_NOT_ASSIGNED, args);
    }
    attributes.put("objectclass", OCs);
    // The protocol for params is to pass the
    // name of the service, and attribute Map containing the
    // OCs to be set and validated attribute map
    idServices.assignService(token, type, name, serviceName, stype, attributes, orgName, univDN);
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) 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) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) SchemaType(com.sun.identity.sm.SchemaType) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 12 with SchemaType

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

the class UpgradeUtils method getServiceSchema.

/**
     * Returns the <code>ServiceSchema</code> of a service.
     *
     * @param serviceName the service name
     * @param subSchemaName the sub schema.
     * @param schemaType the schema type.
     * @return the <code>ServiceSchema</code> object.
     * @throws UpgradeException if there is an error.
     */
public static ServiceSchema getServiceSchema(String serviceName, String subSchemaName, String schemaType, SSOToken adminToken) throws UpgradeException {
    ServiceSchema ss = null;
    try {
        SchemaType sType = getSchemaType(schemaType);
        ServiceSchemaManager ssm = getServiceSchemaManager(serviceName, adminToken);
        ss = ssm.getSchema(sType);
        if (subSchemaName != null) {
            ss = ss.getSubSchema(subSchemaName);
        }
    } catch (SMSException sme) {
        throw new UpgradeException("Cannot get service schema : " + sme.getMessage());
    }
    return ss;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) SchemaType(com.sun.identity.sm.SchemaType) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 13 with SchemaType

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

the class PropertyXMLBuilder method getAttributeSchemas.

private Map getAttributeSchemas(String serviceName) throws SMSException, SSOException {
    Map map = new HashMap();
    if (schemaTypes == null) {
        schemaTypes = svcSchemaManager.getSchemaTypes();
    }
    for (Iterator iter = schemaTypes.iterator(); iter.hasNext(); ) {
        SchemaType type = (SchemaType) iter.next();
        Object sectionTitle = mapSchemaTypeToName.get(type);
        if (sectionTitle != null) {
            Set set = getAttributeSchemas(type);
            if ((set != null) && !set.isEmpty()) {
                map.put(type, set);
            }
        }
    }
    return map;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) SchemaType(com.sun.identity.sm.SchemaType)

Example 14 with SchemaType

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

the class PropertyXMLBuilder method discardAttribute.

/**
     * Discards attributes from the builder.
     * 
     * @param discard Set of attribute names to be discarded.
     */
public void discardAttribute(Set discard) {
    for (Iterator i = mapTypeToAttributeSchema.keySet().iterator(); i.hasNext(); ) {
        SchemaType type = (SchemaType) i.next();
        Set attributeSchema = (Set) mapTypeToAttributeSchema.get(type);
        if ((attributeSchema != null) && !attributeSchema.isEmpty()) {
            for (Iterator j = attributeSchema.iterator(); j.hasNext(); ) {
                AttributeSchema as = (AttributeSchema) j.next();
                if (discard.contains(as.getName())) {
                    j.remove();
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) SchemaType(com.sun.identity.sm.SchemaType)

Example 15 with SchemaType

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

the class ServicesModelImpl method removeNonDisplayableServices.

private void removeNonDisplayableServices(Set serviceNames, Set schemaTypes) {
    for (Iterator i = serviceNames.iterator(); i.hasNext(); ) {
        String svcName = (String) i.next();
        if (getServicePropertiesViewBeanURL(svcName) == null) {
            boolean hasAttr = false;
            for (Iterator j = schemaTypes.iterator(); j.hasNext() && !hasAttr; ) {
                SchemaType type = (SchemaType) j.next();
                Set displayable = AMAdminUtils.getDisplayableAttributeNames(svcName, type);
                hasAttr = !displayable.isEmpty();
            }
            if (!hasAttr) {
                i.remove();
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) SchemaType(com.sun.identity.sm.SchemaType)

Aggregations

SchemaType (com.sun.identity.sm.SchemaType)17 Set (java.util.Set)12 ServiceSchema (com.sun.identity.sm.ServiceSchema)9 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)9 HashSet (java.util.HashSet)9 SMSException (com.sun.identity.sm.SMSException)8 Iterator (java.util.Iterator)8 SSOException (com.iplanet.sso.SSOException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 AttributeSchema (com.sun.identity.sm.AttributeSchema)3 AMHashMap (com.iplanet.am.sdk.AMHashMap)2 SSOToken (com.iplanet.sso.SSOToken)2 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)2 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)2 IdType (com.sun.identity.idm.IdType)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ResourceBundle (java.util.ResourceBundle)2 StringTokenizer (java.util.StringTokenizer)2