/** * Returns attribute value(s) from the subject section of the request. * * @param type the type of the attribute value(s) to find * @param id the id of the attribute value(s) to find * @param issuer the issuer of the attribute value(s) to find or null * @param category the category the attribute value(s) must be in * * @return a result containing a bag either empty because no values were * found or containing at least one value, or status associated with an * Indeterminate result */ public EvaluationResult getSubjectAttribute(URI type, URI id, URI issuer, URI category) { // This is the same as the other three lookups except that this // has an extra level of indirection that needs to be handled first Map map = (Map)(subjectMap.get(category)); if (map == null) { // the request didn't have that category, so we should try asking // the attribute finder return callHelper(type, id, issuer, category, AttributeDesignator.SUBJECT_TARGET); } return getGenericAttributes(type, id, issuer, map, category, AttributeDesignator.SUBJECT_TARGET); }
@Override public ResponseCtx evaluate(RequestCtx request) throws EvaluationException { try { BasicEvaluationCtx evalCtx = new BasicEvaluationCtx(request, m_finder); // not necessary with local EvaluationCtx impl /**for (Object obj:req.getResourceAsList()) { Attribute att = (Attribute)obj; if (att.getId().equals(Constants.XACML1_RESOURCE.ID.attributeId)){ evalCtx.setResourceId(att.getValue()); } }**/ return m_pdp.evaluate(evalCtx); } catch (ParsingException pe) { logger.error("Error parsing request:\n" + request, pe); throw new EvaluationException("Error parsing request:\n" + request); } } /*
String tString = type.toString(); if (values.length == 1) { AttributeValue val = stringToValue(values[0], tString); return (val == null) ? null : new SingletonAttribute(id, iString, getCurrentDateTime(), val); } else { ArrayList<AttributeValue> valCollection = new ArrayList<AttributeValue>(values.length); for (int i=0;i<values.length;i++) { AttributeValue val = stringToValue(values[i], tString); if (val != null) valCollection.add(val); return new BasicAttribute(id, type, iString, getCurrentDateTime(), valCollection);
Attribute contextValue = checkContext(type, id, issuer, category, designatorType); if (contextValue != null) { attrList = Collections.singletonList(contextValue); id); return callHelper(type, id, issuer, category, designatorType); } else {
/** * Returns attribute value(s) from the resource section of the request. * * @param type the type of the attribute value(s) to find * @param id the id of the attribute value(s) to find * @param issuer the issuer of the attribute value(s) to find or null * * @return a result containing a bag either empty because no values were * found or containing at least one value, or status associated with an * Indeterminate result */ public EvaluationResult getResourceAttribute(URI type, URI id, URI issuer) { return getGenericAttributes(type, id, issuer, resourceMap, null, AttributeDesignator.RESOURCE_TARGET); }
/** * Returns the value for the current date. 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 date */ public DateAttribute getCurrentDate() { Date time = dateTimeHelper(); if (useCachedEnvValues) return currentDate; else return new DateAttribute(time); }
@Test public void testContextAttribute() { URI testUri = URI.create("lol:wut"); when(mockContext.getResourceValues(testUri)).thenReturn(new String[]{"foo:bar"}); EvaluationResult eval = test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); // call again to test cache test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); verify(mockContext, times(1)).getResourceValues(testUri); verify(mockFinder, times(0)).findAttribute(any(URI.class), any(URI.class), any(URI.class), any(URI.class), any(EvaluationCtx.class), any(Integer.class)); assertEquals("foo:bar", eval.getAttributeValue().getValue()); }
try { response = m_pdp.evaluate(new BasicEvaluationCtx(request, m_pdpConfig.getAttributeFinder(), context)); } finally { if (debug) {
String tString = type.toString(); if (values.length == 1) { AttributeValue val = stringToValue(values[0], tString); return (val == null) ? null : new SingletonAttribute(id, iString, getCurrentDateTime(), val); } else { ArrayList<AttributeValue> valCollection = new ArrayList<AttributeValue>(values.length); for (int i=0;i<values.length;i++) { AttributeValue val = stringToValue(values[i], tString); if (val != null) valCollection.add(val); return new BasicAttribute(id, type, iString, getCurrentDateTime(), valCollection);
Attribute contextValue = checkContext(type, id, issuer, category, designatorType); if (contextValue != null) { attrList = Collections.singletonList(contextValue); id); return callHelper(type, id, issuer, category, designatorType); } else {
/** * Returns attribute value(s) from the environment section of the request. * * @param type the type of the attribute value(s) to find * @param id the id of the attribute value(s) to find * @param issuer the issuer of the attribute value(s) to find or null * * @return a result containing a bag either empty because no values were * found or containing at least one value, or status associated with an * Indeterminate result */ public EvaluationResult getEnvironmentAttribute(URI type, URI id, URI issuer) { return getGenericAttributes(type, id, issuer, environmentMap, null, AttributeDesignator.ENVIRONMENT_TARGET); }
/** * Returns the value for the current time. 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 time */ public TimeAttribute getCurrentTime() { Date time = dateTimeHelper(); if (useCachedEnvValues) return currentTime; else return new TimeAttribute(time); }
@Test public void testModuleAttribute() { URI testUri = URI.create("lol:wut"); when(mockFinder.findAttribute( any(URI.class), eq(testUri), any(URI.class), any(URI.class), any(EvaluationCtx.class), eq(AttributeDesignator.RESOURCE_TARGET))) .thenReturn(new EvaluationResult(StringAttribute.getInstance("foo:bar"))); EvaluationResult eval = test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); verify(mockContext, times(2)).getResourceValues(testUri); verify(mockFinder, times(2)).findAttribute(any(URI.class), any(URI.class), any(URI.class), any(URI.class), any(EvaluationCtx.class), any(Integer.class)); assertEquals("foo:bar", eval.getAttributeValue().getValue()); } // Supports legacy test runners
response = m_pdp.evaluate(new BasicEvaluationCtx(request, m_pdpConfig.getAttributeFinder(), context)); } finally { long dur = System.currentTimeMillis() - st;
/** * Returns attribute value(s) from the subject section of the request. * * @param type the type of the attribute value(s) to find * @param id the id of the attribute value(s) to find * @param issuer the issuer of the attribute value(s) to find or null * @param category the category the attribute value(s) must be in * * @return a result containing a bag either empty because no values were * found or containing at least one value, or status associated with an * Indeterminate result */ public EvaluationResult getSubjectAttribute(URI type, URI id, URI issuer, URI category) { // This is the same as the other three lookups except that this // has an extra level of indirection that needs to be handled first Map map = (Map)(subjectMap.get(category)); if (map == null) { // the request didn't have that category, so we should try asking // the attribute finder return callHelper(type, id, issuer, category, AttributeDesignator.SUBJECT_TARGET); } return getGenericAttributes(type, id, issuer, map, category, AttributeDesignator.SUBJECT_TARGET); }
/** * Returns attribute value(s) from the environment section of the request. * * @param type the type of the attribute value(s) to find * @param id the id of the attribute value(s) to find * @param issuer the issuer of the attribute value(s) to find or null * * @return a result containing a bag either empty because no values were * found or containing at least one value, or status associated with an * Indeterminate result */ public EvaluationResult getEnvironmentAttribute(URI type, URI id, URI issuer) { return getGenericAttributes(type, id, issuer, environmentMap, null, AttributeDesignator.ENVIRONMENT_TARGET); }
/** * Returns the value for the current date. 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 date */ public DateAttribute getCurrentDate() { Date time = dateTimeHelper(); if (useCachedEnvValues) return currentDate; else return new DateAttribute(time); }
try { response = m_pdp.evaluate(new BasicEvaluationCtx(request, m_pdpConfig.getAttributeFinder())); } finally { if (debug) {
/** * Returns attribute value(s) from the action section of the request. * * @param type the type of the attribute value(s) to find * @param id the id of the attribute value(s) to find * @param issuer the issuer of the attribute value(s) to find or null * * @return a result containing a bag either empty because no values were * found or containing at least one value, or status associated with an * Indeterminate result */ public EvaluationResult getActionAttribute(URI type, URI id, URI issuer) { return getGenericAttributes(type, id, issuer, actionMap, null, AttributeDesignator.ACTION_TARGET); }
/** * 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 DateTimeAttribute getCurrentDateTime() { Date time = dateTimeHelper(); if (useCachedEnvValues) return currentDateTime; else return new DateTimeAttribute(time); }