summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/certsrv/authorization/AuthzToken.java
blob: a0f7133a717983cf8da10680652ba705a9531af1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.authorization;


import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;

import com.netscape.certsrv.base.IAttrSet;


/**
 * Authorization token returned by Authorization Managers.
 * Upon return, it contains the name of the authorization manager that create
 * the AuthzToken, the plugin name of the authorization manager, time of
 * authorization happened, name of the resource, type of operation performed
 * on the resource.
 * <p>
 * @version $Revision$, $Date$
 */
public class AuthzToken implements IAttrSet {
    /**
     *
     */
    private static final long serialVersionUID = 4716145610877112054L;

    private Hashtable mAttrs = null;

    /**
     * Plugin name of the authorization manager that created the 
     * AuthzToken as a string.
     */
    public static final String TOKEN_AUTHZMGR_IMPL_NAME = "authzMgrImplName";

    /**
     * Name of the authorization manager that created the AuthzToken
     * as a string.
     */
    public static final String TOKEN_AUTHZMGR_INST_NAME = "authzMgrInstName";

    /**
     * Time of authorization as a java.util.Date 
     */
    public static final String TOKEN_AUTHZTIME = "authzTime";

    /**
     * name of the resource
     */
    public static final String TOKEN_AUTHZ_RESOURCE = "authzRes";

    /**
     * name of the operation 
     */
    public static final String TOKEN_AUTHZ_OPERATION = "authzOp";

    /*
     * Status of the authorization evaluation
     */
    public static final String TOKEN_AUTHZ_STATUS = "status";
 
    /**
     * Constant for the success status of the authorization evaluation. 
     */
    public static final String AUTHZ_STATUS_SUCCESS = "statusSuccess";

    /**
     * Constructs an instance of a authorization token.
     * The token by default contains the following attributes: <br>
     * <pre>
     *		"authzMgrInstName" - The authorization manager instance name.
     *		"authzMgrImplName" - The authorization manager plugin name.
     *		"authzTime" - The - The time of authorization.
     * </pre>
     * @param authzMgr The authorization manager that created this Token.
     */
    public AuthzToken(IAuthzManager authzMgr) {
        mAttrs = new Hashtable();
        mAttrs.put(TOKEN_AUTHZMGR_INST_NAME, authzMgr.getName()); 
        mAttrs.put(TOKEN_AUTHZMGR_IMPL_NAME, authzMgr.getImplName()); 
        mAttrs.put(TOKEN_AUTHZTIME, new Date());
    }

    /**
     * Get the value of an attribute in the AuthzToken
     * @param attrName The attribute name
     * @return The value of attrName if any. 
     */
    public Object get(String attrName) {
        return mAttrs.get(attrName);
    }

    /**
     * Used by an Authorization manager to set an attribute and value
     *	 in the AuthzToken.
     * @param attrName The name of the attribute
     * @param value The value of the attribute to set.
     */
    public void set(String attrName, Object value) {
        mAttrs.put(attrName, value);
    }

    /**
     * Removes an attribute in the AuthzToken
     * @param attrName The name of the attribute to remove.
     */
    public void delete(String attrName) {
        mAttrs.remove(attrName);
    }

    /**
     * Enumerate all attribute names in the AuthzToken.
     * @return Enumeration of all attribute names in this AuthzToken.
     */
    public Enumeration getElements() {
        return (mAttrs.keys());
    }

    /**
     * Enumerate all attribute values in the AuthzToken.
     * @return Enumeration of all attribute names in this AuthzToken.
     */
    public Enumeration getVals() {
        return (mAttrs.elements());
    }

    /**
     * Gets the name of the authorization manager instance that created 
     * this token.
     * @return The name of the authorization manager instance that created 
     * this token.
     */
    public String getAuthzManagerInstName() {
        return ((String) mAttrs.get(TOKEN_AUTHZMGR_INST_NAME));
    }

    /**
     * Gets the plugin name of the authorization manager that created this
     * token.
     * @return The plugin name of the authorization manager that created this
     * token.
     */
    public String getAuthzManagerImplName() {
        return ((String) mAttrs.get(TOKEN_AUTHZMGR_IMPL_NAME));
    }

    /**
     * Gets the time of authorization.
     * @return The time of authorization
     */
    public Date getAuthzTime() {
        return ((Date) mAttrs.get(TOKEN_AUTHZTIME));
    }
}