Examples of JetspeedPrincipal


Examples of org.apache.jetspeed.security.JetspeedPrincipal

                    // first flag the relation as processed to
                    // prevent synchronizing the same relation from
                    // the other side.
                    syncState.setRelationProcessed(relationTypeForThisEntity, fromEntity, toEntity, entityIsFromEntity);
                    // first create/update principal
                    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;
                    // does association exist in DB ?
                    if (relatedPrincipal != null && !associationExists(fromPrincipal, toPrincipal, relationTypeForThisEntity.getRelationType()))
                    {
                        synchronizeAddedPrincipalAssocation(fromPrincipal, toPrincipal, relationTypeForThisEntity.getRelationType());
                        externalRelatedEntityIds.add(relatedPrincipal.getId());
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

    protected void grantPermission(PersistentJetspeedPermission permission, JetspeedPrincipal principal, boolean checkExists) throws SecurityException
    {
        if (principal.isTransient() || principal.getId() == null)
        {
            JetspeedPrincipal p = getPrincipal(principal.getName(), principal.getType());
            if (p ==  null)
            {
                throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(principal.getType().getName(), principal.getName()));
            }
            principal = p;
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

        QueryByCriteria query = QueryFactory.newQuery(PersistentJetspeedPrincipal.class, criteria);
        List<JetspeedPrincipal> currentList = (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query));
        List<JetspeedPrincipal> targetList = new ArrayList<JetspeedPrincipal>(principals);
        for (Iterator<JetspeedPrincipal> i = currentList.iterator(); i.hasNext(); )
        {
            JetspeedPrincipal current = i.next();
            for (Iterator<JetspeedPrincipal> j = targetList.iterator(); j.hasNext(); )
            {
                JetspeedPrincipal target = j.next();
               
                if (principalType != null && !target.getType().getName().equals(principalType))
                {
                    throw new SecurityException(SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager",
                                                                                    "grantPermissionOnlyTo",
                                                                                    "Specified "+target.getType().getName()+" principal: "+target.getName()+" is not of type: "+principalType));
                }
                if (current.getType().getName().equals(target.getType().getName()) && current.getName().equals(target.getName()))
                {
                    j.remove();
                    current = null;
                    break;
                }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

        }
    }

    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)
                    {
                        logger.error("Unexpected SecurityException: could not synchronize principal " + updatedPrincipal.getName() + " of type " +
                                     updatedPrincipal.getType().getName(), e);
                    }
                }
            }
        }
        else
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

    return user;
  }

  public void removeUser(String username) throws SecurityException
  {
    JetspeedPrincipal user;
   
    user = getUser(username);
    super.removePrincipal(user);
  }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

        return jpam.getPrincipalsByAttribute(attributeName, attributeValue, principalType);
    }

    public void removePrincipal(String name) throws SecurityException
    {
        JetspeedPrincipal principal = jpam.getPrincipal(name, principalType);
        if (principal == null)
        {
            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(principalType.getName(),name));
        }
        removePrincipal(principal);
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

        {
            throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_UNSUPPORTED.createScoped(from.getType().getName(), associationName, to.getType().getName()));
        }
        if (from.isTransient() || from.getId() == null)
        {
            JetspeedPrincipal pfrom = jpah.getManagerFrom().getPrincipal(from.getName());
            if (pfrom == null)
            {
                throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(from.getType().getName(), from.getName()));
            }
            from = pfrom;
        }
        if (to.isTransient() || to.getId() == null)
        {
            JetspeedPrincipal pto = jpah.getManagerTo().getPrincipal(to.getName());
            if (pto == null)
            {
                throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(to.getType().getName(), to.getName()));
            }
            to = pto;
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

                                                                                                          assType.getAssociationName(),
                                                                                                          assType.getToPrincipalType().getName()));            
            }
            if (from.isTransient() || from.getId() == null)
            {
                JetspeedPrincipal pfrom = jpah.getManagerFrom().getPrincipal(from.getName());
                if (pfrom == null)
                {
                    throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(from.getType().getName(), from.getName()));
                }
                from = pfrom;
            }
            if (to.isTransient() || to.getId() == null)
            {
                JetspeedPrincipal pto = jpah.getManagerTo().getPrincipal(to.getName());
                if (pto == null)
                {
                    throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(to.getType().getName(), to.getName()));
                }
                to = pto;
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

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

Examples of org.apache.jetspeed.security.JetspeedPrincipal

        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())
            {
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.