Search in sources :

Example 1 with Attribute

use of org.apereo.portal.portlets.Attribute 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 2 with Attribute

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

the class PersonQueryValidator method validatePersonLookup.

/** Ensures all passed attributes are part of the valid query attribute set. */
public void validatePersonLookup(PersonQuery personQuery, MessageContext context) {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final ExternalContext externalContext = requestContext.getExternalContext();
    final Set<String> queryAttributes = personLookupHelper.getQueryAttributes(externalContext);
    final Map<String, Attribute> attributes = personQuery.getAttributes();
    for (final String attribute : attributes.keySet()) {
        if (!queryAttributes.contains(attribute)) {
            final MessageBuilder messageBuilder = new MessageBuilder();
            messageBuilder.error();
            messageBuilder.source("attributes[" + attribute + "].value");
            messageBuilder.code("personLookup.invalidQueryAttribute");
            messageBuilder.arg(attribute);
            final MessageResolver errorMessage = messageBuilder.build();
            context.addMessage(errorMessage);
        }
    }
}
Also used : MessageResolver(org.springframework.binding.message.MessageResolver) MessageBuilder(org.springframework.binding.message.MessageBuilder) Attribute(org.apereo.portal.portlets.Attribute) ExternalContext(org.springframework.webflow.context.ExternalContext) RequestContext(org.springframework.webflow.execution.RequestContext)

Example 3 with Attribute

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

the class AttributeSwapRequestValidator method validateAttributesForm.

/** Ensures all passed attributes are part of the valid query attribute set. */
public void validateAttributesForm(AttributeSwapRequest attributeSwapRequest, MessageContext context) {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final ExternalContext externalContext = requestContext.getExternalContext();
    final Set<String> swappableAttributes = this.attributeSwapperHelper.getSwappableAttributes(externalContext);
    final Map<String, Attribute> currentAttributes = attributeSwapRequest.getCurrentAttributes();
    this.checkAttributesMap(context, "currentAttributes", swappableAttributes, currentAttributes);
    final Map<String, Attribute> attributesToCopy = attributeSwapRequest.getAttributesToCopy();
    this.checkAttributesMap(context, "attributesToCopy", swappableAttributes, attributesToCopy);
}
Also used : Attribute(org.apereo.portal.portlets.Attribute) ExternalContext(org.springframework.webflow.context.ExternalContext) RequestContext(org.springframework.webflow.execution.RequestContext)

Example 4 with Attribute

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

the class AttributeSwapperHelperImpl method populateSwapRequest.

/* (non-Javadoc)
     * @see org.apereo.portal.portlets.swapper.IAttributeSwapperHelper#populateSwapRequest(org.springframework.webflow.context.ExternalContext, org.apereo.portal.portlets.swapper.AttributeSwapRequest)
     */
public void populateSwapRequest(ExternalContext externalContext, AttributeSwapRequest attributeSwapRequest) {
    final Principal currentUser = externalContext.getCurrentUser();
    final String uid = currentUser.getName();
    final IPersonAttributes person = this.overwritingPersonAttributeDao.getPerson(uid);
    final Map<String, Attribute> currentAttributes = attributeSwapRequest.getCurrentAttributes();
    currentAttributes.clear();
    final Set<String> swappableAttributes = this.getSwappableAttributes(externalContext);
    for (final String attribute : swappableAttributes) {
        final Object value = person.getAttributeValue(attribute);
        if (value != null) {
            currentAttributes.put(attribute, new Attribute(String.valueOf(value)));
        }
    }
}
Also used : IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) Attribute(org.apereo.portal.portlets.Attribute) Principal(java.security.Principal)

Example 5 with Attribute

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

the class AttributeSwapperHelperImpl method copyAttributes.

protected void copyAttributes(final Map<String, Object> destination, final Map<String, Attribute> source) {
    for (final Map.Entry<String, Attribute> sourceEntry : source.entrySet()) {
        final Attribute attribute = sourceEntry.getValue();
        if (attribute != null && StringUtils.isNotEmpty(attribute.getValue())) {
            final String name = sourceEntry.getKey();
            destination.put(name, attribute.getValue());
        }
    }
}
Also used : Attribute(org.apereo.portal.portlets.Attribute) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Attribute (org.apereo.portal.portlets.Attribute)7 HashMap (java.util.HashMap)3 Principal (java.security.Principal)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)2 MultiValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType)2 Parameter (org.apereo.portal.portletpublishing.xml.Parameter)2 ParameterInputType (org.apereo.portal.portletpublishing.xml.ParameterInputType)2 Preference (org.apereo.portal.portletpublishing.xml.Preference)2 PreferenceInputType (org.apereo.portal.portletpublishing.xml.PreferenceInputType)2 SingleValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType)2 Step (org.apereo.portal.portletpublishing.xml.Step)2 BooleanAttribute (org.apereo.portal.portlets.BooleanAttribute)2 StringListAttribute (org.apereo.portal.portlets.StringListAttribute)2 IPersonAttributes (org.jasig.services.persondir.IPersonAttributes)2 ExternalContext (org.springframework.webflow.context.ExternalContext)2 RequestContext (org.springframework.webflow.execution.RequestContext)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1