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

Commit

Permalink
Removed support to for setting default ids
Browse files Browse the repository at this point in the history
This commit removes the rather 'confusing' feature of being able to override
the default key for subject, resource and action ids defined by XACML
spec.

Users who relied on feature can easily switch to use #addAttribute to achieve
the same.
  • Loading branch information
Dirk Koehler committed Jun 21, 2016
1 parent 43082dc commit 4a47357
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 390 deletions.
36 changes: 10 additions & 26 deletions openaz-pep/src/main/java/org/apache/openaz/pepapi/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@

package org.apache.openaz.pepapi;

import org.apache.openaz.xacml.api.Identifier;
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 Identifier DEFAULT_IDENTIFIER_ID = XACML3.ID_ACTION_ACTION_ID;
private String idValue;
private String id;

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

/**
* Sets the Id of the action
*
* @param idValue
* @param id
* @return
*/
public Action withId(String idValue) {
this.idValue = idValue;
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
public Action withId(String id) {
this.id = id;
addAttribute(XACML3.ID_ACTION_ACTION_ID.stringValue(), id);
return this;
}

/**
* Sets the id of the action and allows to set/override the default attribute key
*
* @param idKey
* @param idValue
* @return
*/
public Action withId(Identifier idKey, String idValue) {
this.idValue = idValue;
addAttribute(idKey.stringValue(), idValue);
return this;
}

/**
/**
* Returns the value of the id
*
* @return
*/
public String getId() {
return idValue;
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
83 changes: 20 additions & 63 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,7 +20,6 @@

package org.apache.openaz.pepapi;

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

import java.net.URI;
Expand All @@ -30,11 +29,8 @@
*/
public final class Resource extends CategoryContainer {

public static final Identifier DEFAULT_IDENTIFIER_ID = XACML3.ID_RESOURCE_RESOURCE_ID;
public static final Identifier DEFAULT_IDENTIFIER_LOCATION = XACML3.ID_RESOURCE_RESOURCE_LOCATION;

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

private Resource() {
super(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
Expand All @@ -52,95 +48,56 @@ public static Resource newInstance() {
/**
* Creates a new Resource instance containing a single default attribute with the given String value.
*
* @param idValue
* @param id
* @return
*/
public static Resource newInstance(String idValue) {
return newInstance().withId(idValue);
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 idValue
* @param id
* @return
*/
public static Resource newInstance(URI idValue) {
return newInstance().withId(idValue);
}

/**
* Sets resource id value
*
* @param idValue
* @return this
*/
public Resource withId(URI idValue) {
this.idValue = idValue;
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
return this;
public static Resource newInstance(URI id) {
return newInstance().withId(id);
}

/**
* Sets resource id value
*
* @param id
* @param idValue
* @return this
*/
public Resource withId(Identifier id, URI idValue) {
this.idValue = idValue;
addAttribute(id.stringValue(), idValue);
return this;
}

/**
* Sets resource id value
*
* @param idValue
* @return this
*/
public Resource withId(String idValue) {
this.idValue = idValue;
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
public Resource withId(URI id) {
this.id = id;
addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
return this;
}

/**
* Sets resource id value
*
* @param id
* @param idValue
* @return this
*/
public Resource withId(Identifier id, String idValue) {
this.idValue = idValue;
addAttribute(id.stringValue(), idValue);
return this;
}

/**
* Sets resource location
*
* @param locationValue
* @return this
*/
public Resource withLocation(URI locationValue) {
this.locationValue = locationValue;
addAttribute(DEFAULT_IDENTIFIER_LOCATION.stringValue(), locationValue);
public Resource withId(String id) {
this.id = id;
addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
return this;
}

/**
* Sets resource location
*
* @param id
* @param locationValue
* @param location
* @return this
*/
public Resource withLocation(Identifier id, URI locationValue) {
this.locationValue = locationValue;
addAttribute(id.stringValue(), locationValue);
public Resource withLocation(URI location) {
this.location = location;
addAttribute(XACML3.ID_RESOURCE_RESOURCE_LOCATION.stringValue(), location);
return this;
}

Expand All @@ -150,7 +107,7 @@ public Resource withLocation(Identifier id, URI locationValue) {
* @return
*/
public Object getId() {
return this.idValue;
return this.id;
}

/**
Expand All @@ -159,7 +116,7 @@ public Object getId() {
* @return
*/
public URI getLocation() {
return locationValue;
return location;
}

}
33 changes: 9 additions & 24 deletions openaz-pep/src/main/java/org/apache/openaz/pepapi/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@

package org.apache.openaz.pepapi;

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

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

public static final Identifier DEFAULT_IDENTIFIER_ID = XACML3.ID_SUBJECT_SUBJECT_ID;
private String idValue;
private String id;

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

/**
* Sets the Id of the subject
*
* @param idValue
* @param id
* @return
*/
public Subject withId(String idValue) {
this.idValue = idValue;
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
return this;
}

/**
* Sets the id of the subject and allows to set/override the default attribute key
*
* @param idKey
* @param idValue
* @return
*/
public Subject withId(Identifier idKey, String idValue) {
this.idValue = idValue;
addAttribute(idKey.stringValue(), idValue);
public Subject withId(String id) {
this.id = id;
addAttribute(XACML3.ID_SUBJECT_SUBJECT_ID.stringValue(), id);
return this;
}

Expand All @@ -85,7 +70,7 @@ public Subject withId(Identifier idKey, String idValue) {
* @return
*/
public String getId() {
return idValue;
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,10 @@
package org.apache.openaz.pepapi.std;

import org.apache.openaz.pepapi.Action;
import org.apache.openaz.pepapi.PepRequest;
import org.apache.openaz.pepapi.PepRequestAttributes;

public class ActionMapper extends CategoryContainerMapper {

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

@Override
public void map(Object o, PepRequest pepRequest) {
Action action = (Action) o;
String id = action.getId();
if (id == null) {
id = getPepConfig().getDefaultActionId();
if (id != null) {
PepRequestAttributes resourceAttributes = pepRequest
.getPepRequestAttributes(action.getCategoryIdentifier());
resourceAttributes.addAttribute(Action.DEFAULT_IDENTIFIER_ID.stringValue(), (String) id);
}
}
super.map(o, pepRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,11 @@

package org.apache.openaz.pepapi.std;

import org.apache.openaz.pepapi.PepRequest;
import org.apache.openaz.pepapi.PepRequestAttributes;
import org.apache.openaz.pepapi.Resource;

import java.net.URI;

public class ResourceMapper extends CategoryContainerMapper {

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

@Override
public void map(Object o, PepRequest pepRequest) {
Resource resource = (Resource) o;
Object id = resource.getId();
if (id == null) {
id = getPepConfig().getDefaultResourceId();

if (id != null) {
PepRequestAttributes resourceAttributes = pepRequest
.getPepRequestAttributes(resource.getCategoryIdentifier());
if (id instanceof String)
resourceAttributes.addAttribute(Resource.DEFAULT_IDENTIFIER_ID.stringValue(), (String) id);
else if (id instanceof URI)
resourceAttributes.addAttribute(Resource.DEFAULT_IDENTIFIER_ID.stringValue(), (URI) id);
else
throw new IllegalStateException("resource id is not an instance of String nor java.net.URI but " +
resource.getClass().getName());
}
}
super.map(o, pepRequest);
}
}
Loading

0 comments on commit 4a47357

Please sign in to comment.