use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class AbstractMigrationTest method testLdapKerberosMigration_2_5_0.
protected void testLdapKerberosMigration_2_5_0() {
log.info("testing ldap kerberos migration");
RealmRepresentation realmRep = migrationRealm2.toRepresentation();
List<ComponentRepresentation> components = migrationRealm2.components().query(realmRep.getId(), UserStorageProvider.class.getName());
assertEquals(2, components.size());
boolean testedLdap = false;
boolean testedKerberos = false;
for (ComponentRepresentation component : components) {
if (component.getName().equals("ldap-provider")) {
assertEquals("2", component.getConfig().getFirst(PrioritizedComponentModel.PRIORITY));
assertEquals("READ_ONLY", component.getConfig().getFirst(LDAPConstants.EDIT_MODE));
assertEquals("true", component.getConfig().getFirst(LDAPConstants.SYNC_REGISTRATIONS));
assertEquals(LDAPConstants.VENDOR_RHDS, component.getConfig().getFirst(LDAPConstants.VENDOR));
assertEquals("uid", component.getConfig().getFirst(LDAPConstants.USERNAME_LDAP_ATTRIBUTE));
assertEquals("uid", component.getConfig().getFirst(LDAPConstants.RDN_LDAP_ATTRIBUTE));
assertEquals("nsuniqueid", component.getConfig().getFirst(LDAPConstants.UUID_LDAP_ATTRIBUTE));
assertEquals("inetOrgPerson, organizationalPerson", component.getConfig().getFirst(LDAPConstants.USER_OBJECT_CLASSES));
assertEquals("http://localhost", component.getConfig().getFirst(LDAPConstants.CONNECTION_URL));
assertEquals("dn", component.getConfig().getFirst(LDAPConstants.USERS_DN));
assertEquals(LDAPConstants.AUTH_TYPE_NONE, component.getConfig().getFirst(LDAPConstants.AUTH_TYPE));
assertEquals("true", component.getConfig().getFirst(KerberosConstants.ALLOW_KERBEROS_AUTHENTICATION));
assertEquals("realm", component.getConfig().getFirst(KerberosConstants.KERBEROS_REALM));
assertEquals("principal", component.getConfig().getFirst(KerberosConstants.SERVER_PRINCIPAL));
assertEquals("keytab", component.getConfig().getFirst(KerberosConstants.KEYTAB));
testedLdap = true;
} else if (component.getName().equals("kerberos-provider")) {
assertEquals("3", component.getConfig().getFirst(PrioritizedComponentModel.PRIORITY));
assertEquals("realm", component.getConfig().getFirst(KerberosConstants.KERBEROS_REALM));
assertEquals("principal", component.getConfig().getFirst(KerberosConstants.SERVER_PRINCIPAL));
assertEquals("keytab", component.getConfig().getFirst(KerberosConstants.KEYTAB));
}
}
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedEcdsaKeyProviderTest method supportedEc.
private String supportedEc(String ecInNistRep) {
long priority = System.currentTimeMillis();
ComponentRepresentation rep = createRep("valid", GeneratedEcdsaKeyProviderFactory.ID);
rep.setConfig(new MultivaluedHashMap<>());
rep.getConfig().putSingle("priority", Long.toString(priority));
if (ecInNistRep != null) {
rep.getConfig().putSingle(ECDSA_ELLIPTIC_CURVE_KEY, ecInNistRep);
} else {
ecInNistRep = DEFAULT_EC;
}
Response response = adminClient.realm(TEST_REALM_NAME).components().add(rep);
String id = ApiUtil.getCreatedId(response);
getCleanup().addComponentId(id);
response.close();
ComponentRepresentation createdRep = adminClient.realm(TEST_REALM_NAME).components().component(id).toRepresentation();
// stands for the number of properties in the key provider config
assertEquals(2, createdRep.getConfig().size());
assertEquals(Long.toString(priority), createdRep.getConfig().getFirst("priority"));
assertEquals(ecInNistRep, createdRep.getConfig().getFirst(ECDSA_ELLIPTIC_CURVE_KEY));
KeysMetadataRepresentation keys = adminClient.realm(TEST_REALM_NAME).keys().getKeyMetadata();
KeysMetadataRepresentation.KeyMetadataRepresentation key = null;
for (KeyMetadataRepresentation k : keys.getKeys()) {
if (KeyType.EC.equals(k.getType()) && id.equals(k.getProviderId())) {
key = k;
break;
}
}
assertNotNull(key);
assertEquals(id, key.getProviderId());
assertEquals(KeyType.EC, key.getType());
assertEquals(priority, key.getProviderPriority());
// created key's component id
return id;
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class FallbackKeyProviderTest method fallbackAfterDeletingAllKeysInRealm.
@Test
public void fallbackAfterDeletingAllKeysInRealm() {
String realmId = realmsResouce().realm("test").toRepresentation().getId();
List<ComponentRepresentation> providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
assertEquals(3, providers.size());
for (ComponentRepresentation p : providers) {
realmsResouce().realm("test").components().component(p.getId()).remove();
}
providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
assertEquals(0, providers.size());
oauth.doLogin("test-user@localhost", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
OAuthClient.AccessTokenResponse response = oauth.doAccessTokenRequest(code, "password");
assertNotNull(response.getAccessToken());
Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
assertProviders(providers, "fallback-RS256", "fallback-HS256");
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class FallbackKeyProviderTest method assertProviders.
private void assertProviders(List<ComponentRepresentation> providers, String... expected) {
List<String> names = new LinkedList<>();
for (ComponentRepresentation p : providers) {
names.add(p.getName());
}
assertThat(names, hasSize(expected.length));
assertThat(names, containsInAnyOrder(expected));
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedHmacKeyProviderTest method largeKeysize.
@Test
public void largeKeysize() {
long priority = System.currentTimeMillis();
ComponentRepresentation rep = createRep("valid", GeneratedHmacKeyProviderFactory.ID);
rep.setConfig(new MultivaluedHashMap<>());
rep.getConfig().putSingle("priority", Long.toString(priority));
rep.getConfig().putSingle("secretSize", "512");
Response response = adminClient.realm("test").components().add(rep);
String id = ApiUtil.getCreatedId(response);
response.close();
ComponentRepresentation createdRep = adminClient.realm("test").components().component(id).toRepresentation();
assertEquals(2, createdRep.getConfig().size());
assertEquals("512", createdRep.getConfig().getFirst("secretSize"));
KeysMetadataRepresentation keys = adminClient.realm("test").keys().getKeyMetadata();
KeysMetadataRepresentation.KeyMetadataRepresentation key = null;
for (KeysMetadataRepresentation.KeyMetadataRepresentation k : keys.getKeys()) {
if (k.getAlgorithm().equals(Algorithm.HS256)) {
key = k;
break;
}
}
assertEquals(id, key.getProviderId());
assertEquals(KeyType.OCT, key.getType());
assertEquals(priority, key.getProviderPriority());
ComponentRepresentation component = testingClient.server("test").fetch(RunHelpers.internalComponent(id));
assertEquals(512, Base64Url.decode(component.getConfig().getFirst("secret")).length);
}
Aggregations