01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package acl_data;
28:
29: import java.util.Vector;
30:
31: /**
32: * This class represents JCRMI permission.
33: */
34: public class JCRMIPermission {
35:
36: /**
37: * Hash modifier value.
38: */
39: private String hashModifier;
40: /**
41: * The list of class names.
42: */
43: private String[] classes;
44: /**
45: * The list of method identifiers.
46: */
47: private int[] methods;
48:
49: /**
50: * Constructor.
51: * @param hashModifier hash modifier string.
52: * @param classList the list of classes.
53: * @param methodList the list of method names and signatures.
54: */
55: public JCRMIPermission(String hashModifier, Vector classList,
56: Vector methodList) {
57:
58: this .hashModifier = hashModifier;
59:
60: classes = new String[classList.size()];
61: classList.copyInto(classes);
62:
63: if (!methodList.isEmpty()) {
64: methods = new int[methodList.size()];
65: for (int i = 0; i < methodList.size(); i++) {
66: if (methodList.elementAt(i) instanceof String) {
67: methods[i] = getMethodId(hashModifier,
68: (String) methodList.elementAt(i));
69: } else {
70: methods[i] = getMethodId(hashModifier, new String(
71: (byte[]) methodList.elementAt(i)));
72: }
73: }
74: }
75: }
76:
77: /**
78: * Calculates method ID for given hash modifier and method name.
79: * @param hashModifier hash modifier value.
80: * @param method method name and signature.
81: * @return the identifier.
82: */
83: private static int getMethodId(String hashModifier, String method) {
84: if (hashModifier != null) {
85: method = hashModifier + method;
86: }
87: byte data[] = Utils.stringToBytes(method);
88: // data = AccessControlManager.getHash(data, 0, data.length);
89: data = Utils.getHash(data, 0, data.length);
90: return Utils.getInt(data, 0);
91: }
92: }
|