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

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


        {
            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


        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)
                        {
                            if (logger.isDebugEnabled())
                            {
                                logger.debug("Removing attribute "+principalAttr.getName()+" for principal "+principal.getName()+".");
                            }
                            principalAttrs.removeAttribute(principalAttr.getName());
                            updated = true;
                        }
                    }
                }
                else if (syncAll)
                {
                    SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(), true);
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Adding attribute "+principalAttr.getName()+" for principal "+principal.getName()+". Value: "+attr.getValue());
                    }
                    principalAttr.setStringValue(attr.getValue());
                    updated = true;
                }
                else
                {
                    SecurityAttribute principalAttr = principalAttrs.getAttribute(attrDef.getMappedName(), true);
                    if (!StringUtils.equals(principalAttr.getStringValue(), attr.getValue()))
                    {
                        if (logger.isDebugEnabled())
                        {
                            logger.debug("Updating attribute "+principalAttr.getName()+" for principal "+principal.getName()+". Old value: "+(principalAttr.getStringValue())+" new value: "+attr.getValue());
                        }
                        principalAttr.setStringValue(attr.getValue());
                        updated = true;
                    }
                }
            }
        }
View Full Code Here

        if (debugMode)
        {
            Set<AttributeDef> defs = ent.getAllowedAttributes();
            for (AttributeDef attributeDef : defs)
            {
                Attribute attr = ent.getAttribute(attributeDef.getName());
                if (attr != null)
                {
                    if (attr.getDefinition().isMultiValue())
                    {
                        System.out.println("Values for " + attr.getName()
                                + " :");
                        System.out.println("===");
                        for (String val : attr.getValues())
                        {
                            System.out.println(val);
                        }
                        System.out.println("===");
                    } else
                    {
                        System.out.print("Value for " + attr.getName() + " :");
                        System.out.println(attr.getValue());
                    }

                }
            }
        }
View Full Code Here

    private Collection<Entity> internalGetRelatedEntities(EntityDAO fromDAO, EntityDAO toDAO, boolean useFromEntityAttribute, Entity entity)
    {
        if (useFromEntityAttribute)
        {
            Attribute relationAttrValue = entity.getAttribute(relationAttribute);
            if (relationAttrValue != null)
            {
                Collection<String> values = relationAttrValue.getValues();
                if (attributeContainsInternalId)
                {
                    return toDAO.getEntitiesByInternalId(values);
                }
                else
View Full Code Here

        }
        else
        {
            attrValue = toEntity.getId();
        }
        Attribute relationAttribute = fromEntity.getAttribute(this.relationAttribute);
       
        if(relationAttribute == null)
        {
            fromEntity.setAttribute(this.relationAttribute,new ArrayList<String>());   
        }
        else
        {
            if(relationAttribute.getValues().contains(attrValue))
            {
                throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_ALREADY_EXISTS.createScoped(fromEntity.getType(), fromEntity.getId(), relationAttribute, toEntity.getId()));
            }
        }
       
        if (relationAttribute.getDefinition().isMultiValue())
        {
            relationAttribute.getValues().add(attrValue);
        }
        else
        {
            relationAttribute.setValue(attrValue);
        }
        fromEntityDAO.updateInternalAttributes(fromEntity);
    }
View Full Code Here

        }
        else
        {
            attrValue = toEntity.getId();
        }
        Attribute relationAttribute = fromEntity.getAttribute(this.relationAttribute);
        if (relationAttribute.getDefinition().isMultiValue())
        {
            DistinguishedName attrib = new DistinguishedName(attrValue);
            if (attributeContainsInternalId)
            {
                boolean found = false;
                String attribValue = null;
                Iterator<String> iterator = relationAttribute.getValues().iterator();
                while(iterator.hasNext() && !found)
                {
                    attribValue = iterator.next();
                    DistinguishedName ldapAttr = new DistinguishedName(attribValue);
                    if (ldapAttr.equals(attrib))
                    {
                        relationAttribute.getValues().remove(attribValue);
                        found = true;
                    }
                }
            }
            else
            {
                relationAttribute.getValues().remove(attrValue);
            }
        }
        else
        {
            relationAttribute.setValue(null);
        }
        fromEntityDAO.updateInternalAttributes(fromEntity);
    }
View Full Code Here

        if (dn != null)
        {
            dn.add(configuration.getLdapIdAttribute(), entity.getId());
            for (AttributeDef attrDef : configuration.getAttributeDefinitions())
            {
                Attribute entityAttr = entity.getAttribute(attrDef.getName());
                BasicAttribute basicAttr = null;
                if (entityAttr != null)
                {
                    if (attrDef.isMultiValue())
                    {
                        Collection<String> entityAttrValues = entityAttr.getValues();
                        if (entityAttrValues != null && entityAttrValues.size() > 0)
                        {
                            basicAttr = new BasicAttribute(attrDef.getName());
                            for (String val : entityAttrValues)
                            {
                                basicAttr.add(val);
                            }
                        }
                    } else
                    {
                        basicAttr = new BasicAttribute(attrDef.getName());
                        basicAttr.add(entityAttr.getValue());
                    }
                } else
                {
                    if (attrDef.isIdAttribute())
                    {
View Full Code Here

        {
            if (!attrDef.getName().equals(configuration.getLdapIdAttribute()))
            {
                if (umode == UpdateMode.ALL || (umode == UpdateMode.MAPPED && attrDef.isMapped()) || (umode == UpdateMode.INTERNAL && !attrDef.isMapped()))
                {
                    Attribute entityAttr = entity.getAttribute(attrDef.getName());
                    boolean attrAdded = false;
                    if (entityAttr != null)
                    {
                        if (attrDef.isMultiValue())
                        {
                            Collection<String> values = entityAttr.getValues();
                            if (values != null)
                            {
                                javax.naming.directory.Attribute namingAttr = new BasicAttribute(entityAttr.getName());
                                if (values.size() > 0)
                                {
                                    for (String val : values)
                                    {
                                        namingAttr.add(val);
                                    }
                                    modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, namingAttr));
                                    attrAdded = true;
                                }
                            }
                        } else
                        {
                            String value = entityAttr.getValue();
                            if (value != null)
                            {
                                javax.naming.directory.Attribute namingAttr = new BasicAttribute(entityAttr.getName(), entityAttr.getValue());
                                modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, namingAttr));
                                attrAdded = true;
                            }
                        }
                    }
View Full Code Here

                }
                SecurityAttributes principalAttrs = updatedPrincipal.getSecurityAttributes();
                for (Map.Entry<String, Attribute> entityAttrEntry : mappedEntityAttrs.entrySet())
                {
                    SecurityAttribute principalAttr = principalAttrs.getAttribute(entityAttrEntry.getKey());
                    Attribute entityAttr = entityAttrEntry.getValue();
                    if (principalAttr != null)
                    {
                        if (entityAttr.getDefinition().isMultiValue())
                        {
                            // TODO : multi-valued Principal attrs are not yet
                            // supported
                        }
                        else
                        {
                            if (!StringUtils.equals(principalAttr.getStringValue(), entityAttr.getValue()))
                            {
                                attrsToBeUpdated.add(entityAttr);
                            }
                        }
                    }
View Full Code Here

        return null;
    }

    public void setAttribute(String name, String value)
    {
        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.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.