Search in sources :

Example 1 with PortletSession

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

the class SearchPortletController method getPortalSearchResults.

/**
 * Get the {@link PortalSearchResults} for the specified query id from the session. If there are
 * no results null is returned.
 */
private PortalSearchResults getPortalSearchResults(PortletRequest request, String queryId) {
    final PortletSession session = request.getPortletSession();
    @SuppressWarnings("unchecked") final Cache<String, PortalSearchResults> searchResultsCache = (Cache<String, PortalSearchResults>) session.getAttribute(SEARCH_RESULTS_CACHE_NAME);
    if (searchResultsCache == null) {
        return null;
    }
    return searchResultsCache.getIfPresent(queryId);
}
Also used : PortletSession(javax.portlet.PortletSession) Cache(com.google.common.cache.Cache)

Example 2 with PortletSession

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

the class SearchPortletController method handleSearchRequest.

/**
 * Performs a search of the explicitly configured {@link IPortalSearchService}s. This is done as
 * an event handler so that it can run concurrently with the other portlets handling the search
 * request
 */
@SuppressWarnings("unchecked")
@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING)
public void handleSearchRequest(EventRequest request, EventResponse response) {
    // UP-3887 Design flaw.  Both the searchLauncher portlet instance and the search portlet
    // instance receive
    // searchRequest and searchResult events because they are in the same portlet code base (to
    // share
    // autosuggest_handler.jsp and because we have to calculate the search portlet url for the
    // ajax call)
    // and share the portlet.xml which defines the event handling behavior.
    // If this instance is the searchLauncher, ignore the searchResult. The search was submitted
    // to the search
    // portlet instance.
    final String searchLaunchFname = request.getPreferences().getValue(SEARCH_LAUNCH_FNAME, null);
    if (searchLaunchFname != null) {
        // discarding message");
        return;
    }
    final Event event = request.getEvent();
    final SearchRequest searchQuery = (SearchRequest) event.getValue();
    // Map used to track searches that have been handled, used so that one search doesn't get
    // duplicate results
    ConcurrentMap<String, Boolean> searchHandledCache;
    final PortletSession session = request.getPortletSession();
    synchronized (org.springframework.web.portlet.util.PortletUtils.getSessionMutex(session)) {
        searchHandledCache = (ConcurrentMap<String, Boolean>) session.getAttribute(SEARCH_HANDLED_CACHE_NAME, PortletSession.APPLICATION_SCOPE);
        if (searchHandledCache == null) {
            searchHandledCache = CacheBuilder.newBuilder().maximumSize(20).expireAfterAccess(5, TimeUnit.MINUTES).<String, Boolean>build().asMap();
            session.setAttribute(SEARCH_HANDLED_CACHE_NAME, searchHandledCache, PortletSession.APPLICATION_SCOPE);
        }
    }
    final String queryId = searchQuery.getQueryId();
    if (searchHandledCache.putIfAbsent(queryId, Boolean.TRUE) != null) {
        // Already handled this search request
        return;
    }
    // Create the results
    final SearchResults results = new SearchResults();
    results.setQueryId(queryId);
    results.setWindowId(request.getWindowID());
    final List<SearchResult> searchResultList = results.getSearchResult();
    // Run the search for each service appending the results
    for (IPortalSearchService searchService : searchServices) {
        try {
            logger.debug("For queryId {}, query '{}', searching search service {}", queryId, searchQuery.getSearchTerms(), searchService.getClass().toString());
            final SearchResults serviceResults = searchService.getSearchResults(request, searchQuery);
            logger.debug("For queryId {}, obtained {} results from search service {}", queryId, serviceResults.getSearchResult().size(), searchService.getClass().toString());
            searchResultList.addAll(serviceResults.getSearchResult());
        } catch (Exception e) {
            logger.warn(searchService.getClass() + " threw an exception when searching, it will be ignored. " + searchQuery, e);
        }
    }
    // Respond with a results event if results were found
    if (!searchResultList.isEmpty()) {
        response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, results);
    }
}
Also used : SearchRequest(org.apereo.portal.search.SearchRequest) PortletSession(javax.portlet.PortletSession) Event(javax.portlet.Event) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) SpelParseException(org.springframework.expression.spel.SpelParseException) SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) IOException(java.io.IOException) EventMapping(org.springframework.web.portlet.bind.annotation.EventMapping)

Example 3 with PortletSession

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

the class TenantManagerController method showReport.

/**
 * @since 4.3
 */
@RenderMapping(params = "action=showReport")
public ModelAndView showReport(final RenderRequest req) {
    Map<String, Object> model = new HashMap<String, Object>();
    PortletSession session = req.getPortletSession();
    model.put(OPERATION_NAME_CODE, session.getAttribute(OPERATION_NAME_CODE));
    model.put(OPERATIONS_LISTENER_RESPONSES, session.getAttribute(OPERATIONS_LISTENER_RESPONSES));
    return new ModelAndView(REPORT_VIEW_NAME, model);
}
Also used : PortletSession(javax.portlet.PortletSession) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 4 with PortletSession

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

the class AuthorizationHeaderProvider method createHeader.

@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
    // Username
    final String username = getUsername(renderRequest);
    // Attributes
    final Map<String, List<String>> attributes = new HashMap<>();
    final IPersonAttributes person = personAttributeDao.getPerson(username);
    if (person != null) {
        for (Entry<String, List<Object>> y : person.getAttributes().entrySet()) {
            final List<String> values = new ArrayList<>();
            for (Object value : y.getValue()) {
                if (value instanceof String) {
                    values.add((String) value);
                }
            }
            attributes.put(y.getKey(), values);
        }
    }
    logger.debug("Found the following user attributes for username='{}':  {}", username, attributes);
    // Groups
    final List<String> groups = new ArrayList<>();
    final IGroupMember groupMember = GroupService.getGroupMember(username, IPerson.class);
    if (groupMember != null) {
        Set<IEntityGroup> ancestors = groupMember.getAncestorGroups();
        for (IEntityGroup g : ancestors) {
            groups.add(g.getName());
        }
    }
    logger.debug("Found the following group affiliations for username='{}':  {}", username, groups);
    // Expiration of the Bearer token
    final PortletSession portletSession = renderRequest.getPortletSession();
    final Date expires = new Date(portletSession.getLastAccessedTime() + ((long) portletSession.getMaxInactiveInterval() * 1000L));
    // Authorization header
    final Bearer bearer = bearerService.createBearer(username, attributes, groups, expires);
    final Header rslt = new BasicHeader(Headers.AUTHORIZATION.getName(), Headers.BEARER_TOKEN_PREFIX + bearer.getEncryptedToken());
    logger.debug("Produced the following Authorization header for username='{}':  {}", username, rslt);
    return rslt;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) PortletSession(javax.portlet.PortletSession) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) ArrayList(java.util.ArrayList) List(java.util.List) Bearer(org.apereo.portal.soffit.model.v1_0.Bearer) BasicHeader(org.apache.http.message.BasicHeader)

Example 5 with PortletSession

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

the class AbstractHeaderProvider method getExpiration.

/**
 * Point at which the JWT expires
 */
protected final Date getExpiration(RenderRequest renderRequest) {
    // Expiration of the JWT
    final PortletSession portletSession = renderRequest.getPortletSession();
    final Date rslt = new Date(portletSession.getLastAccessedTime() + ((long) portletSession.getMaxInactiveInterval() * 1000L));
    return rslt;
}
Also used : PortletSession(javax.portlet.PortletSession) Date(java.util.Date)

Aggregations

PortletSession (javax.portlet.PortletSession)22 IOException (java.io.IOException)5 HashMap (java.util.HashMap)4 PortletRequest (javax.portlet.PortletRequest)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 SessionUser (org.alfresco.repo.SessionUser)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 PortletException (javax.portlet.PortletException)2 PortletRequestDispatcher (javax.portlet.PortletRequestDispatcher)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)2 AuthenticationService (org.alfresco.service.cmr.security.AuthenticationService)2 ErrorBean (org.alfresco.web.bean.ErrorBean)2 User (org.alfresco.web.bean.repository.User)2 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)2