View Javadoc

1   package no.feide.mellon.jaas.principals;
2   
3   import java.security.Principal;
4   
5   /***
6    * This is the general Principal class.
7    * 
8    * @author Rikke Amilde Løvlid
9    */
10  
11  public class MoriaPrincipal implements Principal{
12  
13  	protected String attributeName;
14  	protected String attributeValue;
15  	
16  	
17  	/***
18  	 * @param name	the principal name that are used in the policy file,
19  	 * 				has to have the format attributeName:attributeValue,
20  	 * 				ex: eduPersonAffiliation:student
21  	 */
22  	public MoriaPrincipal(String name){
23  		if(name == null){
24  			throw new NullPointerException("illegal null input");
25  		}
26  		if(name.indexOf(":")!=-1){	
27  			this.attributeName = name.substring(0, name.indexOf(":"));
28  			this.attributeValue = name.substring(name.indexOf(":")+1);
29  		}
30  	}
31  	/***
32  	 * @param attributeName		the FEIDE attribute name
33  	 * @param attributeValue	the FEIDE attribute value
34  	 */
35  	public MoriaPrincipal(String attributeName, String attributeValue){
36  		if(attributeName == null || attributeValue == null){
37  			throw new NullPointerException("illegal null input");
38  		}
39  		this.attributeName = attributeName;
40  		this.attributeValue = attributeValue;
41  	}
42  	
43  	/***
44  	 * @return attributeName:attributeValue
45  	 */
46  	public String getName(){
47  		return attributeName + ":" + attributeValue;
48  	}
49  	
50  	public String getAttributeName(){
51  		return attributeName;
52  	}
53  	
54  	public String getAttributeValue(){
55  		return attributeValue;
56  	}
57  	
58  	/***
59  	 * @return MoriaPrincipal: attributeName:attributeValue
60  	 */
61  	public String toString(){
62  		return ("MoriaPrincipal: " + this.getName());
63  	}
64  	
65  	/***
66  	 * @param o			the object we want to compare to <code>this</code>
67  	 * @return true		if <code>this</code> is the same object as <code>o</code> or
68  	 * 					<code>this</code> and <code>o</code> have the same
69  	 * 					<code>attributeName</code> and </code>attributeValue</code>.
70  	 * @return false 	otherwise 
71  	 */
72  	public boolean equals(Object o){
73  		if(o == null){
74  			return false;
75  		}
76  		if(this == o){
77  			return true;
78  		}
79  		if(!(o instanceof MoriaPrincipal)){
80  			return false;
81  		}
82  		return this.getName().equals(((MoriaPrincipal)o).getName());
83  	}
84  	
85  	public int hashCode(){
86  		return this.getName().hashCode();
87  	}
88  	
89  	
90  }