Java Code Examples for org.jboss.as.controller.OperationContext#authorizeOperation()

The following examples show how to use org.jboss.as.controller.OperationContext#authorizeOperation() . 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: ReadOperationDescriptionHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    String operationName = NAME.resolveModelAttribute(context, operation).asString();
    boolean accessControl = ACCESS_CONTROL.resolveModelAttribute(context, operation).asBoolean();

    final DescribedOp describedOp = getDescribedOp(context, operationName, operation, !accessControl);
    if (describedOp == null || (context.getProcessType() == ProcessType.DOMAIN_SERVER &&
            !(describedOp.flags.contains(OperationEntry.Flag.RUNTIME_ONLY) || describedOp.flags.contains(OperationEntry.Flag.READ_ONLY)))) {
        throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.operationNotRegistered(operationName, context.getCurrentAddress()));
    } else {
        ModelNode result = describedOp.getDescription();

        if (accessControl) {
            final PathAddress address = context.getCurrentAddress();
            ModelNode operationToCheck = Util.createOperation(operationName, address);
            operationToCheck.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS));
            AuthorizationResult authorizationResult = context.authorizeOperation(operationToCheck);
            result.get(ACCESS_CONTROL.getName(), EXECUTE).set(authorizationResult.getDecision() == Decision.PERMIT);

        }

        context.getResult().set(result);
    }
}
 
Example 2
Source File: ReadOperationNamesHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    final ImmutableManagementResourceRegistration registry = context.getResourceRegistration();
    if (registry == null) {
        throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noSuchResourceType(context.getCurrentAddress()));
    }
    final Map<String, OperationEntry> operations = registry.getOperationDescriptions(PathAddress.EMPTY_ADDRESS, true);

    final boolean accessControl = ACCESS_CONTROL.resolveModelAttribute(context, operation).asBoolean();

    final ModelNode result = new ModelNode();
    if (operations.size() > 0) {
        final PathAddress address = context.getCurrentAddress();
        for (final Map.Entry<String, OperationEntry> entry : operations.entrySet()) {
            if (isVisible(entry.getValue(), context)) {
                boolean add = true;
                if (accessControl) {
                    ModelNode operationToCheck = Util.createOperation(entry.getKey(), address);
                    operationToCheck.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS));
                    AuthorizationResult authorizationResult = context.authorizeOperation(operationToCheck);
                    add = authorizationResult.getDecision() == Decision.PERMIT;
                }

                if (add) {
                    result.add(entry.getKey());
                } else {
                    context.getResponseHeaders().get(ModelDescriptionConstants.ACCESS_CONTROL, FILTERED_OPERATIONS).add(entry.getKey());
                }
            }
        }
    } else {
        result.setEmptyList();
    }
    context.getResult().set(result);
}
 
Example 3
Source File: ReadResourceDescriptionHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void addOperationAuthorizationResult(OperationContext context, ModelNode result, ModelNode operation, String operationName) {
    AuthorizationResult authorizationResult = context.authorizeOperation(operation);
    result.get(EXECUTE).set(authorizationResult.getDecision() == Decision.PERMIT);
}