use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project carbon-identity-framework by wso2.
the class TestJSONRequestParser method testParse.
@Test
public void testParse() {
AttributeValue attributeValue = new StringAttribute("http://127.0.0.1");
List<AttributeValue> attributeValues = new ArrayList<>();
attributeValues.add(attributeValue);
Attribute attribute = new Attribute(URI.create("urn:oasis:names:tc:xacml:1.0:resource:resource-id"), null, null, null, attributeValues, false, XACMLConstants.XACML_VERSION_3_0);
Set<Attribute> attributeSet = new HashSet<>();
attributeSet.add(attribute);
Attributes category = new Attributes(URI.create(EntitlementEndpointConstants.CATEGORY_RESOURCE_URI), attributeSet);
Set<Attributes> categories = new HashSet<>();
categories.add(category);
RequestCtx requestCtx = new RequestCtx(categories, null);
String jsonRequest = "{\n" + " \"Request\":{\n" + " \"Action\":{\n" + " \"Attribute\":[{\n" + " \"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:action:action-id\",\n" + " \"Value\":\"read\"\n" + " }]\n" + " },\n" + " \"Resource\":{\n" + " \"Attribute\":[{\n" + " \"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:resource:resource-id\",\n" + " \"Value\":\"http://127.0.0.1/service/very_secure/\"\n" + " }]\n" + " }\n" + " }\n" + "}";
String jsonRequest2 = "{\"Request\":\n" + "{\n" + "\"AccessSubject\":{\n" + " \"Content\": \"PD94bWwgdmVyc2lvbj0iMS4wIj8+DQo8Y2F0YWxvZz48Ym9vayBpZD0iYmsxMDEiPjxhdXRob3I+R2FtYmFyZGVsbGEsIE1hdHRoZXc8L2F1dGhvcj48dGl0bGU+WE1MIERldmVsb3BlcidzIEd1aWRlPC90aXRsZT48Z2VucmU+Q29tcHV0ZXI8L2dlbnJlPjxwcmljZT40NC45NTwvcHJpY2U+PHB1Ymxpc2hfZGF0ZT4yMDAwLTEwLTAxPC9wdWJsaXNoX2RhdGU+PGRlc2NyaXB0aW9uPkFuIGluLWRlcHRoIGxvb2sgYXQgY3JlYXRpbmcgYXBwbGljYXRpb25zIHdpdGggWE1MLjwvZGVzY3JpcHRpb24+PC9ib29rPjwvY2F0YWxvZz4=\"\n" + "}\n" + "}}";
try {
RequestCtx requestCtx1 = JSONRequestParser.parse(jsonRequest);
} catch (Exception e) {
log.error("Exception in JSON Parser Test");
}
}
use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project carbon-identity-framework by wso2.
the class CarbonAttributeFinder method encodeContext.
/**
* Converts DOM object to String. This is a helper method for creating cache key
*
* @param evaluationCtx EvaluationCtx
* @return String Object
* @throws TransformerException Exception throws if fails
*/
private String encodeContext(EvaluationCtx evaluationCtx) throws TransformerException {
OutputStream stream = new ByteArrayOutputStream();
evaluationCtx.getRequestCtx().encode(stream);
String rowContext = stream.toString();
String contextWithAttributeValues = rowContext + "][";
StringBuilder builder = new StringBuilder();
for (Attributes attributes : evaluationCtx.getRequestCtx().getAttributesSet()) {
builder.append("<Attributes ").append(">");
for (Attribute attribute : attributes.getAttributes()) {
attribute.encode(builder);
}
builder.append("</Attributes>");
}
contextWithAttributeValues += builder.toString();
return contextWithAttributeValues;
}
use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes in project core-pdp-api by authzforce.
the class BaseXacmlJaxbRequestPreprocessor method process.
@Override
public final List<IndividualXacmlJaxbRequest> process(final Request jaxbRequest, final Map<String, String> namespaceURIsByPrefix) throws IndeterminateEvaluationException {
if (jaxbRequest == null) {
throw NULL_REQUEST_EXCEPTION;
}
/*
* No support for MultiRequests (ยง2.4 of Multiple Decision Profile).
*/
if (jaxbRequest.getMultiRequests() != null) {
/*
* According to 7.19.1 Unsupported functionality, return Indeterminate with syntax-error code for unsupported element
*/
throw UNSUPPORTED_MULTI_REQUESTS_EXCEPTION;
}
/*
* No support for CombinedDecision = true if no decisionCombiner defined. (The use of the CombinedDecision attribute is specified in Multiple Decision Profile.)
*/
if (jaxbRequest.isCombinedDecision() && !this.isCombinedDecisionSupported) {
/*
* According to XACML core spec, 5.42, <i>If the PDP does not implement the relevant functionality in [Multiple Decision Profile], then the PDP must return an Indeterminate with a status
* code of urn:oasis:names:tc:xacml:1.0:status:processing-error if it receives a request with this attribute set to "true"</i>.
*/
throw UNSUPPORTED_COMBINED_DECISION_EXCEPTION;
}
final RequestDefaults jaxbReqDefaults = jaxbRequest.getRequestDefaults();
final Optional<XPathCompilerProxy> xPathCompiler;
final Map<String, String> newNsPrefixToUriMap;
if (jaxbReqDefaults == null) {
xPathCompiler = Optional.empty();
newNsPrefixToUriMap = namespaceURIsByPrefix;
} else {
try {
final XPathVersion xPathVersion = XPathVersion.fromURI(jaxbReqDefaults.getXPathVersion());
xPathCompiler = Optional.of(new BasicImmutableXPathCompilerProxy(xPathVersion, namespaceURIsByPrefix));
/*
namespaceURIsByPrefix already held by xPathCompiler and retrievable from it with getDeclaredNamespacePrefixToUriMap().
*/
newNsPrefixToUriMap = Map.of();
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid/unsupported XPathVersion in Request/RequestDefaults", e);
}
}
final SingleCategoryXacmlAttributesParser<Attributes> xacmlAttrsParser = xacmlAttrsParserFactory.getInstance();
return process(jaxbRequest.getAttributes(), xacmlAttrsParser, jaxbRequest.isReturnPolicyIdList(), jaxbRequest.isCombinedDecision(), xPathCompiler, newNsPrefixToUriMap);
}
Aggregations