Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unchecked method variants according to #141 #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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
Expand Down Expand Up @@ -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.
*
* <p>
* The name of the provider specific factory implementation class is obtained from the
* value of the system property,
* <pre>{@code
* jakarta.security.jacc.PolicyConfigurationFactory.provider.
* }
* </pre>
*
* <p>
* 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
Expand Down
28 changes: 27 additions & 1 deletion 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
Expand Down Expand Up @@ -245,4 +245,30 @@ public static <T> T getContext(String key) throws PolicyContextException {
return returnValue;
}

/**
* This method may be used by a <code>Policy</code> provider to activate the <code>PolicyContextHandler</code>
* 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 <code>String</code> that identifies the <code>PolicyContextHandler</code> 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 <code>null</code> value is
* returned if the corresponding handler has been registered, and the value of the corresponding context is null.
*
* @throws IllegalArgumentException if a <code>PolicyContextHandler</code> 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> T get(String key) {
try {
return PolicyContext.getContext(key);
} catch (PolicyContextException e) {
throw new IllegalStateException(e);
}
}

}