Java Code Examples for org.wildfly.security.auth.server.SecurityIdentity#runAs()

The following examples show how to use org.wildfly.security.auth.server.SecurityIdentity#runAs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelControllerImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Executes an operation on the controller
 * @param operation the operation
 * @param handler the handler
 * @param control the transaction control
 * @param attachments the operation attachments
 * @return the result of the operation
 */
@Override
public ModelNode execute(final ModelNode operation, final OperationMessageHandler handler, final OperationTransactionControl control, final OperationAttachments attachments) {
    SecurityIdentity securityIdentity = securityIdentitySupplier.get();
    OperationResponse or = securityIdentity.runAs((PrivilegedAction<OperationResponse>) () -> internalExecute(operation,
            handler, control, attachments, prepareStep, false, partialModelIndicator.isModelPartial()));

    ModelNode result = or.getResponseNode();
    try {
        or.close();
    } catch (IOException e) {
        ROOT_LOGGER.debugf(e, "Caught exception closing response to %s whose associated streams, " +
                "if any, were not wanted", operation);
    }
    return result;
}
 
Example 2
Source File: ModelControllerImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public OperationResponse execute(Operation operation, OperationMessageHandler handler, OperationTransactionControl control) {
    SecurityIdentity securityIdentity = securityIdentitySupplier.get();
    return securityIdentity.runAs((PrivilegedAction<OperationResponse>) () -> internalExecute(operation.getOperation(),
            handler, control, operation, prepareStep, false, partialModelIndicator.isModelPartial()));
}
 
Example 3
Source File: AccessAuditContext.java    From wildfly-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Perform work with a new {@code AccessAuditContext} as a particular {@code SecurityIdentity}
 * @param inflowed was the identity inflowed from a remote process?
 * @param securityIdentity the {@code SecurityIdentity} that the specified {@code action} will run as. May be {@code null}
 * @param remoteAddress the remote address of the caller.
 * @param action the work to perform. Cannot be {@code null}
 * @param <T> the type of teh return value
 * @return the value returned by the PrivilegedAction's <code>run</code> method
 *
 * @exception NullPointerException if the specified
 *                  <code>PrivilegedExceptionAction</code> is
 *                  <code>null</code>.
 *
 * @exception SecurityException if the caller does not have permission
 *                  to invoke this method.
 */
public static <T> T doAs(final boolean inflowed, final SecurityIdentity securityIdentity, final InetAddress remoteAddress, final PrivilegedAction<T> action) {
    final AccessAuditContext previous = contextThreadLocal.get();
    try {
        contextThreadLocal.set(new AccessAuditContext(inflowed, securityIdentity, remoteAddress, previous));
        return securityIdentity != null ? securityIdentity.runAs(action) : action.run();
    } finally {
        contextThreadLocal.set(previous);
    }
}