Changeset 88e139a


Ignore:
Timestamp:
Mar 14, 2011 11:24:06 PM (8 years ago)
Author:
Ted Faber <faber@…>
Branches:
abac0-leak, abac0-mei, compt_changes, gec13, master, mei-id, mei-rt0-n, mei_rt0, mei_rt2, mei_rt2_fix_1, meiyap-rt1, meiyap1, rt2, tvf-new-xml
Children:
3a52bed
Parents:
f797fca
Message:

Add some basic features, comparability.

Location:
java/net/deterlab/abac
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • java/net/deterlab/abac/Credential.java

    rf797fca r88e139a  
    2222import java.security.PrivateKey;
    2323
    24 public class Credential {
     24public class Credential implements Comparable {
    2525    protected static Vector<Identity> s_ids = new Vector<Identity>();
    2626    protected static String attrOID = "1.3.6.1.5.5.7.10.4";
     
    162162    }
    163163
     164    public int compareTo(Object o) {
     165        if (o instanceof Credential) {
     166            Credential c = (Credential) o;
     167
     168            if (head().equals(c.head())) return tail().compareTo(c.tail());
     169            else return head().compareTo(c.head());
     170        }
     171        else return 1;
     172    }
     173
     174
    164175    /**
    165176     * Get the head role from the credential.
  • java/net/deterlab/abac/CredentialGraph.java

    ra624bd1 r88e139a  
    4646
    4747        /* explicitly add the vertices, otherwise get a null pointer exception */
    48         g.addVertex(tail);
    49         g.addVertex(head);
    50 
    51         g.addEdge(cred, tail, head);
     48        if ( !g.containsVertex(tail))
     49            g.addVertex(tail);
     50        if ( !g.containsVertex(tail))
     51            g.addVertex(head);
     52
     53        if (!g.containsEdge(cred))
     54            g.addEdge(cred, tail, head);
    5255
    5356        // add the prereqs of an intersection to the graph
     
    6972
    7073    /**
     74     * Add a role w/o an edge
     75     */
     76    public void add_vertex(Role v) {
     77        if (!g.containsVertex(v)) {
     78            g.addVertex(v);
     79            m_dirty = true;
     80        }
     81    }
     82
     83    public void remove_vertex(Role v) {
     84        if (g.containsVertex(v)) {
     85            g.removeVertex(v);
     86            m_dirty = true;
     87        }
     88    }
     89
     90    /**
    7191     * Returns a collection of the credentials in the graph.
    7292     */
     
    80100
    81101        return creds;
     102    }
     103
     104    public Collection<Role> roles() {
     105        return g.getVertices();
    82106    }
    83107
  • java/net/deterlab/abac/Role.java

    re1c49ce r88e139a  
    88 * Represents a role, which is a vertex in a Credential graph.
    99 */
    10 public class Role {
     10public class Role implements Comparable {
    1111    private String m_string;
    1212    private String[] m_parts;
     
    167167    }
    168168
     169    public int compareTo(Object o) {
     170        if (o instanceof Role)
     171            return m_string.compareTo(((Role)o).m_string);
     172        else return 1;
     173    }
     174
    169175    public int hashCode() {
    170176        return m_string.hashCode();
Note: See TracChangeset for help on using the changeset viewer.