/* * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code 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 in the LICENSE file that * accompanied this code). * * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.rmi.rmid; import java.security.*; import java.io.*; import java.util.*; /** * The ExecOptionPermission class represents permission for rmid to use * a specific command-line option when launching an activation group. * * @author Ann Wollrath * * @serial exclude */ public final class ExecOptionPermission extends Permission { /** * does this permission have a wildcard at the end? */ private transient boolean wildcard; /** * the name without the wildcard on the end */ private transient String name; /** * UID for serialization */ private static final long serialVersionUID = 5842294756823092756L; public ExecOptionPermission(String name) { super(name); init(name); } public ExecOptionPermission(String name, String actions) { this(name); } /** * Checks if the specified permission is "implied" by * this object. *
* More specifically, this method returns true if: *
getName().hashCode()
, where getName
is
* from the Permission superclass.
*
* @return a hash code value for this object.
*/
public int hashCode() {
return this.getName().hashCode();
}
/**
* Returns the canonical string representation of the actions.
*
* @return the canonical string representation of the actions.
*/
public String getActions() {
return "";
}
/**
* Returns a new PermissionCollection object for storing
* ExecOptionPermission objects.
* * An ExecOptionPermissionCollection stores a collection of * ExecOptionPermission permissions. * *
ExecOptionPermission objects must be stored in a manner that allows
* them to be inserted in any order, but that also enables the
* PermissionCollection implies
method
* to be implemented in an efficient (and consistent) manner.
*
* @return a new PermissionCollection object suitable for
* storing ExecOptionPermissions.
*/
public PermissionCollection newPermissionCollection() {
return new ExecOptionPermissionCollection();
}
/**
* readObject is called to restore the state of the ExecOptionPermission
* from a stream.
*/
private synchronized void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException
{
s.defaultReadObject();
// init is called to initialize the rest of the values.
init(getName());
}
/**
* Initialize a ExecOptionPermission object. Common to all constructors.
* Also called during de-serialization.
*/
private void init(String name)
{
if (name == null)
throw new NullPointerException("name can't be null");
if (name.isEmpty()) {
throw new IllegalArgumentException("name can't be empty");
}
if (name.endsWith(".*") || name.endsWith("=*") || name.equals("*")) {
wildcard = true;
if (name.length() == 1) {
this.name = "";
} else {
this.name = name.substring(0, name.length()-1);
}
} else {
this.name = name;
}
}
/**
* A ExecOptionPermissionCollection stores a collection
* of ExecOptionPermission permissions. ExecOptionPermission objects
* must be stored in a manner that allows them to be inserted in any
* order, but enable the implies function to evaluate the implies
* method in an efficient (and consistent) manner.
*
* A ExecOptionPermissionCollection handles comparing a permission like
* "a.b.c.d.e" * with a Permission such as "a.b.*", or "*".
*
* @serial include
*/
private static class ExecOptionPermissionCollection
extends PermissionCollection
implements java.io.Serializable
{
private Hashtable