@Test public void testBootWithBadProviderId() throws Exception { KeycloakSession session = keycloakRule.startSession(); // set this system property System.setProperty(RealmAdapter.COMPONENT_PROVIDER_EXISTS_DISABLED, "true"); RealmModel realm = session.realms().getRealmByName("master"); String masterId = realm.getId(); UserStorageProviderModel model; model = new UserStorageProviderModel(); model.setName("bad-provider-id"); model.setPriority(2); model.setParentId(realm.getId()); model.setProviderId("error"); ComponentModel component = realm.importComponentModel(model); keycloakRule.stopSession(session, true); keycloakRule.restartServer(); keycloakRule.deployServlet("app", "/app", ApplicationServlet.class); loginSuccessAndLogout("test-user@localhost", "password"); // make sure we can list components and delete provider as this is an admin console operation Keycloak keycloakAdmin = Keycloak.getInstance( AUTH_SERVER_URL, "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID); RealmResource master = keycloakAdmin.realms().realm("master"); List<ComponentRepresentation> components = master.components().query(masterId, UserStorageProvider.class.getName()); boolean found = false; for (ComponentRepresentation rep : components) { if (rep.getName().equals("bad-provider-id")) { found = true; } } Assert.assertTrue(found); master.components().component(component.getId()).remove(); List<ComponentRepresentation> components2 = master.components().query(masterId, UserStorageProvider.class.getName()); Assert.assertEquals(components.size() - 1, components2.size()); }
private void generateNewRealmKey() { String realmId = adminClient.realm(DEMO).toRepresentation().getId(); ComponentRepresentation keys = new ComponentRepresentation(); keys.setName("generated"); keys.setProviderType(KeyProvider.class.getName()); keys.setProviderId("rsa-generated"); keys.setParentId(realmId); keys.setConfig(new MultivaluedHashMap<>()); keys.getConfig().putSingle("priority", "150"); Response response = adminClient.realm(DEMO).components().add(keys); assertEquals(201, response.getStatus()); response.close(); }
private void rotateKeys() { String activeKid = providerRealm().keys().getKeyMetadata().getActive().get("RSA"); // Rotate public keys on the parent broker String realmId = providerRealm().toRepresentation().getId(); ComponentRepresentation keys = new ComponentRepresentation(); keys.setName("generated"); keys.setProviderType(KeyProvider.class.getName()); keys.setProviderId("rsa-generated"); keys.setParentId(realmId); keys.setConfig(new MultivaluedHashMap<>()); keys.getConfig().putSingle("priority", Long.toString(System.currentTimeMillis())); Response response = providerRealm().components().add(keys); assertEquals(201, response.getStatus()); response.close(); String updatedActiveKid = providerRealm().keys().getKeyMetadata().getActive().get("RSA"); assertNotEquals(activeKid, updatedActiveKid); }