01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
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
26: java.io.Serializable {
27: private static final Logger log = Logging
28: .getLoggerInstance(ContextUserContext.class);
29: private static final long serialVersionUID = 1L;
30:
31: private String username;
32: private Rank rank;
33: private long key;
34: /** The SecurityManager, who (eventually) created this instance */
35: protected MMBaseCop manager;
36:
37: public ContextUserContext(String username, Rank rank, long key,
38: MMBaseCop manager, String app) {
39: super (app);
40: this .rank = rank;
41: this .username = username;
42: this .key = key;
43: this .manager = manager;
44: }
45:
46: public String getIdentifier() {
47: return username;
48: }
49:
50: public String getOwnerField() {
51: if (manager == null) {
52: manager = org.mmbase.module.core.MMBase.getMMBase()
53: .getMMBaseCop();
54: }
55: Authorization auth = manager.getAuthorization();
56: if (auth instanceof ContextAuthorization) {
57: return ((ContextAuthorization) auth)
58: .getDefaultContext(this );
59: } else {
60: log.error("Authorization is not ContextAuxthorization but "
61: + auth.getClass());
62: return getIdentifier();
63: }
64: }
65:
66: public Rank getRank() {
67: return rank;
68: }
69:
70: long getKey() {
71: return key;
72: }
73:
74: private void readObject(java.io.ObjectInputStream in)
75: throws java.io.IOException, ClassNotFoundException {
76: username = in.readUTF();
77: rank = (Rank) in.readObject();
78: key = in.readLong();
79: }
80:
81: private void writeObject(java.io.ObjectOutputStream out)
82: throws java.io.IOException {
83: out.writeUTF(username);
84: out.writeObject(rank);
85: out.writeLong(key);
86: }
87:
88: public boolean equals(Object o) {
89: if (o instanceof ContextUserContext) {
90: ContextUserContext ou = (ContextUserContext) o;
91: return super .equals(o) && key == ou.key;
92: } else {
93: return false;
94: }
95: }
96:
97: }
|