Search in sources :

Example 1 with PortletRequest

use of javax.portlet.PortletRequest in project uPortal by Jasig.

the class FragmentAdministrationHelper method swapToFragmentOwner.

/**
     * @param remoteUser
     * @param targetFragmentOwner
     * @return "yes" for success, "no" otherwise
     */
public String swapToFragmentOwner(final String remoteUser, final String targetFragmentOwner, RequestContext requestContext) {
    PortletRequest portletRequest = (PortletRequest) requestContext.getExternalContext().getNativeRequest();
    this.identitySwapperManager.impersonateUser(portletRequest, remoteUser, targetFragmentOwner);
    return "yes";
}
Also used : PortletRequest(javax.portlet.PortletRequest)

Example 2 with PortletRequest

use of javax.portlet.PortletRequest in project uPortal by Jasig.

the class AttributeSwapperHelperImpl method getSwappableAttributes.

/* (non-Javadoc)
     * @see org.apereo.portal.portlets.swapper.IAttributeSwapperHelper#getSwappableAttributes(org.springframework.webflow.context.ExternalContext)
     */
public Set<String> getSwappableAttributes(ExternalContext externalContext) {
    final PortletRequest portletRequest = (PortletRequest) externalContext.getNativeRequest();
    final PortletPreferences preferences = portletRequest.getPreferences();
    final Set<String> swappableAttributes;
    //Use prefs configured list if available
    final String[] configuredAttributes = preferences.getValues(ATTRIBUTE_SWAPPER_ATTRIBUTES_FORM_SWAPPABLE_ATTRIBUTES, null);
    final String[] excludedAttributes = preferences.getValues(ATTRIBUTE_SWAPPER_ATTRIBUTES_FORM_SWAPPABLE_ATTRIBUTES_EXCLUDES, null);
    if (configuredAttributes != null) {
        swappableAttributes = new LinkedHashSet<String>(Arrays.asList(configuredAttributes));
    } else {
        //If no prefs try the 'possibleUserAttributeNames' from the IPersonAttributeDao
        final Set<String> possibleAttributes = this.overwritingPersonAttributeDao.getPossibleUserAttributeNames();
        if (possibleAttributes != null) {
            swappableAttributes = new TreeSet<String>(possibleAttributes);
        } else //If no possible names try getting the current user's attributes and use the key set
        {
            final Principal currentUser = externalContext.getCurrentUser();
            final IPersonAttributes baseUserAttributes = this.getOriginalUserAttributes(currentUser.getName());
            if (baseUserAttributes != null) {
                final Map<String, List<Object>> attributes = baseUserAttributes.getAttributes();
                swappableAttributes = new LinkedHashSet<String>(attributes.keySet());
            } else {
                swappableAttributes = Collections.emptySet();
            }
        }
    }
    if (excludedAttributes != null) {
        for (final String excludedAttribute : excludedAttributes) {
            swappableAttributes.remove(excludedAttribute);
        }
    }
    return swappableAttributes;
}
Also used : PortletRequest(javax.portlet.PortletRequest) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) PortletPreferences(javax.portlet.PortletPreferences) List(java.util.List) Principal(java.security.Principal)

Example 3 with PortletRequest

use of javax.portlet.PortletRequest in project uPortal by Jasig.

the class AttributeSwapperHelperImpl method resetAttributes.

/* (non-Javadoc)
     * @see org.apereo.portal.portlets.swapper.IAttributeSwapperHelper#resetAttributes(java.lang.String)
     */
public void resetAttributes(ExternalContext externalContext) {
    final Principal currentUser = externalContext.getCurrentUser();
    final String uid = currentUser.getName();
    this.logger.warn("User '" + uid + "' reseting to default attributes");
    //Remove the person directory override
    this.overwritingPersonAttributeDao.removeUserAttributeOverride(uid);
    //Remove the IPerson attribute override, bit of a hack as we really just remove all overrides
    //then re-add all attributes from person directory
    final PortletRequest portletRequest = (PortletRequest) externalContext.getNativeRequest();
    final HttpServletRequest portalRequest = this.portalRequestUtils.getPortletHttpRequest(portletRequest);
    final IPerson person = this.personManager.getPerson(portalRequest);
    final Set<String> overriddenAttributes = (Set<String>) person.getAttribute(OVERRIDDEN_ATTRIBUTES);
    if (overriddenAttributes != null) {
        person.setAttribute(OVERRIDDEN_ATTRIBUTES, null);
        for (final String attribute : overriddenAttributes) {
            person.setAttribute(attribute, null);
        }
    }
    final IPersonAttributes originalUserAttributes = this.getOriginalUserAttributes(uid);
    final Map<String, List<Object>> attributes = originalUserAttributes.getAttributes();
    person.setAttributes(attributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) PortletRequest(javax.portlet.PortletRequest) TreeSet(java.util.TreeSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) List(java.util.List) Principal(java.security.Principal)

Example 4 with PortletRequest

use of javax.portlet.PortletRequest in project uPortal by Jasig.

the class AttributeSwapperHelperImpl method swapAttributes.

/* (non-Javadoc)
     * @see org.apereo.portal.portlets.swapper.IAttributeSwapperHelper#swapAttributes(org.springframework.webflow.context.ExternalContext, org.apereo.portal.portlets.swapper.AttributeSwapRequest)
     */
public void swapAttributes(ExternalContext externalContext, AttributeSwapRequest attributeSwapRequest) {
    //Collate the swap request into a single overrides map
    final Map<String, Object> attributes = new HashMap<String, Object>();
    final Map<String, Attribute> currentAttributes = attributeSwapRequest.getCurrentAttributes();
    this.copyAttributes(attributes, currentAttributes);
    final Map<String, Attribute> attributesToCopy = attributeSwapRequest.getAttributesToCopy();
    this.copyAttributes(attributes, attributesToCopy);
    final Principal currentUser = externalContext.getCurrentUser();
    final String uid = currentUser.getName();
    final IPersonAttributes originalUserAttributes = this.getOriginalUserAttributes(uid);
    //Filter out unchanged attributes
    for (final Iterator<Map.Entry<String, Object>> overrideAttrEntryItr = attributes.entrySet().iterator(); overrideAttrEntryItr.hasNext(); ) {
        final Entry<String, Object> overrideAttrEntry = overrideAttrEntryItr.next();
        final String attribute = overrideAttrEntry.getKey();
        final Object originalValue = originalUserAttributes.getAttributeValue(attribute);
        final Object overrideValue = overrideAttrEntry.getValue();
        if (originalValue == overrideValue || (originalValue != null && originalValue.equals(overrideValue))) {
            overrideAttrEntryItr.remove();
        }
    }
    final PortletRequest portletRequest = (PortletRequest) externalContext.getNativeRequest();
    final PortletPreferences preferences = portletRequest.getPreferences();
    final String[] configuredAttributes = preferences.getValues(ATTRIBUTE_SWAPPER_ATTRIBUTES_FORM_SWAPPABLE_ATTRIBUTES, null);
    final String[] excludedAttributes = preferences.getValues(ATTRIBUTE_SWAPPER_ATTRIBUTES_FORM_SWAPPABLE_ATTRIBUTES_EXCLUDES, null);
    //Calculate the Set of attributes that are OK to be swapped
    final Set<String> allowedAttributes = new LinkedHashSet<String>();
    if (configuredAttributes != null) {
        allowedAttributes.addAll(Arrays.asList(configuredAttributes));
    } else {
        allowedAttributes.addAll(attributes.keySet());
    }
    if (excludedAttributes != null) {
        allowedAttributes.removeAll(Arrays.asList(excludedAttributes));
    }
    //Filter the attributes map
    for (final Iterator<String> attributeItr = attributes.keySet().iterator(); attributeItr.hasNext(); ) {
        final String attribute = attributeItr.next();
        if (!allowedAttributes.contains(attribute)) {
            attributeItr.remove();
            this.logger.warn("User '" + uid + "' attempted overriding attribute '" + attribute + "' which is not allowed in the current configuration. The attribute will be ignored.");
        }
    }
    this.logger.warn("User '" + uid + "' setting attribute overrides: " + attributes);
    //Override attributes retrieved the person directory
    this.overwritingPersonAttributeDao.setUserAttributeOverride(uid, attributes);
    //Update the IPerson, setting the overridden attributes
    final HttpServletRequest portalRequest = this.portalRequestUtils.getPortletHttpRequest(portletRequest);
    final IPerson person = this.personManager.getPerson(portalRequest);
    final Map<String, List<Object>> multivaluedAttributes = MultivaluedPersonAttributeUtils.toMultivaluedMap(attributes);
    person.setAttributes(multivaluedAttributes);
    person.setAttribute(OVERRIDDEN_ATTRIBUTES, multivaluedAttributes.keySet());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Attribute(org.apereo.portal.portlets.Attribute) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) Entry(java.util.Map.Entry) PortletRequest(javax.portlet.PortletRequest) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) PortletPreferences(javax.portlet.PortletPreferences) List(java.util.List) Principal(java.security.Principal)

Example 5 with PortletRequest

use of javax.portlet.PortletRequest in project uPortal by Jasig.

the class PersonLookupHelperImpl method getDisplayAttributes.

/* (non-Javadoc)
     * @see org.apereo.portal.portlets.swapper.IPersonLookupHelper#getDisplayAttributes(org.springframework.webflow.context.ExternalContext)
     */
public Set<String> getDisplayAttributes(ExternalContext externalContext) {
    final PortletRequest portletRequest = (PortletRequest) externalContext.getNativeRequest();
    final PortletPreferences preferences = portletRequest.getPreferences();
    final Set<String> displayAttributes;
    final String[] configuredAttributes = preferences.getValues(PERSON_LOOKUP_PERSON_DETAILS_DETAILS_ATTRIBUTES, null);
    final String[] excludedAttributes = preferences.getValues(PERSON_LOOKUP_PERSON_DETAILS_DETAILS_ATTRIBUTES_EXCLUDES, null);
    //If attributes are configured in portlet prefs use those the user has
    if (configuredAttributes != null) {
        displayAttributes = new LinkedHashSet<String>();
        displayAttributes.addAll(Arrays.asList(configuredAttributes));
    } else //Otherwise provide all available attributes from the IPersonAttributes
    {
        displayAttributes = new TreeSet<String>(personAttributeDao.getPossibleUserAttributeNames());
    }
    //Remove any excluded attributes
    if (excludedAttributes != null) {
        for (final String excludedAttribute : excludedAttributes) {
            displayAttributes.remove(excludedAttribute);
        }
    }
    return displayAttributes;
}
Also used : PortletRequest(javax.portlet.PortletRequest) PortletPreferences(javax.portlet.PortletPreferences)

Aggregations

PortletRequest (javax.portlet.PortletRequest)12 PortletPreferences (javax.portlet.PortletPreferences)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 Principal (java.security.Principal)3 List (java.util.List)3 IPersonAttributes (org.jasig.services.persondir.IPersonAttributes)3 LinkedHashSet (java.util.LinkedHashSet)2 PortletSession (javax.portlet.PortletSession)2 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)2 IPerson (org.apereo.portal.security.IPerson)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PortletResponse (javax.portlet.PortletResponse)1 RenderRequest (javax.portlet.RenderRequest)1 RenderResponse (javax.portlet.RenderResponse)1 HttpSession (javax.servlet.http.HttpSession)1 DelegationRequest (org.apereo.portal.api.portlet.DelegationRequest)1