Search in sources :

Example 16 with AuthorizationException

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);
}
Also used : PortletLifecycleState(org.apereo.portal.portlet.om.PortletLifecycleState) AuthorizationException(org.apereo.portal.AuthorizationException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestCache(org.apereo.portal.concurrency.caching.RequestCache)

Example 17 with AuthorizationException

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);
    }
}
Also used : AuthorizationException(org.apereo.portal.AuthorizationException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) AuthorizationException(org.apereo.portal.AuthorizationException) SQLException(java.sql.SQLException)

Example 18 with AuthorizationException

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);
        }
    }
}
Also used : AuthorizationException(org.apereo.portal.AuthorizationException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) AuthorizationException(org.apereo.portal.AuthorizationException) SQLException(java.sql.SQLException)

Aggregations

AuthorizationException (org.apereo.portal.AuthorizationException)18 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)5 IPerson (org.apereo.portal.security.IPerson)5 ArrayList (java.util.ArrayList)4 RequestCache (org.apereo.portal.concurrency.caching.RequestCache)4 Iterator (java.util.Iterator)3 GroupsException (org.apereo.portal.groups.GroupsException)2 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)2 PortletLifecycleState (org.apereo.portal.portlet.om.PortletLifecycleState)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 PortalSecurityException (org.apereo.portal.security.PortalSecurityException)2 PersonImpl (org.apereo.portal.security.provider.PersonImpl)2 Document (org.w3c.dom.Document)2 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1