< prev index next >

src/share/classes/javax/security/auth/Policy.java

Print this page
rev 1461 : 6987827: security/util/Resources.java needs improvement
Reviewed-by: valeriep
   1 /*
   2  * Copyright (c) 1998, 2006, 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


 237                                         ).asSubclass(Policy.class);
 238                                         return implClass.newInstance();
 239                                     }
 240                                 });
 241                         if (untrustedImpl.acc == null) {
 242                             throw new NullPointerException();
 243                         }
 244                         AccessController.doPrivileged(
 245                                 new PrivilegedExceptionAction<Void>() {
 246                                     public Void run() {
 247                                         setPolicy(untrustedImpl);
 248                                         isCustomPolicy =
 249                                             !finalClass.equals("com.sun.security.auth.PolicyFile");
 250                                         return null;
 251                                     }
 252                                 }, untrustedImpl.acc
 253                         );
 254                     } catch (Exception e) {
 255                         throw new SecurityException
 256                                 (sun.security.util.ResourcesMgr.getString
 257                                 ("unable to instantiate Subject-based policy"));
 258                     }
 259                 }
 260             }
 261         }
 262         return policy;
 263     }
 264 
 265 
 266     /**
 267      * Sets the system-wide Policy object. This method first calls
 268      * <code>SecurityManager.checkPermission</code> with the
 269      * <code>AuthPermission("setPolicy")</code>
 270      * permission to ensure the caller has permission to set the Policy.
 271      *
 272      * <p>
 273      *
 274      * @param policy the new system Policy object.
 275      *
 276      * @exception java.lang.SecurityException if the current thread does not
 277      *          have permission to set the Policy.


   1 /*
   2  * Copyright (c) 1998, 2010, 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


 237                                         ).asSubclass(Policy.class);
 238                                         return implClass.newInstance();
 239                                     }
 240                                 });
 241                         if (untrustedImpl.acc == null) {
 242                             throw new NullPointerException();
 243                         }
 244                         AccessController.doPrivileged(
 245                                 new PrivilegedExceptionAction<Void>() {
 246                                     public Void run() {
 247                                         setPolicy(untrustedImpl);
 248                                         isCustomPolicy =
 249                                             !finalClass.equals("com.sun.security.auth.PolicyFile");
 250                                         return null;
 251                                     }
 252                                 }, untrustedImpl.acc
 253                         );
 254                     } catch (Exception e) {
 255                         throw new SecurityException
 256                                 (sun.security.util.ResourcesMgr.getString
 257                                 ("unable.to.instantiate.Subject.based.policy"));
 258                     }
 259                 }
 260             }
 261         }
 262         return policy;
 263     }
 264 
 265 
 266     /**
 267      * Sets the system-wide Policy object. This method first calls
 268      * <code>SecurityManager.checkPermission</code> with the
 269      * <code>AuthPermission("setPolicy")</code>
 270      * permission to ensure the caller has permission to set the Policy.
 271      *
 272      * <p>
 273      *
 274      * @param policy the new system Policy object.
 275      *
 276      * @exception java.lang.SecurityException if the current thread does not
 277      *          have permission to set the Policy.


< prev index next >