source: fedd/abac-src/ttg/credential/RtmlEntity.java @ 70caa72

axis_examplecompt_changesinfo-opsversion-2.00version-3.01version-3.02
Last change on this file since 70caa72 was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package com.nailabs.abac.credential;
2
3import edu.stanford.peer.rbtm.credential.*;
4import edu.stanford.rt.credential.Principal;
5
6/**
7 * A hybrid entity instance which is RTML aware but can also emulate a simple
8 * entity used by the RBTM package.
9 */
10public class RtmlEntity implements Entity {
11    //The entity will have either a key OR a value but not both
12    /** a base-64 encoded hash of the entity's key material */
13    protected String hashCode = null;
14
15    /** a short name used in the RTML to refer back to a Principal */
16    protected String shortName = null;
17
18    /** constructor for discovery service */
19    public RtmlEntity(String shortName) {
20        this.shortName = shortName;
21    }
22
23    public RtmlEntity(String shortName, String hashCode) {
24        this.shortName = shortName;
25        this.hashCode = hashCode;
26    }
27
28    /** default constructor */
29    public RtmlEntity(String shortName, Principal principal) {
30        this.shortName = shortName;
31        hashCode = principal.toString();
32    }
33
34    /** public accessor method for the abbreviated name of an entity */
35    public String getName() { return shortName; }
36
37    /** public accessor method for the BASE-64 encoded signature hash */
38    public String getHash() { return hashCode; }
39
40    /** public accessor method for the hash code of an entity's key material */
41    public int hashCode() { 
42        if(hashCode == null) {
43            return shortName.hashCode();
44        }
45        return hashCode.hashCode(); 
46    }
47
48    /**
49     * equivalency should be based on identical hash codes (but potentially
50     * short names may be desired).
51     */
52    public boolean equals(Object o) {
53        // warning this is allows an RtmlEntity to be matched by EITHER
54        // the hash or the short name. It should probably only be the hash.
55        // The RtmlEngine may need to make sure entities have proper hash
56        // codes.
57        return(o.hashCode()==hashCode() || o.hashCode()==shortName.hashCode());
58    }
59   
60    /** compare to entities based on their unique hash codes */
61    public int compareTo(Object obj) {
62        return obj.hashCode() - hashCode();
63    }
64
65    /** returns the entity's unique hash code as a string */
66    public String toString() { return shortName; }
67
68}
Note: See TracBrowser for help on using the repository browser.