KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > security > implementation > context > ContextUserContext


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.implementation.context;
11
12 import org.mmbase.security.*;
13 import org.mmbase.util.logging.Logger;
14 import org.mmbase.util.logging.Logging;
15
16 /**
17  * This UserContext class provides a storage for the authentication
18  * and authorization, so that information can be shared.
19  * This class is NOT a container class for client related stuff, altrough
20  * this is possible.
21  *
22  * @author Eduard Witteveen
23  * @version $Id: ContextUserContext.java,v 1.11 2006/07/18 12:46:05 michiel Exp $
24  */

25 public class ContextUserContext extends BasicUser implements java.io.Serializable JavaDoc {
26     private static final Logger log = Logging.getLoggerInstance(ContextUserContext.class);
27     private static final long serialVersionUID = 1L;
28
29     private String JavaDoc username;
30     private Rank rank;
31     private long key;
32     /** The SecurityManager, who (eventually) created this instance */
33     protected MMBaseCop manager;
34
35     public ContextUserContext(String JavaDoc username, Rank rank, long key, MMBaseCop manager, String JavaDoc app) {
36         super(app);
37         this.rank = rank;
38         this.username = username;
39         this.key = key;
40         this.manager=manager;
41     }
42
43     public String JavaDoc getIdentifier() {
44         return username;
45     }
46
47     public String JavaDoc getOwnerField() {
48         if (manager == null) {
49             manager = org.mmbase.module.core.MMBase.getMMBase().getMMBaseCop();
50         }
51         Authorization auth = manager.getAuthorization();
52         if (auth instanceof ContextAuthorization) {
53             return ((ContextAuthorization)auth).getDefaultContext(this);
54         } else {
55             log.error("Authorization is not ContextAuxthorization but " + auth.getClass());
56             return getIdentifier();
57         }
58     }
59
60     public Rank getRank() {
61         return rank;
62     }
63
64     long getKey() {
65         return key;
66     }
67
68     private void readObject(java.io.ObjectInputStream JavaDoc in) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc {
69         username = in.readUTF();
70         rank = (Rank)in.readObject();
71         key = in.readLong();
72     }
73
74     private void writeObject(java.io.ObjectOutputStream JavaDoc out) throws java.io.IOException JavaDoc {
75         out.writeUTF(username);
76         out.writeObject(rank);
77         out.writeLong(key);
78     }
79
80     public boolean equals(Object JavaDoc o) {
81         if (o instanceof ContextUserContext) {
82             ContextUserContext ou = (ContextUserContext) o;
83             return super.equals(o) && key == ou.key;
84         } else {
85             return false;
86         }
87     }
88
89
90 }
91
Popular Tags