Source code: jreceiver/common/rpc/xmlrpc/RoleAuthsImpl.java
1 /* $Header: /cvsroot/jreceiver/jreceiver/src/jreceiver/common/rpc/xmlrpc/RoleAuthsImpl.java,v 1.3 2002/09/24 18:40:56 reedesau Exp $ */
2
3 package jreceiver.common.rpc.xmlrpc;
4
5 import java.net.URL;
6 import java.util.Hashtable;
7 import java.util.Vector;
8
9 import jreceiver.common.rec.Key;
10 import jreceiver.common.rec.Rec;
11 import jreceiver.common.rec.RecException;
12 import jreceiver.common.rec.security.MethodKey;
13 import jreceiver.common.rec.security.RoleAuthKey;
14 import jreceiver.common.rec.security.RoleAuthRec;
15 import jreceiver.common.rec.security.User;
16 import jreceiver.common.rpc.RoleAuths;
17 import jreceiver.common.rpc.RpcException;
18
19 /**
20 * RoleAuth-definition queries and updates via XML-RPC
21 *
22 * @author Reed Esau
23 * @version $Revision: 1.3 $ $Date: 2002/09/24 18:40:56 $
24 */
25 public class RoleAuthsImpl extends ServerTableImpl implements RoleAuths {
26
27 /**
28 * ctor for this implementation
29 */
30 public RoleAuthsImpl(URL remote_host, User user)
31 throws RpcException {
32 super(HANDLER_NAME, remote_host, user);
33 }
34
35
36 /**
37 * restore a rec object from hashtable form
38 */
39 public Rec reconstituteRec(Hashtable hash) throws RecException {
40 return new RoleAuthRec(hash);
41 }
42
43 /**
44 * restore a key object from hashtable form
45 */
46 public Key reconstituteKey(Hashtable hash) {
47 return new RoleAuthKey(hash);
48 }
49
50 /**
51 * Obtain a total count of RoleAuth keys for a role
52 */
53 public int getKeyCountForRole(String role_id) throws RpcException {
54 Vector params = new Vector();
55 params.add( role_id );
56 Integer ii = (Integer)execute(GET_KEY_COUNT_FOR_ROLE, params);
57 return ii.intValue();
58 }
59
60 /**
61 * Obtain an ordered range of RoleAuth keys for the specified role.
62 */
63 public Vector getKeysForRole(String role_id, String order_by,
64 int rec_offset, int rec_count) throws RpcException {
65 if (log.isDebugEnabled())
66 log.debug("getKeysForRole");
67 Vector params = new Vector();
68 params.add( role_id != null ? role_id : "");
69 params.add( order_by != null ? order_by : "");
70 params.add( new Integer(rec_offset) );
71 params.add( new Integer(rec_count) );
72 Vector keys = (Vector)execute(GET_KEYS_FOR_ROLE, params);
73 if (keys.size() > 0)
74 reconstituteKeys(keys);
75 return keys;
76 }
77
78
79
80 /**
81 * plural - obtain an ordered range of keys for the specified role
82 */
83 public Vector getRecsForMethods(User user, Vector method_keys,
84 String order_by, Hashtable args) throws RpcException {
85 if (user == null || method_keys == null)
86 throw new IllegalArgumentException();
87 if (log.isDebugEnabled())
88 log.debug("getRecsForMethods");
89 try {
90 Vector params = new Vector();
91 params.add( user.toHash() );
92 params.add( MethodKey.dissolve(method_keys) );
93 params.add( order_by != null ? order_by : "");
94 params.add( args != null ? args : new Hashtable());
95 Vector recs = (Vector)execute(GET_RECS_FOR_METHODS, params);
96 if (recs.size() > 0)
97 reconstituteRecs(recs);
98 return recs;
99 }
100 catch (RecException e) {
101 throw new RpcException("rec-problem getting role_auth recs for a method", e);
102 }
103 }
104
105
106 /**
107 * singular - obtain an ordered range of keys for the specified role
108 */
109 public boolean isAuthorized(User user, MethodKey method)
110 throws RpcException {
111 if (user == null || method == null)
112 throw new IllegalArgumentException();
113 if (log.isDebugEnabled())
114 log.debug("isAuthorized");
115 Vector params = new Vector();
116 params.add( user.toHash() );
117 params.add( method.toHash() );
118 Object obj = execute(IS_AUTHORIZED, params);
119 return((obj != null && obj instanceof Boolean)
120 ? ((Boolean)obj).booleanValue()
121 : false);
122 }
123 }
124 /*
125 JRECEIVER MODIFIED BSD LICENSE
126
127 Copyright (c) 2002, Reed Esau (reed.esau@pobox.com) All rights reserved.
128
129 Redistribution and use in source and binary forms, with or without
130 modification, are permitted provided that the following conditions are
131 met:
132
133 Redistributions of source code must retain the above copyright notice,
134 this list of conditions and the following disclaimer.
135
136 Redistributions in binary form must reproduce the above copyright notice,
137 this list of conditions and the following disclaimer in the documentation
138 and/or other materials provided with the distribution.
139
140 Neither the name of the JReceiver Project
141 (http://jreceiver.sourceforge.net) nor the names of its contributors may
142 be used to endorse or promote products derived from this software without
143 specific prior written permission.
144
145 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
146 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
147 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
148 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
149 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
150 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
151 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
152 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
153 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
154 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
155 POSSIBILITY OF SUCH DAMAGE.
156 */
157