Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/crypto/CryptoAllPermission.java
38829 views
/*1* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.crypto;2627import java.security.*;28import java.util.Enumeration;29import java.util.Vector;3031/**32* The CryptoAllPermission is a permission that implies33* any other crypto permissions.34* <p>35*36* @see java.security.Permission37* @see java.security.AllPermission38*39* @author Sharon Liu40* @since 1.441*/4243final class CryptoAllPermission extends CryptoPermission {4445private static final long serialVersionUID = -5066513634293192112L;4647// This class is similar to java.security.AllPermission.48static final String ALG_NAME = "CryptoAllPermission";49static final CryptoAllPermission INSTANCE =50new CryptoAllPermission();5152private CryptoAllPermission() {53super(ALG_NAME);54}5556/**57* Checks if the specified permission is implied by58* this object.59*60* @param p the permission to check against.61*62* @return true if the specified permission is an63* instance of CryptoPermission.64*/65public boolean implies(Permission p) {66return (p instanceof CryptoPermission);67}6869/**70* Checks two CryptoAllPermission objects for equality.71* Two CryptoAllPermission objects are always equal.72*73* @param obj the object to test for equality with this object.74*75* @return true if <i>obj</i> is a CryptoAllPermission object.76*/77public boolean equals(Object obj) {78return (obj == INSTANCE);79}8081/**82*83* Returns the hash code value for this object.84*85* @return a hash code value for this object.86*/87public int hashCode() {88return 1;89}9091/**92* Returns a new PermissionCollection object for storing93* CryptoAllPermission objects.94* <p>95*96* @return a new PermissionCollection object suitable for97* storing CryptoAllPermissions.98*/99public PermissionCollection newPermissionCollection() {100return new CryptoAllPermissionCollection();101}102}103104/**105* A CryptoAllPermissionCollection stores a collection106* of CryptoAllPermission permissions.107*108* @see java.security.Permission109* @see java.security.Permissions110* @see javax.crypto.CryptoPermission111*112* @author Sharon Liu113*/114final class CryptoAllPermissionCollection extends PermissionCollection115implements java.io.Serializable116{117118private static final long serialVersionUID = 7450076868380144072L;119120// true if a CryptoAllPermission has been added121private boolean all_allowed;122123/**124* Create an empty CryptoAllPermissions object.125*/126CryptoAllPermissionCollection() {127all_allowed = false;128}129130/**131* Adds a permission to the CryptoAllPermissions.132*133* @param permission the Permission object to add.134*135* @exception SecurityException - if this CryptoAllPermissionCollection136* object has been marked readonly137*/138public void add(Permission permission) {139if (isReadOnly())140throw new SecurityException("attempt to add a Permission to " +141"a readonly PermissionCollection");142143if (permission != CryptoAllPermission.INSTANCE)144return;145146all_allowed = true;147}148149/**150* Check and see if this set of permissions implies the permissions151* expressed in "permission".152*153* @param permission the Permission object to compare154*155* @return true if the given permission is implied by this156* CryptoAllPermissionCollection.157*/158public boolean implies(Permission permission) {159if (!(permission instanceof CryptoPermission)) {160return false;161}162return all_allowed;163}164165/**166* Returns an enumeration of all the CryptoAllPermission167* objects in the container.168*169* @return an enumeration of all the CryptoAllPermission objects.170*/171public Enumeration<Permission> elements() {172Vector<Permission> v = new Vector<>(1);173if (all_allowed) v.add(CryptoAllPermission.INSTANCE);174return v.elements();175}176}177178179