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

Commit 43082dc

Browse files
author
Dirk Koehler
committed
Introduce APIs to set attribute identifiers
This mainly addresses a concern raised where someone may want to set an attribute id (e.g. key of subject-id) which deviates from what XACML defines in its specification.
1 parent b888080 commit 43082dc

File tree

7 files changed

+136
-64
lines changed

7 files changed

+136
-64
lines changed

openaz-pep/src/main/java/org/apache/openaz/pepapi/Action.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020

2121
package org.apache.openaz.pepapi;
2222

23+
import org.apache.openaz.xacml.api.Identifier;
2324
import org.apache.openaz.xacml.api.XACML3;
2425

2526
/**
2627
* Container class that maps attributes to predefined XACML Action category.
2728
*/
2829
public class Action extends CategoryContainer {
2930

30-
private String id;
31+
public static final Identifier DEFAULT_IDENTIFIER_ID = XACML3.ID_ACTION_ACTION_ID;
32+
private String idValue;
3133

3234
private Action() {
3335
super(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION);
@@ -42,35 +44,48 @@ public static Action newInstance() {
4244
return new Action();
4345
}
4446

47+
/**
48+
* Creates a new Subject instance containing a single default attribute with the given String value.
49+
*
50+
* @param idValue
51+
* @return
52+
*/
53+
public static Action newInstance(String idValue) {
54+
return newInstance().withId(idValue);
55+
}
4556

4657
/**
47-
* Creates a new Action instance with id
58+
* Sets the Id of the action
4859
*
49-
* @param id
60+
* @param idValue
5061
* @return
5162
*/
52-
public static Action newInstance(String id) {
53-
Action a = newInstance().withId(id);
54-
a.addAttribute(XACML3.ID_ACTION_ACTION_ID.stringValue(), id);
55-
return a;
63+
public Action withId(String idValue) {
64+
this.idValue = idValue;
65+
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
66+
return this;
5667
}
5768

5869
/**
70+
* Sets the id of the action and allows to set/override the default attribute key
5971
*
60-
* @param id
72+
* @param idKey
73+
* @param idValue
6174
* @return
6275
*/
63-
public Action withId(String id) {
64-
this.id = id;
76+
public Action withId(Identifier idKey, String idValue) {
77+
this.idValue = idValue;
78+
addAttribute(idKey.stringValue(), idValue);
6579
return this;
6680
}
6781

6882
/**
83+
* Returns the value of the id
6984
*
7085
* @return
7186
*/
7287
public String getId() {
73-
return id;
88+
return idValue;
7489
}
7590

7691
}

openaz-pep/src/main/java/org/apache/openaz/pepapi/Resource.java

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package org.apache.openaz.pepapi;
2222

23+
import org.apache.openaz.xacml.api.Identifier;
2324
import org.apache.openaz.xacml.api.XACML3;
2425

2526
import java.net.URI;
@@ -29,9 +30,11 @@
2930
*/
3031
public final class Resource extends CategoryContainer {
3132

32-
// only java.lang.String or java.net.URI
33-
private Object id;
34-
private URI location;
33+
public static final Identifier DEFAULT_IDENTIFIER_ID = XACML3.ID_RESOURCE_RESOURCE_ID;
34+
public static final Identifier DEFAULT_IDENTIFIER_LOCATION = XACML3.ID_RESOURCE_RESOURCE_LOCATION;
35+
36+
private Object idValue; // only java.lang.String or java.net.URI
37+
private URI locationValue;
3538

3639
private Resource() {
3740
super(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
@@ -49,64 +52,105 @@ public static Resource newInstance() {
4952
/**
5053
* Creates a new Resource instance containing a single default attribute with the given String value.
5154
*
52-
* @param id
55+
* @param idValue
5356
* @return
5457
*/
55-
public static Resource newInstance(String id) {
56-
Resource r = newInstance().withId(id);
57-
r.addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
58-
return r;
58+
public static Resource newInstance(String idValue) {
59+
return newInstance().withId(idValue);
5960
}
6061

6162
/**
6263
* Creates a new Resource instance containing a single default attribute with the given URI value.
6364
*
64-
* @param id
65+
* @param idValue
6566
* @return
6667
*/
67-
public static Resource newInstance(URI id) {
68-
Resource r = newInstance().withId(id);
69-
r.addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
70-
return r;
68+
public static Resource newInstance(URI idValue) {
69+
return newInstance().withId(idValue);
70+
}
71+
72+
/**
73+
* Sets resource id value
74+
*
75+
* @param idValue
76+
* @return this
77+
*/
78+
public Resource withId(URI idValue) {
79+
this.idValue = idValue;
80+
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
81+
return this;
82+
}
83+
84+
/**
85+
* Sets resource id value
86+
*
87+
* @param id
88+
* @param idValue
89+
* @return this
90+
*/
91+
public Resource withId(Identifier id, URI idValue) {
92+
this.idValue = idValue;
93+
addAttribute(id.stringValue(), idValue);
94+
return this;
7195
}
7296

7397
/**
7498
* Sets resource id value
7599
*
100+
* @param idValue
76101
* @return this
77102
*/
78-
public Resource withId(URI id) {
79-
this.id = id;
103+
public Resource withId(String idValue) {
104+
this.idValue = idValue;
105+
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
80106
return this;
81107
}
82108

83109
/**
84110
* Sets resource id value
85111
*
112+
* @param id
113+
* @param idValue
86114
* @return this
87115
*/
88-
public Resource withId(String id) {
89-
this.id = id;
116+
public Resource withId(Identifier id, String idValue) {
117+
this.idValue = idValue;
118+
addAttribute(id.stringValue(), idValue);
90119
return this;
91120
}
92121

93122
/**
94123
* Sets resource location
95124
*
125+
* @param locationValue
126+
* @return this
127+
*/
128+
public Resource withLocation(URI locationValue) {
129+
this.locationValue = locationValue;
130+
addAttribute(DEFAULT_IDENTIFIER_LOCATION.stringValue(), locationValue);
131+
return this;
132+
}
133+
134+
/**
135+
* Sets resource location
136+
*
137+
* @param id
138+
* @param locationValue
96139
* @return this
97140
*/
98-
public Resource withLocation(URI location) {
99-
addAttribute(XACML3.ID_RESOURCE_RESOURCE_LOCATION.stringValue(), location);
141+
public Resource withLocation(Identifier id, URI locationValue) {
142+
this.locationValue = locationValue;
143+
addAttribute(id.stringValue(), locationValue);
100144
return this;
101145
}
102146

103147
/**
104-
* Returns the value of the default id attribute
148+
* Returns the value of the id attribute
105149
*
106150
* @return
107151
*/
108152
public Object getId() {
109-
return this.id;
153+
return this.idValue;
110154
}
111155

112156
/**
@@ -115,7 +159,7 @@ public Object getId() {
115159
* @return
116160
*/
117161
public URI getLocation() {
118-
return location;
162+
return locationValue;
119163
}
120164

121165
}

openaz-pep/src/main/java/org/apache/openaz/pepapi/Subject.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020

2121
package org.apache.openaz.pepapi;
2222

23+
import org.apache.openaz.xacml.api.Identifier;
2324
import org.apache.openaz.xacml.api.XACML3;
2425

2526
/**
2627
* Container class that maps attributes to predefined XACML AccessSubject category.
2728
*/
2829
public class Subject extends CategoryContainer {
2930

30-
private String id;
31+
public static final Identifier DEFAULT_IDENTIFIER_ID = XACML3.ID_SUBJECT_SUBJECT_ID;
32+
private String idValue;
3133

3234
private Subject() {
3335
super(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT);
@@ -45,33 +47,45 @@ public static Subject newInstance() {
4547
/**
4648
* Creates a new Subject instance containing a single default attribute with the given String value.
4749
*
48-
* @param id
50+
* @param idValue
4951
* @return
5052
*/
51-
public static Subject newInstance(String id) {
52-
Subject s = newInstance().withId(id);
53-
s.addAttribute(XACML3.ID_SUBJECT_SUBJECT_ID.stringValue(), id);
54-
return s;
53+
public static Subject newInstance(String idValue) {
54+
return newInstance().withId(idValue);
5555
}
5656

57+
/**
58+
* Sets the Id of the subject
59+
*
60+
* @param idValue
61+
* @return
62+
*/
63+
public Subject withId(String idValue) {
64+
this.idValue = idValue;
65+
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
66+
return this;
67+
}
5768

5869
/**
59-
* Sets resource id value
70+
* Sets the id of the subject and allows to set/override the default attribute key
6071
*
61-
* @return this
72+
* @param idKey
73+
* @param idValue
74+
* @return
6275
*/
63-
public Subject withId(String id) {
64-
this.id = id;
76+
public Subject withId(Identifier idKey, String idValue) {
77+
this.idValue = idValue;
78+
addAttribute(idKey.stringValue(), idValue);
6579
return this;
6680
}
6781

6882
/**
69-
* Returns the value of the default subjectIdValue attribute
83+
* Returns the value of the id
7084
*
7185
* @return
7286
*/
7387
public String getId() {
74-
return id;
88+
return idValue;
7589
}
7690

7791
}

openaz-pep/src/main/java/org/apache/openaz/pepapi/std/ActionMapper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.openaz.pepapi.Action;
2424
import org.apache.openaz.pepapi.PepRequest;
2525
import org.apache.openaz.pepapi.PepRequestAttributes;
26-
import org.apache.openaz.xacml.api.XACML3;
2726

2827
public class ActionMapper extends CategoryContainerMapper {
2928

@@ -33,14 +32,14 @@ public ActionMapper() {
3332

3433
@Override
3534
public void map(Object o, PepRequest pepRequest) {
36-
Action a = (Action) o;
37-
String id = a.getId();
35+
Action action = (Action) o;
36+
String id = action.getId();
3837
if (id == null) {
3938
id = getPepConfig().getDefaultActionId();
4039
if (id != null) {
4140
PepRequestAttributes resourceAttributes = pepRequest
42-
.getPepRequestAttributes(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION);
43-
resourceAttributes.addAttribute(XACML3.ID_ACTION_ACTION_ID.stringValue(), (String) id);
41+
.getPepRequestAttributes(action.getCategoryIdentifier());
42+
resourceAttributes.addAttribute(Action.DEFAULT_IDENTIFIER_ID.stringValue(), (String) id);
4443
}
4544
}
4645
super.map(o, pepRequest);

openaz-pep/src/main/java/org/apache/openaz/pepapi/std/ResourceMapper.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.openaz.pepapi.PepRequest;
2424
import org.apache.openaz.pepapi.PepRequestAttributes;
2525
import org.apache.openaz.pepapi.Resource;
26-
import org.apache.openaz.xacml.api.XACML3;
2726

2827
import java.net.URI;
2928

@@ -35,21 +34,21 @@ public ResourceMapper() {
3534

3635
@Override
3736
public void map(Object o, PepRequest pepRequest) {
38-
Resource r = (Resource) o;
39-
Object id = r.getId();
37+
Resource resource = (Resource) o;
38+
Object id = resource.getId();
4039
if (id == null) {
4140
id = getPepConfig().getDefaultResourceId();
4241

4342
if (id != null) {
4443
PepRequestAttributes resourceAttributes = pepRequest
45-
.getPepRequestAttributes(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
44+
.getPepRequestAttributes(resource.getCategoryIdentifier());
4645
if (id instanceof String)
47-
resourceAttributes.addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), (String) id);
46+
resourceAttributes.addAttribute(Resource.DEFAULT_IDENTIFIER_ID.stringValue(), (String) id);
4847
else if (id instanceof URI)
49-
resourceAttributes.addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), (URI) id);
48+
resourceAttributes.addAttribute(Resource.DEFAULT_IDENTIFIER_ID.stringValue(), (URI) id);
5049
else
5150
throw new IllegalStateException("resource id is not an instance of String nor java.net.URI but " +
52-
r.getClass().getName());
51+
resource.getClass().getName());
5352
}
5453
}
5554
super.map(o, pepRequest);

openaz-pep/src/main/java/org/apache/openaz/pepapi/std/SubjectMapper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.openaz.pepapi.PepRequest;
2424
import org.apache.openaz.pepapi.PepRequestAttributes;
2525
import org.apache.openaz.pepapi.Subject;
26-
import org.apache.openaz.xacml.api.XACML3;
2726

2827
public class SubjectMapper extends CategoryContainerMapper {
2928

@@ -33,14 +32,14 @@ public SubjectMapper() {
3332

3433
@Override
3534
public void map(Object o, PepRequest pepRequest) {
36-
Subject s = (Subject) o;
37-
String id = s.getId();
35+
Subject subject = (Subject) o;
36+
String id = subject.getId();
3837
if (id == null) {
3938
id = getPepConfig().getDefaultSubjectId();
4039
if (id != null) {
4140
PepRequestAttributes resourceAttributes = pepRequest
42-
.getPepRequestAttributes(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT);
43-
resourceAttributes.addAttribute(XACML3.ID_SUBJECT_SUBJECT_ID.stringValue(), (String) id);
41+
.getPepRequestAttributes(subject.getCategoryIdentifier());
42+
resourceAttributes.addAttribute(Subject.DEFAULT_IDENTIFIER_ID.stringValue(), (String) id);
4443
}
4544
}
4645
super.map(o, pepRequest);

0 commit comments

Comments
 (0)