use of org.apereo.portal.AuthorizationException in project uPortal by Jasig.
the class AuthorizationImpl method canPrincipalSubscribe.
/**
* Answers if the principal has permission to SUBSCRIBE to this Channel.
*
* @return boolean
* @param principal IAuthorizationPrincipal
* @param portletDefinitionId
* @exception AuthorizationException indicates authorization information could not be retrieved.
*/
@Override
@RequestCache
public boolean canPrincipalSubscribe(IAuthorizationPrincipal principal, String portletDefinitionId) {
String owner = IPermission.PORTAL_SUBSCRIBE;
// retrieve the indicated channel from the channel registry store and
// determine its current lifecycle state
IPortletDefinition portlet = this.portletDefinitionRegistry.getPortletDefinition(portletDefinitionId);
if (portlet == null) {
return false;
}
String target = PermissionHelper.permissionTargetIdForPortletDefinition(portlet);
PortletLifecycleState state = portlet.getLifecycleState();
/*
* Each channel lifecycle state now has its own subscribe permission. The
* following logic checks the appropriate permission for the lifecycle.
*/
String permission;
if (state.equals(PortletLifecycleState.PUBLISHED) || state.equals(PortletLifecycleState.MAINTENANCE)) {
// NB: There is no separate SUBSCRIBE permission for MAINTENANCE
// mode; everyone simply sees the 'out of service' message
permission = IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
} else if (state.equals(PortletLifecycleState.APPROVED)) {
permission = IPermission.PORTLET_SUBSCRIBER_APPROVED_ACTIVITY;
} else if (state.equals(PortletLifecycleState.CREATED)) {
permission = IPermission.PORTLET_SUBSCRIBER_CREATED_ACTIVITY;
} else if (state.equals(PortletLifecycleState.EXPIRED)) {
permission = IPermission.PORTLET_SUBSCRIBER_EXPIRED_ACTIVITY;
} else {
throw new AuthorizationException("Unrecognized lifecycle state for channel " + portletDefinitionId);
}
// Test the appropriate permission.
return doesPrincipalHavePermission(principal, owner, permission, target);
}
use of org.apereo.portal.AuthorizationException in project uPortal by Jasig.
the class RDBMPermissionImpl method delete.
/**
* Delete a single IPermission from the store.
*
* @param perm org.apereo.portal.security.IPermission
* @exception AuthorizationException - wraps an Exception specific to the store.
*/
@Override
public void delete(IPermission perm) throws AuthorizationException {
Connection conn = null;
try {
conn = RDBMServices.getConnection();
String sQuery = getDeletePermissionSql();
PreparedStatement ps = conn.prepareStatement(sQuery);
try {
primDelete(perm, ps);
} finally {
ps.close();
}
} catch (Exception ex) {
log.error("Exception deleting permission [" + perm + "]", ex);
throw new AuthorizationException("Problem deleting Permission " + perm, ex);
} finally {
RDBMServices.releaseConnection(conn);
}
}
use of org.apereo.portal.AuthorizationException in project uPortal by Jasig.
the class RDBMPermissionImpl method primAdd.
/**
* Add the IPermissions to the store.
*
* @param perms org.apereo.portal.security.IPermission[]
* @exception Exception
*/
private void primAdd(IPermission[] perms) throws Exception {
Connection conn = null;
int rc = 0;
try {
conn = RDBMServices.getConnection();
String sQuery = getInsertPermissionSql();
PreparedStatement ps = conn.prepareStatement(sQuery);
try {
RDBMServices.setAutoCommit(conn, false);
for (int i = 0; i < perms.length; i++) {
primAdd(perms[i], ps);
if (log.isDebugEnabled())
log.debug("RDBMPermissionImpl.primAdd(): " + ps);
rc = ps.executeUpdate();
if (rc != 1) {
String errMsg = "Problem adding " + perms[i] + " RC: " + rc;
log.error(errMsg);
RDBMServices.rollback(conn);
throw new AuthorizationException(errMsg);
}
}
} finally {
ps.close();
}
RDBMServices.commit(conn);
} catch (Exception ex) {
log.error("Exception adding permissions " + Arrays.toString(perms), ex);
RDBMServices.rollback(conn);
throw ex;
} finally {
try {
RDBMServices.setAutoCommit(conn, true);
} finally {
RDBMServices.releaseConnection(conn);
}
}
}
Aggregations