Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Add support for resource-location attributes #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions openaz-pep/src/main/java/org/apache/openaz/pepapi/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@

import org.apache.openaz.xacml.api.XACML3;

;

/**
* Container class that maps attributes to predefined XACML Action category.
*/
public class Action extends CategoryContainer {

public static final String ACTION_ID_KEY = "ACTION_ID_KEY";

private String actionIdValue;
private String id;

private Action() {
super(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION);
Expand All @@ -47,33 +43,33 @@ public static Action newInstance() {
}

/**
* Create a new Action instance containing a single default attribute with the given value
* Creates a new Subject instance containing a single default attribute with the given String value.
*
* @param actionIdValue
* @param id
* @return
*/
public static Action newInstance(String actionIdValue) {
Action a = new Action();
a.actionIdValue = actionIdValue;
a.addAttribute(ACTION_ID_KEY, actionIdValue);
return a;
public static Action newInstance(String id) {
return newInstance().withId(id);
}

/**
* Get the value for default attribute.
* Sets the Id of the action
*
* @param id
* @return
*/
public String getActionIdValue() {
return actionIdValue;
public Action withId(String id) {
this.id = id;
addAttribute(XACML3.ID_ACTION_ACTION_ID.stringValue(), id);
return this;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("action-id value: " + actionIdValue);
builder.append("\n");
builder.append(super.toString());
return builder.toString();
/**
* Returns the value of the id
*
* @return
*/
public String getId() {
return id;
}

}
15 changes: 0 additions & 15 deletions openaz-pep/src/main/java/org/apache/openaz/pepapi/PepConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ public interface PepConfig {
*/
String getIssuer();

/**
* @return
*/
String getDefaultSubjectId();

/**
* @return
*/
String getDefaultResourceId();

/**
* @return
*/
String getDefaultActionId();

/**
* @return
*/
Expand Down
98 changes: 37 additions & 61 deletions openaz-pep/src/main/java/org/apache/openaz/pepapi/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@

package org.apache.openaz.pepapi;

import java.net.URI;
import java.util.Date;

import org.apache.openaz.xacml.api.XACML3;

import java.net.URI;

/**
* Container class that maps attributes to predefined XACML Resource category.
*/
public final class Resource extends CategoryContainer {

public static final String RESOURCE_ID_KEY = "RESOURCE_ID_KEY";

private Object resourceIdValue;
private Object id; // only java.lang.String or java.net.URI
private URI location;

private Resource() {
super(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
Expand All @@ -50,97 +48,75 @@ public static Resource newInstance() {
/**
* Creates a new Resource instance containing a single default attribute with the given String value.
*
* @param resourceIdValue
* @param id
* @return
*/
public static Resource newInstance(String resourceIdValue) {
Resource r = new Resource();
r.resourceIdValue = resourceIdValue;
r.addAttribute(RESOURCE_ID_KEY, resourceIdValue);
return r;
public static Resource newInstance(String id) {
return newInstance().withId(id);
}

/**
* Creates a new Resource instance containing a single default attribute with the given URI value.
*
* @param resourceIdValue
* @param id
* @return
*/
public static Resource newInstance(URI resourceIdValue) {
Resource r = new Resource();
r.resourceIdValue = resourceIdValue;
r.addAttribute(RESOURCE_ID_KEY, resourceIdValue);
return r;
public static Resource newInstance(URI id) {
return newInstance().withId(id);
}

/**
* Creates a new Resource instance containing a single default attribute with the given Long value.
* Sets resource id value
*
* @param resourceIdValue
* @return
* @param id
* @return this
*/
public static Resource newInstance(Long resourceIdValue) {
Resource r = new Resource();
r.resourceIdValue = resourceIdValue;
r.addAttribute(RESOURCE_ID_KEY, resourceIdValue);
return r;
public Resource withId(URI id) {
this.id = id;
addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
return this;
}

/**
* Creates a new Resource instance containing a single default attribute with the given Double value.
* Sets resource id value
*
* @param resourceIdValue
* @return
* @param id
* @return this
*/
public static Resource newInstance(Double resourceIdValue) {
Resource r = new Resource();
r.resourceIdValue = resourceIdValue;
r.addAttribute(RESOURCE_ID_KEY, resourceIdValue);
return r;
public Resource withId(String id) {
this.id = id;
addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
return this;
}

/**
* Creates a new Resource instance containing a single default attribute with the given Boolean value.
* Sets resource location
*
* @param resourceIdValue
* @return
* @param location
* @return this
*/
public static Resource newInstance(Boolean resourceIdValue) {
Resource r = new Resource();
r.resourceIdValue = resourceIdValue;
r.addAttribute(RESOURCE_ID_KEY, resourceIdValue);
return r;
public Resource withLocation(URI location) {
this.location = location;
addAttribute(XACML3.ID_RESOURCE_RESOURCE_LOCATION.stringValue(), location);
return this;
}

/**
* Creates a new Resource instance containing a single default attribute with the given
* <code>java.util.Date</code> value.
* Returns the value of the id attribute
*
* @param resourceIdValue
* @return
*/
public static Resource newInstance(Date resourceIdValue) {
Resource r = new Resource();
r.resourceIdValue = resourceIdValue;
r.addAttribute(RESOURCE_ID_KEY, resourceIdValue);
return r;
public Object getId() {
return this.id;
}

/**
* Returns the value of the default resourceIdValue attribute
* Returns the value of the location attribute
*
* @return
*/
public Object getResourceIdValue() {
return resourceIdValue;
public URI getLocation() {
return location;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("resource-id value : " + resourceIdValue);
builder.append("\n");
builder.append(super.toString());
return builder.toString();
}
}
37 changes: 18 additions & 19 deletions openaz-pep/src/main/java/org/apache/openaz/pepapi/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
*/
public class Subject extends CategoryContainer {

public static final String SUBJECT_ID_KEY = "SUBJECT_ID_KEY";

private String subjectIdValue;
private String id;

private Subject() {
super(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT);
Expand All @@ -47,31 +45,32 @@ public static Subject newInstance() {
/**
* Creates a new Subject instance containing a single default attribute with the given String value.
*
* @param subjectIdValue
* @param id
* @return
*/
public static Subject newInstance(String subjectIdValue) {
Subject s = new Subject();
s.subjectIdValue = subjectIdValue;
s.addAttribute(SUBJECT_ID_KEY, subjectIdValue);
return s;
public static Subject newInstance(String id) {
return newInstance().withId(id);
}

/**
* Returns the value of the default subjectIdValue attribute
* Sets the Id of the subject
*
* @param id
* @return
*/
public String getSubjectIdValue() {
return subjectIdValue;
public Subject withId(String id) {
this.id = id;
addAttribute(XACML3.ID_SUBJECT_SUBJECT_ID.stringValue(), id);
return this;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("subject-id value : " + subjectIdValue);
builder.append("\n");
builder.append(super.toString());
return builder.toString();
/**
* Returns the value of the id
*
* @return
*/
public String getId() {
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,9 @@

import org.apache.openaz.pepapi.Action;

/**
* Created by ajith on 12/11/14.
*/
public class ActionMapper extends CategoryContainerMapper {

public ActionMapper() {
super(Action.class);
}

@Override
protected String resolveAttributeId(String attributeId) {
if (attributeId.equals(Action.ACTION_ID_KEY)) {
return getPepConfig().getDefaultActionId();
}
return attributeId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,9 @@

import org.apache.openaz.pepapi.Resource;

/**
* Created by ajith on 12/11/14.
*/
public class ResourceMapper extends CategoryContainerMapper {

public ResourceMapper() {
super(Resource.class);
}

@Override
protected String resolveAttributeId(String attributeId) {
if (attributeId.equals(Resource.RESOURCE_ID_KEY)) {
return getPepConfig().getDefaultResourceId();
}
return attributeId;
}
}
Loading