use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.
the class AccountRestServiceTest method createConsentForClientWithoutPermissionWithPut.
@Test
public void createConsentForClientWithoutPermissionWithPut() throws IOException {
TokenUtil token = new TokenUtil("view-consent-access", "password");
String appId = "security-admin-console";
ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
consentScopeRepresentation.setId(clientScopeRepresentation.getId());
ConsentRepresentation requestedConsent = new ConsentRepresentation();
requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
SimpleHttp.Response response = SimpleHttp.doPut(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asResponse();
assertEquals(403, response.getStatus());
}
use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.
the class AccountRestServiceTest method createConsentForNotExistingClient.
@Test
public void createConsentForNotExistingClient() throws IOException {
TokenUtil token = new TokenUtil("manage-consent-access", "password");
String appId = "not-existing";
ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
consentScopeRepresentation.setId(clientScopeRepresentation.getId());
ConsentRepresentation requestedConsent = new ConsentRepresentation();
requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
SimpleHttp.Response response = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asResponse();
assertEquals(404, response.getStatus());
}
use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.
the class AccountRestServiceTest method createConsentForNotExistingClientWithPut.
@Test
public void createConsentForNotExistingClientWithPut() throws IOException {
TokenUtil token = new TokenUtil("manage-consent-access", "password");
String appId = "not-existing";
ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
consentScopeRepresentation.setId(clientScopeRepresentation.getId());
ConsentRepresentation requestedConsent = new ConsentRepresentation();
requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
SimpleHttp.Response response = SimpleHttp.doPut(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asResponse();
assertEquals(404, response.getStatus());
}
use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.
the class AccountRestServiceTest method getConsentForClient.
@Test
public void getConsentForClient() throws IOException {
TokenUtil token = new TokenUtil("manage-consent-access", "password");
String appId = "security-admin-console";
ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
consentScopeRepresentation.setId(clientScopeRepresentation.getId());
ConsentRepresentation requestedConsent = new ConsentRepresentation();
requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
ConsentRepresentation consentRepresentation1 = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
assertTrue(consentRepresentation1.getCreatedDate() > 0);
assertTrue(consentRepresentation1.getLastUpdatedDate() > 0);
assertEquals(1, consentRepresentation1.getGrantedScopes().size());
assertEquals(consentScopeRepresentation.getId(), consentRepresentation1.getGrantedScopes().get(0).getId());
ConsentRepresentation consentRepresentation2 = SimpleHttp.doGet(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").auth(token.getToken()).asJson(ConsentRepresentation.class);
assertEquals(consentRepresentation1.getLastUpdatedDate(), consentRepresentation2.getLastUpdatedDate());
assertEquals(consentRepresentation1.getCreatedDate(), consentRepresentation2.getCreatedDate());
assertEquals(consentRepresentation1.getGrantedScopes().get(0).getId(), consentRepresentation2.getGrantedScopes().get(0).getId());
}
use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.
the class AccountRestServiceTest method listApplicationsThirdParty.
@Test
public void listApplicationsThirdParty() throws Exception {
String appId = "third-party";
TokenUtil token = new TokenUtil("view-applications-access", "password");
ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
consentScopeRepresentation.setId(clientScopeRepresentation.getId());
ConsentRepresentation requestedConsent = new ConsentRepresentation();
requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
List<ClientRepresentation> applications = SimpleHttp.doGet(getAccountUrl("applications"), httpClient).header("Accept", "application/json").auth(token.getToken()).asJson(new TypeReference<List<ClientRepresentation>>() {
});
assertFalse(applications.isEmpty());
SimpleHttp.doDelete(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").auth(token.getToken()).asResponse();
Map<String, ClientRepresentation> apps = applications.stream().collect(Collectors.toMap(x -> x.getClientId(), x -> x));
Assert.assertThat(apps.keySet(), containsInAnyOrder(appId, "always-display-client", "direct-grant"));
ClientRepresentation app = apps.get(appId);
assertClientRep(app, null, "A third party application", true, false, false, null, "http://localhost:8180/auth/realms/master/app/auth");
assertFalse(app.getConsent().getGrantedScopes().isEmpty());
ConsentScopeRepresentation grantedScope = app.getConsent().getGrantedScopes().get(0);
assertEquals(clientScopeRepresentation.getId(), grantedScope.getId());
assertEquals(clientScopeRepresentation.getName(), grantedScope.getName());
}
Aggregations