1 | package com.nailabs.abac.process; |
---|
2 | |
---|
3 | import java.util.*; |
---|
4 | import edu.stanford.peer.rbtm.credential.*; |
---|
5 | |
---|
6 | /** |
---|
7 | * Access control policy for credentials. The policy can be queried using the |
---|
8 | * <code>requires</code> method with a specific credential. |
---|
9 | */ |
---|
10 | public class ACPolicy implements java.io.Serializable { |
---|
11 | /** Implicitly allow access if there is no relevant policy */ |
---|
12 | public static final Role TRUE = null; |
---|
13 | |
---|
14 | /** Internal hash table for policy storage */ |
---|
15 | private HashMap accessControl = null; |
---|
16 | |
---|
17 | /** Default constructor with a non-resstrictive policy */ |
---|
18 | public ACPolicy() { |
---|
19 | accessControl = new HashMap(); |
---|
20 | } |
---|
21 | |
---|
22 | /** Accessor for all the access control policy keys */ |
---|
23 | public Vector getProtectedCredentials() { |
---|
24 | return new Vector(accessControl.keySet()); |
---|
25 | } |
---|
26 | |
---|
27 | /** |
---|
28 | * Useful for forward discovery. |
---|
29 | * @return a set of all roles which satisfy the AC policy requirements |
---|
30 | */ |
---|
31 | public Vector getRequiredRoles() { |
---|
32 | return new Vector(accessControl.values()); |
---|
33 | } |
---|
34 | |
---|
35 | /** Adds a single policy atom from String parameters. */ |
---|
36 | public void addACFact(String cred, String expr) |
---|
37 | throws CredentialParsingException { |
---|
38 | addACFact(new StaticCredential(cred), |
---|
39 | StaticCredential.getEntityExpression(expr)); |
---|
40 | } |
---|
41 | |
---|
42 | /** Adds a single policy atom. */ |
---|
43 | public void addACFact(Credential key, EntityExpression expr) { |
---|
44 | accessControl.put(key, expr); |
---|
45 | } |
---|
46 | |
---|
47 | /** Query the policy to determine the required role for a credential */ |
---|
48 | public EntityExpression requires(Credential resource) { |
---|
49 | return (EntityExpression)accessControl.get(resource); |
---|
50 | } |
---|
51 | |
---|
52 | /** Returns the underlying storage data structure in a printable format */ |
---|
53 | public String toString() { |
---|
54 | if(accessControl == null) |
---|
55 | return null; |
---|
56 | else |
---|
57 | return accessControl.toString(); |
---|
58 | } |
---|
59 | |
---|
60 | } |
---|