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

Commit d556e3b

Browse files
author
Dirk Koehler
committed
Removed support to for setting default ids
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.
1 parent 43082dc commit d556e3b

File tree

12 files changed

+38
-388
lines changed

12 files changed

+38
-388
lines changed

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

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

2121
package org.apache.openaz.pepapi;
2222

23-
import org.apache.openaz.xacml.api.Identifier;
2423
import org.apache.openaz.xacml.api.XACML3;
2524

2625
/**
2726
* Container class that maps attributes to predefined XACML Action category.
2827
*/
2928
public class Action extends CategoryContainer {
3029

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

3432
private Action() {
3533
super(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION);
@@ -47,45 +45,31 @@ public static Action newInstance() {
4745
/**
4846
* Creates a new Subject instance containing a single default attribute with the given String value.
4947
*
50-
* @param idValue
48+
* @param id
5149
* @return
5250
*/
53-
public static Action newInstance(String idValue) {
54-
return newInstance().withId(idValue);
51+
public static Action newInstance(String id) {
52+
return newInstance().withId(id);
5553
}
5654

5755
/**
5856
* Sets the Id of the action
5957
*
60-
* @param idValue
58+
* @param id
6159
* @return
6260
*/
63-
public Action withId(String idValue) {
64-
this.idValue = idValue;
65-
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
61+
public Action withId(String id) {
62+
this.id = id;
63+
addAttribute(XACML3.ID_ACTION_ACTION_ID.stringValue(), id);
6664
return this;
6765
}
68-
69-
/**
70-
* Sets the id of the action and allows to set/override the default attribute key
71-
*
72-
* @param idKey
73-
* @param idValue
74-
* @return
75-
*/
76-
public Action withId(Identifier idKey, String idValue) {
77-
this.idValue = idValue;
78-
addAttribute(idKey.stringValue(), idValue);
79-
return this;
80-
}
81-
82-
/**
66+
/**
8367
* Returns the value of the id
8468
*
8569
* @return
8670
*/
8771
public String getId() {
88-
return idValue;
72+
return id;
8973
}
9074

9175
}

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ public interface PepConfig {
3131
*/
3232
String getIssuer();
3333

34-
/**
35-
* @return
36-
*/
37-
String getDefaultSubjectId();
38-
39-
/**
40-
* @return
41-
*/
42-
String getDefaultResourceId();
43-
44-
/**
45-
* @return
46-
*/
47-
String getDefaultActionId();
48-
4934
/**
5035
* @return
5136
*/

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

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

2121
package org.apache.openaz.pepapi;
2222

23-
import org.apache.openaz.xacml.api.Identifier;
2423
import org.apache.openaz.xacml.api.XACML3;
2524

2625
import java.net.URI;
@@ -30,11 +29,8 @@
3029
*/
3130
public final class Resource extends CategoryContainer {
3231

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;
32+
private Object id; // only java.lang.String or java.net.URI
33+
private URI location;
3834

3935
private Resource() {
4036
super(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
@@ -52,95 +48,56 @@ public static Resource newInstance() {
5248
/**
5349
* Creates a new Resource instance containing a single default attribute with the given String value.
5450
*
55-
* @param idValue
51+
* @param id
5652
* @return
5753
*/
58-
public static Resource newInstance(String idValue) {
59-
return newInstance().withId(idValue);
54+
public static Resource newInstance(String id) {
55+
return newInstance().withId(id);
6056
}
6157

6258
/**
6359
* Creates a new Resource instance containing a single default attribute with the given URI value.
6460
*
65-
* @param idValue
61+
* @param id
6662
* @return
6763
*/
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;
64+
public static Resource newInstance(URI id) {
65+
return newInstance().withId(id);
8266
}
8367

8468
/**
8569
* Sets resource id value
8670
*
8771
* @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;
95-
}
96-
97-
/**
98-
* Sets resource id value
99-
*
100-
* @param idValue
10172
* @return this
10273
*/
103-
public Resource withId(String idValue) {
104-
this.idValue = idValue;
105-
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
74+
public Resource withId(URI id) {
75+
this.id = id;
76+
addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
10677
return this;
10778
}
10879

10980
/**
11081
* Sets resource id value
11182
*
11283
* @param id
113-
* @param idValue
114-
* @return this
115-
*/
116-
public Resource withId(Identifier id, String idValue) {
117-
this.idValue = idValue;
118-
addAttribute(id.stringValue(), idValue);
119-
return this;
120-
}
121-
122-
/**
123-
* Sets resource location
124-
*
125-
* @param locationValue
12684
* @return this
12785
*/
128-
public Resource withLocation(URI locationValue) {
129-
this.locationValue = locationValue;
130-
addAttribute(DEFAULT_IDENTIFIER_LOCATION.stringValue(), locationValue);
86+
public Resource withId(String id) {
87+
this.id = id;
88+
addAttribute(XACML3.ID_RESOURCE_RESOURCE_ID.stringValue(), id);
13189
return this;
13290
}
13391

13492
/**
13593
* Sets resource location
13694
*
137-
* @param id
138-
* @param locationValue
95+
* @param location
13996
* @return this
14097
*/
141-
public Resource withLocation(Identifier id, URI locationValue) {
142-
this.locationValue = locationValue;
143-
addAttribute(id.stringValue(), locationValue);
98+
public Resource withLocation(URI location) {
99+
this.location = location;
100+
addAttribute(XACML3.ID_RESOURCE_RESOURCE_LOCATION.stringValue(), location);
144101
return this;
145102
}
146103

@@ -150,7 +107,7 @@ public Resource withLocation(Identifier id, URI locationValue) {
150107
* @return
151108
*/
152109
public Object getId() {
153-
return this.idValue;
110+
return this.id;
154111
}
155112

156113
/**
@@ -159,7 +116,7 @@ public Object getId() {
159116
* @return
160117
*/
161118
public URI getLocation() {
162-
return locationValue;
119+
return location;
163120
}
164121

165122
}

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

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

2121
package org.apache.openaz.pepapi;
2222

23-
import org.apache.openaz.xacml.api.Identifier;
2423
import org.apache.openaz.xacml.api.XACML3;
2524

2625
/**
2726
* Container class that maps attributes to predefined XACML AccessSubject category.
2827
*/
2928
public class Subject extends CategoryContainer {
3029

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

3432
private Subject() {
3533
super(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT);
@@ -47,11 +45,11 @@ public static Subject newInstance() {
4745
/**
4846
* Creates a new Subject instance containing a single default attribute with the given String value.
4947
*
50-
* @param idValue
48+
* @param id
5149
* @return
5250
*/
53-
public static Subject newInstance(String idValue) {
54-
return newInstance().withId(idValue);
51+
public static Subject newInstance(String id) {
52+
return newInstance().withId(id);
5553
}
5654

5755
/**
@@ -61,21 +59,8 @@ public static Subject newInstance(String idValue) {
6159
* @return
6260
*/
6361
public Subject withId(String idValue) {
64-
this.idValue = idValue;
65-
addAttribute(DEFAULT_IDENTIFIER_ID.stringValue(), idValue);
66-
return this;
67-
}
68-
69-
/**
70-
* Sets the id of the subject and allows to set/override the default attribute key
71-
*
72-
* @param idKey
73-
* @param idValue
74-
* @return
75-
*/
76-
public Subject withId(Identifier idKey, String idValue) {
77-
this.idValue = idValue;
78-
addAttribute(idKey.stringValue(), idValue);
62+
this.id = idValue;
63+
addAttribute(XACML3.ID_SUBJECT_SUBJECT_ID.stringValue(), idValue);
7964
return this;
8065
}
8166

@@ -85,7 +70,7 @@ public Subject withId(Identifier idKey, String idValue) {
8570
* @return
8671
*/
8772
public String getId() {
88-
return idValue;
73+
return id;
8974
}
9075

9176
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,10 @@
2121
package org.apache.openaz.pepapi.std;
2222

2323
import org.apache.openaz.pepapi.Action;
24-
import org.apache.openaz.pepapi.PepRequest;
25-
import org.apache.openaz.pepapi.PepRequestAttributes;
2624

2725
public class ActionMapper extends CategoryContainerMapper {
2826

2927
public ActionMapper() {
3028
super(Action.class);
3129
}
32-
33-
@Override
34-
public void map(Object o, PepRequest pepRequest) {
35-
Action action = (Action) o;
36-
String id = action.getId();
37-
if (id == null) {
38-
id = getPepConfig().getDefaultActionId();
39-
if (id != null) {
40-
PepRequestAttributes resourceAttributes = pepRequest
41-
.getPepRequestAttributes(action.getCategoryIdentifier());
42-
resourceAttributes.addAttribute(Action.DEFAULT_IDENTIFIER_ID.stringValue(), (String) id);
43-
}
44-
}
45-
super.map(o, pepRequest);
46-
}
4730
}

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

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

2121
package org.apache.openaz.pepapi.std;
2222

23-
import org.apache.openaz.pepapi.PepRequest;
24-
import org.apache.openaz.pepapi.PepRequestAttributes;
2523
import org.apache.openaz.pepapi.Resource;
2624

27-
import java.net.URI;
28-
2925
public class ResourceMapper extends CategoryContainerMapper {
3026

3127
public ResourceMapper() {
3228
super(Resource.class);
3329
}
34-
35-
@Override
36-
public void map(Object o, PepRequest pepRequest) {
37-
Resource resource = (Resource) o;
38-
Object id = resource.getId();
39-
if (id == null) {
40-
id = getPepConfig().getDefaultResourceId();
41-
42-
if (id != null) {
43-
PepRequestAttributes resourceAttributes = pepRequest
44-
.getPepRequestAttributes(resource.getCategoryIdentifier());
45-
if (id instanceof String)
46-
resourceAttributes.addAttribute(Resource.DEFAULT_IDENTIFIER_ID.stringValue(), (String) id);
47-
else if (id instanceof URI)
48-
resourceAttributes.addAttribute(Resource.DEFAULT_IDENTIFIER_ID.stringValue(), (URI) id);
49-
else
50-
throw new IllegalStateException("resource id is not an instance of String nor java.net.URI but " +
51-
resource.getClass().getName());
52-
}
53-
}
54-
super.map(o, pepRequest);
55-
}
5630
}

0 commit comments

Comments
 (0)