Search in sources :

Example 6 with SimpleHttp

use of org.keycloak.broker.provider.util.SimpleHttp in project keycloak by keycloak.

the class AccountRestServiceTest method getUser.

protected UserRepresentation getUser(boolean fetchMetadata) throws IOException {
    String accountUrl = getAccountUrl(null) + "?userProfileMetadata=" + fetchMetadata;
    SimpleHttp a = SimpleHttp.doGet(accountUrl, httpClient).auth(tokenUtil.getToken());
    try {
        return a.asJson(UserRepresentation.class);
    } catch (IOException e) {
        System.err.println("Error during user reading: " + a.asString());
        throw e;
    }
}
Also used : SimpleHttp(org.keycloak.broker.provider.util.SimpleHttp) IOException(java.io.IOException)

Example 7 with SimpleHttp

use of org.keycloak.broker.provider.util.SimpleHttp in project keycloak by keycloak.

the class TokenRevocationTest method isAccessTokenDisabled.

private void isAccessTokenDisabled(String accessTokenString, String clientId) throws IOException {
    // Test introspection endpoint not possible
    String introspectionResponse = oauth.introspectAccessTokenWithClientCredential(clientId, "password", accessTokenString);
    TokenMetadataRepresentation rep = JsonSerialization.readValue(introspectionResponse, TokenMetadataRepresentation.class);
    assertFalse(rep.isActive());
    // Test userInfo endpoint not possible
    Response response = UserInfoClientUtil.executeUserInfoRequest_getMethod(userInfoClient, accessTokenString);
    assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
    // Test account REST not possible
    String accountUrl = OAuthClient.AUTH_SERVER_ROOT + "/realms/test/account";
    SimpleHttp accountRequest = SimpleHttp.doGet(accountUrl, restHttpClient).auth(accessTokenString).acceptJson();
    assertEquals(Status.UNAUTHORIZED.getStatusCode(), accountRequest.asStatus());
    // Test admin REST not possible
    try (Keycloak adminClient = Keycloak.getInstance(OAuthClient.AUTH_SERVER_ROOT, "test", "test-app", accessTokenString)) {
        try {
            adminClient.realms().realm("test").toRepresentation();
            Assert.fail("Not expected to obtain realm");
        } catch (NotAuthorizedException nae) {
        // Expected
        }
    }
}
Also used : AccessTokenResponse(org.keycloak.testsuite.util.OAuthClient.AccessTokenResponse) Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) TokenMetadataRepresentation(org.keycloak.representations.oidc.TokenMetadataRepresentation) SimpleHttp(org.keycloak.broker.provider.util.SimpleHttp) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Keycloak(org.keycloak.admin.client.Keycloak)

Aggregations

SimpleHttp (org.keycloak.broker.provider.util.SimpleHttp)7 IOException (java.io.IOException)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 URI (java.net.URI)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 Response (javax.ws.rs.core.Response)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 Keycloak (org.keycloak.admin.client.Keycloak)1 ClientModel (org.keycloak.models.ClientModel)1 TokenMetadataRepresentation (org.keycloak.representations.oidc.TokenMetadataRepresentation)1 ErrorResponseException (org.keycloak.services.ErrorResponseException)1 AccessTokenResponse (org.keycloak.testsuite.util.OAuthClient.AccessTokenResponse)1