001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexey V. Varlamov
020: * @version $Revision$
021: */package java.security;
022:
023: import java.io.Serializable;
024:
025: /**
026: * Abstract superclass of all classes which represent permission to access
027: * system resources.
028: *
029: */
030: public abstract class Permission implements Guard, Serializable {
031:
032: /**
033: * @com.intel.drl.spec_ref
034: */
035: private static final long serialVersionUID = -5636570222231596674L;
036:
037: private final String name;
038:
039: /**
040: * @com.intel.drl.spec_ref
041: */
042: public abstract boolean equals(Object obj);
043:
044: /**
045: * Answers an integer hash code for the receiver. Any two objects which
046: * answer <code>true</code> when passed to <code>.equals</code> must
047: * answer the same value for this method.
048: *
049: *
050: * @return int the receiver's hash.
051: *
052: * @see #equals
053: */
054: public abstract int hashCode();
055:
056: /**
057: * Answers the actions associated with the receiver. Subclasses should
058: * return their actions in canonical form. If no actions are associated with
059: * the receiver, the empty string should be returned.
060: *
061: *
062: * @return String the receiver's actions.
063: */
064: public abstract String getActions();
065:
066: /**
067: * Indicates whether the argument permission is implied by the receiver.
068: *
069: *
070: * @return boolean <code>true</code> if the argument permission is implied
071: * by the receiver, and <code>false</code> if it is not.
072: * @param permission
073: * Permission the permission to check.
074: */
075: public abstract boolean implies(Permission permission);
076:
077: /**
078: * Constructs a new instance of this class with its name set to the
079: * argument.
080: *
081: *
082: * @param name
083: * String the name of the permission.
084: */
085: public Permission(String name) {
086: this .name = name;
087: }
088:
089: /**
090: * Answers the name of the receiver.
091: *
092: *
093: * @return String the receiver's name.
094: */
095: public final String getName() {
096: return name;
097: }
098:
099: /**
100: * @com.intel.drl.spec_ref
101: */
102: public void checkGuard(Object obj) throws SecurityException {
103: SecurityManager sm = System.getSecurityManager();
104: if (sm != null) {
105: sm.checkPermission(this );
106: }
107: }
108:
109: /**
110: * Answers a new PermissionCollection for holding permissions of this class.
111: * Answer null if any permission collection can be used.
112: *
113: *
114: * @return PermissionCollection or null a suitable permission collection for
115: * instances of the class of the receiver.
116: */
117: public PermissionCollection newPermissionCollection() {
118: return null;
119: }
120:
121: /**
122: * Answers a string containing a concise, human-readable description of the
123: * receiver.
124: *
125: *
126: * @return String a printable representation for the receiver.
127: */
128: public String toString() {
129: String actions = getActions();
130: actions = (actions == null || actions.length() == 0) ? "" : " " //$NON-NLS-1$ //$NON-NLS-2$
131: + getActions();
132: return "(" + getClass().getName() + " " + getName() + actions + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
133: }
134: }
|