Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
*
* The Apereo Foundation licenses this file to you under the Educational
* Community License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License
* at:
*
* http://opensource.org/licenses/ecl2.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
*/
package org.opencastproject.security.api;
import static com.entwinemedia.fn.Prelude.chuck;
import static com.entwinemedia.fn.Stream.$;
import static org.opencastproject.security.api.SecurityConstants.GLOBAL_ADMIN_ROLE;
import static org.opencastproject.util.EqualsUtil.bothNotNull;
import static org.opencastproject.util.EqualsUtil.eqListUnsorted;
import static org.opencastproject.util.data.Either.left;
import static org.opencastproject.util.data.Either.right;
import static org.opencastproject.util.data.Monadics.mlist;
import static org.opencastproject.util.data.Option.none;
import static org.opencastproject.util.data.Option.some;
import org.opencastproject.util.Checksum;
import org.opencastproject.util.data.Either;
import org.opencastproject.util.data.Function;
import org.opencastproject.util.data.Function2;
import org.opencastproject.util.data.Option;
import org.opencastproject.util.data.Tuple;
import com.entwinemedia.fn.Fn;
import com.entwinemedia.fn.Fn2;
import com.entwinemedia.fn.Pred;
import com.entwinemedia.fn.Stream;
import com.entwinemedia.fn.fns.Booleans;
import org.apache.commons.lang3.StringUtils;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
/**
* Provides common functions helpful in dealing with {@link AccessControlList}s.
*/
public final class AccessControlUtil {
/** Disallow construction of this utility class */
private AccessControlUtil() {
}
/**
* Determines whether the {@link AccessControlList} permits a user to perform an action.
*
* There are three ways a user can be allowed to perform an action:
*
*
They have the superuser role
*
They have their local organization's admin role
*
They have a role listed in the series ACL, with write permission
*
*
* @param acl
* the {@link AccessControlList}
* @param user
* the user
* @param org
* the organization
* @param action
* The action to perform. action may be an arbitrary object. The authorization check is done on
* the string representation of the object (#toString()). This allows to group actions as enums
* and use them without converting them to a string manually. See
* {@link org.opencastproject.security.api.Permissions.Action}.
* @return whether this action should be allowed
* @throws IllegalArgumentException
* if any of the arguments are null
*/
public static boolean isAuthorized(AccessControlList acl, User user, Organization org, Object action) {
if (action == null || user == null || acl == null || org == null)
throw new IllegalArgumentException();
// Check for the global and local admin role
if (user.hasRole(GLOBAL_ADMIN_ROLE) || user.hasRole(org.getAdminRole()))
return true;
Set userRoles = user.getRoles();
for (AccessControlEntry entry : acl.getEntries()) {
if (!action.toString().equals(entry.getAction()))
continue;
String aceRole = entry.getRole();
for (Role role : userRoles) {
if (!role.getName().equals(aceRole))
continue;
return entry.isAllow();
}
}
return false;
}
/**
* {@link AccessControlUtil#isAuthorized(org.opencastproject.security.api.AccessControlList, org.opencastproject.security.api.User, org.opencastproject.security.api.Organization, Object)}
* as a predicate function.
*/
private static Pred