1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.authn;
18
19
20 import java.io.Serializable;
21 import java.security.Principal;
22
23 import javax.naming.Name;
24
25 import org.apache.ldap.common.name.LdapName;
26
27
28 /***
29 * An alternative X500 user implementation that has access to the distinguished
30 * name of the principal as well as the String representation.
31 *
32 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33 * @version $Rev: 264732 $
34 */
35 public final class LdapPrincipal implements Principal, Serializable
36 {
37 private static final long serialVersionUID = 3906650782395676720L;
38
39 /*** the normalized distinguished name of the principal */
40 private final Name name;
41
42 /*** the no name anonymous user whose DN is the empty String */
43 public static final LdapPrincipal ANONYMOUS = new LdapPrincipal();
44
45
46 /***
47 * Creates a new LDAP/X500 principal. Keep this package friendly so only code
48 * in the package can create a trusted principal.
49 *
50 * @param name the normalized distinguished name of the principal
51 */
52 LdapPrincipal( Name name )
53 {
54 this.name = name;
55 }
56
57
58 /***
59 * Creates a principal for the no name anonymous user whose DN is the empty
60 * String.
61 */
62 private LdapPrincipal()
63 {
64 this.name = new LdapName();
65 }
66
67
68 /***
69 * Gets a cloned copy of the normalized distinguished name of this
70 * principal as a JNDI {@link Name}.
71 *
72 * @return the normalized distinguished name of the principal as a JNDI {@link Name}
73 */
74 public Name getJndiName()
75 {
76 return ( Name ) name.clone();
77 }
78
79
80 /***
81 * Returns the normalized distinguished name of the principal as a String.
82 */
83 public String getName()
84 {
85 return name.toString();
86 }
87
88 /***
89 * Returns string representation of the normalized distinguished name
90 * of this principal.
91 */
92 public String toString()
93 {
94 return name.toString();
95 }
96 }