org.wso2.balana.attr.DateTimeAttribute Java Examples

The following examples show how to use org.wso2.balana.attr.DateTimeAttribute. 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 vote down vote up
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: DateMathFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the return type 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.
 */
private static String getReturnType(String functionName) {
	if (functionName.equals(NAME_DATE_ADD_YEARMONTHDURATION)
			|| functionName.equals(NAME_DATE_SUBTRACT_YEARMONTHDURATION))
		return DateAttribute.identifier;
	else
		return DateTimeAttribute.identifier;
}
 
Example #3
Source File: CurrentEnvModule.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Handles requests for the current DateTime.
 */
private EvaluationResult handleDateTime(URI type, String issuer, EvaluationCtx context) {
    // make sure they're asking for a dateTime attribute
    if (!type.toString().equals(DateTimeAttribute.identifier))
        return new EvaluationResult(BagAttribute.createEmptyBag(type));

    // get the value from the context
    return makeBag(context.getCurrentDateTime());
}
 
Example #4
Source File: DateTimeAttributeProxy.java    From balana with Apache License 2.0 4 votes vote down vote up
public AttributeValue getInstance(Node root) throws Exception {
    return DateTimeAttribute.getInstance(root);
}
 
Example #5
Source File: DateTimeAttributeProxy.java    From balana with Apache License 2.0 4 votes vote down vote up
public AttributeValue getInstance(String value) throws Exception {
    return DateTimeAttribute.getInstance(value);
}
 
Example #6
Source File: Attribute.java    From balana with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new <code>Attribute</code>
 * 
 * @param id the id of the attribute
 * @param type the type of the attribute
 * @param issuer the attribute's issuer or null if there is none
 * @param issueInstant the moment when the attribute was issued, or null if it's unspecified
 * @param attributeValues actual <code>List</code> of <code>AttributeValue</code>  associated with
 * @param includeInResult whether to include this attribute in the result.
 * @param xacmlVersion xacml version
 */
public Attribute(URI id, URI type, String issuer, DateTimeAttribute issueInstant,
        List<AttributeValue> attributeValues, boolean includeInResult, int xacmlVersion) {
    this.id = id;
    this.type = type;
    this.issuer = issuer;
    this.issueInstant = issueInstant;
    this.attributeValues = attributeValues;
    this.includeInResult = includeInResult;
    this.xacmlVersion = xacmlVersion;
}
 
Example #7
Source File: BasicEvaluationCtx.java    From balana with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the value for the current dateTime. The current time, current date, and current
 * dateTime are consistent, so that they all represent the same moment. If this is the first
 * time that one of these three values has been requested, and caching is enabled, then the
 * three values will be resolved and stored.
 * <p/>
 * Note that the value supplied here applies only to dynamically resolved values, not those
 * supplied in the Request. In other words, this always returns a dynamically resolved value
 * local to the PDP, even if a different value was supplied in the Request. This is handled
 * correctly when the value is requested by its identifier.
 *
 * @return the current dateTime
 */
public synchronized DateTimeAttribute getCurrentDateTime() {
    long millis = dateTimeHelper();

    if (useCachedEnvValues)
        return currentDateTime;
    else
        return new DateTimeAttribute(new Date(millis));
}
 
Example #8
Source File: Attribute.java    From balana with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new <code>Attribute</code> of the type specified in the given
 * <code>AttributeValue</code>.for XACML 3 with one  <code>AttributeValue</code>
 *
 * @param id the id of the attribute
 * @param issuer the attribute's issuer or null if there is none
 * @param issueInstant the moment when the attribute was issued, or null if it's unspecified
 * @param value the actual value associated with the attribute meta-data
 * @param includeInResult  whether to include this attribute in the result.
 * @param version XACML version
 */
public Attribute(URI id, String issuer, DateTimeAttribute issueInstant, AttributeValue value,
                  boolean includeInResult, int version) {
    this(id, value.getType(), issuer, issueInstant, Arrays.asList(value), includeInResult,version);
}
 
Example #9
Source File: Attribute.java    From balana with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new <code>Attribute</code>  for XACML 2 and XACML 1.X with one <code>AttributeValue</code>
 *
 * @param id the id of the attribute
 * @param issuer the attribute's issuer or null if there is none
 * @param issueInstant the moment when the attribute was issued, or null if it's unspecified
 * @param value actual <code>List</code> of <code>AttributeValue</code>  associated with
 * @param version XACML version
 */
public Attribute(URI id, String issuer, DateTimeAttribute issueInstant, AttributeValue value,
                                                                                int version) {

    this(id, value.getType(), issuer, issueInstant, Arrays.asList(value), false, version);
}
 
Example #10
Source File: Attribute.java    From balana with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the moment at which the attribute was issued, or null if no issue time was provided
 * 
 * @return the time of issuance or null
 */
public DateTimeAttribute getIssueInstant() {
    return issueInstant;
}
 
Example #11
Source File: EvaluationCtx.java    From balana with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the value for the current dateTime as known by the PDP (if this value was also
 * supplied in the Request, this will generally be a different value). Details of caching or
 * location-based resolution are left to the underlying implementation.
 * 
 * @return the current date
 */
public DateTimeAttribute getCurrentDateTime();