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.
/*
* File: ContextUtil.java
*
* Copyright 2007 Macquarie E-Learning Centre Of Excellence
*
* Licensed under the Apache 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://www.apache.org/licenses/LICENSE-2.0
*
* 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.fcrepo.server.security.xacml.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.fcrepo.common.Constants;
import org.fcrepo.server.security.xacml.MelcoeXacmlException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.xacml.Indenter;
import com.sun.xacml.ParsingException;
import com.sun.xacml.attr.AnyURIAttribute;
import com.sun.xacml.attr.AttributeValue;
import com.sun.xacml.attr.StringAttribute;
import com.sun.xacml.ctx.Attribute;
import com.sun.xacml.ctx.RequestCtx;
import com.sun.xacml.ctx.ResponseCtx;
import com.sun.xacml.ctx.Result;
import com.sun.xacml.ctx.Subject;
/**
* Utility class that provides various methods for creating/converting contexts.
* This class can convert requests and responses from their string
* representations to their object representations and vice versa as well as a
* few utility methods for getting information from the contexts. It also
* contains methods for constructing requests.
*
* @author [email protected]
*/
public class ContextUtil {
private static final Logger logger =
LoggerFactory.getLogger(ContextUtil.class);
private static final URI XACML_RESOURCE_ID =
Constants.XACML1_RESOURCE.ID.getURI();
private final Map actionMap =
new ConcurrentHashMap();
private final Map actionValueMap =
new ConcurrentHashMap();
public ContextUtil() {
logger.info("created");
}
public void setActionMap(Map actions) {
for (String from: actions.keySet()){
URI key;
String to = actions.get(from);
try {
key = new URI(from);
URI value = new URI(actions.get(from));
actionMap.put(key, value);
} catch (URISyntaxException e) {
logger.warn("Mapping contained invalid URI: ["
+ from + "] / [" + to + "]");
}
}
}
public void setActionValueMap(Map values) {
actionValueMap.putAll(values);
}
/**
* Sets up the Subject section of the request. Takes a list of Maps of
* URI/AttributeValue pairs. Each list element represents one subject which
* contains a map of URI/AttributeValues.
*
* @return a Set of Subject instances for inclusion in a Request
*/
public Set setupSubjects(List