org.opencastproject.external.util.AclUtils Maven / Gradle / Ivy
The newest version!
/*
* 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.external.util;
import static com.entwinemedia.fn.data.json.Jsons.f;
import static com.entwinemedia.fn.data.json.Jsons.obj;
import static com.entwinemedia.fn.data.json.Jsons.v;
import org.opencastproject.security.api.AccessControlEntry;
import org.opencastproject.security.api.AccessControlList;
import com.entwinemedia.fn.data.json.JValue;
import com.entwinemedia.fn.data.json.Jsons;
import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public final class AclUtils {
private static final String ACTION_JSON_KEY = "action";
private static final String ALLOW_JSON_KEY = "allow";
private static final String ROLE_JSON_KEY = "role";
private AclUtils() {
}
/**
* De-serialize an JSON into an {@link AccessControlList}.
*
* @param json
* The {@link AccessControlList} to serialize.
* @param assumeAllow
* Assume that all entries are allows.
* @return An {@link AccessControlList} representation of the Json
* @throws IllegalArgumentException
* Thrown if essential parts of an access control element is missing.
* @throws ParseException
* Thrown if unable to parse the json value of the acl.
*/
public static AccessControlList deserializeJsonToAcl(String json, boolean assumeAllow)
throws IllegalArgumentException, ParseException {
JSONParser parser = new JSONParser();
JSONArray aclJson = (JSONArray) parser.parse(json);
@SuppressWarnings("unchecked")
ListIterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy