Search in sources :

Example 41 with AttributeSchema

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

the class PropertyXMLBuilderBase method buildAttributeSchemaTypeXML.

protected void buildAttributeSchemaTypeXML(AttributeSchema as, StringBuffer xml, AMModel model, ResourceBundle serviceBundle, boolean addSubSection) {
    String tagClassName = getTagClassName(as);
    if (tagClassName != null) {
        String name = getAttributeNameForPropertyXML(as);
        boolean editableList = tagClassName.equals(TAGNAME_EDITABLE_LIST);
        boolean orderedList = tagClassName.equals(TAGNAME_ORDERED_LIST);
        boolean unorderedList = tagClassName.equals(TAGNAME_UNORDERED_LIST);
        boolean mapList = tagClassName.equals(TAGNAME_MAP_LIST);
        boolean globalMapList = tagClassName.equals(TAGNAME_GLOBAL_MAP_LIST);
        AttributeSchema.Type type = as.getType();
        AttributeSchema.UIType uitype = as.getUIType();
        boolean addremovelist = type.equals(AttributeSchema.Type.MULTIPLE_CHOICE) && (uitype != null) && uitype.equals(AttributeSchema.UIType.ADDREMOVELIST);
        boolean listTyped = editableList || orderedList || unorderedList || mapList || globalMapList || addremovelist;
        if (listTyped && addSubSection) {
            /*
                * create a subsection without a title to hold the 
                * editable list component.
                */
            xml.append(SUBSECTION_DUMMY_START_TAG);
        }
        if (needRequiredTag(as)) {
            xml.append(PROPERTY_REQUIRED_START_TAG);
        } else {
            xml.append(PROPERTY_START_TAG);
        }
        addLabel(as, xml, serviceBundle);
        if (addremovelist) {
            xml.append(GROUP_START_TAG).append(PROPERTY_START_TAG);
            appendAddRemoveListComponent(as, xml, serviceBundle);
            addremovelist = true;
        } else {
            //need to handle link specially.
            if (tagClassName.equals(TAGNAME_BUTTON)) {
                String editString = model.getLocalizedString("label.edit");
                Object[] pLink = { "'" + name + "'", editString };
                xml.append(MessageFormat.format(COMPONENT_BUTTON_START_TAG, pLink));
            } else if (tagClassName.equals(TAGNAME_HREF)) {
                String editString = model.getLocalizedString("label.edit");
                Object[] pLink = { PropertyTemplate.PARAM_ATTR_NAME + "=" + name + "&" + PropertyTemplate.PARAM_PROPERTIES_VIEW_BEAN_URL + "=" + as.getPropertiesViewBeanURL(), "linkLabel" + name, editString };
                xml.append(MessageFormat.format(COMPONENT_LINK_START_TAG, pLink));
            } else if (tagClassName.equals(TAGNAME_CHECKBOX)) {
                Object[] param = { name, tagClassName, model.getLocalizedString("label.Enable") };
                xml.append(MessageFormat.format(COMPONENT_BOOLEAN_START_TAG, param));
            } else if (listTyped) {
                /* 
                     * putting the editable list component wihin a group tag
                     * to help isolate the list box and text box together on the
                     * page. Otherwise the list component blends in with other
                     * components on the page.
                     */
                Object[] param = { name, model.getLocalizedString("label.current.value"), model.getLocalizedString("label.new.value") };
                xml.append(GROUP_START_TAG).append(PROPERTY_START_TAG);
                if (editableList) {
                    xml.append(MessageFormat.format(COMPONENT_EDITABLE_LIST_START_TAG, param));
                } else if (orderedList) {
                    xml.append(MessageFormat.format(COMPONENT_ORDERED_LIST_START_TAG, param));
                } else if (unorderedList) {
                    xml.append(MessageFormat.format(COMPONENT_UNORDERED_LIST_START_TAG, param));
                } else if (mapList) {
                    xml.append(MessageFormat.format(COMPONENT_MAP_LIST_START_TAG, param));
                    appendChoiceValues(as, xml, model, serviceBundle);
                } else if (globalMapList) {
                    xml.append(MessageFormat.format(COMPONENT_GLOBAL_MAP_LIST_START_TAG, param));
                }
            } else {
                Object[] param = { name, tagClassName };
                xml.append(MessageFormat.format(COMPONENT_START_TAG, param));
                /*
                     * if its a textarea component add the no localize attribute
                     * set the size of the text field based on its syntax
                     */
                if (tagClassName.equals(TAGNAME_TEXTFIELD)) {
                    Object[] pSize = { getStringFieldSize(as) };
                    xml.append(MessageFormat.format(TEXTBOX_SIZE_TAG, pSize));
                    xml.append(NON_LOCALIZED_FIELD);
                    xml.append(NO_AUTO_SUBMIT);
                } else if (tagClassName.equals(TAGNAME_TEXTAREA)) {
                    final Map<String, String> sizeMap = getTextAreaSize(as);
                    if (!sizeMap.isEmpty()) {
                        Object[] textAreaSize = { sizeMap.get("columns"), sizeMap.get("rows") };
                        xml.append(MessageFormat.format(TEXTAREA_SIZE_TAG, textAreaSize));
                    }
                    xml.append(NON_LOCALIZED_FIELD);
                } else if (tagClassName.equals(TAGNAME_PASSWORD)) {
                    xml.append(NO_AUTO_SUBMIT);
                }
                appendChoiceValues(as, xml, model, serviceBundle);
            }
            xml.append(COMPONENT_END_TAG);
        }
        if (type.equals(AttributeSchema.Type.MULTIPLE_CHOICE)) {
            if ((uitype == null) || !uitype.equals(AttributeSchema.UIType.ADDREMOVELIST)) {
                appendMultipleChoiceCheckboxes(as, xml, serviceBundle);
            }
        }
        appendDateMarker(as, xml);
        getInlineHelp(as, xml, serviceBundle);
        xml.append(PROPERTY_END_TAG);
        // close off the group and subsection tags for the editable list
        if (listTyped) {
            xml.append(GROUP_END_TAG).append("&lt;p>").append(PROPERTY_END_TAG);
            if (addSubSection) {
                xml.append(SUBSECTION_END_TAG);
            }
        }
    }
}
Also used : UIType(com.sun.identity.sm.AttributeSchema.UIType) AttributeSchema(com.sun.identity.sm.AttributeSchema)

Example 42 with AttributeSchema

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

the class PropertyXMLBuilderBase method getTagClassName.

static String getTagClassName(AttributeSchema as) {
    String tagClassName = null;
    AttributeSchema.UIType uitype = as.getUIType();
    if (uitype != null) {
        String val = (String) mapUITypeToName.get(uitype);
        try {
            tagClassName = properties.getString(val);
        } catch (MissingResourceException e) {
        // do nothing
        }
    }
    AttributeSchema.Type type = as.getType();
    String valType = (String) mapTypeToName.get(type);
    if ((tagClassName == null) && (valType != null)) {
        try {
            tagClassName = properties.getString(valType);
        } catch (MissingResourceException e) {
        // do nothing
        }
    }
    if (tagClassName == null) {
        AttributeSchema.Syntax syntax = as.getSyntax();
        String valSyntax = (String) mapSyntaxToName.get(syntax);
        if (valSyntax != null) {
            try {
                tagClassName = properties.getString(valType + "." + valSyntax);
            } catch (MissingResourceException e) {
            // do nothing
            }
        }
    }
    // last try
    if (tagClassName == null) {
        try {
            tagClassName = properties.getString(valType + ".whatever");
        } catch (MissingResourceException e) {
        // do nothing
        }
    }
    if ((tagClassName != null) && (tagClassName.trim().length() == 0)) {
        tagClassName = null;
    }
    return tagClassName;
}
Also used : UIType(com.sun.identity.sm.AttributeSchema.UIType) MissingResourceException(java.util.MissingResourceException) AttributeSchema(com.sun.identity.sm.AttributeSchema)

Example 43 with AttributeSchema

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

the class PropertyXMLBuilderBase method removeAttributeSchemaWithoutI18nKey.

/**
     * Removes attribute schema that does not have <code>i18nKey</code>.
     *
     * @param attributeSchemas Set of Attribute Schemas.
     */
public static void removeAttributeSchemaWithoutI18nKey(Set attributeSchemas) {
    for (Iterator iter = attributeSchemas.iterator(); iter.hasNext(); ) {
        AttributeSchema as = (AttributeSchema) iter.next();
        String i18n = as.getI18NKey();
        if ((i18n == null) || (i18n.trim().length() == 0)) {
            iter.remove();
        }
    }
}
Also used : Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema)

Example 44 with AttributeSchema

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

the class AMCrypt method decryptPasswords.

public static Map decryptPasswords(Map attributes, ServiceSchema serviceSchema) {
    if (serviceSchema == null || attributes == null) {
        return attributes;
    }
    Iterator iter = attributes.keySet().iterator();
    while (iter.hasNext()) {
        String attributeName = (String) (iter.next());
        AttributeSchema as = serviceSchema.getAttributeSchema(attributeName);
        if (as != null && (as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD) || as.getSyntax().equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD))) {
            Set valueSet = (Set) (attributes.get(attributeName));
            if (valueSet != null) {
                HashSet tmpValueSet = new HashSet(valueSet);
                valueSet.clear();
                Iterator valIter = tmpValueSet.iterator();
                while (valIter.hasNext()) {
                    String value = (String) valIter.next();
                    if (value != null) {
                        value = (String) AccessController.doPrivileged(new DecodeAction(value));
                    }
                    valueSet.add(value);
                }
            }
        }
    }
    return attributes;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) DecodeAction(com.sun.identity.security.DecodeAction) HashSet(java.util.HashSet)

Example 45 with AttributeSchema

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

the class AMCrypt method encryptPasswords.

public static Map encryptPasswords(Map attributes, ServiceSchema serviceSchema) {
    if (serviceSchema == null || attributes == null) {
        return attributes;
    }
    Iterator iter = attributes.keySet().iterator();
    while (iter.hasNext()) {
        String attributeName = (String) (iter.next());
        AttributeSchema as = serviceSchema.getAttributeSchema(attributeName);
        if (as != null && (as.getSyntax().equals(AttributeSchema.Syntax.PASSWORD) || as.getSyntax().equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD))) {
            Set valueSet = (Set) (attributes.get(attributeName));
            if (valueSet != null) {
                HashSet tmpValueSet = new HashSet(valueSet);
                valueSet.clear();
                Iterator valIter = tmpValueSet.iterator();
                while (valIter.hasNext()) {
                    String value = (String) valIter.next();
                    if (value != null) {
                        value = (String) AccessController.doPrivileged(new EncodeAction(value));
                    }
                    valueSet.add(value);
                }
            }
        }
    }
    return attributes;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) EncodeAction(com.sun.identity.security.EncodeAction) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) HashSet(java.util.HashSet)

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