Search in sources :

Example 6 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupListHelperImpl method getEntityTypesForGroupType.

/*
     * (non-Javadoc)
     * @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getEntityTypesForGroupType(java.lang.String)
     */
@Override
public Set<String> getEntityTypesForGroupType(String groupType) {
    // add the group type itself to the allowed list
    Set<String> set = new HashSet<String>();
    set.add(groupType);
    /*
         * If the supplied type is a person group, add the person entity type.
         * If the supplied type is a category, add the channel type.  Otherwise,
         * throw an exception.
         *
         * This method will require an update if more entity types are added
         * in the future.
         */
    EntityEnum type = EntityEnum.getEntityEnum(groupType);
    if (EntityEnum.GROUP.equals(type)) {
        set.add(EntityEnum.PERSON.toString());
    } else if (EntityEnum.CATEGORY.equals(type)) {
        set.add(EntityEnum.PORTLET.toString());
    } else {
        throw new IllegalArgumentException("Unable to determine a root entity for group type '" + groupType + "'");
    }
    return set;
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) HashSet(java.util.HashSet)

Example 7 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupListHelperImplTest method testLookupEntityNameTypeIsNull.

@Test(expected = IllegalArgumentException.class)
public void testLookupEntityNameTypeIsNull() {
    GroupListHelperImpl helper = new GroupListHelperImpl();
    Mockito.when(entityGroup.getKey()).thenReturn("test-key");
    Mockito.when(entityGroup.getName()).thenReturn("test-name");
    Mockito.when(entityGroup.getCreatorID()).thenReturn("test-cid");
    Mockito.when(entityGroup.getDescription()).thenReturn("test-desc");
    JsonEntityBean jeb = new JsonEntityBean(entityGroup, EntityEnum.PORTLET);
    EntityEnum ee = null;
    jeb.setEntityType(ee);
    helper.lookupEntityName(jeb);
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) GroupListHelperImpl(org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl) Test(org.junit.Test)

Example 8 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupListHelperImplTest method testGetPrincipalForEntityTypeIsNull.

@Test(expected = IllegalArgumentException.class)
public void testGetPrincipalForEntityTypeIsNull() {
    GroupListHelperImpl helper = new GroupListHelperImpl();
    Mockito.when(entityGroup.getKey()).thenReturn("test-key");
    Mockito.when(entityGroup.getName()).thenReturn("test-name");
    Mockito.when(entityGroup.getCreatorID()).thenReturn("test-cid");
    Mockito.when(entityGroup.getDescription()).thenReturn("test-desc");
    JsonEntityBean jeb = new JsonEntityBean(entityGroup, EntityEnum.PORTLET);
    EntityEnum ee = null;
    jeb.setEntityType(ee);
    helper.getPrincipalForEntity(jeb);
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) GroupListHelperImpl(org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl) Test(org.junit.Test)

Example 9 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class PortletAdministrationHelper method savePortletRegistration.

/**
 * Persist a new or edited PortletDefinition from a form, replacing existing values.
 *
 * @param publisher {@code IPerson} that requires permission to save this definition
 * @param form form data to persist
 * @return new {@code PortletDefinitionForm} for this portlet ID
 */
public PortletDefinitionForm savePortletRegistration(IPerson publisher, PortletDefinitionForm form) {
    logger.trace("In savePortletRegistration() - for: {}", form.getPortletName());
    // is made when the user enters the lifecycle-selection step in the wizard.)
    if (!hasLifecyclePermission(publisher, form.getLifecycleState(), form.getCategories())) {
        logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the selected MANAGE permission:  " + form);
        throw new SecurityException("Not Authorized");
    }
    if (!form.isNew()) {
        // User must have the previous lifecycle permission
        // in AT LEAST ONE previous category as well
        IPortletDefinition def = this.portletDefinitionRegistry.getPortletDefinition(form.getId());
        Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def);
        SortedSet<JsonEntityBean> categoryBeans = new TreeSet<>();
        for (PortletCategory cat : categories) {
            categoryBeans.add(new JsonEntityBean(cat));
        }
        if (!hasLifecyclePermission(publisher, def.getLifecycleState(), categoryBeans)) {
            logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the previous MANAGE permission:  " + form);
            throw new SecurityException("Not Authorized");
        }
    }
    if (form.isNew() || portletDefinitionRegistry.getPortletDefinition(form.getId()).getType().getId() != form.getTypeId()) {
        // User must have access to the selected CPD if s/he selected it in this interaction
        final int selectedTypeId = form.getTypeId();
        final PortletPublishingDefinition cpd = portletPublishingDefinitionDao.getChannelPublishingDefinition(selectedTypeId);
        final Map<IPortletType, PortletPublishingDefinition> allowableCpds = this.getAllowableChannelPublishingDefinitions(publisher);
        if (!allowableCpds.containsValue(cpd)) {
            logger.warn("User '" + publisher.getUserName() + "' attempted to administer the following portlet without the selected " + IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE + " permission:  " + form);
            throw new SecurityException("Not Authorized");
        }
    }
    // create the principal array from the form's principal list -- only principals with
    // permissions
    final Set<IGroupMember> subscribePrincipalSet = new HashSet<>(form.getPrincipals().size());
    final Set<IGroupMember> browsePrincipalSet = new HashSet<>(form.getPrincipals().size());
    final Set<IGroupMember> configurePrincipalSet = new HashSet<>(form.getPrincipals().size());
    for (JsonEntityBean bean : form.getPrincipals()) {
        final String subscribePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
        final String browsePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_BROWSE_ACTIVITY;
        final String configurePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_MODE_CONFIG;
        final EntityEnum entityEnum = bean.getEntityType();
        final IGroupMember principal = entityEnum.isGroup() ? (GroupService.findGroup(bean.getId())) : (GroupService.getGroupMember(bean.getId(), entityEnum.getClazz()));
        if (form.getPermissions().contains(subscribePerm)) {
            logger.info("In savePortletRegistration() - Found a subscribePerm for principal: {}", principal);
            subscribePrincipalSet.add(principal);
        }
        if (form.getPermissions().contains(browsePerm)) {
            logger.info("In savePortletRegistration() - Found a browsePerm for principal: {}", principal);
            browsePrincipalSet.add(principal);
        }
        if (form.getPermissions().contains(configurePerm)) {
            logger.info("In savePortletRegistration() - Found a configurePerm for principal: {}", principal);
            configurePrincipalSet.add(principal);
        }
    }
    // create the category list from the form's category bean list
    List<PortletCategory> categories = new ArrayList<>();
    for (JsonEntityBean category : form.getCategories()) {
        String id = category.getId();
        String iCatID = id.startsWith("cat") ? id.substring(3) : id;
        categories.add(portletCategoryRegistry.getPortletCategory(iCatID));
    }
    final IPortletType portletType = portletTypeRegistry.getPortletType(form.getTypeId());
    if (portletType == null) {
        throw new IllegalArgumentException("No IPortletType exists for ID " + form.getTypeId());
    }
    IPortletDefinition portletDef;
    if (form.getId() == null) {
        portletDef = new PortletDefinitionImpl(portletType, form.getFname(), form.getName(), form.getTitle(), form.getApplicationId(), form.getPortletName(), form.isFramework());
    } else {
        portletDef = portletDefinitionRegistry.getPortletDefinition(form.getId());
        portletDef.setType(portletType);
        portletDef.setFName(form.getFname());
        portletDef.setName(form.getName());
        portletDef.setTitle(form.getTitle());
        portletDef.getPortletDescriptorKey().setWebAppName(form.getApplicationId());
        portletDef.getPortletDescriptorKey().setPortletName(form.getPortletName());
        portletDef.getPortletDescriptorKey().setFrameworkPortlet(form.isFramework());
    }
    portletDef.setDescription(form.getDescription());
    portletDef.setTimeout(form.getTimeout());
    // portletDef reflect the state of the form, in case any have changed.
    for (String key : form.getParameters().keySet()) {
        String value = form.getParameters().get(key).getValue();
        if (!StringUtils.isBlank(value)) {
            portletDef.addParameter(key, value);
        }
    }
    portletDef.addParameter(IPortletDefinition.EDITABLE_PARAM, Boolean.toString(form.isEditable()));
    portletDef.addParameter(IPortletDefinition.CONFIGURABLE_PARAM, Boolean.toString(form.isConfigurable()));
    portletDef.addParameter(IPortletDefinition.HAS_HELP_PARAM, Boolean.toString(form.isHasHelp()));
    portletDef.addParameter(IPortletDefinition.HAS_ABOUT_PARAM, Boolean.toString(form.isHasAbout()));
    // Now add portlet preferences
    List<IPortletPreference> preferenceList = new ArrayList<>();
    for (String key : form.getPortletPreferences().keySet()) {
        List<String> prefValues = form.getPortletPreferences().get(key).getValue();
        if (prefValues != null && prefValues.size() > 0) {
            String[] values = prefValues.toArray(new String[0]);
            BooleanAttribute readOnly = form.getPortletPreferenceReadOnly().get(key);
            preferenceList.add(new PortletPreferenceImpl(key, readOnly.getValue(), values));
        }
    }
    portletDef.setPortletPreferences(preferenceList);
    // Lastly update the PortletDefinition's lifecycle state & lifecycle-related metadata
    updateLifecycleState(form, portletDef, publisher);
    // The final parameter of IGroupMembers is used to set the initial SUBSCRIBE permission set
    portletPublishingService.savePortletDefinition(portletDef, publisher, categories, new ArrayList<>(subscribePrincipalSet));
    // updatePermissions(portletDef, subscribePrincipalSet,
    // IPermission.PORTLET_SUBSCRIBER_ACTIVITY);
    updatePermissions(portletDef, browsePrincipalSet, IPermission.PORTAL_SUBSCRIBE, IPermission.PORTLET_BROWSE_ACTIVITY);
    updatePermissions(portletDef, configurePrincipalSet, IPermission.PORTAL_PUBLISH, IPermission.PORTLET_MODE_CONFIG);
    return this.createPortletDefinitionForm(publisher, portletDef.getPortletDefinitionId().getStringId());
}
Also used : BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) ArrayList(java.util.ArrayList) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) TreeSet(java.util.TreeSet) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) HashSet(java.util.HashSet) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletDefinitionImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl)

Example 10 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupAdministrationHelper method updateGroupMembers.

/**
 * Update the members of an existing group in the group store.
 *
 * @param groupForm Form representing the new group configuration
 * @param updater Updating user
 */
public void updateGroupMembers(GroupForm groupForm, IPerson updater) {
    if (!canEditGroup(updater, groupForm.getKey())) {
        throw new RuntimeAuthorizationException(updater, IPermission.EDIT_GROUP_ACTIVITY, groupForm.getKey());
    }
    if (log.isDebugEnabled()) {
        log.debug("Updating group members for group form [" + groupForm.toString() + "]");
    }
    // find the current version of this group entity
    IEntityGroup group = GroupService.findGroup(groupForm.getKey());
    // clear the current group membership list
    for (IGroupMember child : group.getChildren()) {
        group.removeChild(child);
    }
    // to the group
    for (JsonEntityBean child : groupForm.getMembers()) {
        EntityEnum type = EntityEnum.getEntityEnum(child.getEntityTypeAsString());
        if (type.isGroup()) {
            IEntityGroup member = GroupService.findGroup(child.getId());
            group.addChild(member);
        } else {
            IGroupMember member = GroupService.getGroupMember(child.getId(), type.getClazz());
            group.addChild(member);
        }
    }
    // save the group, updating both its basic information and group
    // membership
    group.updateMembers();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Aggregations

EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)29 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)14 IEntityGroup (org.apereo.portal.groups.IEntityGroup)13 IGroupMember (org.apereo.portal.groups.IGroupMember)13 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)7 GroupListHelperImpl (org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl)4 ArrayList (java.util.ArrayList)3 EntityIdentifier (org.apereo.portal.EntityIdentifier)3 Principal (org.apereo.portal.api.Principal)2 PrincipalImpl (org.apereo.portal.api.PrincipalImpl)2 IPermission (org.apereo.portal.security.IPermission)2 RuntimeAuthorizationException (org.apereo.portal.security.RuntimeAuthorizationException)2 AuthorizationServiceFacade (org.apereo.portal.services.AuthorizationServiceFacade)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 TreeSet (java.util.TreeSet)1 IEntityNameFinder (org.apereo.portal.groups.IEntityNameFinder)1