1 package com.randomnoun.common.security;
2
3 /* (c) 2013 randomnoun. All Rights Reserved. This work is licensed under a
4 * BSD Simplified License. (http://www.randomnoun.com/bsd-simplified.html)
5 */
6
7 import java.io.*;
8 import java.util.*;
9
10 /**
11 * A criteria than can be used to evaluate fine-grained resources. (e.g.
12 * an 'account' resource where account.balance > 1000). This class should be
13 * subclassed by security implementations that wish to perform access control
14 * over fine-grained resources.
15 *
16 * <p>It is the responsibility of this class to translate its criteriaString into
17 * a form that can return a true or false value when supplied a
18 * criteria context (in this case, an instance of the account).
19 * This class provides a default implementation of the
20 * {@link #evaluate(Map)} method, which currently always returns true.
21 *
22 * @author knoxg
23 */
24 public abstract class ResourceCriteria
25 implements Serializable
26 {
27
28 /** generated serialVersionUID */
29 private static final long serialVersionUID = 7387179933750418124L;
30
31 /** The string used to construct this ResourceCriteria object */
32 private String criteriaString;
33
34 /** Create a ResourceCriteria object */
35 public ResourceCriteria(String criteriaString)
36 {
37 this.criteriaString = criteriaString;
38 }
39
40 /** Returns the string used to construct this ResourceCriteria object.
41 *
42 * @return the string used to construct this ResourceCriteria object.
43 */
44 public String getCriteriaString()
45 {
46 return criteriaString;
47 }
48
49 /** Returns a string representing this ResourceCriteria object.
50 * This method Should be overridden by subclasses.
51 *
52 * @return a string representing this ResourceCriteria object
53 */
54 public String toString()
55 {
56 return criteriaString;
57 }
58
59 /**
60 * Returns true if this resourceCriteria identifies a resource with the
61 * supplied criteriaContext. The context used is resource-specific, but
62 * is always expressed as a name/value Map. e.g. for a message resource,
63 * the context may include a the headers of that message, and the values
64 * for those headers. For a system property resource, the context may
65 * just be the name of that system property.
66 *
67 * @param criteriaContext The context used to identify the resource
68 * @return true if this ResourceCriteria matches the supplied context,
69 * false if it does not.
70 */
71 public boolean evaluate(Map<String, Object> criteriaContext)
72 {
73 return true;
74
75 }
76 }