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);
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations