1 package org.astrogrid.security;
2
3 import java.security.Principal;
4
5 /***
6 * The name of an account in a community. This
7 * is essentially a user name but the "user" may be
8 * a groups or a software agent rather than a human
9 * individual.
10 *
11 * No constraints are placed on the name, so this
12 * class just aggregates a String. The purpose of
13 * this wrapper is to provide a class that
14 * implements java.security.Principal so that it
15 * can be used with JAAS.
16 *
17 * @author Guy Rixon
18 */
19 public class AccountName implements Principal {
20
21 /***
22 * The name.
23 */
24 private String name = "anonymous";
25
26
27 /***
28 * Constructs an AccountName with a given value.
29 */
30 public AccountName (String name) {
31 this.name = name;
32 }
33
34 /***
35 * Serializes the object as a String.
36 */
37 public String getName() {
38 return this.name;
39 }
40
41 /***
42 * Serializes the object as a String.
43 */
44 public String toString() {
45 return this.name;
46 }
47
48 /***
49 * Tests equality with another object.
50 *
51 * @return true if the other object is the same or
52 * if the other object is a Principal with the same name
53 */
54 public boolean equals (Object other) {
55 if (other instanceof Principal) {
56 return this.name.equals(((Principal)other).getName());
57 }
58 else {
59 return false;
60 }
61 }
62
63 }