org.wso2.balana.attr.StringAttribute Java Examples
The following examples show how to use
org.wso2.balana.attr.StringAttribute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MobiAttributeFinder.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
private AttributeValue getAttributeValue(Literal literal) { IRI datatype = literal.getDatatype(); switch (datatype.stringValue()) { case "http://www.w3.org/2001/XMLSchema#string": return new StringAttribute(literal.stringValue()); case "http://www.w3.org/2001/XMLSchema#boolean": return BooleanAttribute.getInstance(literal.booleanValue()); case "http://www.w3.org/2001/XMLSchema#double": return new DoubleAttribute(literal.doubleValue()); case "http://www.w3.org/2001/XMLSchema#integer": return new IntegerAttribute(literal.longValue()); case "http://www.w3.org/2001/XMLSchema#anyURI": try { return new AnyURIAttribute(new URI(literal.stringValue())); } catch (URISyntaxException e) { throw new ProcessingException("Not a valid URI"); } case "https://www.w3.org/2001/XMLSchema#dateTime": return new DateTimeAttribute(new Date(literal.dateTimeValue().toInstant().toEpochMilli())); default: throw new ProcessingException("Datatype " + datatype + " is not supported"); } }
Example #2
Source File: StringFunction.java From balana with Apache License 2.0 | 6 votes |
/** * 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; switch (getFunctionId()) { case ID_STRING_CONCATENATE: String str = ((StringAttribute) argValues[0]).getValue(); StringBuffer buffer = new StringBuffer(str); for (int i = 1; i < argValues.length; i++) { buffer.append(((StringAttribute) (argValues[i])).getValue()); } result = new EvaluationResult(new StringAttribute(buffer.toString())); break; } return result; }
Example #3
Source File: SampleAttributeFinderModule.java From balana with Apache License 2.0 | 6 votes |
@Override public EvaluationResult findAttribute(URI attributeType, URI attributeId, String issuer, URI category, EvaluationCtx context) { String roleName = null; List<AttributeValue> attributeValues = new ArrayList<AttributeValue>(); EvaluationResult result = context.getAttribute(attributeType, defaultSubjectId, issuer, category); if(result != null && result.getAttributeValue() != null && result.getAttributeValue().isBag()){ BagAttribute bagAttribute = (BagAttribute) result.getAttributeValue(); if(bagAttribute.size() > 0){ String userName = ((AttributeValue) bagAttribute.iterator().next()).encode(); roleName = findRole(userName); } } if (roleName != null) { attributeValues.add(new StringAttribute(roleName)); } return new EvaluationResult(new BagAttribute(attributeType, attributeValues)); }
Example #4
Source File: SampleAttributeFinderModule.java From balana with Apache License 2.0 | 6 votes |
@Override public EvaluationResult findAttribute(URI attributeType, URI attributeId, String issuer, URI category, EvaluationCtx context) { String roleName = null; List<AttributeValue> attributeValues = new ArrayList<AttributeValue>(); EvaluationResult result = context.getAttribute(attributeType, defaultSubjectId, issuer, category); if(result != null && result.getAttributeValue() != null && result.getAttributeValue().isBag()){ BagAttribute bagAttribute = (BagAttribute) result.getAttributeValue(); if(bagAttribute.size() > 0){ String userName = ((AttributeValue) bagAttribute.iterator().next()).encode(); roleName = findRole(userName); } } if (roleName != null) { attributeValues.add(new StringAttribute(roleName)); } return new EvaluationResult(new BagAttribute(attributeType, attributeValues)); }
Example #5
Source File: SampleAttributeFinderModule.java From balana with Apache License 2.0 | 6 votes |
@Override public EvaluationResult findAttribute(URI attributeType, URI attributeId, String issuer, URI category, EvaluationCtx context) { String roleName = null; List<AttributeValue> attributeValues = new ArrayList<AttributeValue>(); EvaluationResult result = context.getAttribute(attributeType, defaultSubjectId, issuer, category); if(result != null && result.getAttributeValue() != null && result.getAttributeValue().isBag()){ BagAttribute bagAttribute = (BagAttribute) result.getAttributeValue(); if(bagAttribute.size() > 0){ String userName = ((AttributeValue) bagAttribute.iterator().next()).encode(); roleName = findRole(userName); } } if (roleName != null) { attributeValues.add(new StringAttribute(roleName)); } return new EvaluationResult(new BagAttribute(attributeType, attributeValues)); }
Example #6
Source File: SampleAttributeFinderModule.java From balana with Apache License 2.0 | 6 votes |
@Override public EvaluationResult findAttribute(URI attributeType, URI attributeId, String issuer, URI category, EvaluationCtx context) { String roleName = null; List<AttributeValue> attributeValues = new ArrayList<AttributeValue>(); EvaluationResult result = context.getAttribute(attributeType, defaultSubjectId, issuer, category); if(result != null && result.getAttributeValue() != null && result.getAttributeValue().isBag()){ BagAttribute bagAttribute = (BagAttribute) result.getAttributeValue(); if(bagAttribute.size() > 0){ String userName = ((AttributeValue) bagAttribute.iterator().next()).encode(); roleName = findRole(userName); } } if (roleName != null) { attributeValues.add(new StringAttribute(roleName)); } return new EvaluationResult(new BagAttribute(attributeType, attributeValues)); }
Example #7
Source File: URLStringCatFunction.java From balana with Apache License 2.0 | 6 votes |
/** * Checks the inputs of this function assuming no parameters are bags. * * @param inputs a <code>List></code> of <code>Evaluatable</code>s * * @throws IllegalArgumentException if the inputs won't work */ public void checkInputsNoBag(List inputs) throws IllegalArgumentException { // make sure it's long enough if (inputs.size() < 2) throw new IllegalArgumentException("not enough args to " + NAME_URI_STRING_CONCATENATE); // check that the parameters are of the correct types... Iterator it = inputs.iterator(); // ...the first argument must be a URI... if (!((Expression) (it.next())).getType().toString().equals(AnyURIAttribute.identifier)) throw new IllegalArgumentException("illegal parameter"); // ...and all following arguments must be strings while (it.hasNext()) { if (!((Expression) (it.next())).getType().toString().equals(StringAttribute.identifier)) throw new IllegalArgumentException("illegal parameter"); } }
Example #8
Source File: EqualFunction.java From balana with Apache License 2.0 | 6 votes |
/** * 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])); } }
Example #9
Source File: XACML3HigherOrderFunctionTest.java From balana with Apache License 2.0 | 5 votes |
private Apply getApply(String[] values) { List<StringAttribute> applyList = new ArrayList(); for (String value : values) { applyList.add(new StringAttribute(value)); } return new Apply(new GeneralBagFunction(FUNCTION_BAG), applyList); }
Example #10
Source File: DefaultAttributeFinder.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * This method is introduced in order to check whether the user is local or federated. If it is a * federated user, obtaining user attributes from userstore will be prevented. * * @param attributeType The type of the required attribute. * @param attributeId The unique id of the required attribute. * @param category The category of the required attribute. * @param issuer The attribute issuer. * @param evaluationCtx The evaluation context object. * @return return the set of values for the required attribute. * @throws Exception throws if fails. */ @Override public Set<String> getAttributeValues(URI attributeType, URI attributeId, URI category, String issuer, EvaluationCtx evaluationCtx) throws Exception { Set<String> values = null; EvaluationResult userType = evaluationCtx.getAttribute(new URI(StringAttribute.identifier), new URI( PDPConstants.USER_TYPE_ID), issuer, new URI(PDPConstants.USER_CATEGORY)); String userTypeId = null; if (userType != null && userType.getAttributeValue() != null && userType.getAttributeValue().isBag()) { BagAttribute bagAttribute = (BagAttribute) userType.getAttributeValue(); if (bagAttribute.size() > 0) { userTypeId = ((AttributeValue) bagAttribute.iterator().next()).encode(); if (log.isDebugEnabled()) { log.debug(String.format("The user type of the user is %s", userTypeId)); } } } if (!StringUtils.equalsIgnoreCase(userTypeId, FEDERATED_USER_DOMAIN)) { // If the user is not a federated user, user attributes should be be populated from local userstore. values = super.getAttributeValues(attributeType, attributeId, category, issuer, evaluationCtx); } else if (mapFederatedUsersToLocal) { // If the user is federated and the MapFederatedToLocal config is enabled, then populate user attributes // from userstore. values = super.getAttributeValues(attributeType, attributeId, category, issuer, evaluationCtx); } return values; }
Example #11
Source File: URLStringCatFunction.java From balana with Apache License 2.0 | 5 votes |
/** * Evaluates the function given the input data. This function expects an * <code>AnyURIAttribute</code> followed by one or more <code>StringAttribute</code>s, and * returns an <code>AnyURIAttribute</code>. * * @param inputs the input agrument list * @param context the representation of the request * * @return the result of evaluation */ public EvaluationResult evaluate(List inputs, EvaluationCtx context) { // Evaluate the arguments AttributeValue[] argValues = new AttributeValue[inputs.size()]; EvaluationResult result = evalArgs(inputs, context, argValues); if (result != null) return result; // the first argument is always a URI String str = ((AnyURIAttribute) (argValues[0])).getValue().toString(); // the remaining arguments are strings StringBuffer buffer = new StringBuffer(str); for (int i = 1; i < argValues.length; i++) { buffer.append(((StringAttribute) (argValues[i])).getValue()); } // finally, try to convert the string back to a URI try { return new EvaluationResult(new AnyURIAttribute(new URI(str))); } catch (URISyntaxException use) { List code = new ArrayList(); code.add(Status.STATUS_PROCESSING_ERROR); String message = NAME_URI_STRING_CONCATENATE + " didn't produce" + " a valid URI: " + str; return new EvaluationResult(new Status(code, message)); } }
Example #12
Source File: SubStringFunction.java From balana with Apache License 2.0 | 5 votes |
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; } String processedString = argValues[0].encode().substring(Integer.parseInt(argValues[1].encode()), Integer.parseInt(argValues[2].encode())); return new EvaluationResult(new StringAttribute(processedString)); }
Example #13
Source File: TestJSONRequestParser.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
@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"); } }
Example #14
Source File: StringAttributeProxy.java From balana with Apache License 2.0 | 4 votes |
public AttributeValue getInstance(String value) { return StringAttribute.getInstance(value); }
Example #15
Source File: StringAttributeProxy.java From balana with Apache License 2.0 | 4 votes |
public AttributeValue getInstance(Node root) { return StringAttribute.getInstance(root); }
Example #16
Source File: AbstractPIPResourceFinder.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public Set<String> findDescendantResources(String parentResourceId, EvaluationCtx context) throws Exception { EvaluationResult environment; String environmentId = null; Set<String> resourceNames = null; NodeList children = context.getRequestRoot().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child != null) { if (PDPConstants.ENVIRONMENT_ELEMENT.equals(child.getLocalName())) { if (child.getChildNodes() != null && child.getChildNodes().getLength() > 0) { environment = context.getAttribute(new URI(StringAttribute.identifier), new URI(PDPConstants.ENVIRONMENT_ID_DEFAULT), null, new URI(XACMLConstants.ENT_CATEGORY)); if (environment != null && environment.getAttributeValue() != null && environment.getAttributeValue().isBag()) { BagAttribute attr = (BagAttribute) environment.getAttributeValue(); environmentId = ((AttributeValue) attr.iterator().next()).encode(); } } } } } if (isAbstractResourceCacheEnabled) { IdentityCacheKey cacheKey; String key = PDPConstants.RESOURCE_DESCENDANTS + parentResourceId + (environmentId != null ? environmentId : ""); tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); cacheKey = new IdentityCacheKey(tenantId, key); IdentityCacheEntry cacheEntry = (IdentityCacheEntry) abstractResourceCache.getValueFromCache(cacheKey); if (cacheEntry != null) { String[] values = cacheEntry.getCacheEntryArray(); resourceNames = new HashSet<String>(Arrays.asList(values)); if (log.isDebugEnabled()) { log.debug("Carbon Resource Cache Hit"); } } if (resourceNames != null) { resourceNames = findDescendantResources(parentResourceId, environmentId); if (log.isDebugEnabled()) { log.debug("Carbon Resource Cache Miss"); } if (resourceNames != null && !resourceNames.isEmpty()) { cacheEntry = new IdentityCacheEntry(resourceNames.toArray(new String[resourceNames.size()])); abstractResourceCache.addToCache(cacheKey, cacheEntry); } } } else { resourceNames = findDescendantResources(parentResourceId, environmentId); } return resourceNames; }
Example #17
Source File: AbstractPIPResourceFinder.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
@Override public Set<String> findDescendantResources(String parentResourceId, EvaluationCtx context) throws Exception { EvaluationResult environment; String environmentId = null; Set<String> resourceNames = null; NodeList children = context.getRequestRoot().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child != null) { if (PDPConstants.ENVIRONMENT_ELEMENT.equals(child.getLocalName())) { if (child.getChildNodes() != null && child.getChildNodes().getLength() > 0) { environment = context.getAttribute(new URI(StringAttribute.identifier), new URI(PDPConstants.ENVIRONMENT_ID_DEFAULT), null, new URI(XACMLConstants.ENT_CATEGORY)); if (environment != null && environment.getAttributeValue() != null && environment.getAttributeValue().isBag()) { BagAttribute attr = (BagAttribute) environment.getAttributeValue(); environmentId = ((AttributeValue) attr.iterator().next()).encode(); } } } } } if (isAbstractResourceCacheEnabled) { IdentityCacheKey cacheKey; String key = PDPConstants.RESOURCE_DESCENDANTS + parentResourceId + (environmentId != null ? environmentId : ""); tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); cacheKey = new IdentityCacheKey(tenantId, key); IdentityCacheEntry cacheEntry = (IdentityCacheEntry) abstractResourceCache.getValueFromCache(cacheKey); if (cacheEntry != null) { String[] values = cacheEntry.getCacheEntryArray(); resourceNames = new HashSet<String>(Arrays.asList(values)); if (log.isDebugEnabled()) { log.debug("Carbon Resource Cache Hit"); } } if (resourceNames != null) { resourceNames = findDescendantResources(parentResourceId, environmentId); if (log.isDebugEnabled()) { log.debug("Carbon Resource Cache Miss"); } if (resourceNames != null && !resourceNames.isEmpty()) { cacheEntry = new IdentityCacheEntry(resourceNames.toArray(new String[resourceNames.size()])); abstractResourceCache.addToCache(cacheKey, cacheEntry); } } } else { resourceNames = findDescendantResources(parentResourceId, environmentId); } return resourceNames; }
Example #18
Source File: EvalPermissionTreeFunction.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
public EvalPermissionTreeFunction() { super(SUBJECT_HAS_PERMISSION, ID_EVAL_PERMISSION_TREE, StringAttribute.identifier, false, 2, 2, BooleanAttribute.identifier, false); }
Example #19
Source File: JSONResponseWriter.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
/** * 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; }
Example #20
Source File: SubStringFunction.java From balana with Apache License 2.0 | 3 votes |
/** * Private helper that returns the type used for the given standard function. Note that this * doesn't check on the return value since the method always is called after getId, so we assume * that the function is present. * * @param functionName function name * @return identifier of the Data type */ private static String getArgumentType(String functionName) { if (functionName.equals(NAME_STRING_SUB_STRING)){ return StringAttribute.identifier; } else { return AnyURIAttribute.identifier; } }
Example #21
Source File: SubStringFunction.java From balana with Apache License 2.0 | 2 votes |
/** * Creates a new <code>StringFunction</code> object. * * @param functionName the standard XACML name of the function to be handled by this object, * including the full namespace * * @throws IllegalArgumentException if the function is unknown */ public SubStringFunction(String functionName) { super(functionName, getId(functionName), getArgumentType(functionName), false, 3, StringAttribute.identifier, false); }
Example #22
Source File: StringFunction.java From balana with Apache License 2.0 | 2 votes |
/** * Creates a new <code>StringFunction</code> object. * * @param functionName the standard XACML name of the function to be handled by this object, * including the full namespace * * @throws IllegalArgumentException if the function is unknown */ public StringFunction(String functionName) { super(functionName, ID_STRING_CONCATENATE, StringAttribute.identifier, false, -1, 2, StringAttribute.identifier, false); }
Example #23
Source File: StringNormalizeFunction.java From balana with Apache License 2.0 | 2 votes |
/** * Creates a new <code>StringNormalizeFunction</code> object. * * @param functionName the standard XACML name of the function to be handled by this object, * including the full namespace * * @throws IllegalArgumentException if the function is unknown */ public StringNormalizeFunction(String functionName) { super(functionName, getId(functionName), StringAttribute.identifier, false, 1, StringAttribute.identifier, false); }