      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  */
     44
     45 public abstract class PolicySpi {
     46
     47     /**
     48      * Constructor for subclasses to call.
     49      */
     50     public PolicySpi() {}
     51
     52     /**
     53      * Check whether the policy has granted a Permission to a ProtectionDomain.
     54      *
     55      * @param domain the ProtectionDomain to check.
     56      *
     57      * @param permission check whether this permission is granted to the
     58      *          specified domain.
     59      *
     60      * @return boolean true if the permission is granted to the domain.
     61      */
     62     protected abstract boolean engineImplies
     63         (ProtectionDomain domain, Permission permission);
     64
     65     /**
     66      * Refreshes/reloads the policy configuration. The behavior of this method
     67      * depends on the implementation. For example, calling {@code refresh}
     68      * on a file-based policy will cause the file to be re-read.
     69      *
     70      * <p> The default implementation of this method does nothing.
     71      * This method should be overridden if a refresh operation is supported
     72      * by the policy implementation.
     73      */
     74     protected void engineRefresh() { }
     75
     76     /**
     77      * Return a PermissionCollection object containing the set of
     78      * permissions granted to the specified CodeSource.
     79      *
     80      * <p> The default implementation of this method returns
     81      * Policy.UNSUPPORTED_EMPTY_COLLECTION object.  This method can be
     82      * overridden if the policy implementation can return a set of
     83      * permissions granted to a CodeSource.
     84      *
     85      * @param codesource the CodeSource to which the returned
     86      *          PermissionCollection has been granted.
     87      *
     88      * @return a set of permissions granted to the specified CodeSource.
     89      *          If this operation is supported, the returned
     90      *          set of permissions must be a new mutable instance
     91      *          and it must support heterogeneous Permission types.
     92      *          If this operation is not supported,
     93      *          Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.
     94      */
     95     protected PermissionCollection engineGetPermissions
     96                                         (CodeSource codesource) {
     97         return Policy.UNSUPPORTED_EMPTY_COLLECTION;
     98     }
     99
    100     /**
    101      * Return a PermissionCollection object containing the set of
    102      * permissions granted to the specified ProtectionDomain.
    103      *
    104      * <p> The default implementation of this method returns
    105      * Policy.UNSUPPORTED_EMPTY_COLLECTION object.  This method can be
    106      * overridden if the policy implementation can return a set of
    107      * permissions granted to a ProtectionDomain.
    108      *
    109      * @param domain the ProtectionDomain to which the returned
    110      *          PermissionCollection has been granted.
    111      *
    112      * @return a set of permissions granted to the specified ProtectionDomain.
    113      *          If this operation is supported, the returned
    114      *          set of permissions must be a new mutable instance
    115      *          and it must support heterogeneous Permission types.
    116      *          If this operation is not supported,
    117      *          Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.
    118      */
    119     protected PermissionCollection engineGetPermissions
    120                                         (ProtectionDomain domain) {
    121         return Policy.UNSUPPORTED_EMPTY_COLLECTION;
    122     }
    123 }