use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class OIDCClientRegistrationTest method testClientWithNotDefinedScope.
@Test
public void testClientWithNotDefinedScope() throws Exception {
OIDCClientRepresentation clientRep = null;
OIDCClientRepresentation response = null;
String clientScope = "notdefinedscope address";
clientRep = createRep();
clientRep.setScope(clientScope);
try {
response = reg.oidc().create(clientRep);
fail("Expected 403");
} catch (ClientRegistrationException e) {
assertEquals(403, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
}
}
use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class RegistrationAccessTokenTest method assertRead.
private ClientRepresentation assertRead(String id, String registrationAccess, boolean expectSuccess) throws ClientRegistrationException {
if (expectSuccess) {
reg.auth(Auth.token(registrationAccess));
ClientRepresentation rep = reg.get(id);
assertNotNull(rep);
return rep;
} else {
reg.auth(Auth.token(registrationAccess));
try {
reg.get(client.getClientId());
fail("Expected 403");
} catch (Exception e) {
assertEquals(401, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
}
}
return null;
}
use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class InitialAccessTokenResourceTest method testPeriodicExpiration.
@Test
public void testPeriodicExpiration() throws ClientRegistrationException, InterruptedException {
ClientInitialAccessPresentation response1 = resource.create(new ClientInitialAccessCreatePresentation(1, 1));
ClientInitialAccessPresentation response2 = resource.create(new ClientInitialAccessCreatePresentation(1000, 1));
ClientInitialAccessPresentation response3 = resource.create(new ClientInitialAccessCreatePresentation(1000, 0));
ClientInitialAccessPresentation response4 = resource.create(new ClientInitialAccessCreatePresentation(0, 1));
List<ClientInitialAccessPresentation> list = resource.list();
assertEquals(4, list.size());
setTimeOffset(10);
testingClient.testing().removeExpired(REALM_NAME);
list = resource.list();
assertEquals(2, list.size());
List<String> remainingIds = list.stream().map(initialAccessPresentation -> initialAccessPresentation.getId()).collect(Collectors.toList());
Assert.assertNames(remainingIds, response2.getId(), response4.getId());
setTimeOffset(2000);
testingClient.testing().removeExpired(REALM_NAME);
list = resource.list();
assertEquals(1, list.size());
Assert.assertEquals(list.get(0).getId(), response4.getId());
// Cleanup
realm.clientInitialAccess().delete(response4.getId());
}
use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class TestsHelper method createClient.
public static String createClient(ClientRepresentation clientRepresentation) {
ClientRegistration reg = ClientRegistration.create().url(keycloakBaseUrl, testRealm).build();
reg.auth(Auth.token(initialAccessCode));
try {
clientRepresentation = reg.create(clientRepresentation);
registrationAccessCode = clientRepresentation.getRegistrationAccessToken();
ObjectMapper mapper = new ObjectMapper();
reg.auth(Auth.token(registrationAccessCode));
clientConfiguration = mapper.writeValueAsString(reg.getAdapterConfig(clientRepresentation.getClientId()));
} catch (ClientRegistrationException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return clientConfiguration;
}
Aggregations