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(",")));
}
Aggregations