use of org.wildfly.extras.creaper.core.online.OnlineManagementClient 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");
}
use of org.wildfly.extras.creaper.core.online.OnlineManagementClient in project keycloak by keycloak.
the class AbstractHostnameTest method executeCli.
private void executeCli(String... commands) throws Exception {
OnlineManagementClient client = AuthServerTestEnricher.getManagementClient();
Administration administration = new Administration(client);
LOGGER.debug("Running CLI commands:");
for (String c : commands) {
LOGGER.debug(c);
client.execute(c).assertSuccess();
}
LOGGER.debug("Done");
administration.reload();
client.close();
}
use of org.wildfly.extras.creaper.core.online.OnlineManagementClient in project keycloak by keycloak.
the class KeycloakContainerEventsController method deployAndDropAllTables.
/**
* Drop all KeycloakDS database tables using liquibase dropAll method.
* @param restartContainer to pass more information from test annotation
*/
private void deployAndDropAllTables(RestartContainer restartContainer) {
for (Container c : containerRegistry.get().getContainers()) {
String containerName = c.getName();
log.infof("Deploy and dropAll at '%s'", containerName);
if (containerName == null || !containerName.startsWith("auth-server")) {
log.infof("Skipping deployAndDropAllTables for '%s'", containerName);
continue;
}
ContainerDef conf = c.getContainerConfiguration();
String mgmtPort = conf.getContainerProperty("managementPort");
if (mgmtPort == null || mgmtPort.isEmpty()) {
log.warnf("Skipping deployAndDropAllTables for '%s' due to not defined 'managementPort' property.", containerName);
continue;
}
OnlineManagementClient client = null;
try {
client = ManagementClient.online(OnlineOptions.standalone().hostAndPort("localhost", Integer.valueOf(mgmtPort).intValue()).build());
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
WebArchive war = ShrinkWrap.create(WebArchive.class, DropAllServlet.WAR_NAME).addClass(DropAllServlet.class).addAsWebInfResource(new StringAsset(DropAllServlet.jbossDeploymentStructureContent), "jboss-deployment-structure.xml");
client.apply(new Deploy.Builder(war.as(ZipExporter.class).exportAsInputStream(), DropAllServlet.WAR_NAME, true).build());
if (restartContainer.intializeDatabaseWait() > 0) {
try {
Thread.sleep(restartContainer.intializeDatabaseWait());
} catch (InterruptedException e) {
log.warn(e);
}
}
client.apply(new Undeploy.Builder(DropAllServlet.WAR_NAME).build());
} catch (CommandFailedException e) {
log.error(e);
throw new RuntimeException(e);
}
}
}
Aggregations