use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedRsaKeyProviderTest method createRep.
protected ComponentRepresentation createRep(String name, String providerId) {
ComponentRepresentation rep = new ComponentRepresentation();
rep.setName(name);
rep.setParentId("test");
rep.setProviderId(providerId);
rep.setProviderType(KeyProvider.class.getName());
rep.setConfig(new MultivaluedHashMap<>());
return rep;
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class JavaKeystoreKeyProviderTest method invalidKeystore.
@Test
public void invalidKeystore() throws Exception {
ComponentRepresentation rep = createRep("valid", System.currentTimeMillis());
rep.getConfig().putSingle("keystore", "/nosuchfile");
Response response = adminClient.realm("test").components().add(rep);
assertErrror(response, "Failed to load keys. File not found on server.");
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class JavaKeystoreKeyProviderTest method invalidKeyAlias.
@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void invalidKeyAlias() throws Exception {
ComponentRepresentation rep = createRep("valid", System.currentTimeMillis());
rep.getConfig().putSingle("keyAlias", "invalid");
Response response = adminClient.realm("test").components().add(rep);
assertErrror(response, "Failed to load keys. Error creating X509v1Certificate.");
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class FallbackKeyProviderTest method differentAlgorithms.
@Test
public void differentAlgorithms() {
String realmId = realmsResouce().realm("test").toRepresentation().getId();
String[] algorithmsToTest = new String[] { Algorithm.RS384, Algorithm.RS512, Algorithm.PS256, Algorithm.PS384, Algorithm.PS512, Algorithm.ES256, Algorithm.ES384, Algorithm.ES512 };
oauth.doLogin("test-user@localhost", "password");
for (String algorithm : algorithmsToTest) {
RealmRepresentation rep = realmsResouce().realm("test").toRepresentation();
rep.setDefaultSignatureAlgorithm(algorithm);
realmsResouce().realm("test").update(rep);
oauth.openLoginForm();
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
OAuthClient.AccessTokenResponse response = oauth.doAccessTokenRequest(code, "password");
assertNotNull(response.getAccessToken());
}
List<ComponentRepresentation> providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
List<String> expected = new LinkedList<>();
expected.add("rsa");
expected.add("hmac-generated");
expected.add("aes-generated");
for (String a : algorithmsToTest) {
expected.add("fallback-" + a);
}
assertProviders(providers, expected.toArray(new String[providers.size()]));
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GeneratedHmacKeyProviderTest method updateKeysize.
@Test
public void updateKeysize() throws Exception {
long priority = System.currentTimeMillis();
ComponentRepresentation rep = createRep("valid", GeneratedHmacKeyProviderFactory.ID);
rep.setConfig(new MultivaluedHashMap<>());
rep.getConfig().putSingle("priority", Long.toString(priority));
Response response = adminClient.realm("test").components().add(rep);
String id = ApiUtil.getCreatedId(response);
response.close();
ComponentRepresentation component = testingClient.server("test").fetch(RunHelpers.internalComponent(id));
assertEquals(64, Base64Url.decode(component.getConfig().getFirst("secret")).length);
ComponentRepresentation createdRep = adminClient.realm("test").components().component(id).toRepresentation();
createdRep.getConfig().putSingle("secretSize", "512");
adminClient.realm("test").components().component(id).update(createdRep);
component = testingClient.server("test").fetch(RunHelpers.internalComponent(id));
assertEquals(512, Base64Url.decode(component.getConfig().getFirst("secret")).length);
}
Aggregations