use of org.apereo.portal.security.IAuthorizationPrincipal in project uPortal by Jasig.
the class PortletEventCoordinatationService method resolvePortletEvents.
@Override
public void resolvePortletEvents(HttpServletRequest request, PortletEventQueue portletEventQueue) {
final Queue<QueuedEvent> events = portletEventQueue.getUnresolvedEvents();
// Skip all processing if there are no new events.
if (events.isEmpty()) {
return;
}
// Get all the portlets the user is subscribed to
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
// Make a local copy so we can remove data from it
final Set<String> allLayoutNodeIds = new LinkedHashSet<String>(userLayoutManager.getAllSubscribedChannels());
final Map<String, IPortletEntity> portletEntityCache = new LinkedHashMap<String, IPortletEntity>();
while (!events.isEmpty()) {
final QueuedEvent queuedEvent = events.poll();
if (queuedEvent == null) {
// no more queued events, done resolving
return;
}
final IPortletWindowId sourceWindowId = queuedEvent.getPortletWindowId();
final Event event = queuedEvent.getEvent();
final boolean globalEvent = isGlobalEvent(request, sourceWindowId, event);
final Set<IPortletDefinition> portletDefinitions = new LinkedHashSet<IPortletDefinition>();
if (globalEvent) {
portletDefinitions.addAll(this.portletDefinitionRegistry.getAllPortletDefinitions());
}
// Check each subscription to see what events it is registered to see
for (final Iterator<String> layoutNodeIdItr = allLayoutNodeIds.iterator(); layoutNodeIdItr.hasNext(); ) {
final String layoutNodeId = layoutNodeIdItr.next();
IPortletEntity portletEntity = portletEntityCache.get(layoutNodeId);
if (portletEntity == null) {
portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, layoutNodeId);
// remove it (see UP-3378)
if (portletEntity == null) {
layoutNodeIdItr.remove();
continue;
}
final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
if (portletDescriptor == null) {
// Missconfigured portlet, remove it from the list so we don't check again
// and ignore it
layoutNodeIdItr.remove();
continue;
}
final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
// they are not checked again
if (supportedProcessingEvents == null || supportedProcessingEvents.size() == 0) {
layoutNodeIdItr.remove();
continue;
}
portletEntityCache.put(layoutNodeId, portletEntity);
}
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
if (this.supportsEvent(event, portletDefinitionId)) {
this.logger.debug("{} supports event {}", portletDefinition, event);
// If this is the default portlet entity remove the definition from the all defs
// set to avoid duplicate processing
final IPortletEntity defaultPortletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
if (defaultPortletEntity.equals(portletEntity)) {
portletDefinitions.remove(portletDefinition);
}
// Is this portlet permitted to receive events? (Or is it
// disablePortletEvents=true?)
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.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());
continue;
}
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
for (final IPortletWindow portletWindow : portletWindows) {
this.logger.debug("{} resolved target {}", event, portletWindow);
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
}
} else {
portletDefinitions.remove(portletDefinition);
}
}
if (!portletDefinitions.isEmpty()) {
final IPerson user = userInstance.getPerson();
final EntityIdentifier ei = user.getEntityIdentifier();
final IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
// targeting
for (final IPortletDefinition portletDefinition : portletDefinitions) {
// Is this portlet permitted to receive events? (Or is it
// disablePortletEvents=true?)
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.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());
continue;
}
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
// Check if the user can render the portlet definition before doing event tests
if (ap.canRender(portletDefinitionId.getStringId())) {
if (this.supportsEvent(event, portletDefinitionId)) {
this.logger.debug("{} supports event {}", portletDefinition, event);
final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
for (final IPortletWindow portletWindow : portletWindows) {
this.logger.debug("{} resolved target {}", event, portletWindow);
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
}
}
}
}
}
}
}
use of org.apereo.portal.security.IAuthorizationPrincipal in project uPortal by Jasig.
the class AuthorizationTester method testAlternativePermissionPolicies.
public void testAlternativePermissionPolicies() throws Exception {
print("***** ENTERING AuthorizationTester.testAlternativePermissionPolicies() *****");
String msg = null;
boolean testResult = false;
String activity = IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
String existingTarget = "CHAN_ID.1";
String nonExistingTarget = "CHAN_ID.9999";
msg = "Creating a group member for everyone (" + EVERYONE_GROUP_PRINCIPAL_KEY + ").";
print(msg);
IGroupMember everyone = GroupService.getGroupMember(EVERYONE_GROUP_KEY, GROUP_CLASS);
assertNotNull(msg, everyone);
msg = "Getting principal for " + everyone;
print(msg);
IAuthorizationPrincipal prin = getService().newPrincipal(everyone);
assertNotNull(msg, prin);
msg = "Testing DEFAULT permission policy for an existing channel";
print(msg);
testResult = prin.hasPermission(OWNER, activity, existingTarget);
assertTrue(msg, testResult);
msg = "Testing POSITIVE permission policy for an existing channel";
print(msg);
testResult = prin.hasPermission(OWNER, activity, existingTarget, getPositivePermissionPolicy());
assertTrue(msg, testResult);
msg = "Testing NEGATIVE permission policy for an existing channel";
print(msg);
testResult = prin.hasPermission(OWNER, activity, existingTarget, getNegativePermissionPolicy());
assertTrue(msg, !testResult);
msg = "Testing DEFAULT permission policy for a nonexistent channel";
print(msg);
testResult = prin.hasPermission(OWNER, activity, nonExistingTarget);
assertTrue(msg, !testResult);
msg = "Testing POSITIVE permission policy for nonexistent channel";
print(msg);
testResult = prin.hasPermission(OWNER, activity, nonExistingTarget, getPositivePermissionPolicy());
assertTrue(msg, testResult);
msg = "Testing NEGATIVE permission policy for a nonexistent channel";
print(msg);
testResult = prin.hasPermission(OWNER, activity, nonExistingTarget, getNegativePermissionPolicy());
assertTrue(msg, !testResult);
print("***** LEAVING AuthorizationTester.testAlternativePermissionPolicies() *****" + CR);
}
Aggregations