From 392e73bfdd217b42c50b51510e3443ea5f159a5f Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Wed, 6 Mar 2024 23:52:41 +0100 Subject: [PATCH] Add unchecked method variants according to #141 Signed-off-by: Arjan Tijms --- .../jacc/PolicyConfigurationFactory.java | 32 ++++++++++++++++++- .../jakarta/security/jacc/PolicyContext.java | 28 +++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/jakarta/security/jacc/PolicyConfigurationFactory.java b/api/src/main/java/jakarta/security/jacc/PolicyConfigurationFactory.java index 504287f..31eacd2 100755 --- a/api/src/main/java/jakarta/security/jacc/PolicyConfigurationFactory.java +++ b/api/src/main/java/jakarta/security/jacc/PolicyConfigurationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Contributors to Eclipse Foundation. All rights reserved. + * Copyright (c) 2021, 2024 Contributors to Eclipse Foundation. All rights reserved. * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -105,6 +105,36 @@ public static PolicyConfigurationFactory getPolicyConfigurationFactory() throws return policyConfigurationFactory; } + /** + * This static method uses a system property to find and instantiate (via a public constructor) a provider specific + * factory implementation class. + * + *

+ * The name of the provider specific factory implementation class is obtained from the + * value of the system property, + *

{@code
+     *     jakarta.security.jacc.PolicyConfigurationFactory.provider.
+     * }
+     * 
+ * + *

+ * This method is logically equivalent to {@link PolicyConfigurationFactory#getPolicyConfigurationFactory()} with the + * difference that any of the declared exceptions are captured into an IllegalStateException. + * + * @return the singleton instance of the provider specific PolicyConfigurationFactory implementation class. + * + * @throws IllegalStateException thrown at least when {@link PolicyConfigurationFactory#getPolicyConfigurationFactory()} throws + * a ClassNotFoundException or an PolicyContextException; in that case the IllegalStateException contains one of those exceptions + * as the cause. + */ + public static PolicyConfigurationFactory get() { + try { + return PolicyConfigurationFactory.getPolicyConfigurationFactory(); + } catch (ClassNotFoundException | PolicyContextException e) { + throw new IllegalStateException(e); + } + } + /** * This method is used to obtain an instance of the provider specific class that implements the PolicyConfiguration * interface that corresponds to the identified policy context within the provider. The methods of the diff --git a/api/src/main/java/jakarta/security/jacc/PolicyContext.java b/api/src/main/java/jakarta/security/jacc/PolicyContext.java index c86f4a5..4282f4a 100644 --- a/api/src/main/java/jakarta/security/jacc/PolicyContext.java +++ b/api/src/main/java/jakarta/security/jacc/PolicyContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Contributors to Eclipse Foundation. All rights reserved. + * Copyright (c) 2021, 2024 Contributors to Eclipse Foundation. All rights reserved. * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -245,4 +245,30 @@ public static T getContext(String key) throws PolicyContextException { return returnValue; } + /** + * This method may be used by a Policy provider to activate the PolicyContextHandler + * registered to the context object key and cause it to return the corresponding policy context object from the + * container. When this method activates a handler, it passes to the handler the context object key and the handler data + * associated with the calling thread. + * + * @param key a String that identifies the PolicyContextHandler to activate and the context + * object to be acquired from the handler. The value of this parameter must not be null. + * @return the container and handler specific object containing the desired context. A null value is + * returned if the corresponding handler has been registered, and the value of the corresponding context is null. + * + * @throws IllegalArgumentException if a PolicyContextHandler has not been registered for the key + * or the registered handler no longer supports the key. + * + * @throws IllegalStateException if an operation by this method on the identified + * PolicyContextHandler causes it to throw a checked exception that is not accounted for in the signature of this + * method. The IllegalStateException may contain a PolicyContextException containing the actual cause. + */ + public static T get(String key) { + try { + return PolicyContext.getContext(key); + } catch (PolicyContextException e) { + throw new IllegalStateException(e); + } + } + }