use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletAdministrationHelper method createPortletDefinitionForm.
/**
* Construct a new PortletDefinitionForm for the given IPortletDefinition id. If a
* PortletDefinition matching this ID already exists, the form will be pre-populated with the
* PortletDefinition's current configuration. If the PortletDefinition does not yet exist, a new
* default form will be created.
*
* @param person user that is required to have related lifecycle permission
* @param portletId identifier for the portlet definition
* @return {@PortletDefinitionForm} with set values based on portlet definition or default
* category and principal if no definition is found
*/
public PortletDefinitionForm createPortletDefinitionForm(IPerson person, String portletId) {
IPortletDefinition def = portletDefinitionRegistry.getPortletDefinition(portletId);
// create the new form
final PortletDefinitionForm form;
if (def != null) {
// if this is a pre-existing portlet, set the category and permissions
form = new PortletDefinitionForm(def);
form.setId(def.getPortletDefinitionId().getStringId());
// create a JsonEntityBean for each current category and add it
// to our form bean's category list
Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def);
for (PortletCategory cat : categories) {
form.addCategory(new JsonEntityBean(cat));
}
addPrincipalPermissionsToForm(def, form);
} else {
form = createNewPortletDefinitionForm();
}
// hierarchical, so we'll test with the weakest.
if (!hasLifecyclePermission(person, PortletLifecycleState.CREATED, form.getCategories())) {
logger.warn("User '" + person.getUserName() + "' attempted to edit the following portlet without MANAGE permission: " + def);
throw new SecurityException("Not Authorized");
}
return form;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class SearchPortletController method modifySearchResultLinkTitle.
/**
* Since portlets don't have access to the portlet definition to create a useful search results
* link using something like the portlet definition's title, post-process the link text and for
* those portlets whose type is present in the substitution set, replace the title with the
* portlet definition's title.
*
* @param result Search results object (may be modified)
* @param httpServletRequest HttpServletRequest
* @param portletWindowId Portlet Window ID
*/
protected void modifySearchResultLinkTitle(SearchResult result, final HttpServletRequest httpServletRequest, final IPortletWindowId portletWindowId) {
// evaluation context.
if (result.getType().size() > 0 && result.getTitle().contains("${")) {
final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final SpELEnvironmentRoot spelEnvironment = new SpELEnvironmentRoot(portletDefinition);
try {
result.setTitle(spELService.getValue(result.getTitle(), spelEnvironment));
} catch (SpelParseException | SpelEvaluationException e) {
result.setTitle("(Invalid portlet title) - see details in log file");
logger.error("Invalid Spring EL expression {} in search result portlet title", result.getTitle(), e);
}
}
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletRegistrySearchService method getSearchResults.
@Override
public SearchResults getSearchResults(PortletRequest request, SearchRequest query) {
final String queryString = query.getSearchTerms().toLowerCase();
final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
final SearchResults results = new SearchResults();
for (IPortletDefinition portlet : portlets) {
if (portletRegistryUtil.matches(queryString, portlet)) {
final SearchResult result = new SearchResult();
result.setTitle(portlet.getTitle());
result.setSummary(portlet.getDescription());
result.getType().add(searchResultType);
String url = portletRegistryUtil.buildPortletUrl(httpServletRequest, portlet);
if (url != null) {
result.setExternalUrl(url);
results.getSearchResult().add(result);
}
}
}
return results;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class CachedPasswordUserInfoService method isPasswordRequested.
/**
* Determine whether the portlet has expects a password as one of the user attributes.
*
* @param request portlet request
* @param plutoPortletWindow portlet window
* @return <code>true</code> if a password is expected, <code>false</code> otherwise
* @throws PortletContainerException if expeced attributes cannot be determined
*/
public boolean isPasswordRequested(PortletRequest request, PortletWindow plutoPortletWindow) throws PortletContainerException {
// get the list of requested user attributes
final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
final IPortletWindow portletWindow = this.portletWindowRegistry.convertPortletWindow(httpServletRequest, plutoPortletWindow);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final PortletApplicationDefinition portletApplicationDescriptor = this.portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinition.getPortletDefinitionId());
// check to see if the password key is one of the requested user attributes
List<? extends UserAttribute> requestedUserAttributes = portletApplicationDescriptor.getUserAttributes();
for (final UserAttribute userAttributeDD : requestedUserAttributes) {
final String attributeName = userAttributeDD.getName();
if (attributeName.equals(this.passwordKey))
return true;
}
// if the password key wasn't found in the list of requested attributes
return false;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PersonDirectoryUserInfoService method getExpectedUserAttributes.
/**
* Get the list of user attributes the portlet expects
*
* @param request The current request.
* @param portletWindow The window to get the expected user attributes for.
* @return The List of expected user attributes for the portlet
* @throws PortletContainerException If expected attributes cannot be determined
*/
protected List<? extends UserAttribute> getExpectedUserAttributes(HttpServletRequest request, final IPortletWindow portletWindow) throws PortletContainerException {
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final PortletApplicationDefinition portletApplicationDescriptor = this.portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinition.getPortletDefinitionId());
return portletApplicationDescriptor.getUserAttributes();
}
Aggregations