Examples of JetspeedPrincipal


Examples of org.apache.jetspeed.security.JetspeedPrincipal

        }
    }

    protected JetspeedPrincipal synchronizeEntity(final Entity entity, final Map<String,Set<String>> processing, final Map<String,Map<String,String>> processed) throws SecurityException
    {
        JetspeedPrincipal principal = null;
        if (processing != null && processing.get(entity.getType()) != null && processing.get(entity.getType()).contains(entity.getId()))
        {
            // TODO: throw proper security exception type
            throw new IllegalStateException("Circular relationship detected for Entity type "+entity.getType()+" id: "+entity.getId());
        }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

                    @Override
                    protected boolean processSearchResult(Entity relatedEntity, int pageSize, int pageIndex, int index)
                    {
                        try
                        {
                            JetspeedPrincipal principal = null;
                            if (processingToType != null && processingToType.contains(relatedEntity.getId()))
                            {
                                // TODO: throw proper security exception type
                                throw new IllegalStateException("Circular relationship detected for Entity type "+toEntityType+" id: "+relatedEntity.getId());
                            }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

        return toAssociations;
    }
   
    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())
        {
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

                    new PropertyModel(this, "associations"))
            {

                public void populateItem(final ListItem listItem)
                {
                    final JetspeedPrincipal principal = (JetspeedPrincipal) listItem
                            .getModelObject();
                    listItem.add(new Label("Name", principal.getName()));
                    boolean deleteAllowed = modificationAllowed;
                    Link deleteLink = new Link("delete")
                    {

                        @Override
                        public void onClick()
                        {
                            try
                            {
                                if (!associationsFrom)
                                {
                                    getManager().removeAssociation(principal,
                                            getPrincipal(), assoctionName);
                                } else
                                {
                                    getManager().removeAssociation(
                                            getPrincipal(), principal,
                                            assoctionName);
                                }
                                refreshList();
                            } catch (Exception e)
                            {
                                // TODO: handle exception
                            }
                        }
                    };
                    deleteLink.add(new Label("deleteLabel", new ResourceModel(
                            "common.delete")));
                    if (!admin && deleteAllowed && !principal.getType().getName().equals(JetspeedPrincipalType.USER))
                    {
                        // restrict deleting non-user type principals to only those the current user itself has
                        UserSubjectPrincipal currentUser = (UserSubjectPrincipal)getPortletRequest().getUserPrincipal();               
                        if (!hasPrincipal(currentUser.getSubject(), principal))
                        {
                            deleteAllowed = false;
                        }                   
                    }
                    if (!deleteAllowed || !modificationAllowed)
                    {
                        deleteLink.setEnabled(false);
                        deleteLink.setVisible(false);
                    }
                    listItem.add(deleteLink);
                }
            };
            if(AssociationType.getFromPrincipalType().equals(principalType))
            {
                add(new Label("principalReleation",new ResourceModel(AssociationType.getToPrincipalType().getName())));   
            }
            else
            {
                add(new Label("principalReleation",new ResourceModel(AssociationType.getFromPrincipalType().getName())));
            }
            add(commentListView);
            add(new FeedbackPanel("feedback"));
            Form assocationsForm = new Form("assocationsForm");
            add(assocationsForm);
            DropDownChoice dropDown = new DropDownChoice(
                    "associationPrincipal", new PropertyModel(this,
                            "associationPrincipal"), getNames(),
                    new ChoiceRenderer("name", "name"));
            dropDown.setRequired(true);
            assocationsForm.add(dropDown);
            Button addRelations = new Button("addRelations", new ResourceModel("common.association.add"))
            {

                @Override
                public void onSubmit()
                {
                    try
                    {
                        JetspeedPrincipal toPrincipal = getPrincipal();
                        // JetspeedPrincipal fromPrincipal =
                        // getJetspeedPrincipalManagerProvider().getManager(type).getPrincipal(getAssociationPrincipal());
                        JetspeedPrincipal fromPrincipal = getAssociationPrincipal();
                        if (!associationsFrom)
                        {
                            getManager().addAssociation(fromPrincipal,
                                    toPrincipal, associationName);
                        } else
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

                            associationType.getFromPrincipalType()).getPrincipals(
                            "");
                    for (int index = 0; index < tempNames.size(); index++)
                    {
                       
                        JetspeedPrincipal tmpPrincipal = (JetspeedPrincipal)tempNames.get(index);
                        if (!(tmpPrincipal.getType().getName().equals(principal.getType().getName()) &&
                                        tmpPrincipal.getName().equals(principal.getName())))
                        {
                            names.add(tmpPrincipal);
                        }
                    }
              }
                associationsFrom = false;
            }
          else
            {
              associations = getBaseManager(
                        associationType.getToPrincipalType())
                        .getAssociatedFrom(principal.getName(),
                                principal.getType(),
                                associationType.getAssociationName());
              if (modificationAllowed)
              {                 
                    List tempNames = getBaseManager(
                            associationType.getToPrincipalType()).getPrincipals("");
                    for (int index = 0; index < tempNames.size(); index++)
                    {
                        JetspeedPrincipal tmpPrincipal = (JetspeedPrincipal)tempNames.get(index);
                        if (!(tmpPrincipal.getType().getName().equals(principal.getType().getName()) &&
                                        tmpPrincipal.getName().equals(principal.getName())))
                        {
                            names.add(tmpPrincipal);
                        }
                    }
                }
                associationsFrom = true;
            }
          if (modificationAllowed)
          {
                for (int count = 0; count < associations.size(); count++)
                {
                    JetspeedPrincipal tmpPrincipal = (JetspeedPrincipal) associations.get(count);
                    JetspeedPrincipal listPrincipal;
                    for (int index = names.size()-1; index > -1; index--)
                    {
                        listPrincipal = (JetspeedPrincipal) names.get(index);
                        if (listPrincipal.getName().equals(tmpPrincipal.getName()))
                        {
                            names.remove(index);
                        }
                    }
                }
          }
            if (names.size() > 0 && !admin)
            {
                // restrict creating new associations to only those the user itself belongs to
                String jptName = associationsFrom ? associationType.getToPrincipalType().getName() : associationType.getFromPrincipalType().getName();
                if (!jptName.equals(JetspeedPrincipalType.USER))
                {
                    // get all current user principals of asssignable type as restricted list
                    UserSubjectPrincipal currentUser = (UserSubjectPrincipal)getPortletRequest().getUserPrincipal();               
                    List<JetspeedPrincipal> filter = SubjectHelper.getPrincipals(currentUser.getSubject(), jptName);
                    if (filter.isEmpty())
                    {
                        names.clear();
                    }
                    else
                    {
                        for (int index = names.size()-1; index > -1; index--)
                        {
                            boolean found = false;
                            JetspeedPrincipal listPrincipal = (JetspeedPrincipal) names.get(index);
                            for (int count = 0; count < filter.size(); count++)
                            {
                                JetspeedPrincipal tmpPrincipal = filter.get(count);
                                if (listPrincipal.getName().equals(tmpPrincipal.getName()))
                                {
                                    found = true;
                                    break;
                                }
                            }
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

        final DataView<JetspeedPrincipal> principalView = new DataView<JetspeedPrincipal>("entries", principalDataProvider)
        {
            @Override
            protected void populateItem(Item<JetspeedPrincipal> item)
            {
                final JetspeedPrincipal user = (JetspeedPrincipal) item.getModelObject();
                Link editLink = new Link("link", item.getModel())
                {
                    @Override
                    public void onClick()
                    {
                        JetspeedPrincipal user = (JetspeedPrincipal) getModelObject();
                        setPrincipal(user);
                        controlPannels(true);
                    }
                };
                editLink.add(new Label("name", user.getName()));
                item.add(editLink);
            }
        };
        principalView.setItemsPerPage(10);
        group.add(principalView);
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

                @Override
                public void onSubmit()
                {
                    UserManager userManager = (UserManager)getManager();
                    JetspeedPrincipal principal = getManager().newPrincipal(
                            getUserName(), false);
                    RoleManager roleManager = ((AbstractAdminWebApplication)getApplication()).getServiceLocator().getRoleManager();
                    PageManager pageManager = ((AbstractAdminWebApplication) getApplication()).getServiceLocator().getPageManager();
                    try
                    {
View Full Code Here

Examples of org.apache.jetspeed.security.JetspeedPrincipal

            userName.add(new PrincipalNameValidator());
            userForm.add(userName);
            Button newUser = new Button("addUser",new ResourceModel(principalParam +".add.button")){
        @Override
        public void onSubmit() {
          JetspeedPrincipal principal =  getManager().newPrincipal(getUserName(),false);
          try{
            getManager().addPrincipal(principal, null);
            setPrincipal(principal);
            controlPannels(true);
            principalDataProvider.refresh(getManager(),getSearchString());
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.