2424
2525import java .io .Serializable ;
2626import java .util .Map ;
27+ import java .util .Set ;
2728import java .util .TreeMap ;
29+ import java .util .TreeSet ;
2830import java .util .function .Predicate ;
2931import org .opensolaris .opengrok .configuration .Nameable ;
3032
5355 */
5456public abstract class AuthorizationEntity implements Nameable , Serializable , Cloneable {
5557
58+ /**
59+ * Predicate specialized for the the plugin decisions. The caller should
60+ * implement the <code>decision</code> method. Returning true if the plugin
61+ * allows the action or false when the plugin forbids the action.
62+ */
63+ public static abstract class PluginDecisionPredicate implements Predicate <IAuthorizationPlugin > {
64+
65+ @ Override
66+ public boolean test (IAuthorizationPlugin t ) {
67+ return decision (t );
68+ }
69+
70+ /**
71+ * Perform the authorization check for this plugin.
72+ *
73+ * @param t the plugin
74+ * @return true if plugin allows the action; false otherwise
75+ */
76+ public abstract boolean decision (IAuthorizationPlugin t );
77+
78+ }
79+
80+ /**
81+ * Predicate specialized for the the entity skipping decisions. The caller
82+ * should implement the <code>shouldSkip</code> method. Returning true if
83+ * the entity should be skipped for this action and false if the entity
84+ * should be used.
85+ */
86+ public static abstract class PluginSkippingPredicate implements Predicate <AuthorizationEntity > {
87+
88+ @ Override
89+ public boolean test (AuthorizationEntity t ) {
90+ return shouldSkip (t );
91+ }
92+
93+ /**
94+ * Decide if the entity should be skipped in this step of authorization.
95+ *
96+ * @param t the entity
97+ * @return true if skipped (authorization decision will not be affected
98+ * by this entity) or false if it should be used (authorization decision
99+ * will be affected by this entity)
100+ */
101+ public abstract boolean shouldSkip (AuthorizationEntity t );
102+ }
103+
56104 private static final long serialVersionUID = 1L ;
57105 /**
58106 * One of "required", "requisite", "sufficient".
@@ -61,6 +109,9 @@ public abstract class AuthorizationEntity implements Nameable, Serializable, Clo
61109 protected String name ;
62110 protected Map <String , Object > setup = new TreeMap <>();
63111
112+ private Set <String > forProjects = new TreeSet <>();
113+ private Set <String > forGroups = new TreeSet <>();
114+
64115 protected transient boolean working = true ;
65116
66117 public AuthorizationEntity () {
@@ -82,6 +133,8 @@ public AuthorizationEntity(AuthorizationEntity x) {
82133 name = x .name ;
83134 setup = new TreeMap <>(x .setup );
84135 working = x .working ;
136+ forGroups = new TreeSet <>(x .forGroups );
137+ forProjects = new TreeSet <>(x .forProjects );
85138 }
86139
87140 public AuthorizationEntity (AuthControlFlag flag , String name ) {
@@ -111,12 +164,16 @@ public AuthorizationEntity(AuthControlFlag flag, String name) {
111164 *
112165 * @param entity the given entity - this is either group or project and is
113166 * passed just for the logging purposes.
114- * @param predicate predicate returning true or false for the given entity
115- * which determines if the authorization for such entity is successful or
116- * failed
167+ * @param pluginPredicate predicate returning true or false for the given
168+ * entity which determines if the authorization for such entity is
169+ * successful or failed
170+ * @param skippingPredicate predicate returning true if this authorization
171+ * entity should be omitted from the authorization process
117172 * @return true if successful; false otherwise
118173 */
119- abstract public boolean isAllowed (Nameable entity , Predicate <IAuthorizationPlugin > predicate );
174+ abstract public boolean isAllowed (Nameable entity ,
175+ PluginDecisionPredicate pluginPredicate ,
176+ PluginSkippingPredicate skippingPredicate );
120177
121178 /**
122179 * Set the plugin to all classes which requires this class in the
@@ -201,6 +258,104 @@ public void setSetup(Map<String, Object> setup) {
201258 this .setup = setup ;
202259 }
203260
261+ /**
262+ * Get the value of forProjects
263+ *
264+ * @return the value of forProjects
265+ */
266+ public Set <String > forProjects () {
267+ return getForProjects ();
268+ }
269+
270+ /**
271+ * Get the value of forProjects
272+ *
273+ * @return the value of forProjects
274+ */
275+ public Set <String > getForProjects () {
276+ return forProjects ;
277+ }
278+
279+ /**
280+ * Set the value of forProjects
281+ *
282+ * @param forProjects new value of forProjects
283+ */
284+ public void setForProjects (Set <String > forProjects ) {
285+ this .forProjects = forProjects ;
286+ }
287+
288+ /**
289+ * Set the value of forProjects
290+ *
291+ * @param project add this project into the set
292+ */
293+ public void setForProjects (String project ) {
294+ this .forProjects .add (project );
295+ }
296+
297+ /**
298+ * Set the value of forProjects
299+ *
300+ * @param projects add all projects in this array into the set
301+ *
302+ * @see #setForProjects(java.lang.String)
303+ */
304+ public void setForProjects (String [] projects ) {
305+ for (String project : projects ) {
306+ setForProjects (project );
307+ }
308+ }
309+
310+ /**
311+ * Get the value of forGroups
312+ *
313+ * @return the value of forGroups
314+ */
315+ public Set <String > forGroups () {
316+ return getForGroups ();
317+ }
318+
319+ /**
320+ * Get the value of forGroups
321+ *
322+ * @return the value of forGroups
323+ */
324+ public Set <String > getForGroups () {
325+ return forGroups ;
326+ }
327+
328+ /**
329+ * Set the value of forGroups
330+ *
331+ * @param forGroups new value of forGroups
332+ */
333+ public void setForGroups (Set <String > forGroups ) {
334+ this .forGroups = forGroups ;
335+ }
336+
337+ /**
338+ * Set the value of forGroups
339+ *
340+ * @param group add this group into the set
341+ */
342+ public void setForGroups (String group ) {
343+ this .forGroups .add (group );
344+ }
345+
346+ /**
347+ * Set the value of forGroups
348+ *
349+ * @param groups add all groups in this array into the set
350+ *
351+ * @see #setForGroups(java.lang.String)
352+ */
353+ public void setForGroups (String [] groups ) {
354+ for (String group : groups ) {
355+ setForGroups (group );
356+ }
357+ }
358+
204359 /**
205360 * Check if the plugin exists and has not failed while loading.
206361 *
0 commit comments