home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / security / ProtectionDomain.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  3.0 KB  |  105 lines

  1. /*
  2.  * @(#)ProtectionDomain.java    1.23 98/03/18
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.security;
  16.  
  17. /** 
  18.  *
  19.  * <p> This ProtectionDomain class encapulates the characteristics of
  20.  * a domain, which encloses a set of classes whose instances
  21.  * are granted the same set of permissions.
  22.  * 
  23.  * <p>In addition to a set of permissions, a domain is comprised of a 
  24.  * CodeSource, which is a set of PublicKeys together with a codebase (in 
  25.  * the form of a URL). Thus, classes signed by the same keys and
  26.  * from the same URL are placed in the same domain.
  27.  * Classes that have the same permissions but are from different code
  28.  * sources belong to different domains.
  29.  *
  30.  * <p> A class belongs to one and only one ProtectionDomain.
  31.  * 
  32.  * @version     1.23, 03/18/98
  33.  * @author Li Gong 
  34.  * @author Roland Schemers
  35.  */
  36.  
  37. public class ProtectionDomain {
  38.  
  39.     /* CodeSource */
  40.     private CodeSource codesource ;
  41.  
  42.     /* the rights this protection domain is granted */
  43.     private Permissions permissions;
  44.  
  45.     /**
  46.      * Creates a new ProtectionDomain with the given CodeSource and
  47.      * Permissions. If the permissions object is not null, then
  48.      * <code>setReadOnly()</code> will be called on the passed in 
  49.      * Permissions object.
  50.      *
  51.      * @param codesource the codesource associated with this domain
  52.      * @param permissions the permissions granted to this domain
  53.      */
  54.     public ProtectionDomain(CodeSource codesource, Permissions permissions) {
  55.     this.codesource = codesource;
  56.     if (permissions != null) {
  57.         this.permissions = permissions;
  58.         this.permissions.setReadOnly();
  59.     }
  60.     }
  61.  
  62.     /**
  63.      * Returns the CodeSource of this domain.
  64.      * @return the CodeSource of this domain.
  65.      */
  66.     public final CodeSource getCodeSource() {
  67.     return this.codesource;
  68.     }
  69.  
  70.  
  71.     /** 
  72.      * Returns the Permissions of this domain.
  73.      * @return the Permissions of this domain.
  74.      */
  75.     public final Permissions getPermissions() {
  76.     return this.permissions;
  77.     }
  78.  
  79.     /**
  80.      * Check and see if this ProtectionDomain implies the permissions 
  81.      * expressed in the Permission object.
  82.      *
  83.      * @param permission the Permission object to check.
  84.      *
  85.      * @return true if "permission" is a proper subset of a permission in 
  86.      * this ProtectionDomain, false if not.
  87.      */
  88.  
  89.     public boolean implies(Permission permission) {
  90.     if (permissions != null) {
  91.         return permissions.implies(permission);
  92.     } else {
  93.         return false;
  94.     }
  95.     }
  96.  
  97.     /**
  98.      * Convert a ProtectionDomain to a String.
  99.      */
  100.     public String toString() {
  101.     // XXXX: security check?
  102.     return "ProtectionDomain "+codesource+"\n"+permissions+"\n";
  103.     }
  104. }
  105.