Search in sources :

Example 1 with ConsentRepresentation

use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.

the class AccountRestServiceTest method createConsentForClientWithoutPermission.

@Test
public void createConsentForClientWithoutPermission() 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.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asResponse();
    assertEquals(403, response.getStatus());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) SimpleHttp(org.keycloak.broker.provider.util.SimpleHttp) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 2 with ConsentRepresentation

use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.

the class AccountRestServiceTest method updateConsentForClientWithPut.

@Test
public void updateConsentForClientWithPut() 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 consentRepresentation = SimpleHttp.doPut(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertTrue(consentRepresentation.getCreatedDate() > 0);
    assertTrue(consentRepresentation.getLastUpdatedDate() > 0);
    assertEquals(1, consentRepresentation.getGrantedScopes().size());
    assertEquals(consentScopeRepresentation.getId(), consentRepresentation.getGrantedScopes().get(0).getId());
    clientScopeRepresentation = testRealm().clientScopes().findAll().get(1);
    consentScopeRepresentation = new ConsentScopeRepresentation();
    consentScopeRepresentation.setId(clientScopeRepresentation.getId());
    requestedConsent = new ConsentRepresentation();
    requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
    ConsentRepresentation consentRepresentation2 = SimpleHttp.doPut(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertTrue(consentRepresentation2.getCreatedDate() > 0);
    assertEquals(consentRepresentation.getCreatedDate(), consentRepresentation2.getCreatedDate());
    assertTrue(consentRepresentation2.getLastUpdatedDate() > 0);
    assertTrue(consentRepresentation2.getLastUpdatedDate() > consentRepresentation.getLastUpdatedDate());
    assertEquals(1, consentRepresentation2.getGrantedScopes().size());
    assertEquals(consentScopeRepresentation.getId(), consentRepresentation2.getGrantedScopes().get(0).getId());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 3 with ConsentRepresentation

use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.

the class AccountRestServiceTest method deleteConsentForClient.

@Test
public void deleteConsentForClient() 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 consentRepresentation = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertTrue(consentRepresentation.getCreatedDate() > 0);
    assertTrue(consentRepresentation.getLastUpdatedDate() > 0);
    assertEquals(1, consentRepresentation.getGrantedScopes().size());
    assertEquals(consentScopeRepresentation.getId(), consentRepresentation.getGrantedScopes().get(0).getId());
    SimpleHttp.Response response = SimpleHttp.doDelete(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").auth(token.getToken()).asResponse();
    assertEquals(204, response.getStatus());
    response = SimpleHttp.doDelete(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").auth(token.getToken()).asResponse();
    assertEquals(204, response.getStatus());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) SimpleHttp(org.keycloak.broker.provider.util.SimpleHttp) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 4 with ConsentRepresentation

use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.

the class AccountRestServiceTest method updateConsentForClient.

@Test
public void updateConsentForClient() 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 consentRepresentation = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertTrue(consentRepresentation.getCreatedDate() > 0);
    assertTrue(consentRepresentation.getLastUpdatedDate() > 0);
    assertEquals(1, consentRepresentation.getGrantedScopes().size());
    assertEquals(consentScopeRepresentation.getId(), consentRepresentation.getGrantedScopes().get(0).getId());
    clientScopeRepresentation = testRealm().clientScopes().findAll().get(1);
    consentScopeRepresentation = new ConsentScopeRepresentation();
    consentScopeRepresentation.setId(clientScopeRepresentation.getId());
    requestedConsent = new ConsentRepresentation();
    requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
    ConsentRepresentation consentRepresentation2 = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertTrue(consentRepresentation2.getCreatedDate() > 0);
    assertEquals(consentRepresentation.getCreatedDate(), consentRepresentation2.getCreatedDate());
    assertTrue(consentRepresentation2.getLastUpdatedDate() > 0);
    assertTrue(consentRepresentation2.getLastUpdatedDate() > consentRepresentation.getLastUpdatedDate());
    assertEquals(1, consentRepresentation2.getGrantedScopes().size());
    assertEquals(consentScopeRepresentation.getId(), consentRepresentation2.getGrantedScopes().get(0).getId());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 5 with ConsentRepresentation

use of org.keycloak.representations.account.ConsentRepresentation in project keycloak by keycloak.

the class AccountRestServiceTest method createConsentForClientWithPut.

@Test
public void createConsentForClientWithPut() 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 consentRepresentation = SimpleHttp.doPut(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertTrue(consentRepresentation.getCreatedDate() > 0);
    assertTrue(consentRepresentation.getLastUpdatedDate() > 0);
    assertEquals(1, consentRepresentation.getGrantedScopes().size());
    assertEquals(consentScopeRepresentation.getId(), consentRepresentation.getGrantedScopes().get(0).getId());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Aggregations

Test (org.junit.Test)11 ConsentRepresentation (org.keycloak.representations.account.ConsentRepresentation)11 ConsentScopeRepresentation (org.keycloak.representations.account.ConsentScopeRepresentation)11 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)11 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)11 TokenUtil (org.keycloak.testsuite.util.TokenUtil)11 SimpleHttp (org.keycloak.broker.provider.util.SimpleHttp)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Response (javax.ws.rs.core.Response)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 Assert (org.junit.Assert)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1