use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletExecutionManager method doPortletAction.
/* (non-Javadoc)
* @see org.apereo.portal.portlet.rendering.IPortletExecutionManager#doPortletAction(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void doPortletAction(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
final long timeout = getPortletActionTimeout(portletWindowId, request);
final IPortletExecutionWorker<Long> portletActionExecutionWorker = this.portletWorkerFactory.createActionWorker(request, response, portletWindowId);
portletActionExecutionWorker.submit();
try {
portletActionExecutionWorker.get(timeout);
} catch (Exception e) {
// put the exception into the error map for the session
final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
portletFailureMap.put(portletWindowId, e);
}
// If the worker is still running add it to the hung-workers queue
if (!portletActionExecutionWorker.isComplete()) {
cancelWorker(request, portletActionExecutionWorker);
}
// Is this portlet permitted to emit events? (Or is it disablePortletEvents=true?)
final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
IPortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition();
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(DISABLE_PORTLET_EVENTS_PARAMETER);
if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
} else {
// Proceed with events...
final PortletEventQueue portletEventQueue = this.eventCoordinationService.getPortletEventQueue(request);
this.doPortletEvents(portletEventQueue, request, response);
}
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletExecutionManager method startPortletRenderInternal.
/**
* create and submit the portlet content rendering job to the thread pool
*/
protected IPortletRenderExecutionWorker startPortletRenderInternal(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
// first check to see if there is a Throwable in the session for this IPortletWindowId
final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
final Exception cause = portletFailureMap.remove(portletWindowId);
final IPortletRenderExecutionWorker portletRenderExecutionWorker;
if (null != cause) {
// previous action failed, dispatch to errorPortlet immediately
portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, cause);
} else {
IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
IPortletDefinition portletDef = portletWindow.getPortletEntity().getPortletDefinition();
if (portletDef.getLifecycleState().equals(PortletLifecycleState.MAINTENANCE)) {
// Prevent the portlet from rendering; replace with a helpful "Out of Service"
// message
portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, new MaintenanceModeException());
} else {
// Happy path
portletRenderExecutionWorker = this.portletWorkerFactory.createRenderWorker(request, response, portletWindowId);
}
}
portletRenderExecutionWorker.submit();
final Map<IPortletWindowId, IPortletRenderExecutionWorker> portletRenderingMap = this.getPortletRenderingMap(request);
portletRenderingMap.put(portletWindowId, portletRenderExecutionWorker);
return portletRenderExecutionWorker;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletRendererImpl method enforceConfigPermission.
/**
* Enforces config mode access control. If requesting user does not have CONFIG permission, and
* the PortletWindow specifies config mode, throws AuthorizationException. Otherwise does
* nothing.
*
* @param httpServletRequest the non-null current HttpServletRequest (for determining requesting
* user)
* @param portletWindow a non-null portlet window that might be in config mode
* @throws AuthorizationException if the user is not permitted to access config mode yet portlet
* window specifies config mode
* @throws java.lang.IllegalArgumentException if the request or window are null
* @since 4.0.13.1, 4.0.14, 4.1.
*/
protected void enforceConfigPermission(final HttpServletRequest httpServletRequest, final IPortletWindow portletWindow) {
Validate.notNull(httpServletRequest, "Servlet request must not be null to determine remote user.");
Validate.notNull(portletWindow, "Portlet window must not be null to determine its mode.");
final PortletMode portletMode = portletWindow.getPortletMode();
if (portletMode != null) {
if (IPortletRenderer.CONFIG.equals(portletMode)) {
final IPerson person = this.personManager.getPerson(httpServletRequest);
final EntityIdentifier ei = person.getEntityIdentifier();
final AuthorizationServiceFacade authorizationServiceFacade = AuthorizationServiceFacade.instance();
final IAuthorizationPrincipal ap = authorizationServiceFacade.newPrincipal(ei.getKey(), ei.getType());
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
if (!ap.canConfigure(portletDefinition.getPortletDefinitionId().getStringId())) {
logger.error("User {} attempted to use portlet {} in {} but lacks permission to use that mode. " + "THIS MAY BE AN ATTEMPT TO EXPLOIT A HISTORICAL SECURITY FLAW. " + "You should probably figure out who this user is and why they are trying to access " + "unauthorized portlet modes.", person.getUserName(), portletDefinition.getFName(), portletMode);
throw new AuthorizationException(person.getUserName() + " does not have permission to render '" + portletDefinition.getFName() + "' in " + portletMode + " PortletMode.");
}
}
}
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaPortletDaoTest method testAllDefinitionDaoMethods.
@Test
public void testAllDefinitionDaoMethods() throws Exception {
final IPortletDefinitionId portletDefinitionId = execute(new Callable<IPortletDefinitionId>() {
@Override
public IPortletDefinitionId call() {
final IPortletType channelType = jpaChannelTypeDao.createPortletType("BaseType", "foobar");
// Create a definition
final IPortletDefinition chanDef1 = new PortletDefinitionImpl(channelType, "fname1", "Test Portlet 1", "Test Portlet 1 Title", "/context1", "portletName1", false);
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
// Try all of the retrieval options
final IPortletDefinition portDef1a = jpaPortletDefinitionDao.getPortletDefinition(chanDef1.getPortletDefinitionId());
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
assertEquals(chanDef1, portDef1a);
// Create a second definition with the same app/portlet
final IPortletDefinition chanDef2 = new PortletDefinitionImpl(channelType, "fname2", "Test Portlet 2", "Test Portlet 2 Title", "/uPortal", "portletName2", true);
jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
return chanDef2.getPortletDefinitionId();
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
// Add some preferences
final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
prefsList2.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
prefsList2.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
// verify preferences
final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
assertEquals(2, prefsList2.size());
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
// Check prefs, remove one and another
final IPortletDefinition portDef3 = jpaPortletDefinitionDao.getPortletDefinitionByName("Test Portlet 2");
final List<IPortletPreference> prefsList3 = portDef3.getPortletPreferences();
final List<IPortletPreference> expectedPrefsList3 = new ArrayList<IPortletPreference>();
expectedPrefsList3.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
expectedPrefsList3.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
assertEquals(expectedPrefsList3, prefsList3);
prefsList3.remove(1);
prefsList3.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
jpaPortletDefinitionDao.savePortletDefinition(portDef3);
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
// Check prefs
final IPortletDefinition portDef4 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
final List<IPortletPreference> prefsList4 = portDef4.getPortletPreferences();
final List<IPortletPreference> expectedPrefsList4 = new ArrayList<IPortletPreference>();
expectedPrefsList4.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
expectedPrefsList4.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
assertEquals(expectedPrefsList4, prefsList4);
}
});
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaPortletDaoTest method testAllEntityDaoMethods.
@Test
public void testAllEntityDaoMethods() throws Exception {
final IPortletDefinitionId portletDefinitionId = execute(new Callable<IPortletDefinitionId>() {
@Override
public IPortletDefinitionId call() throws Exception {
final IPortletType channelType = jpaChannelTypeDao.createPortletType("BaseType", "foobar");
// Create a definition
final IPortletDefinition chanDef1 = new PortletDefinitionImpl(channelType, "fname1", "Test Portlet 1", "Test Portlet 1 Title", "/context1", "portletName1", false);
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
return chanDef1.getPortletDefinitionId();
}
});
final IPortletEntityId portletEntityId = execute(new Callable<IPortletEntityId>() {
@Override
public IPortletEntityId call() throws Exception {
IPortletEntity portEnt1 = jpaPortletEntityDao.createPortletEntity(portletDefinitionId, "chanSub1", 1);
return portEnt1.getPortletEntityId();
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final IPortletEntity portEnt1a = jpaPortletEntityDao.getPortletEntity(portletEntityId);
assertNotNull(portEnt1a);
final IPortletEntity portEnt1b = jpaPortletEntityDao.getPortletEntity("chanSub1", 1);
assertEquals(portEnt1a, portEnt1b);
final IPortletEntity portEnt1c = jpaPortletEntityDao.getPortletEntity("chanSub1", 1);
assertEquals(portEnt1b, portEnt1c);
final Set<IPortletEntity> portletEntities1 = jpaPortletEntityDao.getPortletEntities(portletDefinitionId);
assertEquals(Collections.singleton(portEnt1a), portletEntities1);
final Set<IPortletEntity> portletEntitiesByUser = jpaPortletEntityDao.getPortletEntitiesForUser(1);
assertEquals(Collections.singleton(portEnt1a), portletEntitiesByUser);
return null;
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// Add entity and preferences
final IPortletDefinition portDef1 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
portDef1.getPortletPreferences().add(new PortletPreferenceImpl("defpref1", false, "dpv1", "dpv2"));
jpaPortletDefinitionDao.savePortletDefinition(portDef1);
final IPortletEntity portEnt1 = jpaPortletEntityDao.getPortletEntity(portletEntityId);
portEnt1.getPortletPreferences().add(new PortletPreferenceImpl("entpref1", false, "epv1", "epv2"));
// portEnt1.setWindowState(WindowState.MINIMIZED);
jpaPortletEntityDao.updatePortletEntity(portEnt1);
return null;
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// Delete whole tree
final IPortletDefinition portDef2 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
jpaPortletDefinitionDao.deletePortletDefinition(portDef2);
return null;
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
// Verify it is gone
final Set<IPortletEntity> portletEntities2 = jpaPortletEntityDao.getPortletEntities(portletDefinitionId);
assertEquals(Collections.emptySet(), portletEntities2);
return null;
}
});
}
Aggregations