public DefaultSerializer(String fedoraServerHost, Context context) { this.fedoraServerHost = fedoraServerHost; this.fedoraServerPort = context.getEnvironmentValue(Constants.HTTP_REQUEST.SERVER_PORT.attributeId); this.fedoraAppServerContext = context.getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME); if (Constants.HTTP_REQUEST.SECURE.uri .equals(context.getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { this.fedoraServerProtocol = "https"; } else { this.fedoraServerProtocol = "http"; } }
public static boolean isStaleCache(Context context, Property[] headers) { String ifNoneMatch = context.getHeaderValue(INM_KEY); String ifModSince = context.getHeaderValue(IMS_KEY); if (ifModSince == null && ifNoneMatch == null) return true; // parse out the data for comparison Date imsDate = (ifModSince == null) ? null : DateUtility.parseDateLoose(ifModSince); long ims = (imsDate == null) ? Long.MIN_VALUE : imsDate.getTime(); // get the local comparison values String etag = null; long lastMod = Long.MAX_VALUE; for (Property header: headers) { if (HttpHeaders.ETAG.equalsIgnoreCase(header.name)) etag = header.value; if (HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(header.name)) { Date d = DateUtility.parseDateLoose(header.value); if (d != null) lastMod = d.getTime(); } } if (ifNoneMatch != null && !ifNoneMatch.equals(etag)) return true; return (ifModSince != null && ims < lastMod); }
/** * A "copy constructor" that creates a writable context from one that might * be read-only. */ public JournalEntryContext(Context source) { password = source.getPassword(); noOp = source.getNoOp(); now = source.now(); for (Iterator<URI> keys = source.environmentAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(environmentAttributes, key, source .getEnvironmentValues(key)); } for (Iterator<String> keys = source.subjectAttributes(); keys.hasNext();) { String key = keys.next(); storeInMap(subjectAttributes, key, source.getSubjectValues(key)); } for (Iterator<URI> keys = source.actionAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(actionAttributes, key, source.getActionValues(key)); } for (Iterator<URI> keys = source.resourceAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(resourceAttributes, key, source.getResourceValues(key)); } }
@Override public void enforceRIFindObjects(Context context) throws AuthzException { try { logger.debug("Entered enforceRIFindObjects"); String target = Constants.ACTION.RI_FIND_OBJECTS.uri; context.setActionAttributes(null); context.setResourceAttributes(null); xacmlPep.enforce(context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri), target, Constants.ACTION.APIA.uri, "", "", context); } finally { logger.debug("Exiting enforceRIFindObjects"); } }
case AttributeDesignator.SUBJECT_TARGET: String attributeName = attributeId.toString(); if (context.nSubjectValues(attributeName) < 1) { values = null; logger.debug("RETURNING NO VALUES FOR {}", attributeName); if (logger.isDebugEnabled()) { logger.debug("getting n values for {}={}", attributeId, context.nSubjectValues(attributeName)); values = context.getSubjectValues(attributeName); if (logger.isDebugEnabled()) { if (values != null) { if (context.nActionValues(attributeId) < 1) { values = null; } else { values = context.getActionValues(attributeId); if (context.nResourceValues(attributeId) < 1) { values = null; } else { values = context.getResourceValues(attributeId); if (context.nEnvironmentValues(attributeId) < 1) { values = null; } else { values = context.getEnvironmentValues(attributeId);
int nSubjectValues = context.nSubjectValues(targetRole); logger.debug("nSubjectValues=" + nSubjectValues); if (nSubjectValues > 0) { logger.debug("context.getSubjectValue(targetRole)=" + context.getSubjectValue(targetRole)); Iterator<String> subjectNames = context.subjectAttributes(); while (subjectNames.hasNext()) { String name = subjectNames.next(); int n = context.nSubjectValues(name); switch (n) { case 0: break; case 1: String value = context.getSubjectValue(name); logger.debug("single subject attributes for " + name + "=" + value); break; default: String[] values = context.getSubjectValues(name); for (String element : values) { logger Iterator<URI> it = context.environmentAttributes(); while (it.hasNext()) { URI name = it.next(); String value = context.getEnvironmentValue(name); logger.debug("another environment attribute from context "
switch(designatorType){ case AttributeDesignator.SUBJECT_TARGET: values = context.getSubjectValues(id.toString()); break; case AttributeDesignator.RESOURCE_TARGET: values = context.getResourceValues(id); break; case AttributeDesignator.ACTION_TARGET: values = context.getActionValues(id); break; case AttributeDesignator.ENVIRONMENT_TARGET: values = context.getEnvironmentValues(id); break;
private void writeContextNoOp(Context context, XMLEventWriter writer) throws XMLStreamException { putStartTag(writer, QNAME_TAG_NOOP); putCharacters(writer, String.valueOf(context.getNoOp())); putEndTag(writer, QNAME_TAG_NOOP); }
@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()); }
/** * Creates a new audit record and adds it to the digital object audit trail. */ private void addAuditRecord(Context context, DOWriter w, String action, String componentID, String justification, Date nowUTC) throws ServerException { AuditRecord audit = new AuditRecord(); audit.id = w.newAuditRecordID(); audit.processType = "Fedora API-M"; audit.action = action; audit.componentID = componentID; audit.responsibility = context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri); audit.date = nowUTC; audit.justification = justification; w.getAuditRecords().add(audit); }
@Override public void enforceOAIRespond(Context context) throws AuthzException { try { logger.debug("Entered enforceOAIRespond"); String target = Constants.ACTION.OAI.uri; context.setActionAttributes(null); context.setResourceAttributes(null); xacmlPep.enforce(context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri), target, "", "", "", context); } finally { logger.debug("Exiting enforceOAIRespond"); } }
case AttributeDesignator.SUBJECT_TARGET: String attributeName = attributeId.toString(); if (context.nSubjectValues(attributeName) < 1) { values = null; logger.debug("RETURNING NO VALUES FOR {}", attributeName); if (logger.isDebugEnabled()) { logger.debug("getting n values for {}={}", attributeId, context.nSubjectValues(attributeName)); values = context.getSubjectValues(attributeName); if (logger.isDebugEnabled()) { if (values != null) { if (context.nActionValues(attributeId) < 1) { values = null; } else { values = context.getActionValues(attributeId); if (context.nResourceValues(attributeId) < 1) { values = null; } else { values = context.getResourceValues(attributeId); if (context.nEnvironmentValues(attributeId) < 1) { values = null; } else { values = context.getEnvironmentValues(attributeId);
int nSubjectValues = context.nSubjectValues(targetRole); logger.debug("nSubjectValues=" + nSubjectValues); if (nSubjectValues > 0) { logger.debug("context.getSubjectValue(targetRole)=" + context.getSubjectValue(targetRole)); Iterator<String> subjectNames = context.subjectAttributes(); while (subjectNames.hasNext()) { String name = subjectNames.next(); int n = context.nSubjectValues(name); switch (n) { case 0: break; case 1: String value = context.getSubjectValue(name); logger.debug("single subject attributes for " + name + "=" + value); break; default: String[] values = context.getSubjectValues(name); for (String element : values) { logger Iterator<URI> it = context.environmentAttributes(); while (it.hasNext()) { URI name = it.next(); String value = context.getEnvironmentValue(name); logger.debug("another environment attribute from context "
switch(designatorType){ case AttributeDesignator.SUBJECT_TARGET: values = context.getSubjectValues(id.toString()); break; case AttributeDesignator.RESOURCE_TARGET: values = context.getResourceValues(id); break; case AttributeDesignator.ACTION_TARGET: values = context.getActionValues(id); break; case AttributeDesignator.ENVIRONMENT_TARGET: values = context.getEnvironmentValues(id); break;
private void writeContextNoOp(Context context, XMLEventWriter writer) throws XMLStreamException { putStartTag(writer, QNAME_TAG_NOOP); putCharacters(writer, String.valueOf(context.getNoOp())); putEndTag(writer, QNAME_TAG_NOOP); }
@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
/** * Creates a new audit record and adds it to the digital object audit trail. */ private void addAuditRecord(Context context, DOWriter w, String action, String componentID, String justification, Date nowUTC) throws ServerException { AuditRecord audit = new AuditRecord(); audit.id = w.newAuditRecordID(); audit.processType = "Fedora API-M"; audit.action = action; audit.componentID = componentID; audit.responsibility = context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri); audit.date = nowUTC; audit.justification = justification; w.getAuditRecords().add(audit); }
@Override public void enforceServerStatus(Context context) throws AuthzException { try { logger.debug("Entered enforceServerStatus"); String target = Constants.ACTION.SERVER_STATUS.uri; context.setActionAttributes(null); context.setResourceAttributes(null); xacmlPep.enforce(context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri), target, "", "", "", context); } finally { logger.debug("Exiting enforceServerStatus"); } }
/** * A "copy constructor" that creates a writable context from one that might * be read-only. */ public JournalEntryContext(Context source) { password = source.getPassword(); noOp = source.getNoOp(); now = source.now(); for (Iterator<URI> keys = source.environmentAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(environmentAttributes, key, source .getEnvironmentValues(key)); } for (Iterator<String> keys = source.subjectAttributes(); keys.hasNext();) { String key = keys.next(); storeInMap(subjectAttributes, key, source.getSubjectValues(key)); } for (Iterator<URI> keys = source.actionAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(actionAttributes, key, source.getActionValues(key)); } for (Iterator<URI> keys = source.resourceAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(resourceAttributes, key, source.getResourceValues(key)); } }
public DefaultSerializer(String fedoraServerHost, Context context) { this.fedoraServerHost = fedoraServerHost; this.fedoraServerPort = context.getEnvironmentValue(Constants.HTTP_REQUEST.SERVER_PORT.attributeId); this.fedoraAppServerContext = context.getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME); if (Constants.HTTP_REQUEST.SECURE.uri .equals(context.getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { this.fedoraServerProtocol = "https"; } else { this.fedoraServerProtocol = "http"; } }