use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class SAMLServletAdapterTest method createKeys.
private PublicKey createKeys(String priority) throws Exception {
PublicKey publicKey = NEW_KEY_PAIR.getPublic();
ComponentRepresentation rep = new ComponentRepresentation();
rep.setName("mycomponent");
rep.setParentId("demo");
rep.setProviderId(ImportedRsaKeyProviderFactory.ID);
rep.setProviderType(KeyProvider.class.getName());
MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
config.addFirst("priority", priority);
config.addFirst(Attributes.PRIVATE_KEY_KEY, NEW_KEY_PRIVATE_KEY_PEM);
rep.setConfig(config);
testRealmResource().components().add(rep);
return publicKey;
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class OIDCPublicKeyRotationAdapterTest method generateNewRealmKey.
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();
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class ClientRegistrationPoliciesTest method testRedirectUriWithDomain.
@Test
public void testRedirectUriWithDomain() throws Exception {
// Change the policy to avoid checking hosts
ComponentRepresentation trustedHostPolicyRep = findPolicyByProviderAndAuth(TrustedHostClientRegistrationPolicyFactory.PROVIDER_ID, getPolicyAnon());
trustedHostPolicyRep.getConfig().putSingle(TrustedHostClientRegistrationPolicyFactory.HOST_SENDING_REGISTRATION_REQUEST_MUST_MATCH, "false");
// Configure some trusted host and domain
trustedHostPolicyRep.getConfig().put(TrustedHostClientRegistrationPolicyFactory.TRUSTED_HOSTS, Arrays.asList("www.host.com", "*.example.com"));
realmResource().components().component(trustedHostPolicyRep.getId()).update(trustedHostPolicyRep);
// Verify client can be created with the redirectUri from trusted host and domain
OIDCClientRepresentation oidcClientRep = createRepOidc("http://www.host.com", "http://www.example.com");
reg.oidc().create(oidcClientRep);
// Remove domain from the config
trustedHostPolicyRep.getConfig().put(TrustedHostClientRegistrationPolicyFactory.TRUSTED_HOSTS, Arrays.asList("www.host.com", "www1.example.com"));
realmResource().components().component(trustedHostPolicyRep.getId()).update(trustedHostPolicyRep);
// Check new client can't be created anymore
oidcClientRep = createRepOidc("http://www.host.com", "http://www.example.com");
assertOidcFail(ClientRegOp.CREATE, oidcClientRep, 403, "URL doesn't match");
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class ClientRegistrationPoliciesTest method testClientDisabledPolicy.
@Test
// We would need to do domain name -> ip address to set trusted host
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testClientDisabledPolicy() throws Exception {
setTrustedHost("localhost");
// Assert new client is enabled
OIDCClientRepresentation client = create();
String clientId = client.getClientId();
ClientRepresentation clientRep = ApiUtil.findClientByClientId(realmResource(), clientId).toRepresentation();
Assert.assertTrue(clientRep.isEnabled());
// Add client-disabled policy
ComponentRepresentation rep = new ComponentRepresentation();
rep.setName("Clients disabled");
rep.setParentId(REALM_NAME);
rep.setProviderId(ClientDisabledClientRegistrationPolicyFactory.PROVIDER_ID);
rep.setProviderType(ClientRegistrationPolicy.class.getName());
rep.setSubType(getPolicyAnon());
Response response = realmResource().components().add(rep);
String policyId = ApiUtil.getCreatedId(response);
response.close();
// Assert new client is disabled
client = create();
clientId = client.getClientId();
clientRep = ApiUtil.findClientByClientId(realmResource(), clientId).toRepresentation();
Assert.assertFalse(clientRep.isEnabled());
// Try enable client. Should fail
clientRep.setEnabled(true);
assertFail(ClientRegOp.UPDATE, clientRep, 403, "Not permitted to enable client");
// Try update disabled client. Should pass
clientRep.setEnabled(false);
reg.update(clientRep);
// Revert
realmResource().components().component(policyId).remove();
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class ClientRegistrationPoliciesTest method testMaxClientsPolicy.
@Test
// We would need to do domain name -> ip address to set trusted host
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testMaxClientsPolicy() throws Exception {
setTrustedHost("localhost");
int clientsCount = realmResource().clients().findAll().size();
int newClientsLimit = clientsCount + 1;
// Allow to create one more client to current limit
ComponentRepresentation maxClientsPolicyRep = findPolicyByProviderAndAuth(MaxClientsClientRegistrationPolicyFactory.PROVIDER_ID, getPolicyAnon());
maxClientsPolicyRep.getConfig().putSingle(MaxClientsClientRegistrationPolicyFactory.MAX_CLIENTS, String.valueOf(newClientsLimit));
realmResource().components().component(maxClientsPolicyRep.getId()).update(maxClientsPolicyRep);
// I can register one new client
OIDCClientRepresentation client = create();
// I can't register more clients
assertOidcFail(ClientRegOp.CREATE, createRepOidc(), 403, "It's allowed to have max " + newClientsLimit + " clients per realm");
// Revert
maxClientsPolicyRep.getConfig().putSingle(MaxClientsClientRegistrationPolicyFactory.MAX_CLIENTS, String.valueOf(10000));
realmResource().components().component(maxClientsPolicyRep.getId()).update(maxClientsPolicyRep);
}
Aggregations