Search in sources :

Example 56 with AttributeSchema

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

the class MAPCreateDeviceModelImpl method getCreateDeviceDefaultValues.

private void getCreateDeviceDefaultValues(Set attributeSchemas, String clientType, String style) {
    createDeviceDefaultValues = new HashMap(attributeSchemas.size());
    for (Iterator iter = attributeSchemas.iterator(); iter.hasNext(); ) {
        AttributeSchema as = (AttributeSchema) iter.next();
        String asName = as.getName();
        if (asName.equals(ATTRIBUTE_NAME_PARENT_TYPE)) {
            Set set = new HashSet(1);
            set.add(style);
            createDeviceDefaultValues.put(asName, set);
        } else if (asName.equals(ATTRIBUTE_NAME_CLIENT_TYPE)) {
            Set set = new HashSet(1);
            set.add(canonicalize(clientType));
            createDeviceDefaultValues.put(asName, set);
        } else if (asName.equals(ATTRIBUTE_NAME_USER_AGENT)) {
            Set set = new HashSet(1);
            set.add(clientType);
            createDeviceDefaultValues.put(asName, set);
        } else {
            createDeviceDefaultValues.put(as.getName(), as.getDefaultValues());
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) HashSet(java.util.HashSet)

Example 57 with AttributeSchema

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

the class MAPDeviceProfileModelImpl method getAttributeSchemas.

private Set getAttributeSchemas(Set names) {
    Set results = new HashSet(names.size() * 2);
    for (Iterator iter = names.iterator(); iter.hasNext(); ) {
        String name = (String) iter.next();
        AttributeSchema as = getDeviceAttributeSchema(name);
        if (as != null) {
            results.add(as);
        }
    }
    return results;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) HashSet(java.util.HashSet)

Example 58 with AttributeSchema

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

the class MAPCreateDeviceModelImpl method getAttributeSchema.

private AttributeSchema getAttributeSchema(String name) {
    AttributeSchema as = null;
    AMClientCapData internalInstance = getClientCapDataIntInstance();
    AMClientCapData externalInstance = getClientCapDataExtInstance();
    if ((internalInstance != null) && (externalInstance != null)) {
        as = internalInstance.getAttributeSchema(name);
        if (as == null) {
            as = externalInstance.getAttributeSchema(name);
        }
        if (as != null) {
            String i18nKey = as.getI18NKey();
            if ((i18nKey == null) || (i18nKey.length() == 0)) {
                as = null;
            }
        }
    }
    return as;
}
Also used : AMClientCapData(com.iplanet.services.cdm.clientschema.AMClientCapData) AttributeSchema(com.sun.identity.sm.AttributeSchema)

Example 59 with AttributeSchema

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

the class SmsJsonConverter method toJson.

/**
     * Will validate the Map representation of the service configuration against the serviceSchema and return a
     * corresponding JSON representation
     *
     * @param attributeValuePairs The schema attribute values.
     * @param realm The realm, or null if global.
     * @return Json representation of attributeValuePairs
     */
public JsonValue toJson(String realm, Map<String, Set<String>> attributeValuePairs) {
    if (!initialised) {
        init();
    }
    final boolean validAttributes;
    try {
        if (realm == null) {
            validAttributes = schema.validateAttributes(attributeValuePairs);
        } else {
            validAttributes = schema.validateAttributes(attributeValuePairs, realm);
        }
    } catch (SMSException e) {
        debug.error("schema validation threw an exception while validating the attributes: realm=" + realm + " attributes: " + attributeValuePairs, e);
        throw new JsonException("Unable to validate attributes", e);
    }
    JsonValue parentJson = json(new HashMap<String, Object>());
    if (validAttributes) {
        for (String attributeName : attributeValuePairs.keySet()) {
            String jsonResourceName = attributeNameToResourceName.get(attributeName);
            String name;
            if (jsonResourceName != null) {
                name = jsonResourceName;
            } else {
                name = attributeName;
            }
            AttributeSchema attributeSchema = schema.getAttributeSchema(attributeName);
            if (shouldBeIgnored(attributeName)) {
                continue;
            }
            AttributeSchema.Type type = attributeSchema.getType();
            final Set<String> object = attributeValuePairs.get(attributeName);
            Object jsonAttributeValue = null;
            if (type == null) {
                throw new JsonException("Type not defined.");
            }
            AttributeSchemaConverter attributeSchemaConverter = attributeSchemaConverters.get(name);
            if (isASingleValue(type)) {
                if (!object.isEmpty()) {
                    jsonAttributeValue = attributeSchemaConverter.toJson(object.iterator().next());
                }
            } else if (containsMultipleValues(type)) {
                if (isAMap(attributeSchema.getUIType())) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    Iterator<String> itr = object.iterator();
                    while (itr.hasNext()) {
                        Pair<String, String> entry = nameValueParser.parse(itr.next());
                        map.put(entry.getFirst(), attributeSchemaConverter.toJson(entry.getSecond()));
                    }
                    jsonAttributeValue = map;
                } else {
                    List<Object> list = new ArrayList<Object>();
                    Iterator<String> itr = object.iterator();
                    while (itr.hasNext()) {
                        list.add(attributeSchemaConverter.toJson(itr.next()));
                    }
                    jsonAttributeValue = list;
                }
            }
            String sectionName = attributeNameToSection.get(attributeName);
            if (sectionName != null) {
                parentJson.putPermissive(new JsonPointer("/" + sectionName + "/" + name), jsonAttributeValue);
            } else {
                parentJson.put(name, jsonAttributeValue);
            }
        }
    } else {
        throw new JsonException("Invalid attributes");
    }
    return parentJson;
}
Also used : JsonException(org.forgerock.json.JsonException) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) JsonPointer(org.forgerock.json.JsonPointer) AttributeSchema(com.sun.identity.sm.AttributeSchema) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashBiMap(org.forgerock.guava.common.collect.HashBiMap) BiMap(org.forgerock.guava.common.collect.BiMap) Pair(org.forgerock.util.Pair)

Example 60 with AttributeSchema

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

the class SmsJsonConverter method init.

private synchronized void init() {
    if (initialised) {
        return;
    }
    attributeNameToResourceName = getAttributeNameToResourceName(schema);
    hiddenAttributeNames = getHiddenAttributeNames();
    for (Object attributeName : schema.getAttributeSchemaNames()) {
        AttributeSchemaConverter attributeSchemaConverter;
        final AttributeSchema attributeSchema = this.schema.getAttributeSchema((String) attributeName);
        final AttributeSchema.Syntax syntax = attributeSchema.getSyntax();
        attributeSchemaConverter = getAttributeSchemaValue(syntax);
        final String resourceName = attributeSchema.getResourceName();
        if (resourceName == null) {
            attributeSchemaConverters.put((String) attributeName, attributeSchemaConverter);
        } else {
            attributeSchemaConverters.put(resourceName, attributeSchemaConverter);
        }
    }
    resourceNameToAttributeName = attributeNameToResourceName.inverse();
    attributeNameToSection = getAttributeNameToSection();
    initialised = true;
}
Also used : AttributeSchema(com.sun.identity.sm.AttributeSchema)

Aggregations

AttributeSchema (com.sun.identity.sm.AttributeSchema)149 Iterator (java.util.Iterator)80 ServiceSchema (com.sun.identity.sm.ServiceSchema)76 Set (java.util.Set)75 SMSException (com.sun.identity.sm.SMSException)67 HashSet (java.util.HashSet)59 SSOException (com.iplanet.sso.SSOException)58 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)46 HashMap (java.util.HashMap)36 Map (java.util.Map)34 CLIException (com.sun.identity.cli.CLIException)28 CLIRequest (com.sun.identity.cli.CLIRequest)18 AfterTest (org.testng.annotations.AfterTest)18 BeforeTest (org.testng.annotations.BeforeTest)18 Parameters (org.testng.annotations.Parameters)18 Test (org.testng.annotations.Test)18 IOutput (com.sun.identity.cli.IOutput)14 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)10 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)9 SSOToken (com.iplanet.sso.SSOToken)8