      1 /*
      2  * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     23  * questions.
     24  */
     25
     26
     27 package java.security;
     28
     29 /**
     30  * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
     31  * for the {@code Policy} class.
     32  * All the abstract methods in this class must be implemented by each
     33  * service provider who wishes to supply a Policy implementation.
     34  *
     35  * <p> Subclass implementations of this abstract class must provide
     36  * a public constructor that takes a {@code Policy.Parameters}
     37  * object as an input parameter.  This constructor also must throw
     38  * an IllegalArgumentException if it does not understand the
     39  * {@code Policy.Parameters} input.
     40  *
     41  *
     42  * @since 1.6
     43  * @deprecated This class is only useful in conjunction with
     44  *       {@linkplain SecurityManager the Security Manager}, which is deprecated
     45  *       and subject to removal in a future release. Consequently, this class
     46  *       is also deprecated and subject to removal. There is no replacement for
     47  *       the Security Manager or this class.
     48  */
     49
     50 @Deprecated(since="17", forRemoval=true)
     51 public abstract class PolicySpi {
     52
     53     /**
     54      * Constructor for subclasses to call.
     55      */
     56     public PolicySpi() {}
     57
     58     /**
     59      * Check whether the policy has granted a Permission to a ProtectionDomain.
     60      *
     61      * @param domain the ProtectionDomain to check.
     62      *
     63      * @param permission check whether this permission is granted to the
     64      *          specified domain.
     65      *
     66      * @return boolean true if the permission is granted to the domain.
     67      */
     68     protected abstract boolean engineImplies
     69         (ProtectionDomain domain, Permission permission);
     70
     71     /**
     72      * Refreshes/reloads the policy configuration. The behavior of this method
     73      * depends on the implementation. For example, calling {@code refresh}
     74      * on a file-based policy will cause the file to be re-read.
     75      *
     76      * <p> The default implementation of this method does nothing.
     77      * This method should be overridden if a refresh operation is supported
     78      * by the policy implementation.
     79      */
     80     protected void engineRefresh() { }
     81
     82     /**
     83      * Return a PermissionCollection object containing the set of
     84      * permissions granted to the specified CodeSource.
     85      *
     86      * <p> The default implementation of this method returns
     87      * Policy.UNSUPPORTED_EMPTY_COLLECTION object.  This method can be
     88      * overridden if the policy implementation can return a set of
     89      * permissions granted to a CodeSource.
     90      *
     91      * @param codesource the CodeSource to which the returned
     92      *          PermissionCollection has been granted.
     93      *
     94      * @return a set of permissions granted to the specified CodeSource.
     95      *          If this operation is supported, the returned
     96      *          set of permissions must be a new mutable instance
     97      *          and it must support heterogeneous Permission types.
     98      *          If this operation is not supported,
     99      *          Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.
    100      */
    101     protected PermissionCollection engineGetPermissions
    102                                         (CodeSource codesource) {
    103         return Policy.UNSUPPORTED_EMPTY_COLLECTION;
    104     }
    105
    106     /**
    107      * Return a PermissionCollection object containing the set of
    108      * permissions granted to the specified ProtectionDomain.
    109      *
    110      * <p> The default implementation of this method returns
    111      * Policy.UNSUPPORTED_EMPTY_COLLECTION object.  This method can be
    112      * overridden if the policy implementation can return a set of
    113      * permissions granted to a ProtectionDomain.
    114      *
    115      * @param domain the ProtectionDomain to which the returned
    116      *          PermissionCollection has been granted.
    117      *
    118      * @return a set of permissions granted to the specified ProtectionDomain.
    119      *          If this operation is supported, the returned
    120      *          set of permissions must be a new mutable instance
    121      *          and it must support heterogeneous Permission types.
    122      *          If this operation is not supported,
    123      *          Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.
    124      */
    125     protected PermissionCollection engineGetPermissions
    126                                         (ProtectionDomain domain) {
    127         return Policy.UNSUPPORTED_EMPTY_COLLECTION;
    128     }
    129 }
    --- EOF ---