Search in sources :

Example 1 with Pred

use of com.entwinemedia.fn.Pred in project opencast by opencast.

the class Protector method protect.

/**
 * Evaluate a product if the current user is authorized to perform the given actions.
 */
public <A> Protected<A> protect(final AccessControlList acl, List<String> actions, P1<A> p) {
    final User user = secSvc.getUser();
    final Organization org = secSvc.getOrganization();
    final Pred<String> isAuthorizedToDo = new Pred<String>() {

        @Override
        public Boolean apply(String action) {
            return AccessControlUtil.isAuthorized(acl, user, org, action);
        }
    };
    final boolean isAuthorized = $(actions).map(isAuthorizedToDo).foldl(false, or);
    return isAuthorized ? Protected.granted(p.get1()) : Protected.<A>rejected(new UnauthorizedException(user, $(actions).mkString(",")));
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) Pred(com.entwinemedia.fn.Pred) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

Aggregations

Pred (com.entwinemedia.fn.Pred)1 Organization (org.opencastproject.security.api.Organization)1 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)1 User (org.opencastproject.security.api.User)1