本文整理汇总了Java中org.wso2.balana.XACMLConstants类的典型用法代码示例。如果您正苦于以下问题:Java XACMLConstants类的具体用法?Java XACMLConstants怎么用?Java XACMLConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XACMLConstants类属于org.wso2.balana包,在下文中一共展示了XACMLConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPolicyVersion
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
public static String getPolicyVersion(String policy) {
try {
//build XML document
DocumentBuilder documentBuilder = getSecuredDocumentBuilder(false);
InputStream stream = new ByteArrayInputStream(policy.getBytes());
Document doc = documentBuilder.parse(stream);
//get policy version
Element policyElement = doc.getDocumentElement();
return policyElement.getNamespaceURI();
} catch (Exception e) {
log.debug(e);
// ignore exception as default value is used
log.warn("Policy version can not be identified. Default XACML 3.0 version is used");
return XACMLConstants.XACML_3_0_IDENTIFIER;
}
}
示例2: createMetaDataFromConditionElement
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* This extract policy meta data from condition element in the policy
*
* @param omElement condition element as an OMElement
* @param attributeDTOs list of AttributeDTO object which holds the policy meta data
* in String format
* @return list of AttributeDTO object which holds the policy meta data in String format
*/
public List<AttributeDTO> createMetaDataFromConditionElement(OMElement omElement,
List<AttributeDTO> attributeDTOs) {
Iterator iterator = omElement.getChildrenWithLocalName(PDPConstants.APPLY_ELEMENT);
if (iterator.hasNext()) {
if (version == XACMLConstants.XACML_VERSION_3_0) {
createMetaDataFromXACML3ApplyElement(omElement, attributeDTOs);
} else {
createMetaDataFromApplyElement(omElement, attributeDTOs);
}
} else {
AttributeDTO attributeDTO = new AttributeDTO();
attributeDTO.setCategory(PDPConstants.UNKNOWN);
attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE4);
}
// TODO currently only search meta data on Apply Element, support for other elements
return attributeDTOs;
}
示例3: evaluate
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* Evaluate the function, using the specified parameters.
*
* @param inputs a <code>List</code> of <code>Evaluatable</code> objects representing the
* arguments passed to the function
* @param context an <code>EvaluationCtx</code> so that the <code>Evaluatable</code> objects can
* be evaluated
* @return an <code>EvaluationResult</code> representing the function's result
*/
public EvaluationResult evaluate(List<Evaluatable> inputs, EvaluationCtx context) {
// Evaluate the arguments
AttributeValue[] argValues = new AttributeValue[inputs.size()];
EvaluationResult result = evalArgs(inputs, context, argValues);
if (result != null)
return result;
if (argValues[1] instanceof StringAttribute
&& XACMLConstants.ANY.equals(((StringAttribute) argValues[1]).getValue())) {
return EvaluationResult.getInstance(true);
}
// Now that we have real values, perform the equals operation
if(getFunctionId() == ID_EQUAL_CASE_IGNORE){
return EvaluationResult.getInstance(argValues[0].encode().toLowerCase().
equals(argValues[1].encode().toLowerCase()));
} else {
return EvaluationResult.getInstance(argValues[0].equals(argValues[1]));
}
}
示例4: findAttribute
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* Used to get the current time, date, or dateTime. If one of those values isn't being asked
* for, or if the types are wrong, then an empty bag is returned.
*
* @param attributeType the datatype of the attributes to find, which must be time, date, or
* dateTime for this module to resolve a value
* @param attributeId the identifier of the attributes to find, which must be one of the three
* ENVIRONMENT_* fields for this module to resolve a value
* @param issuer the issuer of the attributes, or null if unspecified
* @param category the category of the attribute
* @param context the representation of the request data
*
* @return the result of attribute retrieval, which will be a bag with a single attribute, an
* empty bag, or an error
*/
public EvaluationResult findAttribute(URI attributeType, URI attributeId, String issuer,
URI category, EvaluationCtx context) {
// we only know about environment attributes
if (!XACMLConstants.ENT_CATEGORY.equals(category.toString())){
return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));
}
// figure out which attribute we're looking for
String attrName = attributeId.toString();
if (attrName.equals(ENVIRONMENT_CURRENT_TIME)) {
return handleTime(attributeType, issuer, context);
} else if (attrName.equals(ENVIRONMENT_CURRENT_DATE)) {
return handleDate(attributeType, issuer, context);
} else if (attrName.equals(ENVIRONMENT_CURRENT_DATETIME)) {
return handleDateTime(attributeType, issuer, context);
}
// if we got here, then it's an attribute that we don't know
return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));
}
示例5: getRequestCtx
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* Returns instance of <code>AbstractRequestCtx</code> based one the XACML version.
*
* @param root the node to parse for the <code>AbstractRequestCtx</code>
* @return <code>AbstractRequestCtx</code> object
* @throws org.wso2.balana.ParsingException if the DOM node is invalid
*/
public AbstractRequestCtx getRequestCtx(Node root) throws ParsingException {
String requestCtxNs = root.getNamespaceURI();
if(requestCtxNs != null){
if(XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER.equals(requestCtxNs.trim())){
return RequestCtx.getInstance(root);
} else if(XACMLConstants.REQUEST_CONTEXT_1_0_IDENTIFIER.equals(requestCtxNs.trim()) ||
XACMLConstants.REQUEST_CONTEXT_2_0_IDENTIFIER.equals(requestCtxNs.trim())) {
return org.wso2.balana.ctx.xacml2.RequestCtx.getInstance(root);
} else {
throw new ParsingException("Invalid namespace in XACML request");
}
} else {
log.warn("No Namespace defined in XACML request and Assume as XACML 3.0");
return RequestCtx.getInstance(root);
}
}
示例6: getAttributes
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
public static Attributes getAttributes(AttributeDTO attributeDataDTO) {
try {
AttributeValue value = Balana.getInstance().getAttributeFactory().
createValue(new URI(attributeDataDTO.getAttributeDataType()),
attributeDataDTO.getAttributeValue());
Attribute attribute = new Attribute(new URI(attributeDataDTO.getAttributeId()),
null, null, value, XACMLConstants.XACML_VERSION_3_0);
Set<Attribute> set = new HashSet<Attribute>();
set.add(attribute);
String category = attributeDataDTO.getCategory();
// We are only creating XACML 3.0 requests Therefore covert order XACML categories to new uris
if (PDPConstants.SUBJECT_ELEMENT.equals(category)) {
category = PDPConstants.SUBJECT_CATEGORY_URI;
} else if (PDPConstants.RESOURCE_ELEMENT.equals(category)) {
category = PDPConstants.RESOURCE_CATEGORY_URI;
} else if (PDPConstants.ACTION_ELEMENT.equals(category)) {
category = PDPConstants.ACTION_CATEGORY_URI;
} else if (PDPConstants.ENVIRONMENT_ELEMENT.equals(category)) {
category = PDPConstants.ENVIRONMENT_CATEGORY_URI;
}
return new Attributes(new URI(category), set);
} catch (Exception e) {
log.debug(e);
//ignore and return null;
}
return null;
}
示例7: PolicyAttributeBuilder
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* @param policy policy as a String
*/
public PolicyAttributeBuilder(String policy) {
this.policy = policy;
String version = EntitlementUtil.getPolicyVersion(policy);
if (XACMLConstants.XACML_1_0_IDENTIFIER.equals(version)) {
this.version = XACMLConstants.XACML_VERSION_1_0;
} else if (XACMLConstants.XACML_2_0_IDENTIFIER.equals(version)) {
this.version = XACMLConstants.XACML_VERSION_2_0;
} else {
this.version = XACMLConstants.XACML_VERSION_3_0;
}
}
示例8: searchAttributeValues
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* This searches through attribute values in the attribute elements to extract the policy meta data
*
* @param omElement apply element as an OMElement
* @param values set of String objects
* @param searchDesignators states where, to find designators which are involved in creating
* attribute values
* @return AttributeValueDTO object which holds the policy meta data in String format
*/
public List<String> searchAttributeValues(OMElement omElement, List<String> values,
boolean searchDesignators) {
if (values != null) {
Iterator iterator = omElement.
getChildrenWithLocalName(PDPConstants.ATTRIBUTE_VALUE);
while (iterator.hasNext()) {
OMElement attributeElement = (OMElement) iterator.next();
if (attributeElement != null) {
String dataType = attributeElement.
getAttributeValue(new QName(PDPConstants.DATA_TYPE)); // TODO
values.add(attributeElement.getText());
}
}
}
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.APPLY_ELEMENT);
while (iterator1.hasNext()) {
OMElement applyElement = (OMElement) iterator1.next();
searchAttributeValues(applyElement, values, searchDesignators);
AttributeDTO attributeDTO = new AttributeDTO();
if (searchDesignators) {
if (version == XACMLConstants.XACML_VERSION_3_0) {
searchXACML3Designator(applyElement, attributeDTO);
} else {
searchDesignatorOrSelector(applyElement, attributeDTO);
}
}
if (attributeDTO.getCategory() != null || attributeDTO.getAttributeId() != null ||
attributeDTO.getAttributeDataType() != null) {
values = null;
}
}
return values;
}
示例9: createMetaDataFromRuleElement
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* This extract policy meta data from each rule element in the policy
*
* @param omElement rule element as an OMElement
* @param attributeDTOs list of AttributeDTO object which holds the policy meta data
* in String format
* @return list of AttributeDTO object which holds the policy meta data in String format
*/
public List<AttributeDTO> createMetaDataFromRuleElement(OMElement omElement,
List<AttributeDTO> attributeDTOs) {
if (omElement != null) {
Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.
TARGET_ELEMENT);
while (iterator1.hasNext()) {
OMElement targetElement = (OMElement) iterator1.next();
if (version == XACMLConstants.XACML_VERSION_3_0) {
createMetaDataFromXACML3TargetElement(targetElement, attributeDTOs);
} else {
createMetaDataFromTargetElement(targetElement, attributeDTOs);
}
}
Iterator iterator2 = omElement.getChildrenWithLocalName(PDPConstants.
CONDITION_ELEMENT);
while (iterator2.hasNext()) {
OMElement conditionElement = (OMElement) iterator2.next();
createMetaDataFromConditionElement(conditionElement, attributeDTOs);
}
}
return attributeDTOs;
}
示例10: getXPathResults
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* Gets Xpath results
*
* @param contextNode
* @param xpathValue
* @return
* @throws XPathExpressionException
*/
private NodeList getXPathResults(Node contextNode, String xpathValue)
throws XPathExpressionException {
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
//see if the request root is in a namespace
String namespace = contextNode.getNamespaceURI();
// name spaces are used, so we need to lookup the correct
// prefix to use in the search string
NamedNodeMap namedNodeMap = contextNode.getAttributes();
Map<String, String> nsMap = new HashMap<String, String>();
for (int i = 0; i < namedNodeMap.getLength(); i++) {
Node n = namedNodeMap.item(i);
// we found the matching namespace, so get the prefix
// and then break out
String prefix = DOMHelper.getLocalName(n);
String nodeValue= n.getNodeValue();
nsMap.put(prefix, nodeValue);
}
// if there is not any namespace is defined for content element, default XACML request
// name space would be there.
if(XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER.equals(namespace) ||
XACMLConstants.REQUEST_CONTEXT_2_0_IDENTIFIER.equals(namespace) ||
XACMLConstants.REQUEST_CONTEXT_1_0_IDENTIFIER.equals(namespace)){
nsMap.put("xacml", namespace);
}
NamespaceContext namespaceContext = new DefaultNamespaceContext(nsMap);
xpath.setNamespaceContext(namespaceContext);
XPathExpression expression = xpath.compile(xpathValue);
return (NodeList) expression.evaluate(contextNode, XPathConstants.NODESET);
}
示例11: getAbstractSelector
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
public AbstractAttributeSelector getAbstractSelector(Node root, PolicyMetaData metaData)
throws ParsingException {
if(metaData.getXACMLVersion() == XACMLConstants.XACML_VERSION_3_0){
return org.wso2.balana.attr.xacml3.AttributeSelector.getInstance(root, metaData);
} else {
return org.wso2.balana.attr.AttributeSelector.getInstance(root, metaData);
}
}
示例12: getAbstractDesignator
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
public AbstractDesignator getAbstractDesignator(Node root, PolicyMetaData metaData)
throws ParsingException {
if(metaData.getXACMLVersion() == XACMLConstants.XACML_VERSION_3_0){
return AttributeDesignator.getInstance(root);
} else {
return org.wso2.balana.attr.AttributeDesignator.getInstance(root);
}
}
示例13: RequestCtx
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* Constructor that creates a <code>RequestCtx</code> from components.
*
* @param documentRoot the root node of the DOM tree for this request
* @param attributesSet a <code>Set</code> of <code>Attributes</code>s
* @param returnPolicyIdList a <code>boolean</code> value whether to send back policy list of not
* @param combinedDecision a <code>boolean</code> value whether to combine decisions or not
* @param multiRequests a <code>MultiRequests</code> for the MultiRequests element in request
* @param defaults a <code>RequestDefaults</code> for the RequestDefaults element in request
* @throws IllegalArgumentException if the inputs are not well formed
*/
public RequestCtx(Node documentRoot, Set<Attributes> attributesSet, boolean returnPolicyIdList,
boolean combinedDecision, MultiRequests multiRequests,
RequestDefaults defaults) throws IllegalArgumentException {
this.xacmlVersion = XACMLConstants.XACML_VERSION_3_0;
this.documentRoot = documentRoot;
this.attributesSet = attributesSet;
this.returnPolicyIdList = returnPolicyIdList;
this.combinedDecision = combinedDecision;
this.multiRequests = multiRequests;
this.defaults = defaults;
}
示例14: encode
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
/**
* Encodes this <code>AbstractRequestCtx</code> into its XML representation and writes this encoding to the given
* <code>OutputStream</code> with indentation.
*
* @param output a stream into which the XML-encoded data is written
* @param indenter an object that creates indentation strings
*/
public void encode(OutputStream output, Indenter indenter) {
String indent = indenter.makeString();
PrintStream out = new PrintStream(output);
out.println(indent + "<Request xmlns=\"" + XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER +
"\" ReturnPolicyIdList=\"" + returnPolicyIdList + "\" CombinedDecision=\"" +
combinedDecision + "\" >");
indenter.in();
for(Attributes attributes : attributesSet){
out.println(attributes.encode());
}
if(defaults != null){
defaults.encode(output, indenter);
}
if(multiRequests != null){
// multiRequests
}
indenter.out();
out.println(indent + "</Request>");
}
示例15: getEvaluationCtx
import org.wso2.balana.XACMLConstants; //导入依赖的package包/类
public EvaluationCtx getEvaluationCtx(AbstractRequestCtx requestCtx, PDPConfig pdpConfig)
throws ParsingException {
if(XACMLConstants.XACML_VERSION_3_0 == requestCtx.getXacmlVersion()){
return new XACML3EvaluationCtx((RequestCtx)requestCtx, pdpConfig);
} else {
return new XACML2EvaluationCtx((org.wso2.balana.ctx.xacml2.RequestCtx) requestCtx, pdpConfig);
}
}