KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > authn > LdapPrincipal


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.ldap.server.authn;
18
19
20 import org.apache.ldap.common.name.LdapName;
21
22 import javax.naming.Name JavaDoc;
23 import java.io.Serializable JavaDoc;
24 import java.security.Principal JavaDoc;
25
26
27 /**
28  * An alternative X500 user implementation that has access to the distinguished
29  * name of the principal as well as the String representation.
30  *
31  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
32  * @version $Rev: 169198 $
33  */

34 public final class LdapPrincipal implements Principal JavaDoc, Serializable JavaDoc
35 {
36     private static final long serialVersionUID = 3906650782395676720L;
37
38     /** the normalized distinguished name of the principal */
39     private final Name name;
40
41     /** the no name anonymous user whose DN is the empty String */
42     public static final LdapPrincipal ANONYMOUS = new LdapPrincipal();
43
44
45     /**
46      * Creates a new LDAP/X500 principal. Keep this package friendly so only code
47      * in the package can create a trusted principal.
48      *
49      * @param name the normalized distinguished name of the principal
50      */

51     LdapPrincipal( Name name )
52     {
53         this.name = name;
54     }
55
56
57     /**
58      * Creates a principal for the no name anonymous user whose DN is the empty
59      * String.
60      */

61     private LdapPrincipal()
62     {
63         this.name = new LdapName();
64     }
65
66
67     /**
68      * Gets a cloned copy of the normalized distinguished name of this
69      * principal as a JNDI Name. It must be cloned to protect this Principal
70      * from alteration.
71      *
72      * @return the normalized distinguished name of the principal as a JNDI Name
73      */

74     public Name getDn()
75     {
76         return ( Name ) name.clone();
77     }
78
79
80     /**
81      * Gets the normalized distinguished name of the principal as a String.
82      *
83      * @see Principal#getName()
84      */

85     public String JavaDoc getName()
86     {
87         return name.toString();
88     }
89 }
90
Popular Tags