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 import java.util.Enumeration;
30 import java.util.WeakHashMap;
31 import java.util.concurrent.atomic.AtomicReference;
32 import sun.security.jca.GetInstance;
33 import sun.security.util.Debug;
34 import sun.security.util.SecurityConstants;
35
36
37 /**
38 * A Policy object is responsible for determining whether code executing
39 * in the Java runtime environment has permission to perform a
40 * security-sensitive operation.
41 *
42 * <p> There is only one Policy object installed in the runtime at any
43 * given time. A Policy object can be installed by calling the
44 * {@code setPolicy} method. The installed Policy object can be
45 * obtained by calling the {@code getPolicy} method.
46 *
47 * <p> If no Policy object has been installed in the runtime, a call to
48 * {@code getPolicy} installs an instance of the default Policy
49 * implementation (a default subclass implementation of this abstract class).
50 * The default Policy implementation can be changed by setting the value
51 * of the {@code policy.provider} security property to the fully qualified
355 *
356 * <p> Note that the list of registered providers may be retrieved via
357 * the {@link Security#getProviders() Security.getProviders()} method.
358 *
359 * @implNote
360 * The JDK Reference Implementation additionally uses the
361 * {@code jdk.security.provider.preferred}
362 * {@link Security#getProperty(String) Security} property to determine
363 * the preferred provider order for the specified algorithm. This
364 * may be different than the order of providers returned by
365 * {@link Security#getProviders() Security.getProviders()}.
366 *
367 * @param type the specified Policy type. See the Policy section in the
368 * <a href=
369 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Policy">
370 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
371 * for a list of standard Policy types.
372 *
373 * @param params parameters for the Policy, which may be null.
374 *
375 * @return the new Policy object.
376 *
377 * @exception SecurityException if the caller does not have permission
378 * to get a Policy instance for the specified type.
379 *
380 * @exception NullPointerException if the specified type is null.
381 *
382 * @exception IllegalArgumentException if the specified parameters
383 * are not understood by the PolicySpi implementation
384 * from the selected Provider.
385 *
386 * @exception NoSuchAlgorithmException if no Provider supports a PolicySpi
387 * implementation for the specified type.
388 *
389 * @see Provider
390 * @since 1.6
391 */
392 public static Policy getInstance(String type, Policy.Parameters params)
393 throws NoSuchAlgorithmException {
394
395 checkPermission(type);
396 try {
397 GetInstance.Instance instance = GetInstance.getInstance("Policy",
398 PolicySpi.class,
399 type,
400 params);
401 return new PolicyDelegate((PolicySpi)instance.impl,
402 instance.provider,
403 type,
404 params);
405 } catch (NoSuchAlgorithmException nsae) {
406 return handleException(nsae);
407 }
408 }
409
410 /**
411 * Returns a Policy object of the specified type.
412 *
413 * <p> A new Policy object encapsulating the
414 * PolicySpi implementation from the specified provider
415 * is returned. The specified provider must be registered
416 * in the provider list.
417 *
418 * <p> Note that the list of registered providers may be retrieved via
419 * the {@link Security#getProviders() Security.getProviders()} method.
420 *
421 * @param type the specified Policy type. See the Policy section in the
422 * <a href=
423 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Policy">
424 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
425 * for a list of standard Policy types.
426 *
427 * @param params parameters for the Policy, which may be null.
428 *
429 * @param provider the provider.
430 *
431 * @return the new Policy object.
432 *
433 * @exception SecurityException if the caller does not have permission
434 * to get a Policy instance for the specified type.
435 *
436 * @exception NullPointerException if the specified type is null.
437 *
438 * @exception IllegalArgumentException if the specified provider
439 * is null or empty,
440 * or if the specified parameters are not understood by
441 * the PolicySpi implementation from the specified provider.
442 *
443 * @exception NoSuchProviderException if the specified provider is not
444 * registered in the security provider list.
445 *
446 * @exception NoSuchAlgorithmException if the specified provider does not
447 * support a PolicySpi implementation for the specified type.
448 *
449 * @see Provider
450 * @since 1.6
451 */
452 public static Policy getInstance(String type,
453 Policy.Parameters params,
454 String provider)
455 throws NoSuchProviderException, NoSuchAlgorithmException {
456
457 if (provider == null || provider.length() == 0) {
458 throw new IllegalArgumentException("missing provider");
459 }
460
461 checkPermission(type);
462 try {
463 GetInstance.Instance instance = GetInstance.getInstance("Policy",
464 PolicySpi.class,
465 type,
466 params,
467 provider);
468 return new PolicyDelegate((PolicySpi)instance.impl,
469 instance.provider,
470 type,
471 params);
472 } catch (NoSuchAlgorithmException nsae) {
473 return handleException(nsae);
474 }
475 }
476
477 /**
478 * Returns a Policy object of the specified type.
479 *
480 * <p> A new Policy object encapsulating the
481 * PolicySpi implementation from the specified Provider
482 * object is returned. Note that the specified Provider object
483 * does not have to be registered in the provider list.
484 *
485 * @param type the specified Policy type. See the Policy section in the
486 * <a href=
487 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Policy">
488 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
489 * for a list of standard Policy types.
490 *
491 * @param params parameters for the Policy, which may be null.
492 *
493 * @param provider the Provider.
494 *
495 * @return the new Policy object.
496 *
497 * @exception SecurityException if the caller does not have permission
498 * to get a Policy instance for the specified type.
499 *
500 * @exception NullPointerException if the specified type is null.
501 *
502 * @exception IllegalArgumentException if the specified Provider is null,
503 * or if the specified parameters are not understood by
504 * the PolicySpi implementation from the specified Provider.
505 *
506 * @exception NoSuchAlgorithmException if the specified Provider does not
507 * support a PolicySpi implementation for the specified type.
508 *
509 * @see Provider
510 * @since 1.6
511 */
512 public static Policy getInstance(String type,
513 Policy.Parameters params,
514 Provider provider)
515 throws NoSuchAlgorithmException {
516
517 if (provider == null) {
518 throw new IllegalArgumentException("missing provider");
519 }
520
521 checkPermission(type);
522 try {
523 GetInstance.Instance instance = GetInstance.getInstance("Policy",
524 PolicySpi.class,
525 type,
526 params,
527 provider);
528 return new PolicyDelegate((PolicySpi)instance.impl,
529 instance.provider,
530 type,
531 params);
532 } catch (NoSuchAlgorithmException nsae) {
533 return handleException(nsae);
534 }
535 }
536
|
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 import java.util.Enumeration;
30 import java.util.WeakHashMap;
31 import java.util.concurrent.atomic.AtomicReference;
32 import java.util.Objects;
33 import sun.security.jca.GetInstance;
34 import sun.security.util.Debug;
35 import sun.security.util.SecurityConstants;
36
37
38 /**
39 * A Policy object is responsible for determining whether code executing
40 * in the Java runtime environment has permission to perform a
41 * security-sensitive operation.
42 *
43 * <p> There is only one Policy object installed in the runtime at any
44 * given time. A Policy object can be installed by calling the
45 * {@code setPolicy} method. The installed Policy object can be
46 * obtained by calling the {@code getPolicy} method.
47 *
48 * <p> If no Policy object has been installed in the runtime, a call to
49 * {@code getPolicy} installs an instance of the default Policy
50 * implementation (a default subclass implementation of this abstract class).
51 * The default Policy implementation can be changed by setting the value
52 * of the {@code policy.provider} security property to the fully qualified
356 *
357 * <p> Note that the list of registered providers may be retrieved via
358 * the {@link Security#getProviders() Security.getProviders()} method.
359 *
360 * @implNote
361 * The JDK Reference Implementation additionally uses the
362 * {@code jdk.security.provider.preferred}
363 * {@link Security#getProperty(String) Security} property to determine
364 * the preferred provider order for the specified algorithm. This
365 * may be different than the order of providers returned by
366 * {@link Security#getProviders() Security.getProviders()}.
367 *
368 * @param type the specified Policy type. See the Policy section in the
369 * <a href=
370 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Policy">
371 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
372 * for a list of standard Policy types.
373 *
374 * @param params parameters for the Policy, which may be null.
375 *
376 * @return the new {@code Policy} object
377 *
378 * @throws IllegalArgumentException if the specified parameters
379 * are not understood by the {@code PolicySpi} implementation
380 * from the selected {@code Provider}
381 *
382 * @throws NoSuchAlgorithmException if no {@code Provider} supports
383 * a {@code PolicySpi} implementation for the specified type
384 *
385 * @throws NullPointerException if {@code type} is {@code null}
386 *
387 * @throws SecurityException if the caller does not have permission
388 * to get a {@code Policy} instance for the specified type.
389 *
390 * @see Provider
391 * @since 1.6
392 */
393 public static Policy getInstance(String type, Policy.Parameters params)
394 throws NoSuchAlgorithmException {
395 Objects.requireNonNull(type, "null type name");
396 checkPermission(type);
397 try {
398 GetInstance.Instance instance = GetInstance.getInstance("Policy",
399 PolicySpi.class,
400 type,
401 params);
402 return new PolicyDelegate((PolicySpi)instance.impl,
403 instance.provider,
404 type,
405 params);
406 } catch (NoSuchAlgorithmException nsae) {
407 return handleException(nsae);
408 }
409 }
410
411 /**
412 * Returns a Policy object of the specified type.
413 *
414 * <p> A new Policy object encapsulating the
415 * PolicySpi implementation from the specified provider
416 * is returned. The specified provider must be registered
417 * in the provider list.
418 *
419 * <p> Note that the list of registered providers may be retrieved via
420 * the {@link Security#getProviders() Security.getProviders()} method.
421 *
422 * @param type the specified Policy type. See the Policy section in the
423 * <a href=
424 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Policy">
425 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
426 * for a list of standard Policy types.
427 *
428 * @param params parameters for the Policy, which may be null.
429 *
430 * @param provider the provider.
431 *
432 * @return the new {@code Policy} object
433 *
434 * @throws IllegalArgumentException if the specified provider
435 * is {@code null} or empty, or if the specified parameters are
436 * not understood by the {@code PolicySpi} implementation from
437 * the specified provider
438 *
439 * @throws NoSuchAlgorithmException if the specified provider does not
440 * support a {@code PolicySpi} implementation for the specified
441 * type
442 *
443 * @throws NoSuchProviderException if the specified provider is not
444 * registered in the security provider list
445 *
446 * @throws NullPointerException if {@code type} is {@code null}
447 *
448 * @throws SecurityException if the caller does not have permission
449 * to get a {@code Policy} instance for the specified type
450 *
451 * @see Provider
452 * @since 1.6
453 */
454 public static Policy getInstance(String type,
455 Policy.Parameters params,
456 String provider)
457 throws NoSuchProviderException, NoSuchAlgorithmException {
458
459 Objects.requireNonNull(type, "null type name");
460 if (provider == null || provider.length() == 0) {
461 throw new IllegalArgumentException("missing provider");
462 }
463
464 checkPermission(type);
465 try {
466 GetInstance.Instance instance = GetInstance.getInstance("Policy",
467 PolicySpi.class,
468 type,
469 params,
470 provider);
471 return new PolicyDelegate((PolicySpi)instance.impl,
472 instance.provider,
473 type,
474 params);
475 } catch (NoSuchAlgorithmException nsae) {
476 return handleException(nsae);
477 }
478 }
479
480 /**
481 * Returns a Policy object of the specified type.
482 *
483 * <p> A new Policy object encapsulating the
484 * PolicySpi implementation from the specified Provider
485 * object is returned. Note that the specified Provider object
486 * does not have to be registered in the provider list.
487 *
488 * @param type the specified Policy type. See the Policy section in the
489 * <a href=
490 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Policy">
491 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
492 * for a list of standard Policy types.
493 *
494 * @param params parameters for the Policy, which may be null.
495 *
496 * @param provider the Provider.
497 *
498 * @return the new {@code Policy} object
499 *
500 * @throws IllegalArgumentException if the specified {@code Provider}
501 * is {@code null}, or if the specified parameters are not
502 * understood by the {@code PolicySpi} implementation from the
503 * specified {@code Provider}
504 *
505 * @throws NoSuchAlgorithmException if the specified {@code Provider}
506 * does not support a {@code PolicySpi} implementation for
507 * the specified type
508 *
509 * @throws NullPointerException if {@code type} is {@code null}
510 *
511 * @throws SecurityException if the caller does not have permission
512 * to get a {@code Policy} instance for the specified type
513 *
514 * @see Provider
515 * @since 1.6
516 */
517 public static Policy getInstance(String type,
518 Policy.Parameters params,
519 Provider provider)
520 throws NoSuchAlgorithmException {
521
522 Objects.requireNonNull(type, "null type name");
523 if (provider == null) {
524 throw new IllegalArgumentException("missing provider");
525 }
526
527 checkPermission(type);
528 try {
529 GetInstance.Instance instance = GetInstance.getInstance("Policy",
530 PolicySpi.class,
531 type,
532 params,
533 provider);
534 return new PolicyDelegate((PolicySpi)instance.impl,
535 instance.provider,
536 type,
537 params);
538 } catch (NoSuchAlgorithmException nsae) {
539 return handleException(nsae);
540 }
541 }
542
|