Search in sources :

Example 1 with AuthCallbackHandler

use of org.wildfly.swarm.management.AuthCallbackHandler in project wildfly-swarm by wildfly-swarm.

the class ArqSecuredManagementInterfaceTest method testClient.

@Test
@RunAsClient
public void testClient() throws Exception {
    Security.addProvider(new WildFlyElytronProvider());
    ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990, new AuthCallbackHandler("ManagementRealm", "bob", "tacos!"));
    ModelNode response = client.execute(Operations.createOperation("whoami"));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    ModelNode result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    ModelNode identity = result.get("identity");
    assertThat(identity).isNotNull();
    assertThat(identity.isDefined()).isTrue();
    assertThat(identity.get("username").asString()).isEqualTo("bob");
    // ===
    response = client.execute(Operations.createOperation("read-resource", PathAddress.pathAddress(PathElement.pathElement("deployment", "*")).toModelNode()));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    assertThat(result.getType()).isEqualTo(ModelType.LIST);
    assertThat(result.asList()).hasSize(1);
    ModelNode myapp = result.get(0);
    assertThat(myapp).isNotNull();
    assertThat(myapp.isDefined()).isTrue();
    ModelNode myappResult = myapp.get("result");
    assertThat(myappResult).isNotNull();
    assertThat(myappResult.isDefined()).isTrue();
    assertThat(myappResult.get("name").asString()).isEqualTo("ArqSecuredManagementInterfaceTest.war");
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) AuthCallbackHandler(org.wildfly.swarm.management.AuthCallbackHandler) ModelNode(org.jboss.dmr.ModelNode) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Aggregations

RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1 ModelNode (org.jboss.dmr.ModelNode)1 Test (org.junit.Test)1 WildFlyElytronProvider (org.wildfly.security.WildFlyElytronProvider)1 AuthCallbackHandler (org.wildfly.swarm.management.AuthCallbackHandler)1