use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedRsaKeyProviderTest method defaultKeysize.
private void defaultKeysize(String providerId, KeyUse keyUse) throws Exception {
long priority = System.currentTimeMillis();
ComponentRepresentation rep = createRep("valid", providerId);
rep.setConfig(new MultivaluedHashMap<>());
rep.getConfig().putSingle("priority", Long.toString(priority));
Response response = adminClient.realm("test").components().add(rep);
String id = ApiUtil.getCreatedId(response);
getCleanup().addComponentId(id);
response.close();
ComponentRepresentation createdRep = adminClient.realm("test").components().component(id).toRepresentation();
assertEquals(1, createdRep.getConfig().size());
assertEquals(Long.toString(priority), createdRep.getConfig().getFirst("priority"));
KeysMetadataRepresentation keys = adminClient.realm("test").keys().getKeyMetadata();
KeysMetadataRepresentation.KeyMetadataRepresentation key = keys.getKeys().get(0);
assertEquals(id, key.getProviderId());
assertEquals(AlgorithmType.RSA.name(), key.getType());
assertEquals(priority, key.getProviderPriority());
assertEquals(2048, ((RSAPublicKey) PemUtils.decodePublicKey(keys.getKeys().get(0).getPublicKey())).getModulus().bitLength());
assertEquals(keyUse, key.getUse());
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedRsaKeyProviderTest method invalidKeysize.
private void invalidKeysize(String providerId) throws Exception {
ComponentRepresentation rep = createRep("invalid", providerId);
rep.getConfig().putSingle("keySize", "1234");
Response response = adminClient.realm("test").components().add(rep);
assertErrror(response, "'Key size' should be 1024, 2048 or 4096");
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedRsaKeyProviderTest method updatePriority.
private void updatePriority(String providerId, KeyUse keyUse) throws Exception {
long priority = System.currentTimeMillis();
ComponentRepresentation rep = createRep("valid", providerId);
rep.setConfig(new MultivaluedHashMap<>());
rep.getConfig().putSingle("priority", Long.toString(priority));
Response response = adminClient.realm("test").components().add(rep);
String id = ApiUtil.getCreatedId(response);
getCleanup().addComponentId(id);
response.close();
KeysMetadataRepresentation keys = adminClient.realm("test").keys().getKeyMetadata();
String publicKey = keys.getKeys().get(0).getPublicKey();
ComponentRepresentation createdRep = adminClient.realm("test").components().component(id).toRepresentation();
priority += 1000;
createdRep.getConfig().putSingle("priority", Long.toString(priority));
adminClient.realm("test").components().component(id).update(createdRep);
keys = adminClient.realm("test").keys().getKeyMetadata();
String publicKey2 = keys.getKeys().get(0).getPublicKey();
assertEquals(publicKey, publicKey2);
assertEquals(keyUse, keys.getKeys().get(0).getUse());
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedRsaKeyProviderTest method updateKeysize.
private void updateKeysize(String providerId, KeyUse keyUse) throws Exception {
long priority = System.currentTimeMillis();
ComponentRepresentation rep = createRep("valid", providerId);
rep.setConfig(new MultivaluedHashMap<>());
rep.getConfig().putSingle("priority", Long.toString(priority));
Response response = adminClient.realm("test").components().add(rep);
String id = ApiUtil.getCreatedId(response);
getCleanup().addComponentId(id);
response.close();
KeysMetadataRepresentation keys = adminClient.realm("test").keys().getKeyMetadata();
String publicKey = keys.getKeys().get(0).getPublicKey();
ComponentRepresentation createdRep = adminClient.realm("test").components().component(id).toRepresentation();
createdRep.getConfig().putSingle("keySize", "4096");
adminClient.realm("test").components().component(id).update(createdRep);
keys = adminClient.realm("test").keys().getKeyMetadata();
String publicKey2 = keys.getKeys().get(0).getPublicKey();
assertNotEquals(publicKey, publicKey2);
assertEquals(2048, ((RSAPublicKey) PemUtils.decodePublicKey(publicKey)).getModulus().bitLength());
assertEquals(4096, ((RSAPublicKey) PemUtils.decodePublicKey(publicKey2)).getModulus().bitLength());
assertEquals(keyUse, keys.getKeys().get(0).getUse());
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class JavaKeystoreKeyProviderTest method invalidKeyPassword.
@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void invalidKeyPassword() throws Exception {
ComponentRepresentation rep = createRep("valid", System.currentTimeMillis());
rep.getConfig().putSingle("keyPassword", "invalid");
Response response = adminClient.realm("test").components().add(rep);
assertErrror(response, "Failed to load keys. Keystore on server can not be recovered.");
}
Aggregations