Package org.apache.jetspeed.security.mapping.model

Examples of org.apache.jetspeed.security.mapping.model.Attribute


        attr.setValue(value);
    }

    public void setAttribute(String name, Collection<String> values)
    {
        Attribute attr = nameToAttributeMap.get(name);
        if (attr == null)
        {
            AttributeDef def = getAttributeDefinition(name);
            if (def == null) { return; // TODO: throw proper exception
            }
            if (!def.isMultiValue()) { return; // TODO: throw proper exception
            }
            attr = new AttributeImpl(def);
            nameToAttributeMap.put(name, attr);
        }
        attr.setValues(values);
    }
View Full Code Here


        }
    }

    protected Set<String> getRelatedEntityIds(Entity entity)
    {
        Attribute relatedAttr = entity.getAttribute(relationAttribute);
        Set<String> foundIds = new HashSet();

        if (relatedAttr != null)
        {
            if (relatedAttr.getDefinition().isMultiValue())
            {
                foundIds.addAll(relatedAttr.getValues());
            } else
            {
                // TODO: if single value, parse value as CSV string
            }
        }
View Full Code Here

                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (values != null && values.length > 0)
            {
                Attribute a = new AttributeImpl(attrDef);
                if (attrDef.isMultiValue())
                {
                    Collection<String> attrValues = new ArrayList<String>();
                    attrValues.addAll(Arrays.asList(values));
                    // remove the dummy value for required fields when present.
                    if (attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null && attrValues.contains(attrDef.getRequiredDefaultValue()))
                    {
                        attrValues.remove(attrDef.getRequiredDefaultValue());
                    }
                    if (attrValues.size() != 0)
                    {
                        a.setValues(attrValues);
                        attributes.add(a);
                    }else{
                        attributes.add(a);
                    }
                }
                else
                {
                    if (attrDef.getName().equals(searchConfiguration.getLdapIdAttribute()))
                    {
                        entityId = values[0];
                    }
                    if (values[0] != null)
                    {
                        // check if the value is not the required default value (a dummy value) If it is, ignore the attribute.
                        if (!(attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null && values[0].equals(attrDef.getRequiredDefaultValue())))
                        {
                            a.setValue(values[0]);
                            attributes.add(a);
                        }
                    }
                }
            }
View Full Code Here

        SecurityAttributes principalAttrs = principal.getSecurityAttributes();
        for (AttributeDef attrDef : entity.getAttributeDefinitions())
        {
            if (attrDef.isMapped() && !attrDef.isMultiValue())
            {
                Attribute attr = entity.getAttribute(attrDef.getName());
                if (attr == null)
                {
                    if (!syncAll)
                    {
                        // if principal has attr: remove it
                        SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName());
                        if (principalAttr != null)
                        {
                            feedbackLogger.debug("Removing attribute {} for principal {}", principalAttr.getName(), principal.getName());
                            principalAttrs.removeAttribute(principalAttr.getName());
                            updated = true;
                        }
                    }
                }
                else if (syncAll)
                {
                    SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(), true);
                    if (feedbackLogger.isDebugEnabled())
                    {
                        feedbackLogger.debug("Adding attribute {} for principal {}. Value: {}",
                                             new String[] {principalAttr.getName(), principal.getName(), attr.getValue()});
                    }
                    principalAttr.setStringValue(attr.getValue());
                    updated = true;
                }
                else
                {
                    SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(), true);
                    if (!StringUtils.equals(principalAttr.getStringValue(), attr.getValue()))
                    {
                        if (feedbackLogger.isDebugEnabled())
                        {
                            feedbackLogger.debug("Attribute attribute {} for principal {}. Old value: {}, new value: {}",
                                                 new String[] {principalAttr.getName(), principal.getName(), (principalAttr.getStringValue()), attr.getValue()});
                        }
                        principalAttr.setStringValue(attr.getValue());
                        updated = true;
                    }
                }
            }
        }
View Full Code Here

                    {
                        basicAttr = new BasicAttribute(attrDef.getName());
                        basicAttr.add(attrDef.requiresDnDefaultValue() ? internalId : attrDef.getRequiredDefaultValue());
                    }
                   
                    Attribute entityAttr = entity.getAttribute(attrDef.getName());
                    if (entityAttr != null)
                    {
                        if (attrDef.isMultiValue())
                        {
                            Collection<String> entityAttrValues = entityAttr.getValues();
                            if (entityAttrValues != null && entityAttrValues.size() > 0)
                            {
                                if (basicAttr == null)
                                {
                                    basicAttr = new BasicAttribute(attrDef.getName());
                                }
                                for (String val : entityAttrValues)
                                {
                                    basicAttr.add(val);
                                }
                            }
                        }
                        else if (entityAttr.getValue() != null)
                        {
                            basicAttr = new BasicAttribute(attrDef.getName());
                            basicAttr.add(entityAttr.getValue());
                        }
                    }
                }
                if (basicAttr != null)
                {
View Full Code Here

        Collection<ModificationItem> modItems = new ArrayList<ModificationItem>();
        for (AttributeDef attrDef : configuration.getEntityAttributeDefinitionsMap().values())
        {
            if (attrDef.isMapped() && !attrDef.isIdAttribute() && !attrDef.isEntityIdAttribute())
            {
                Attribute entityAttr = entity.getAttribute(attrDef.getName());
                BasicAttribute namingAttr = new BasicAttribute(attrDef.getName());
                boolean attrAdded = false;
                if (entityAttr != null)
                {
                    if (attrDef.isMultiValue())
                    {
                        if (attrDef.isRequired())
                        {
                            // ensure defaultValue or dnDefaultValue is always present
                            namingAttr.add(attrDef.requiresDnDefaultValue() ? internalId : attrDef.getRequiredDefaultValue());
                            attrAdded = true;
                        }
                        Collection<String> values = entityAttr.getValues();
                        if (values != null && values.size() > 0)
                        {
                            for (String val : values)
                            {
                                namingAttr.add(val);
                            }
                            attrAdded = true;
                        }
                    }
                    else
                    {
                        String value = entityAttr.getValue();
                        if (value != null)
                        {
                            namingAttr.add(value);
                            attrAdded = true;
                        }
View Full Code Here

            {
                List<String> values = null;
                values = getStringAttributes(attrs, attrDef.getName(), attrDef.requiresDnDefaultValue());
                if (values != null)
                {
                    Attribute a = new AttributeImpl(attrDef);
                    if (attrDef.isMultiValue())
                    {
                        // remove the dummy value for required fields when present.
                        if (attrDef.isRequired())
                        {
                            String defaultValue = attrDef.requiresDnDefaultValue() ? dn : attrDef.getRequiredDefaultValue();
                            values.remove(defaultValue);
                        }
                        if (values.size() != 0)
                        {
                            a.setValues(values);
                        }
                        else
                        {
                            attributes.add(a);
                        }
                    }
                    else
                    {
                        String value = values.get(0);
                        if (attrDef.isEntityIdAttribute())
                        {
                            entityId = value;
                        }
                        a.setValue(value);
                    }
                    attributes.add(a);
                }
            }
            if (entityId == null)
View Full Code Here

    private void internalGetRelatedEntities(EntityDAO fromDAO, EntityDAO toDAO, boolean useFromEntityAttribute, Entity entity,
                                           EntitySearchResultHandler handler) throws SecurityException
    {
        if (useFromEntityAttribute)
        {
            Attribute relationAttrValue = entity.getAttribute(relationAttribute);
            if (relationAttrValue != null)
            {
                Collection<String> values = relationAttrValue.getValues();
                AttributeDef attrDef = relationAttrValue.getDefinition();
                if (attrDef.isMultiValue() && attrDef.isRequired())
                {
                    String defaultValue = attrDef.requiresDnDefaultValue() ? entity.getInternalId() : attrDef.getRequiredDefaultValue();
                    values.remove(defaultValue);
                }
View Full Code Here

        return getAttribute(name,false);
    }
   
    public Attribute getAttribute(String name, boolean create)
    {
        Attribute attr = nameToAttributeMap.get(name);
       
        if (attr == null && create)
        {
            AttributeDef def = allowedAttributes.get(name);
            if (def == null)
            {
                // TODO: throw proper exception
            }
            else
            {
                attr = new AttributeImpl(def);
                nameToAttributeMap.put(name, attr);
                if (def.isMultiValue())
                {
                    attr.setValues(new ArrayList<String>());
                }
            }
        }
        return attr;
    }
View Full Code Here

        this.id = id;
    }

    public void setAttribute(String name, String value)
    {
        Attribute attr = nameToAttributeMap.get(name);
        if (attr == null)
        {
            AttributeDef def = allowedAttributes.get(name);
            if (def == null)
            {
                return; // TODO: throw proper exception
            }
            if (def.isMultiValue())
            {
                return; // TODO: throw proper exception
            }
            attr = new AttributeImpl(def);
            nameToAttributeMap.put(name, attr);
        }
        attr.setValue(value);
    }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.security.mapping.model.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.