KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > security > BasicUser


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.security;
11
12 /**
13  * A UserContext object is the result of an authentication, on which authorization can be
14  * based. Normally your authorization/authentication implementation will also provide an extension
15  * to this class.
16  *
17  * This default implementation is the most simple one, actually implementing 'no authorization'
18  * (because the rank is fixed to 'administrator').
19  *
20  * This class is <em>not</em> necessarily also the container class for the client's credentials,
21  * although this is possible.
22  *
23  * @author Eduard Witteveen
24  * @version $Id: BasicUser.java,v 1.2 2006/02/13 18:17:16 michiel Exp $
25  */

26 public class BasicUser implements UserContext {
27
28     protected String JavaDoc authenticationType;
29
30
31     public BasicUser(String JavaDoc authenticationType) {
32         this.authenticationType = authenticationType;
33     }
34
35     /**
36      * Gets the unique identifier for this user. This should be unique
37      * for every different user on the system.
38      *
39      * @return A unique identifier for this user.
40      */

41     public String JavaDoc getIdentifier() {
42         return "anonymous";
43     }
44
45     /**
46      * Gets the owner field value of new objects created by this user. The default implementation
47      * returns the user's identifier. This can be changed if the authorization implementation does
48      * not attribute rights to users directly ('context' implementations).
49      * @return A possible value for the owner field
50      */

51     public String JavaDoc getOwnerField() {
52         return getIdentifier();
53     }
54
55     /**
56      * Gets the rank of this user.
57      * @return the user rank
58      */

59     public Rank getRank() throws org.mmbase.security.SecurityException {
60         // we need the highest rank.. to fool the security checks that we are allowed...
61
return Rank.ADMIN;
62     }
63
64     /**
65      * Gets a string representation of this user context (for debugging)
66      * @return a string describing the usercontext
67      */

68     public String JavaDoc toString() {
69         return getIdentifier() + " (" + getRank() + ")";
70     }
71
72     public boolean isValid() {
73         return org.mmbase.module.core.MMBase.getMMBase().getMMBaseCop().getAuthentication().isValid(this);
74     }
75
76     public String JavaDoc getAuthenticationType() {
77         return authenticationType;
78     }
79
80     public boolean equals(Object JavaDoc o) {
81         if (o instanceof BasicUser) {
82             BasicUser ou = (BasicUser) o;
83             return
84                 (authenticationType == null ? ou.authenticationType == null : authenticationType.equals(ou.authenticationType)) &&
85                 getIdentifier().equals(ou.getIdentifier()) &&
86                 getRank().equals(ou.getRank());
87         } else {
88             return false;
89         }
90     }
91
92     public int hashCode() {
93         int result = 0;
94         result = org.mmbase.util.HashCodeUtil.hashCode(result, authenticationType);
95         return result;
96     }
97
98 }
99
Popular Tags