org.jboss.as.controller.client.ModelControllerClient Java Examples

The following examples show how to use org.jboss.as.controller.client.ModelControllerClient. 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: Util.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ModelNode getRolloutPlan(ModelControllerClient client, String name) throws CommandFormatException {
    final ModelNode request = new ModelNode();
    request.get(OPERATION).set(READ_ATTRIBUTE);
    final ModelNode addr = request.get(ADDRESS);
    addr.add(MANAGEMENT_CLIENT_CONTENT, ROLLOUT_PLANS);
    addr.add(ROLLOUT_PLAN, name);
    request.get(NAME).set(CONTENT);
    final ModelNode response;
    try {
        response = client.execute(request);
    } catch(IOException e) {
        throw new CommandFormatException("Failed to execute request: " + e.getMessage(), e);
    }
    if(!response.hasDefined(OUTCOME)) {
        throw new CommandFormatException("Operation response if missing outcome: " + response);
    }
    if(!response.get(OUTCOME).asString().equals(SUCCESS)) {
        throw new CommandFormatException("Failed to load rollout plan: " + response);
    }
    if(!response.hasDefined(RESULT)) {
        throw new CommandFormatException("Operation response is missing result.");
    }
    return response.get(RESULT);
}
 
Example #2
Source File: AbstractStandardRolesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSuperUser() throws Exception {
    ModelControllerClient client = getClientForUser(SUPERUSER_USER, isAllowLocalAuth(), masterClientConfig);
    readWholeConfig(client, Outcome.SUCCESS, SUPERUSER_USER);
    checkStandardReads(client, null, null, SUPERUSER_USER);
    checkRootRead(client, null, null, Outcome.SUCCESS, SUPERUSER_USER);
    checkRootRead(client, MASTER, null, Outcome.SUCCESS, SUPERUSER_USER);
    checkRootRead(client, MASTER, MASTER_A, Outcome.SUCCESS, SUPERUSER_USER);
    checkSecurityDomainRead(client, null, null, Outcome.SUCCESS, SUPERUSER_USER);
    checkSecurityDomainRead(client, MASTER, MASTER_A, Outcome.SUCCESS, SUPERUSER_USER);
    checkSensitiveAttribute(client, null, null, true, SUPERUSER_USER);
    checkSensitiveAttribute(client, MASTER, MASTER_A, true, SUPERUSER_USER);

    if (readOnly) return;

    runGC(client, MASTER, null, Outcome.SUCCESS, SUPERUSER_USER);
    runGC(client, MASTER, MASTER_A, Outcome.SUCCESS, SUPERUSER_USER);
    addDeployment2(client, Outcome.SUCCESS, SUPERUSER_USER);
    addPath(client, Outcome.SUCCESS, SUPERUSER_USER);
    addSecurityDomain(client, "test2", Outcome.SUCCESS, SUPERUSER_USER);
    removeSecurityDomain(client, "test2", Outcome.SUCCESS, SUPERUSER_USER);
}
 
Example #3
Source File: IncludeAllRoleTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void test(String includeAllRole) throws Exception {
    ModelControllerClient mgmtClient = testSupport.getDomainMasterLifecycleUtil().getDomainClient();

    ModelControllerClient newUserClient = getClientForUser(NEW_USER, false, masterClientConfig);
    assertIsCallerInRole(newUserClient, NEW_ROLE, true);
    assertIsCallerInRole(newUserClient, includeAllRole, false);
    removeClientForUser(NEW_USER, false);

    setRoleMappingIncludeAll(mgmtClient, includeAllRole, true);

    newUserClient = getClientForUser(NEW_USER, false, masterClientConfig);
    assertIsCallerInRole(newUserClient, NEW_ROLE, true);
    assertIsCallerInRole(newUserClient, includeAllRole, true);
    removeClientForUser(NEW_USER, false);

    setRoleMappingIncludeAll(mgmtClient, includeAllRole, false);

    newUserClient = getClientForUser(NEW_USER, false, masterClientConfig);
    assertIsCallerInRole(newUserClient, NEW_ROLE, true);
    assertIsCallerInRole(newUserClient, includeAllRole, false);
    removeClientForUser(NEW_USER, false);
}
 
Example #4
Source File: CLIEmbedServerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void validateRemoteConnection(boolean expectSuccess) {
    ModelControllerClient mcc = null;
    try {
        mcc = TestSuiteEnvironment.getModelControllerClient();
        ModelNode op = new ModelNode();
        op.get(OP).set(READ_RESOURCE_OPERATION);
        ModelNode response = mcc.execute(op);
        assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString());

    } catch (Exception e) {
        if (expectSuccess) {
            e.printStackTrace();
            fail("Cannot connect remotely: " + e.toString());
        }
    } finally {
        StreamUtils.safeClose(mcc);
    }
}
 
Example #5
Source File: ModelControllerClientFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ModelControllerClient getClient(ControllerAddress address, CallbackHandler handler,
        boolean disableLocalAuth, SecurityFactory<SSLContext> sslContextFactory, boolean fallbackSslContext, int connectionTimeout,
        ConnectionCloseHandler closeHandler, ProtocolTimeoutHandler timeoutHandler, String clientBindAddress) throws IOException {
    // TODO - Make use of the ProtocolTimeoutHandler
    Map<String, String> saslOptions = disableLocalAuth ? DISABLED_LOCAL_AUTH : ENABLED_LOCAL_AUTH;
    ModelControllerClientConfiguration config = new ModelControllerClientConfiguration.Builder()
            .setProtocol(address.getProtocol())
            .setHostName(address.getHost())
            .setPort(address.getPort())
            .setHandler(handler)
            .setSslContextFactory(sslContextFactory)
            .setConnectionTimeout(connectionTimeout)
            .setSaslOptions(saslOptions)
            .setClientBindAddress(clientBindAddress)
            .build();
    return ModelControllerClient.Factory.create(config);
}
 
Example #6
Source File: ConstantPermissionMapper.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void create(ModelControllerClient client, CLIWrapper cli) throws Exception {
    ModelNode op = Util.createAddOperation(PATH_ELYTRON.append(CONSTANT_PERMISSION_MAPPER, name));
    if (permissions != null) {
        ModelNode permissionsNode = op.get("permissions");
        for (PermissionRef permissionRef : permissions) {
            ModelNode permissionRefNode = new ModelNode();
            permissionRefNode.get("class-name").set(permissionRef.getClassName());
            setIfNotNull(permissionRefNode, "module", permissionRef.getModule());
            setIfNotNull(permissionRefNode, "target-name", permissionRef.getTargetName());
            setIfNotNull(permissionRefNode, "action", permissionRef.getAction());
            permissionsNode.add(permissionRefNode);
        }
    }
    CoreUtils.applyUpdate(op, client);
}
 
Example #7
Source File: StatisticsControl.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
private void execute(ModelControllerClient mcc, boolean enable) {

        try {
            List<String> hosts = getDomainHosts(mcc);
            if (hosts.isEmpty()) {
                executeForServer(mcc, enable, "");
            } else {
                for (String host : hosts) {
                    List<String> servers = getDomainHostServers(mcc, host);
                    for (String server : servers) {
                        // I was trying to be too clever. This would work awesomely if WildFly would just allow it.
                        // However, this error occurs when you try to set attributes on slave servers:
                        // "User operations are not permitted to directly update the persistent configuration
                        // of a server in a managed domain."
                        // So, for now, comment this out until perhaps in the future WildFly/EAP will allow this.
                        // This means when in domain mode, the user must manually turn on statistics themselves.
                        //executeForServer(mcc, enable, String.format("/host=%s/server=%s", host, server));
                        log.debugf("Statistics for server [/host=%s/server=%s] must be enabled manually", host,
                                server);
                    }
                }
            }
        } catch (Exception e) {
            log.errorf(e, "Aborting statistics enablement");
        }
    }
 
Example #8
Source File: Util.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isValidPath(ModelControllerClient client, String... node) throws CommandLineException {
    if(node == null) {
        return false;
    }
    if(node.length % 2 != 0) {
        return false;
    }
    final ModelNode op = new ModelNode();
    op.get(ADDRESS).setEmptyList();
    op.get(OPERATION).set(VALIDATE_ADDRESS);
    final ModelNode addressValue = op.get(VALUE);
    for(int i = 0; i < node.length; i += 2) {
        addressValue.add(node[i], node[i+1]);
    }
    final ModelNode response;
    try {
        response = client.execute(op);
    } catch (IOException e) {
        throw new CommandLineException("Failed to execute " + VALIDATE_ADDRESS, e);
    }
    final ModelNode result = response.get(Util.RESULT);
    if(!result.isDefined()) {
        return false;
    }
    final ModelNode valid = result.get(Util.VALID);
    if(!valid.isDefined()) {
        return false;
    }
    return valid.asBoolean();
}
 
Example #9
Source File: ServerManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void resetServerToExpectedState(final ModelControllerClient client, final String hostName, final String serverName, final String state) throws IOException {
    final PathAddress serverConfigAddress = PathAddress.pathAddress(HOST, hostName).append(SERVER_CONFIG, serverName);
    if (!checkServerState(client, serverConfigAddress, state)) {
        final ModelNode operation = new ModelNode();
        operation.get(OP_ADDR).set(serverConfigAddress.toModelNode());
        if (state.equals("STARTED")) {
            //start server
            operation.get(OP).set(START);
        } else if (state.equals("STOPPED") || state.equals("DISABLED")) {
            //stop server
            operation.get(OP).set(STOP);
        }
        client.execute(operation);
    }
}
 
Example #10
Source File: DisableLocalAuthServerSetupTask.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void tearDown(final ManagementClient managementClient) throws Exception {
    try (final ModelControllerClient client = createNativeClient()) {

        final Operations.CompositeOperationBuilder compositeOp = Operations.CompositeOperationBuilder.create();

        // Remove the native interface
        compositeOp.addStep(Operations.createRemoveOperation(nativeInterfaceAddress));
        // Remove the native-interface
        compositeOp.addStep(Operations.createRemoveOperation(nativeSecurityRealmAddress));
        // Remove the socket binding for the native-interface
        compositeOp.addStep(Operations.createRemoveOperation(nativeSocketBindingAddress));

        // Re-enable Elytron local-auth
        ModelNode op = Operations.createReadResourceOperation(saslFactoryAddress);
        ModelNode result = client.execute(op);
        if (Operations.isSuccessfulOutcome(result)) {
            op = Operations.createOperation("map-put", saslFactoryAddress);
            op.get("name").set("properties");
            op.get("key").set(defaultUserKey);
            op.get("value").set("$local");
            compositeOp.addStep(op.clone());
        }

        // Re-enable the legacy local-auth
        op = Operations.createReadResourceOperation(managementRealmAddress);
        result = client.execute(op);
        if (Operations.isSuccessfulOutcome(result)) {
            ///core-service=management/security-realm=ManagementRealm/authentication=local:undefine-attribute(name=default-user)
            compositeOp.addStep(Operations.createWriteAttributeOperation(managementRealmAddress, "default-user", "$local"));

        }

        executeForSuccess(client, compositeOp.build());

        // Use the native client to execute the reload, completion waiting should create a new http+remote client
        ServerReload.executeReloadAndWaitForCompletion(client);
    }

}
 
Example #11
Source File: JDBCDriverNameProvider.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Collection<String> getAllCandidates(CommandContext ctx) {

    if(ctx.isDomainMode()) {
        // in the domain it's too complicated
        return Collections.emptyList();
    }

    final ModelControllerClient client = ctx.getModelControllerClient();
    if(client == null) {
        return Collections.emptyList();
    }

    final ModelNode req = new ModelNode();
    req.get(Util.OPERATION).set(Util.INSTALLED_DRIVERS_LIST);
    final ModelNode address = req.get(Util.ADDRESS);
    address.add(Util.SUBSYSTEM, Util.DATASOURCES);

    final ModelNode response;
    try {
        response = client.execute(req);
    } catch (IOException e) {
        return Collections.emptyList();
    }
    if(!response.hasDefined(Util.RESULT)) {
        return Collections.emptyList();
    }
    final List<ModelNode> nodeList = response.get(Util.RESULT).asList();
    final List<String> names = new ArrayList<String>(nodeList.size());
    for(ModelNode node : nodeList) {
        if(node.has(Util.DRIVER_NAME)) {
            names.add(node.get(Util.DRIVER_NAME).asString());
        }
    }
    return names;
}
 
Example #12
Source File: BasicOneOffPatchingScenariosTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Applies a patch using a client provided ModelControllerClient.
 * Test for WFCORE-526
 * @param path  the path to patch archive
 * @return returns true or throws an exception
 * @throws Exception  if the patch command failed
 */
protected boolean applyPatch(String path) throws Exception {
    final CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    final ModelControllerClient client = ModelControllerClient.Factory.create(TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getServerPort());
    ctx.bindClient(client);
    try {
        ctx.handle("patch apply " + path);
    } finally {
        // terminating the session closes the client too
        ctx.terminateSession();
    }
    return true;
}
 
Example #13
Source File: RBACSensitivityConstraintUtilizationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void setRequiresRead(String path, boolean requiresRead, ModelControllerClient client) throws IOException {
    ModelNode operation;
    if(requiresRead) {
        operation = createOpNode(path, WRITE_ATTRIBUTE_OPERATION);
        operation.get(VALUE).set(requiresRead);
    } else {
        operation = createOpNode(path, UNDEFINE_ATTRIBUTE_OPERATION);
    }
    operation.get(NAME).set(ModelDescriptionConstants.CONFIGURED_REQUIRES_READ);
    RbacUtil.executeOperation(client, operation, Outcome.SUCCESS);
}
 
Example #14
Source File: ValidateAddressOrOperationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void validateAddress(ModelControllerClient client, ModelNode address, boolean expectedOutcome) throws IOException {
    ModelNode operation = Util.createOperation(ValidateAddressOperationHandler.OPERATION_NAME, PathAddress.EMPTY_ADDRESS);
    operation.get(VALUE).set(address);
    ModelNode result = client.execute(operation);

    assertModelNodeOnlyContainsKeys(result, LEGAL_ADDRESS_RESP_FIELDS);
    assertModelNodeOnlyContainsKeys(result.get(RESULT), VALID, PROBLEM);
    assertEquals(result.toString(), expectedOutcome, result.get(RESULT, VALID).asBoolean());
    assertEquals(result.toString(), !expectedOutcome, result.get(RESULT).hasDefined(PROBLEM));
    if (!expectedOutcome) {
        assertTrue(result.get(RESULT, PROBLEM).asString().contains("WFLYCTL0335"));
    }
}
 
Example #15
Source File: DomainTestUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Check if a path address exists.
 *
 * @param address the path address
 * @param client the controller client
 * @return whether the child exists or not
 * @throws IOException
 * @throws MgmtOperationException
 */
public static boolean exists(PathAddress address, ModelControllerClient client) throws IOException, MgmtOperationException {
    final PathElement element = address.getLastElement();
    final PathAddress subAddress = address.subAddress(0, address.size() -1);
    final boolean checkType = element.isWildcard();
    final ModelNode e;
    final ModelNode operation;
    if(checkType) {
        e = new ModelNode().set(element.getKey());
        operation = createOperation(READ_CHILDREN_TYPES_OPERATION, subAddress);
    } else {
        e = new ModelNode().set(element.getValue());
        operation = createOperation(READ_CHILDREN_NAMES_OPERATION, subAddress);
        operation.get(CHILD_TYPE).set(element.getKey());
    }
    try {
        final ModelNode result = executeForResult(operation, client);
        return result.asList().contains(e);
    } catch (MgmtOperationException ex) {
        if(! checkType) {
            final String failureDescription = ex.getResult().get(FAILURE_DESCRIPTION).asString();
            if(failureDescription.contains("WFLYCTL0202") && failureDescription.contains(element.getKey())) {
                return false;
            }
        }
        throw ex;
    }
}
 
Example #16
Source File: JmxAuditLogTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void applyUpdate(final ModelControllerClient client, ModelNode update, boolean allowFailure) throws Exception {
    ModelNode result = client.execute(new OperationBuilder(update).build());
    if (result.hasDefined("outcome") && (allowFailure || "success".equals(result.get("outcome").asString()))) {
        if (result.hasDefined("result")) {
            System.out.println(result.get("result"));
        }
    } else if (result.hasDefined("failure-description")) {
        throw new RuntimeException(result.get("failure-description").toString());
    } else {
        throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
    }
}
 
Example #17
Source File: AbstractStandardRolesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDeployer() throws Exception {
    ModelControllerClient client = getClientForUser(DEPLOYER_USER, isAllowLocalAuth(), masterClientConfig);
    readWholeConfig(client, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    checkStandardReads(client, null, null, DEPLOYER_USER);
    checkRootRead(client, null, null, Outcome.SUCCESS, DEPLOYER_USER);
    checkRootRead(client, MASTER, null, Outcome.SUCCESS, DEPLOYER_USER);
    checkRootRead(client, MASTER, MASTER_A, Outcome.SUCCESS, DEPLOYER_USER);
    checkSecurityDomainRead(client, null, null, Outcome.HIDDEN, DEPLOYER_USER);
    checkSecurityDomainRead(client, MASTER, MASTER_A, Outcome.HIDDEN, DEPLOYER_USER);
    checkSensitiveAttribute(client, null, null, false, DEPLOYER_USER);
    checkSensitiveAttribute(client, MASTER, MASTER_A, false, DEPLOYER_USER);

    if (readOnly) return;

    runGC(client, MASTER, null, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    runGC(client, MASTER, MASTER_A, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    addDeployment2(client, Outcome.SUCCESS, DEPLOYER_USER);
    addPath(client, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    removeSecurityDomain(client, Outcome.HIDDEN, DEPLOYER_USER);
    restartServer(client, MASTER, MASTER_A, Outcome.UNAUTHORIZED, DEPLOYER_USER);

    // Deployer can't shutdown
    testWCORE1067(client, DEPLOYER_USER);

    stopServer(client, MASTER, MASTER_A, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    killServer(client, MASTER, MASTER_A, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    destroyServer(client, MASTER, MASTER_A, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    killServersInGroup(client, Outcome.UNAUTHORIZED, DEPLOYER_USER);
    destroyServersInGroup(client, Outcome.UNAUTHORIZED, DEPLOYER_USER);
}
 
Example #18
Source File: DMRDriver.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
public DMRDriver(ModelControllerClient client, MonitoredEndpoint<EndpointConfiguration> endpoint,
        ProtocolDiagnostics diagnostics) {
    super();
    this.client = client;
    this.endpoint = endpoint;
    this.diagnostics = diagnostics;
}
 
Example #19
Source File: ServerRestartRequiredTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode executeOperation(final ModelNode op, final ModelControllerClient modelControllerClient) throws IOException, MgmtOperationException {
    ModelNode ret = modelControllerClient.execute(op);

    if (! SUCCESS.equals(ret.get(OUTCOME).asString())) {
        throw new MgmtOperationException("Management operation failed: ", op, ret);
    }
    return ret.get(RESULT);
}
 
Example #20
Source File: AbstractITest.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
protected void assertResourceExists(ModelControllerClient mcc, ModelNode address, boolean expectedExists)
        throws IOException {
    ModelNode request = new ModelNode();
    request.get(ModelDescriptionConstants.ADDRESS).set(address);
    request.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_RESOURCE_OPERATION);
    request.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(true);
    ModelNode result = mcc.execute(request);

    String message = String.format("Model node [%s] %s unexpectedly", address.toString(),
            (expectedExists ? "does not exist" : "exists"));
    AssertJUnit.assertTrue(String.format(message, result),
            Operations.isSuccessfulOutcome(result) == expectedExists);

}
 
Example #21
Source File: RolesIntegrityCheckingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void addRoleMapping(ModelControllerClient client, String roleName, Outcome expectedOutcome) throws IOException {
    ModelNode operation = Util.createOperation(ADD, pathAddress(
            pathElement(CORE_SERVICE, MANAGEMENT),
            pathElement(ACCESS, ModelDescriptionConstants.AUTHORIZATION),
            pathElement(ROLE_MAPPING, roleName)
    ));
    RbacUtil.executeOperation(client, operation, expectedOutcome);
}
 
Example #22
Source File: AbstractPropertiesRoleMappingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void test(String user, String... expectedRoles) throws IOException {
    Set<String> expectedRolesSet = new HashSet<String>(Arrays.asList(expectedRoles));

    ModelControllerClient client = getClientForUser(user);
    for (String role : allStandardRoles()) {
        assertIsCallerInRole(client, role, expectedRolesSet.contains(role));
    }
}
 
Example #23
Source File: CoreAbstractSecurityDomainSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected static void applyUpdate(final ModelControllerClient client, ModelNode update, boolean allowFailure) throws IOException {
    ModelNode result = client.execute(new OperationBuilder(update).build());
    if (result.hasDefined("outcome") && (allowFailure || "success".equals(result.get("outcome").asString()))) {
        if (result.hasDefined("result")) {
            LOGGER.trace(result.get("result"));
        }
    } else if (result.hasDefined("failure-description")) {
        throw new RuntimeException(result.get("failure-description").toString());
    } else {
        throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
    }
}
 
Example #24
Source File: HTTPSManagementInterfaceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected static void startAndSetupContainer(String provider) throws Exception {
    providerToUse = provider;
    controller.startInAdminMode();

    try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()){
        ManagementClient managementClient = controller.getClient();

        serverSetup(managementClient);
        managementNativeRealmSetup.setup(client);
    }
    // To apply new security realm settings for http interface reload of
    // server is required
    reloadServer();
}
 
Example #25
Source File: CoreAbstractSecurityDomainSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected static void applyUpdates(final ModelControllerClient client, final List<ModelNode> updates) {
    for (ModelNode update : updates) {
        try {
            applyUpdate(client, update, false);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example #26
Source File: MainOperationAccessRequirement.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected boolean checkAccess(CommandContext ctx) {
    final ModelControllerClient client = ctx.getModelControllerClient();
    if(client == null) {
        return false;
    }
    return CLIAccessControl.isExecute(client, address, operation);
}
 
Example #27
Source File: RoleMappingRuntimeReconfigurationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void addIfNotExists(String address, ModelControllerClient client, String... attributePairs) throws IOException {
    ModelNode readOp = createOpNode(address, READ_RESOURCE_OPERATION);
    if (FAILED.equals(client.execute(readOp).get(OUTCOME).asString())) {
        ModelNode addOp = createOpNode(address, ADD);
        for (String attr : attributePairs) {
            String[] parts = attr.split("=");
            addOp.get(parts[0]).set(parts[1]);
        }
        RbacUtil.executeOperation(client, addOp, Outcome.SUCCESS);
    }
    checkIfExists(address, true, client);
}
 
Example #28
Source File: RunMojo.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Process startContainer(final CommandBuilder commandBuilder) throws IOException, InterruptedException, TimeoutException {
    final Launcher launcher = Launcher.of(commandBuilder)
            .inherit();
    if (env != null) {
        launcher.addEnvironmentVariables(env);
    }
    final Process process = launcher.launch();
    try (ModelControllerClient client = createClient()) {
        ServerHelper.waitForStandalone(process, client, startupTimeout);
    }
    return process;
}
 
Example #29
Source File: AccessIdentityConfigurator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String setAccessIdentity(ModelControllerClient client, String domainToSet) throws Exception {
    String origDomainValue = null;
    ModelNode op = Util.createEmptyOperation("read-attribute", IDENTITY_ADDR);
    op.get("name").set("security-domain");
    ModelNode result = client.execute(op);
    boolean identityExists = Operations.isSuccessfulOutcome(result);
    op = null;
    if (identityExists) {
        result = Operations.readResult(result);
        origDomainValue = result.isDefined() ? result.asString() : null;

        if (domainToSet == null) {
            op = Util.createRemoveOperation(IDENTITY_ADDR);
        } else if (!domainToSet.equals(origDomainValue)) {
            op = Util.createEmptyOperation("write-attribute", IDENTITY_ADDR);
            op.get("name").set("security-domain");
            op.get("value").set(domainToSet);
        }
    } else if (domainToSet != null) {
        op = Util.createAddOperation(IDENTITY_ADDR);
        op.get("security-domain").set(domainToSet);
    }

    if (op!=null) {
        CoreUtils.applyUpdate(op, client);
    }
    return origDomainValue;
}
 
Example #30
Source File: CoreUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void applyUpdate(ModelNode update, final ModelControllerClient client) throws Exception {
    ModelNode result = client.execute(new OperationBuilder(update).build());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.info("Client update: " + update);
        LOGGER.info("Client update result: " + result);
    }
    if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
        LOGGER.debug("Operation succeeded.");
    } else if (result.hasDefined("failure-description")) {
        throw new RuntimeException(result.get("failure-description").toString());
    } else {
        throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
    }
}