Search in sources :

Example 1 with PortletPublishingDefinition

use of org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition 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) throws Exception {
    // 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());
    for (JsonEntityBean bean : form.getPrincipals()) {
        final String subscribePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
        final String browsePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_BROWSE_ACTIVITY;
        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)) {
            subscribePrincipalSet.add(principal);
        }
        if (form.getPermissions().contains(browsePerm)) {
            browsePrincipalSet.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[prefValues.size()]);
            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.PORTLET_BROWSE_ACTIVITY);
    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 2 with PortletPublishingDefinition

use of org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition in project uPortal by Jasig.

the class PortletAdministrationHelper method getAllowableChannelPublishingDefinitions.

public Map<IPortletType, PortletPublishingDefinition> getAllowableChannelPublishingDefinitions(IPerson user) {
    Map<IPortletType, PortletPublishingDefinition> rslt;
    final Map<IPortletType, PortletPublishingDefinition> rawMap = portletPublishingDefinitionDao.getChannelPublishingDefinitions();
    final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
    if (principal.hasPermission(IPermission.PORTAL_PUBLISH, IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE, IPermission.ALL_PORTLET_TYPES)) {
        // Send the whole collection back...
        rslt = rawMap;
    } else {
        // Filter the collection by permissions...
        rslt = new HashMap<IPortletType, PortletPublishingDefinition>();
        for (Map.Entry<IPortletType, PortletPublishingDefinition> y : rawMap.entrySet()) {
            if (principal.hasPermission(IPermission.PORTAL_PUBLISH, IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE, y.getKey().getName())) {
                rslt.put(y.getKey(), y.getValue());
            }
        }
    }
    return rslt;
}
Also used : IPortletType(org.apereo.portal.portlet.om.IPortletType) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with PortletPublishingDefinition

use of org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition in project uPortal by Jasig.

the class PortletAdministrationHelper method offerPortletSelection.

public boolean offerPortletSelection(PortletDefinitionForm form) {
    final IPortletType portletType = this.portletTypeRegistry.getPortletType(form.getTypeId());
    final PortletPublishingDefinition portletPublishingDefinition = this.portletPublishingDefinitionDao.getChannelPublishingDefinition(portletType.getId());
    final PortletDescriptor portletDescriptor = portletPublishingDefinition.getPortletDescriptor();
    if (portletDescriptor == null) {
        return true;
    }
    final Boolean isFramework = portletDescriptor.isIsFramework();
    if (isFramework != null && isFramework) {
        form.setFramework(isFramework);
    } else {
        final String webAppName = portletDescriptor.getWebAppName();
        form.setApplicationId(webAppName);
    }
    final String portletName = portletDescriptor.getPortletName();
    form.setPortletName(portletName);
    return false;
}
Also used : PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)

Example 4 with PortletPublishingDefinition

use of org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition in project uPortal by Jasig.

the class XmlChannelPublishingDefinitionDao method loadChannelPublishingDefinition.

private PortletPublishingDefinition loadChannelPublishingDefinition(int channelTypeId) {
    // if the CPD is not already in the cache, determine the CPD URI
    final String cpdUri;
    if (channelTypeId >= 0) {
        final IPortletType type = this.portletTypeRegistry.getPortletType(channelTypeId);
        if (type == null) {
            throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
        }
        cpdUri = type.getCpdUri();
    } else {
        throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
    }
    // read and parse the CPD
    final PortletPublishingDefinition def;
    final Resource cpdResource = this.resourceLoader.getResource("classpath:" + cpdUri);
    if (!cpdResource.exists()) {
        throw new MissingResourceException("Failed to find CPD '" + cpdUri + "' for channel type " + channelTypeId, this.getClass().getName(), cpdUri);
    }
    final InputStream cpdStream;
    try {
        cpdStream = cpdResource.getInputStream();
    } catch (IOException e) {
        throw new MissingResourceException("Failed to load CPD '" + cpdUri + "' for channel type " + channelTypeId, this.getClass().getName(), cpdUri);
    }
    try {
        def = (PortletPublishingDefinition) this.unmarshaller.unmarshal(cpdStream);
        final List<Step> sharedParameters = this.getSharedParameters();
        def.getSteps().addAll(sharedParameters);
        // add the CPD to the cache and return it
        this.cpdCache.put(channelTypeId, def);
        return def;
    } catch (JAXBException e) {
    } finally {
        IOUtils.closeQuietly(cpdStream);
    }
    return null;
}
Also used : IPortletType(org.apereo.portal.portlet.om.IPortletType) InputStream(java.io.InputStream) MissingResourceException(java.util.MissingResourceException) JAXBException(javax.xml.bind.JAXBException) Resource(org.springframework.core.io.Resource) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) IOException(java.io.IOException) Step(org.apereo.portal.portletpublishing.xml.Step)

Example 5 with PortletPublishingDefinition

use of org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition in project uPortal by Jasig.

the class XmlChannelPublishingDefinitionDao method getSharedParameters.

private List<Step> getSharedParameters() {
    if (this.sharedParameters != null) {
        return this.sharedParameters;
    }
    // read and parse the shared CPD
    final Resource paramResource = this.resourceLoader.getResource("classpath:" + SHARED_PARAMETERS_PATH);
    if (!paramResource.exists()) {
        throw new MissingResourceException("Failed to find shared parameters CPD '" + SHARED_PARAMETERS_PATH + "'", this.getClass().getName(), SHARED_PARAMETERS_PATH);
    }
    final InputStream paramStream;
    try {
        paramStream = paramResource.getInputStream();
    } catch (IOException e) {
        throw new MissingResourceException("Failed to load CPD '" + SHARED_PARAMETERS_PATH + "'", this.getClass().getName(), SHARED_PARAMETERS_PATH);
    }
    // parse the shared CPD and add its steps to the end of the type-specific
    try {
        PortletPublishingDefinition config = (PortletPublishingDefinition) unmarshaller.unmarshal(paramStream);
        this.sharedParameters = config.getSteps();
    } catch (JAXBException e) {
        logger.warn("Failed to parse: " + paramResource, e);
    } finally {
        IOUtils.closeQuietly(paramStream);
    }
    return this.sharedParameters;
}
Also used : InputStream(java.io.InputStream) MissingResourceException(java.util.MissingResourceException) JAXBException(javax.xml.bind.JAXBException) Resource(org.springframework.core.io.Resource) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) IOException(java.io.IOException)

Aggregations

PortletPublishingDefinition (org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)10 IPortletType (org.apereo.portal.portlet.om.IPortletType)7 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 Step (org.apereo.portal.portletpublishing.xml.Step)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 MissingResourceException (java.util.MissingResourceException)2 JAXBException (javax.xml.bind.JAXBException)2 Preference (org.apereo.portal.portletpublishing.xml.Preference)2 BooleanAttribute (org.apereo.portal.portlets.BooleanAttribute)2 Resource (org.springframework.core.io.Resource)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1 Matcher (java.util.regex.Matcher)1 IGroupMember (org.apereo.portal.groups.IGroupMember)1