package com.nailabs.abac.process; import java.util.*; import edu.stanford.peer.rbtm.credential.*; //import edu.stanford.peer.rbtm.engine.StaticCredential; /** * Resource policy for negotiations. The policy can be queried using the * requires method with a specific credential resource * identifier, which can be a URl or a mnemonic identifier. */ public class ResourcePolicy implements java.io.Serializable { /** Internal hash table for policy storage */ private HashMap resourcePolicy = null; /** Default constructor with a non-resstrictive policy */ public ResourcePolicy() { resourcePolicy = new HashMap(); } /** Accessor for all the access control policy keys */ public Vector getResourceIdentifiers() { return new Vector(resourcePolicy.keySet()); } /** * Useful for forward discovery. * @return a set of all roles which satisfy the AC policy requirements */ public Vector getRequiredRoles() { return new Vector(resourcePolicy.values()); } /** Adds a single policy atom from String parameters. */ public void addResourceFact(String resourceID, String role) throws CredentialParsingException { try { addResourceFact(resourceID, (Role)StaticCredential.getRole(role)); } catch(Exception ex) { ex.printStackTrace(); } } /** Adds a single policy atom. */ public void addResourceFact(String key, Role role) { resourcePolicy.put(key, role); } /** Query the policy to determine the required role for a credential */ public Role requires(String resource) { return (Role)resourcePolicy.get(resource); } /** Returns the underlying storage data structure in a printable format */ public String toString() { if(resourcePolicy == null) return null; else return resourcePolicy.toString(); } }