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 import java.util.Set;
23 import java.util.Collections;
24
25 import javax.naming.Name;
26
27 import org.apache.ldap.common.name.LdapName;
28 import org.apache.ldap.common.aci.AuthenticationLevel;
29
30
31 /***
32 * An alternative X500 user implementation that has access to the distinguished
33 * name of the principal as well as the String representation.
34 *
35 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36 * @version $Rev: 293444 $
37 */
38 public final class LdapPrincipal implements Principal, Serializable
39 {
40 private static final long serialVersionUID = 3906650782395676720L;
41
42 /*** the normalized distinguished name of the principal */
43 private final Name name;
44
45 /*** the no name anonymous user whose DN is the empty String */
46 public static final LdapPrincipal ANONYMOUS = new LdapPrincipal();
47
48 /*** the authentication level for this principal */
49 private final AuthenticationLevel authenticationLevel;
50
51
52 /***
53 * Creates a new LDAP/X500 principal without any group associations. Keep
54 * this package friendly so only code in the package can create a
55 * trusted principal.
56 *
57 * @param name the normalized distinguished name of the principal
58 * @param authenticationLevel
59 */
60 LdapPrincipal( Name name, AuthenticationLevel authenticationLevel )
61 {
62 this.name = name;
63 this.authenticationLevel = authenticationLevel;
64 }
65
66
67 /***
68 * Creates a principal for the no name anonymous user whose DN is the empty
69 * String.
70 */
71 private LdapPrincipal()
72 {
73 this.name = new LdapName();
74 this.authenticationLevel = AuthenticationLevel.NONE;
75 }
76
77
78 /***
79 * Gets a cloned copy of the normalized distinguished name of this
80 * principal as a JNDI {@link Name}.
81 *
82 * @return the normalized distinguished name of the principal as a JNDI {@link Name}
83 */
84 public Name getJndiName()
85 {
86 return ( Name ) name.clone();
87 }
88
89
90 /***
91 * Returns the normalized distinguished name of the principal as a String.
92 */
93 public String getName()
94 {
95 return name.toString();
96 }
97
98
99 /***
100 * Gets the authentication level associated with this LDAP principle.
101 *
102 * @return the authentication level
103 */
104 public AuthenticationLevel getAuthenticationLevel()
105 {
106 return authenticationLevel;
107 }
108
109
110 /***
111 * Returns string representation of the normalized distinguished name
112 * of this principal.
113 */
114 public String toString()
115 {
116 return name.toString();
117 }
118 }