Search in sources :

Example 1 with CliException

use of org.wildfly.extras.creaper.core.online.CliException in project keycloak by keycloak.

the class ConsoleProtectionTest method beforeConsoleProtectionTest.

@Before
public void beforeConsoleProtectionTest() throws IOException, OperationException {
    Assume.assumeTrue("This testClass doesn't work with phantomjs", !"phantomjs".equals(System.getProperty("js.browser")));
    try (OnlineManagementClient clientWorkerNodeClient = AppServerTestEnricher.getManagementClient()) {
        Operations operations = new Operations(clientWorkerNodeClient);
        Assume.assumeTrue(operations.exists(Address.subsystem("elytron").and("security-domain", "KeycloakDomain")));
        // Create a realm for both wildfly console and mgmt interface
        clientWorkerNodeClient.execute("/subsystem=keycloak/realm=jboss-infra:add(auth-server-url=" + getAuthServerContextRoot() + "/auth,realm-public-key=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB)");
        // Create a secure-deployment in order to protect mgmt interface
        clientWorkerNodeClient.execute("/subsystem=keycloak/secure-deployment=wildfly-management:add(realm=jboss-infra,resource=wildfly-management,principal-attribute=preferred_username,bearer-only=true,ssl-required=EXTERNAL)");
        // Protect HTTP mgmt interface with Keycloak adapter
        clientWorkerNodeClient.execute("/core-service=management/management-interface=http-interface:undefine-attribute(name=security-realm)");
        clientWorkerNodeClient.execute("/subsystem=elytron/http-authentication-factory=keycloak-mgmt-http-authentication:add(security-domain=KeycloakDomain,http-server-mechanism-factory=wildfly-management,mechanism-configurations=[{mechanism-name=KEYCLOAK,mechanism-realm-configurations=[{realm-name=KeycloakOIDCRealm,realm-mapper=keycloak-oidc-realm-mapper}]}])");
        clientWorkerNodeClient.execute("/core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory,value=keycloak-mgmt-http-authentication)");
        clientWorkerNodeClient.execute("/core-service=management/management-interface=http-interface:write-attribute(name=http-upgrade, value={enabled=true, sasl-authentication-factory=management-sasl-authentication})");
        // Enable RBAC where roles are obtained from the identity
        clientWorkerNodeClient.execute("/core-service=management/access=authorization:write-attribute(name=provider,value=rbac)");
        clientWorkerNodeClient.execute("/core-service=management/access=authorization:write-attribute(name=use-identity-roles,value=true)");
        // Create a secure-server in order to publish the wildfly console configuration via mgmt interface
        clientWorkerNodeClient.execute("/subsystem=keycloak/secure-server=wildfly-console:add(realm=jboss-infra,resource=wildfly-console,public-client=true)");
        log.debug("Reloading the server");
        new Administration(clientWorkerNodeClient).reload();
        log.debug("Reloaded");
    } catch (CliException | IOException | InterruptedException | TimeoutException cause) {
        throw new RuntimeException("Failed to configure app server", cause);
    }
    DroneUtils.addWebDriver(jsDriver);
    log.debug("Added jsDriver");
}
Also used : Administration(org.wildfly.extras.creaper.core.online.operations.admin.Administration) CliException(org.wildfly.extras.creaper.core.online.CliException) OnlineManagementClient(org.wildfly.extras.creaper.core.online.OnlineManagementClient) IOException(java.io.IOException) Operations(org.wildfly.extras.creaper.core.online.operations.Operations) TimeoutException(java.util.concurrent.TimeoutException) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Before (org.junit.Before)1 CliException (org.wildfly.extras.creaper.core.online.CliException)1 OnlineManagementClient (org.wildfly.extras.creaper.core.online.OnlineManagementClient)1 Operations (org.wildfly.extras.creaper.core.online.operations.Operations)1 Administration (org.wildfly.extras.creaper.core.online.operations.admin.Administration)1