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

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


    public Entity createEntity(String id, String entityType, String[]... attrKeyValuePairs){
       
        EntityImpl stubEntity = new EntityImpl("user", id, new HashSet<AttributeDef>(attributeDefs.values()));
        for (int i = 0; i < attrKeyValuePairs.length; i++)
        {
            AttributeDef def = attributeDefs.get(attrKeyValuePairs[i][0]);
            if (def!=null){
                stubEntity.setAttribute(def.getName(), attrKeyValuePairs[i][1]);
            }
        }
        stubEntity.setInternalId(id); // simply use the id
        return stubEntity;
    }
View Full Code Here


    protected boolean setNamingAttribute(Attribute entityAttr, DirContextOperations dirCtxOps)
    {
        boolean attrAdded = false;
        if (entityAttr != null)
        {
            AttributeDef attrDef = entityAttr.getDefinition();
            if (attrDef.isMultiValue())
            {
                Collection<String> values = entityAttr.getValues();
                if (values != null)
                {
                    dirCtxOps.setAttributeValues(attrDef.getName(), values.toArray());
                    attrAdded = true;
                }
            } else
            {
                String value = entityAttr.getValue();
                if (value != null)
                {
                    dirCtxOps.setAttributeValue(attrDef.getName(), value);
                    attrAdded = true;
                }
            }
        }
        return attrAdded;
View Full Code Here

    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

    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

        }
    }

    public void addRelation(String entityId, String relatedEntityInternalId, String attributeName) throws SecurityException
    {
        AttributeDef attrDef = configuration.getAttributeDef(attributeName);
        if (attrDef == null)
        {
            throw new SecurityException(SecurityException.ENTITY_ATTRIBUTE_UNDEFINED.createScoped(configuration.getEntityType(), attributeName));
        }
        DirContextOperations dirCtxOps = getEntityContextById(entityId, false);
        if (dirCtxOps == null)
        {
            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(configuration.getEntityType(), entityId));
        }
        ModificationItem[] modItems = new ModificationItem[1];
        modItems[0] = new ModificationItem(attrDef.isMultiValue() ? DirContext.ADD_ATTRIBUTE : DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(attributeName));
        modItems[0].getAttribute().add(relatedEntityInternalId);
       
        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
        try
        {
View Full Code Here

        }
    }

    public void removeRelation(String entityId, String relatedEntityInternalId, String attributeName) throws SecurityException
    {
        AttributeDef attrDef = configuration.getAttributeDef(attributeName);
        if (attrDef == null)
        {
            throw new SecurityException(SecurityException.ENTITY_ATTRIBUTE_UNDEFINED.createScoped(configuration.getEntityType(), attributeName));
        }
        DirContextOperations dirCtxOps = getEntityContextById(entityId, false);
        if (dirCtxOps == null)
        {
            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(configuration.getEntityType(), entityId));
        }
        ModificationItem[] modItems = new ModificationItem[1];
        modItems[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(attributeName));
        if (attrDef.isMultiValue())
        {
            modItems[0].getAttribute().add(relatedEntityInternalId);
        }
       
        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
        try
        {
            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            try
            {
                ldapTemplate.modifyAttributes(getRelativeDN(dirCtxOps.getNameInNamespace()), modItems);
            }
            catch (SchemaViolationException e)
            {
                // required multi-value attribute removal?
                if (!(attrDef.isMultiValue() && attrDef.isRequired()))
                {
                    throw e;
                }
                // replace with required default or dn
                modItems[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new  BasicAttribute(attributeName));
                modItems[0].getAttribute().add(attrDef.requiresDnDefaultValue() ? dirCtxOps.getNameInNamespace() : attrDef.getRequiredDefaultValue());
                // try again
                ldapTemplate.modifyAttributes(getRelativeDN(dirCtxOps.getNameInNamespace()), modItems);
            }
        }
        catch (NamingException e)
View Full Code Here

    public Entity createEntity(String id, String entityType, String[]... attrKeyValuePairs){
       
        EntityImpl stubEntity = new EntityImpl("user", id, attributeDefs);
        for (int i = 0; i < attrKeyValuePairs.length; i++)
        {
            AttributeDef def = attributeDefs.get(attrKeyValuePairs[i][0]);
            if (def!=null){
                stubEntity.setAttribute(def.getName(), attrKeyValuePairs[i][1]);
            }
        }
        stubEntity.setInternalId(id); // simply use the id
        return stubEntity;
    }
View Full Code Here

        {
            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);
                }
                if (attributeContainsInternalId)
                {
                    toDAO.getEntitiesByInternalId(values, handler);
View Full Code Here

    {
        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>());
                }
            }
        }
View Full Code Here

    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);
View Full Code Here

TOP

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

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.