1 package org.objectledge.authentication;
2
3 import java.security.Principal;
4
5 /***
6 * An implementation of {@link Principal} interface.
7 *
8 * @author <a href="mailto:rafal@apache.org">Rafal Krzewski</a>
9 * @author <a href="mailto:pablo@apache.org">Pawel Potempski</a>
10 * @version $Id: DefaultPrincipal.java,v 1.2 2004/12/23 07:16:34 rafal Exp $
11 */
12 public class DefaultPrincipal
13 implements Principal
14 {
15 /*** The name of the principal */
16 private String name;
17
18 /***
19 * Constructor.
20 *
21 * @param name the name of the principal
22 */
23 public DefaultPrincipal(String name)
24 {
25 this.name = name;
26 }
27
28 /***
29 * {@inheritDoc}
30 */
31 public boolean equals(Object obj)
32 {
33 if(obj instanceof Principal)
34 {
35 return name.equals(((Principal)obj).getName());
36 }
37 return false;
38 }
39
40 /***
41 * {@inheritDoc}
42 */
43 public String getName()
44 {
45 return name;
46 }
47
48 /***
49 * {@inheritDoc}
50 */
51 public int hashCode()
52 {
53 if(name != null)
54 {
55 return name.hashCode();
56 }
57 else
58 {
59 return 0;
60 }
61 }
62
63 /***
64 * {@inheritDoc}
65 */
66 public String toString()
67 {
68 if(name != null)
69 {
70 return super.toString()+"("+name.toString()+")";
71 }
72 else
73 {
74 return super.toString()+"(null)";
75 }
76 }
77 }