Search in sources :

Example 1 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class UserAttributeSkinMappingTransformerConfigurationSource method getSkinName.

protected String getSkinName(HttpServletRequest request) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    final IPersonAttributes personAttrs = this.personAttributeDao.getPerson(person.getUserName());
    if (personAttrs == null) {
        logger.debug("No user attributes found for {} no skin override will be done", person.getUserName());
        return null;
    }
    final Object attributeValue = personAttrs.getAttributeValue(this.skinAttributeName);
    if (attributeValue == null) {
        logger.debug("No user {} does not have attribute {} defined, no skin override will be done", person.getUserName(), this.skinAttributeName);
        return null;
    }
    final String mappedSkinName = this.getMappedSkinName(attributeValue.toString());
    if (mappedSkinName == null) {
        logger.debug("No skin is mapped for attribute {}, no skin override will be done", attributeValue);
        return null;
    }
    logger.debug("Overidding skin to {}", mappedSkinName);
    return mappedSkinName;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes)

Example 2 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class UserAccountHelperTest method testMatchingDisplayAttributes.

@Test
public void testMatchingDisplayAttributes() {
    final IPersonAttributes person = mock(IPersonAttributes.class);
    final Map<String, List<Object>> attributes = new HashMap<String, List<Object>>();
    attributes.put("username", Collections.<Object>singletonList("user1"));
    attributes.put("user.login.id", Collections.<Object>singletonList("user1"));
    when(person.getAttributes()).thenReturn(attributes);
    final List<GroupedPersonAttribute> displayed = helper.groupPersonAttributes(person, request);
    assertEquals(1, displayed.size());
    assertEquals(2, displayed.get(0).getAttributeNames().size());
}
Also used : IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Example 3 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class PersonDirectoryUserInfoService method getUserInfo.

/**
     * Commons logic to get a subset of the user's attributes for the specified portlet window.
     *
     * @param remoteUser The user to get attributes for.
     * @param httpServletRequest The current, underlying httpServletRequest
     * @param portletWindow The window to filter attributes for
     * @return A Map of user attributes for the user and windows
     * @throws PortletContainerException
     */
protected Map<String, String> getUserInfo(String remoteUser, HttpServletRequest httpServletRequest, IPortletWindow portletWindow) throws PortletContainerException {
    //Get the list of user attributes the portal knows about the user
    final IPersonAttributes personAttributes = this.personAttributeDao.getPerson(remoteUser);
    if (personAttributes == null) {
        return Collections.emptyMap();
    }
    final List<? extends UserAttribute> expectedUserAttributes = this.getExpectedUserAttributes(httpServletRequest, portletWindow);
    final Map<String, String> portletUserAttributes = this.generateUserInfo(personAttributes, expectedUserAttributes, httpServletRequest);
    return portletUserAttributes;
}
Also used : IPersonAttributes(org.jasig.services.persondir.IPersonAttributes)

Example 4 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class DirectoryPortletController method search2.

@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING)
public void search2(EventRequest request, EventResponse response) {
    // get the search query object from the event
    Event event = request.getEvent();
    SearchRequest query = (SearchRequest) event.getValue();
    // search the portal's directory service for people matching the request
    final List<IPersonAttributes> people = searchDirectory(query.getSearchTerms(), request);
    if (people.size() > 0) {
        // transform the list of directory results into our generic search
        // response object
        final SearchResults results = new SearchResults();
        results.setQueryId(query.getQueryId());
        results.setWindowId(request.getWindowID());
        for (IPersonAttributes person : people) {
            final SearchResult result = new SearchResult();
            result.setTitle((String) person.getAttributeValue("displayName"));
            result.getType().add(directorySearchResultType);
            PortletUrl url = new PortletUrl();
            url.setType(PortletUrlType.RENDER);
            url.setPortletMode("VIEW");
            url.setWindowState("maximized");
            PortletUrlParameter actionParam = new PortletUrlParameter();
            actionParam.setName("action");
            actionParam.getValue().add("findByUsername");
            url.getParam().add(actionParam);
            PortletUrlParameter usernameParam = new PortletUrlParameter();
            usernameParam.setName("username");
            usernameParam.getValue().add(person.getName());
            url.getParam().add(usernameParam);
            result.setPortletUrl(url);
            results.getSearchResult().add(result);
        }
        // fire a search response event
        response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, results);
    }
}
Also used : SearchRequest(org.apereo.portal.search.SearchRequest) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) Event(javax.portlet.Event) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) PortletUrl(org.apereo.portal.search.PortletUrl) EventMapping(org.springframework.web.portlet.bind.annotation.EventMapping)

Example 5 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class LocalAccountPersonAttributeDao method mapPersonAttributes.

/**
     * This implementation uses the result attribute mapping to supplement, rather than replace, the
     * attributes returned from the database.
     */
protected IPersonAttributes mapPersonAttributes(final ILocalAccountPerson person) {
    final Map<String, List<Object>> mappedAttributes = new LinkedHashMap<String, List<Object>>();
    mappedAttributes.putAll(person.getAttributes());
    // map the user's username to the portal's username attribute in the
    // attribute map
    mappedAttributes.put(this.getUsernameAttributeProvider().getUsernameAttribute(), Collections.<Object>singletonList(person.getName()));
    // to build one from the first and last name attributes
    if (!mappedAttributes.containsKey(displayNameAttribute) || mappedAttributes.get(displayNameAttribute).size() == 0 || StringUtils.isBlank((String) mappedAttributes.get(displayNameAttribute).get(0))) {
        final List<Object> firstNames = mappedAttributes.get("givenName");
        final List<Object> lastNames = mappedAttributes.get("sn");
        final StringBuilder displayName = new StringBuilder();
        if (firstNames != null && firstNames.size() > 0) {
            displayName.append(firstNames.get(0)).append(" ");
        }
        if (lastNames != null && lastNames.size() > 0) {
            displayName.append(lastNames.get(0));
        }
        mappedAttributes.put(displayNameAttribute, Collections.<Object>singletonList(displayName.toString()));
    }
    for (final Map.Entry<String, Set<String>> resultAttrEntry : this.getResultAttributeMapping().entrySet()) {
        final String dataKey = resultAttrEntry.getKey();
        //Only map found data attributes
        if (mappedAttributes.containsKey(dataKey)) {
            Set<String> resultKeys = resultAttrEntry.getValue();
            //If dataKey has no mapped resultKeys just use the dataKey
            if (resultKeys == null) {
                resultKeys = Collections.singleton(dataKey);
            }
            //Add the value to the mapped attributes for each mapped key
            final List<Object> value = mappedAttributes.get(dataKey);
            for (final String resultKey : resultKeys) {
                if (resultKey == null) {
                    //TODO is this possible?
                    if (!mappedAttributes.containsKey(dataKey)) {
                        mappedAttributes.put(dataKey, value);
                    }
                } else if (!mappedAttributes.containsKey(resultKey)) {
                    mappedAttributes.put(resultKey, value);
                }
            }
        }
    }
    final IPersonAttributes newPerson;
    final String name = person.getName();
    if (name != null) {
        newPerson = new NamedPersonImpl(name, mappedAttributes);
    } else {
        final String userNameAttribute = this.getConfiguredUserNameAttribute();
        newPerson = new AttributeNamedPersonImpl(userNameAttribute, mappedAttributes);
    }
    return newPerson;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) AttributeNamedPersonImpl(org.jasig.services.persondir.support.AttributeNamedPersonImpl) LinkedHashMap(java.util.LinkedHashMap) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) AttributeNamedPersonImpl(org.jasig.services.persondir.support.AttributeNamedPersonImpl) NamedPersonImpl(org.jasig.services.persondir.support.NamedPersonImpl) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

IPersonAttributes (org.jasig.services.persondir.IPersonAttributes)33 List (java.util.List)12 IPerson (org.apereo.portal.security.IPerson)12 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)8 LinkedHashSet (java.util.LinkedHashSet)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Principal (java.security.Principal)4 Map (java.util.Map)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 PortletRequest (javax.portlet.PortletRequest)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2 PortletPreferences (javax.portlet.PortletPreferences)2 Element (net.sf.ehcache.Element)2 GroupsException (org.apereo.portal.groups.GroupsException)2 IEntityGroup (org.apereo.portal.groups.IEntityGroup)2 Attribute (org.apereo.portal.portlets.Attribute)2