< prev index next >

## src/java.base/share/classes/javax/security/auth/PrivateCredentialPermission.java

Print this page

      1 /*
      2  * Copyright (c) 1999, 2019, 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 package javax.security.auth;
     27
     28 import java.util.*;

     29 import java.text.MessageFormat;
     30 import java.security.Permission;
     31 import java.security.PermissionCollection;
     32 import java.security.Principal;
     33 import sun.security.util.ResourcesMgr;
     34
     35 /**
     36  * This class is used to protect access to private Credentials
     37  * belonging to a particular {@code Subject}.  The {@code Subject}
     38  * is represented by a Set of Principals.
     39  *
     40  * <p> The target name of this {@code Permission} specifies
     41  * a Credential class name, and a Set of Principals.
     42  * The only valid value for this Permission's actions is, "read".
     43  * The target name must abide by the following syntax:
     44  *
     45  * <pre>
     46  *      CredentialClass {PrincipalClass "PrincipalName"}*
     47  * </pre>
     48  *
    458         if (thisP.length == 0)
    459             return false;
    460
    461         for (int i = 0; i < thisP.length; i++) {
    462             boolean foundMatch = false;
    463             for (int j = 0; j < thatP.length; j++) {
    464                 if (thisP[i].implies(thatP[j])) {
    465                     foundMatch = true;
    466                     break;
    467                 }
    468             }
    469             if (!foundMatch) {
    470                 return false;
    471             }
    472         }
    473         return true;
    474     }
    475
    476     /**
    477      * Reads this object from a stream (i.e., deserializes it)

    478      */
    479     @java.io.Serial
    480     private void readObject(java.io.ObjectInputStream s) throws
    481                                         java.io.IOException,
    482                                         ClassNotFoundException {
    483
    484         s.defaultReadObject();
    485
    486         // perform new initialization from the permission name
    487
    488         if (getName().indexOf(' ') == -1 && getName().indexOf('"') == -1) {
    489
    490             // name only has a credential class specified
    491             credentialClass = getName();
    492             credOwners = EMPTY_PRINCIPALS;
    493
    494         } else {
    495
    496             // perform regular initialization
    497             init(getName());
    498         }
    499     }
    500
    501     /**
      1 /*
      2  * Copyright (c) 1999, 2021, 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 package javax.security.auth;
     27
     28 import java.util.*;
     29 import java.io.IOException;
     30 import java.text.MessageFormat;
     31 import java.security.Permission;
     32 import java.security.PermissionCollection;
     33 import java.security.Principal;
     34 import sun.security.util.ResourcesMgr;
     35
     36 /**
     37  * This class is used to protect access to private Credentials
     38  * belonging to a particular {@code Subject}.  The {@code Subject}
     39  * is represented by a Set of Principals.
     40  *
     41  * <p> The target name of this {@code Permission} specifies
     42  * a Credential class name, and a Set of Principals.
     43  * The only valid value for this Permission's actions is, "read".
     44  * The target name must abide by the following syntax:
     45  *
     46  * <pre>
     47  *      CredentialClass {PrincipalClass "PrincipalName"}*
     48  * </pre>
     49  *
    459         if (thisP.length == 0)
    460             return false;
    461
    462         for (int i = 0; i < thisP.length; i++) {
    463             boolean foundMatch = false;
    464             for (int j = 0; j < thatP.length; j++) {
    465                 if (thisP[i].implies(thatP[j])) {
    466                     foundMatch = true;
    467                     break;
    468                 }
    469             }
    470             if (!foundMatch) {
    471                 return false;
    472             }
    473         }
    474         return true;
    475     }
    476
    477     /**
    478      * Reads this object from a stream (i.e., deserializes it)
    479      *
    480      * @param  s the {@code ObjectInputStream} from which data is read
    481      * @throws IOException if an I/O error occurs
    482      * @throws ClassNotFoundException if a serialized class cannot be loaded
    483      */
    484     @java.io.Serial
    485     private void readObject(java.io.ObjectInputStream s) throws
    486                                         IOException,
    487                                         ClassNotFoundException {
    488
    489         s.defaultReadObject();
    490
    491         // perform new initialization from the permission name
    492
    493         if (getName().indexOf(' ') == -1 && getName().indexOf('"') == -1) {
    494
    495             // name only has a credential class specified
    496             credentialClass = getName();
    497             credOwners = EMPTY_PRINCIPALS;
    498
    499         } else {
    500
    501             // perform regular initialization
    502             init(getName());
    503         }
    504     }
    505
    506     /**

< prev index next >