use of org.wso2.balana.attr.StringAttribute in project carbon-identity-framework by wso2.
the class JSONResponseWriter method getJsonObject.
/**
* Create json object value of an Attribute
*
* @param attributes an element of type Attributes
* @return a JSONObject
*/
private static JsonObject getJsonObject(Attributes attributes) {
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
for (Object att : attributes.getAttributes().toArray()) {
Attribute attrib = (Attribute) att;
if (attrib.isIncludeInResult()) {
JsonObject element = new JsonObject();
if (attrib.getId() != null) {
if (xacmlJSONProfileShortFormEnable) {
element.addProperty(EntitlementEndpointConstants.ATTRIBUTE_ID, uriToShortenForm(attrib.getId().toString()));
} else {
element.addProperty(EntitlementEndpointConstants.ATTRIBUTE_ID, attrib.getId().toString());
}
}
if (attrib.getValues() != null) {
for (AttributeValue val : attrib.getValues()) {
if (((StringAttribute) val).getValue() != null) {
element.addProperty(EntitlementEndpointConstants.ATTRIBUTE_VALUE, ((StringAttribute) val).getValue());
}
}
}
element.addProperty(EntitlementEndpointConstants.ATTRIBUTE_INCLUDE_IN_RESULT, String.valueOf(attrib.isIncludeInResult()));
if (attrib.getType() != null) {
if (xacmlJSONProfileShortFormEnable) {
element.addProperty(EntitlementEndpointConstants.ATTRIBUTE_DATA_TYPE, uriToShortenForm(attrib.getType().toString()));
} else {
element.addProperty(EntitlementEndpointConstants.ATTRIBUTE_DATA_TYPE, attrib.getType().toString());
}
}
jsonArray.add(element);
}
}
jsonObject.add(EntitlementEndpointConstants.ATTRIBUTE, jsonArray);
return jsonObject;
}
use of org.wso2.balana.attr.StringAttribute in project carbon-identity-framework by wso2.
the class EvalPermissionTreeFunction method evaluate.
public EvaluationResult evaluate(List<Evaluatable> inputs, EvaluationCtx context) {
AttributeValue[] argValues = new AttributeValue[inputs.size()];
EvaluationResult result = evalArgs(inputs, context, argValues);
if (result != null) {
return result;
}
switch(getFunctionId()) {
case ID_EVAL_PERMISSION_TREE:
String resource = ((StringAttribute) argValues[0]).getValue().trim();
String subject = ((StringAttribute) argValues[1]).getValue().trim();
boolean isAuthorised = false;
try {
isAuthorised = EntitlementServiceComponent.getRealmservice().getBootstrapRealm().getAuthorizationManager().isUserAuthorized(subject, resource, "ui.execute");
} catch (UserStoreException e) {
log.error("Error while authorising" + subject + " to perform ui.execute on " + resource, e);
}
result = new EvaluationResult(BooleanAttribute.getInstance(isAuthorised));
break;
}
return result;
}
use of org.wso2.balana.attr.StringAttribute 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");
}
}
Aggregations