Examples of JetspeedPrincipalManager


Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

    }
   
    protected JetspeedPrincipal synchronizeEntity(Entity entity, Set<JetspeedPrincipalAssociationReference> toAssociations) throws SecurityException
    {
        JetspeedPrincipal principal = getJetspeedPrincipal(entity.getType(), entity.getId());
        JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(principalManagerProvider.getPrincipalType(entity.getType()));

        boolean syncAll = false;
       
        if (principal == null)
        {
            // principal does not exist yet, create a new one using the principal manager
            principal = principalManager.newPrincipal(entity.getId(), true);
            principalManager.addPrincipal(principal, toAssociations);
            syncAll = true;
        }
        else if (!principal.isMapped())
        {
            logger.debug("Found "+principal.getType().getName()+" principal: "+principal.getName()+" is not mapped therefore not synchronized!");
            return null;
        }
        else
        {
            // sync relations
            for (final SecurityEntityRelationType relationType : securityEntityManager.getSupportedEntityRelationTypes(entity.getType()))
            {
                if (relationType.getFromEntityType().equals(entity.getType()))
                {
                    List<? extends JetspeedPrincipal> associatedFrom = principalManager.getAssociatedFrom(principal.getName(), principal.getType(), relationType.getRelationType());
                    for (JetspeedPrincipal p : associatedFrom)
                    {
                        if (toAssociations.isEmpty() ||
                                        !toAssociations.remove(new JetspeedPrincipalAssociationReference(JetspeedPrincipalAssociationReference.Type.TO, p, relationType.getRelationType())))
                        {
                            principalManager.removeAssociation(principal, p, relationType.getRelationType());
                        }
                    }
                }
            }
            for (JetspeedPrincipalAssociationReference ref : toAssociations)
            {
                principalManager.addAssociation(principal, ref.ref, ref.associationName);
            }
        }
        boolean updated = false;       
        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;
                    }
                }
            }
        }
        if (updated)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("Storing attribute changes for principal "+principal.getName());
            }
            principalManager.updatePrincipal(principal);
        }
        if (logger.isDebugEnabled())
        {
            logger.debug("Synchronized entity "+entity.getType()+" id: "+entity.getId()+" mapped attributes");
        }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

        return principal;
    }

    protected JetspeedPrincipal getJetspeedPrincipal(String principalType, String principalName) throws SecurityException
    {
        JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(principalManagerProvider.getPrincipalType(principalType));
        if (principalManager != null)
        {
            return principalManager.getPrincipal(principalName);
        }
        throw new SecurityException(SecurityException.UNKNOWN_PRINCIPAL_TYPE.create(principalType));
    }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

                    JetspeedPrincipal relatedPrincipal = null;
                    if (recursive){
                        relatedPrincipal = recursiveSynchronizeEntity(relatedEntity, syncState,recursive);
                    } else {
                        // don't recursively synchronize the related entity. Only add an association (if missing) when the related entity was previously synchronized.
                        JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(principalManagerProvider.getPrincipalType(relatedEntity.getType()));
                        if (principalManager != null)
                        {
                            relatedPrincipal = principalManager.getPrincipal(relatedEntity.getId());
                        }
                    }
                    // .. then update associations to / from it
                    JetspeedPrincipal fromPrincipal = entityIsFromEntity ? principal : relatedPrincipal;
                    JetspeedPrincipal toPrincipal = entityIsFromEntity ? relatedPrincipal : principal;
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

        // check whether associations were removed in external store (e.g.
        // LDAP), but still present in the DB
        if (logger.isDebugEnabled()){
            logger.debug("--- Synchronize removed associations ---");
        }
        JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(principal.getType());
        List<? extends JetspeedPrincipal> relatedToPrincipals = null;
        if (isFromPrincipal)
        {
            relatedToPrincipals = principalManager.getAssociatedFrom(principal.getName(), principal.getType(), associationName);
        }
        else
        {
            relatedToPrincipals = principalManager.getAssociatedTo(principal.getName(), principal.getType(), associationName);
        }
        for (JetspeedPrincipal relatedPrincipal : relatedToPrincipals)
        {
            // check whether principal association still exists
            if (!externalRelatedEntityIds.contains(relatedPrincipal.getId()))
            {
                try
                {
                    if (isFromPrincipal)
                    {
                        principalManager.removeAssociation(principal, relatedPrincipal, associationName);
                        if (logger.isDebugEnabled()){
                            logger.debug("Removed association ["+principal.getName()+" ("+principal.getType().getName()+")] ---["+associationName+"]--> ["+relatedPrincipal.getName()+" ("+relatedPrincipal.getType().getName()+")]");
                        }
                    }
                    else
                    {
                        principalManager.removeAssociation(relatedPrincipal, principal, associationName);
                        if (logger.isDebugEnabled()){
                            logger.debug("Removed association ["+relatedPrincipal.getName()+" ("+relatedPrincipal.getType().getName()+")] ---["+associationName+"]--> ["+principal.getName()+" ("+principal.getType().getName()+")]");
                        }
                    }
                }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

        }
    }

    protected boolean associationExists(JetspeedPrincipal fromPrincipal, JetspeedPrincipal toPrincipal, String associationName)
    {
        JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(fromPrincipal.getType());
        List<String> toPrincipals = principalManager.getAssociatedNamesFrom(fromPrincipal.getName(), fromPrincipal.getType(), associationName);
        return toPrincipals.contains(toPrincipal.getName());
    }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

        return toPrincipals.contains(toPrincipal.getName());
    }

    protected void synchronizeAddedPrincipalAssocation(JetspeedPrincipal fromPrincipal, JetspeedPrincipal toPrincipal, String associationName)
    {
        JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(fromPrincipal.getType());
        try
        {
            principalManager.addAssociation(fromPrincipal, toPrincipal, associationName);
        }
        catch (SecurityException e)
        {
            logger.error("Unexpected SecurityException during synchronization.", e);
        }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

    }

    protected JetspeedPrincipal synchronizePrincipalAttributes(Entity entity)
    {
        JetspeedPrincipal updatedPrincipal = null;
        JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(principalManagerProvider.getPrincipalType(entity.getType()));
        if (logger.isDebugEnabled()){
            logger.debug("--- Synchronize principal attributes ---");
        }
        if (principalManager != null)
        {
            updatedPrincipal = principalManager.getPrincipal(entity.getId());
            Map<String, Attribute> mappedEntityAttrs = entity.getMappedAttributes();
            Collection<Attribute> attrsToBeUpdated = new ArrayList<Attribute>();
            if (updatedPrincipal == null)
            {
                // principal does not exist yet, create it using the Jetspeed
                // principal manager
                updatedPrincipal = principalManager.newPrincipal(entity.getId(), true);
                try
                {
                    principalManager.addPrincipal(updatedPrincipal, null);
                    if (logger.isDebugEnabled()){
                        logger.debug("Adding principal "+updatedPrincipal.getName()+" of type "+updatedPrincipal.getType().getName()+" ...");
                    }
                }
                catch (SecurityException sexp)
                {
                    if (logger.isErrorEnabled())
                    {
                        logger.error("Unexpected exception in adding new pricipal of type " + updatedPrincipal.getType().getName() + ".", sexp);
                    }
                }
                attrsToBeUpdated.addAll(mappedEntityAttrs.values());
            }
            else if (updatedPrincipal.isMapped())
            {
                if (logger.isDebugEnabled()){
                    logger.debug("Updating principal "+updatedPrincipal.getName()+" of type "+updatedPrincipal.getType().getName()+" ...");
                }
                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);
                            }
                        }
                    }
                    else
                    {
                        attrsToBeUpdated.add(entityAttr);
                    }
                }
            }
            SecurityAttributes principalAttrs = updatedPrincipal.getSecurityAttributes();
            Map<String, SecurityAttributeType> securityAttrTypes = principalAttrs.getSecurityAttributeTypes().getAttributeTypeMap();
            // Step 1. update principal's attributes
            for (Attribute addedEntityAttr : attrsToBeUpdated)
            {
                if (!addedEntityAttr.getDefinition().isMultiValue())
                {
                    SecurityAttribute principalAttr = null;
                    try
                    {
                        SecurityAttributeType securityAttrType = securityAttrTypes.get(addedEntityAttr.getMappedName());
                        if (securityAttrType != null)
                        {
                            principalAttr = principalAttrs.getAttribute(addedEntityAttr.getMappedName(), true);
                        }
                        if (principalAttr != null)
                            principalAttr.setStringValue(addedEntityAttr.getValue());
                        if (logger.isDebugEnabled()){
                            logger.debug("Marked attribute "+principalAttr.getName()+" as updated for principal "+updatedPrincipal.getName()+". New value: "+principalAttr.getStringValue());
                        }
                    }
                    catch (SecurityException e)
                    {
                        if (logger.isErrorEnabled())
                        {
                            logger.error("Unexpected exception for attribute " + addedEntityAttr.getMappedName() + ".", e);
                        }
                    }
                }
            }
            if (updatedPrincipal.isMapped())
            {
                boolean updated = (attrsToBeUpdated.size() > 0);
                // Step 2, check whether attributes should be removed.
                for (Map.Entry<String, SecurityAttribute> principalAttrEntry : principalAttrs.getAttributeMap().entrySet())
                {
                    // TODO: check whether this attribute is mapped
                    if (!mappedEntityAttrs.containsKey(principalAttrEntry.getKey()))
                    {
                        try
                        {
                            principalAttrs.removeAttribute(principalAttrEntry.getKey());
                            updated = true;
                            if (logger.isDebugEnabled()){
                                logger.debug("Marked attribute "+principalAttrEntry.getKey()+" as removed for principal "+updatedPrincipal.getName());
                            }
                        }
                        catch (SecurityException e)
                        {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
                // step 3, update synchronized principal
                if (updated)
                {
                    try
                    {
                        principalManager.updatePrincipal(updatedPrincipal);
                        if (logger.isDebugEnabled()){
                            logger.debug("Committing attribute changes for principal "+updatedPrincipal.getName());
                        }
                    }
                    catch (SecurityException e)
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

                for (JetspeedPrincipalType type : principalManagerProvider.getPrincipalTypeMap().values())
                {
                    String typeName = type.getName();
                    userType = JetspeedPrincipalType.USER.equals(typeName);
                   
                    JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(type);
                   
                    for (JetspeedPrincipal principal : principalManager.getPrincipals(""))
                    {
                        if (!(userType && anonymousUser.equals(principal.getName())))
                        {
                            principalManager.removePrincipal(principal);
                        }
                    }
                }
            }
            catch (Exception e)
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

        }
        log.debug("recreateOldUsers - done");
       
        log.debug("processing jetspeed principals");
       
        JetspeedPrincipalManager principalManager = null;
       
        for (JSPrincipal jsPrincipal : snapshot.getPrincipals())
        {
            String typeName = jsPrincipal.getType();
            if (JetspeedPrincipalType.USER.equals(typeName))
            {
                recreateUserPrincipal(refs, snapshot, settings, log, jsPrincipal, passwordEncoding);
            }
            else
            {
                String name = jsPrincipal.getName();
               
                try
                {
                    JetspeedPrincipalType type = this.principalManagerProvider.getPrincipalType(typeName);
                    principalManager = this.principalManagerProvider.getManager(type);
                    JetspeedPrincipal principal = null;
                   
                    if (!(principalManager.principalExists(name)))
                    {
                        principal = principalManager.newPrincipal(name, jsPrincipal.isMapped());
                        JSSecurityAttributes jsSecAttrs = jsPrincipal.getSecurityAttributes();
                        if (jsSecAttrs != null)
                        {
                            for (JSNVPElement elem : jsSecAttrs.getValues())
                            {
                                principal.getSecurityAttributes().getAttribute(elem.getKey(), true).setStringValue(elem.getValue());
                            }
                        }
                        principalManager.addPrincipal(principal, null);
                    }
                   
                    principal = principalManager.getPrincipal(name);
                    refs.getPrincipalMap(typeName).put(name, principal);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipalManager

            throws SerializerException
    {
        log.debug("recreateJetspeedPrincipalAssociations");
       
        Map<String, JetspeedPrincipalType> principalTypes = this.principalManagerProvider.getPrincipalTypeMap();
        JetspeedPrincipalManager principalManager = null;
        JetspeedPrincipalManager fromPrincipalManager = null;
        JetspeedPrincipal from = null;
        JetspeedPrincipal to = null;
       
        try
        {
            for (JSPrincipalAssociation jsAssoc : snapshot.getPrincipalAssociations())
            {
                principalManager = this.principalManagerProvider.getManager(principalTypes.get(jsAssoc.getToType()));
                to = principalManager.getPrincipal(jsAssoc.getToName());
                fromPrincipalManager = this.principalManagerProvider.getManager(principalTypes.get(jsAssoc.getFromType()));
                from = fromPrincipalManager.getPrincipal(jsAssoc.getFromName());
                principalManager.addAssociation(from, to, jsAssoc.getName());
            }
        }
        catch (Exception e)
        {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.