/* * * * Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * 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 version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */ package acl_data; import java.util.Vector; /** * This class represents JCRMI permission. */ public class JCRMIPermission { /** * Hash modifier value. */ private String hashModifier; /** * The list of class names. */ private String[] classes; /** * The list of method identifiers. */ private int[] methods; /** * Constructor. * @param hashModifier hash modifier string. * @param classList the list of classes. * @param methodList the list of method names and signatures. */ public JCRMIPermission(String hashModifier, Vector classList, Vector methodList) { this.hashModifier = hashModifier; classes = new String[classList.size()]; classList.copyInto(classes); if (! methodList.isEmpty()) { methods = new int[methodList.size()]; for (int i = 0; i < methodList.size(); i++) { if (methodList.elementAt(i) instanceof String) { methods[i] = getMethodId(hashModifier, (String) methodList.elementAt(i)); } else { methods[i] = getMethodId(hashModifier, new String((byte[])methodList.elementAt(i))); } } } } /** * Calculates method ID for given hash modifier and method name. * @param hashModifier hash modifier value. * @param method method name and signature. * @return the identifier. */ private static int getMethodId(String hashModifier, String method) { if (hashModifier != null) { method = hashModifier + method; } byte data[] = Utils.stringToBytes(method); // data = AccessControlManager.getHash(data, 0, data.length); data = Utils.getHash(data, 0, data.length); return Utils.getInt(data, 0); } }