diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/provider/OAuthClientProvider.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/provider/OAuthClientProvider.java index 3ff7da9842..b51a3bdd7f 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/provider/OAuthClientProvider.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/provider/OAuthClientProvider.java @@ -21,7 +21,6 @@ import org.jboss.arquillian.core.api.Instance; import org.jboss.arquillian.core.api.annotation.Inject; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider; -import org.keycloak.testsuite.util.DeleteMeOAuthClient; import org.keycloak.testsuite.util.OAuthClient; import java.lang.annotation.Annotation; diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/DeleteMeOAuthClient.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/DeleteMeOAuthClient.java deleted file mode 100644 index d834491ebc..0000000000 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/DeleteMeOAuthClient.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.testsuite.util; - -import org.apache.commons.io.IOUtils; -import org.apache.http.NameValuePair; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicNameValuePair; -import org.keycloak.OAuth2Constants; -import org.keycloak.protocol.oidc.OIDCLoginProtocolService; -import org.keycloak.representations.AccessTokenResponse; -import org.keycloak.util.BasicAuthHelper; -import org.keycloak.util.JsonSerialization; - -import javax.ws.rs.core.UriBuilder; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.LinkedList; -import java.util.List; - -/** - * @author Stian Thorgersen - */ -public class DeleteMeOAuthClient { - - private String baseUrl; - - public DeleteMeOAuthClient(String baseUrl) { - this.baseUrl = baseUrl; - } - - public AccessTokenResponse getToken(String realm, String clientId, String clientSecret, String username, String password) { - CloseableHttpClient httpclient = HttpClients.createDefault(); - try { - HttpPost post = new HttpPost(OIDCLoginProtocolService.tokenUrl(UriBuilder.fromUri(baseUrl)).build(realm)); - - List parameters = new LinkedList(); - parameters.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, OAuth2Constants.PASSWORD)); - parameters.add(new BasicNameValuePair("username", username)); - parameters.add(new BasicNameValuePair("password", password)); - if (clientSecret != null) { - String authorization = BasicAuthHelper.createHeader(clientId, clientSecret); - post.setHeader("Authorization", authorization); - } else { - parameters.add(new BasicNameValuePair("client_id", clientId)); - } - - UrlEncodedFormEntity formEntity; - try { - formEntity = new UrlEncodedFormEntity(parameters, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - post.setEntity(formEntity); - - CloseableHttpResponse response = httpclient.execute(post); - - if (response.getStatusLine().getStatusCode() != 200) { - throw new RuntimeException("Failed to retrieve token: " + response.getStatusLine().toString() + " / " + IOUtils.toString(response.getEntity().getContent())); - } - - return JsonSerialization.readValue(response.getEntity().getContent(), AccessTokenResponse.class); - } catch (Exception e) { - throw new RuntimeException(e); - } - finally { - try { - httpclient.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - -} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java index 345843ae03..e1a1df26c4 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java @@ -54,7 +54,6 @@ import org.keycloak.testsuite.arquillian.AuthServerTestEnricher; import org.keycloak.testsuite.arquillian.SuiteContext; import org.keycloak.testsuite.auth.page.WelcomePage; import org.keycloak.testsuite.client.KeycloakTestingClient; -import org.keycloak.testsuite.util.DeleteMeOAuthClient; import org.keycloak.testsuite.util.OAuthClient; import org.openqa.selenium.WebDriver; import org.keycloak.testsuite.auth.page.AuthServer; @@ -96,8 +95,6 @@ public abstract class AbstractKeycloakTest { @ArquillianResource protected OAuthClient oauth; - protected DeleteMeOAuthClient deleteMeOAuthClient; - protected List testRealmReps; @Drone @@ -131,7 +128,6 @@ public abstract class AbstractKeycloakTest { public void beforeAbstractKeycloakTest() throws Exception { adminClient = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", MASTER, ADMIN, ADMIN, Constants.ADMIN_CLI_CLIENT_ID); - deleteMeOAuthClient = new DeleteMeOAuthClient(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth"); getTestingClient(); @@ -161,7 +157,7 @@ public abstract class AbstractKeycloakTest { } removeTestRealms(); // Remove realms after tests. Tests should cleanup after themselves! -// adminClient.close(); // keeping admin connection open + adminClient.close(); // don't keep admin connection open } private void updateMasterAdminPassword() { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java index b7fd462265..29a3661aa5 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/PermissionsTest.java @@ -137,11 +137,11 @@ public class PermissionsTest extends AbstractKeycloakTest { @Override public void afterAbstractKeycloakTest() { - super.afterAbstractKeycloakTest(); - for (UserRepresentation u : adminClient.realm("master").users().search("permissions-test-master-", 0, 100)) { adminClient.realm("master").users().get(u.getId()).remove(); } + + super.afterAbstractKeycloakTest(); } @Test diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/AbstractGroupTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/AbstractGroupTest.java index 543482d221..2cc6813d30 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/AbstractGroupTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/AbstractGroupTest.java @@ -26,12 +26,12 @@ import org.keycloak.events.Details; import org.keycloak.jose.jws.JWSInput; import org.keycloak.jose.jws.crypto.RSAProvider; import org.keycloak.representations.AccessToken; -import org.keycloak.representations.AccessTokenResponse; import org.keycloak.representations.RefreshToken; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.testsuite.AbstractKeycloakTest; import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.arquillian.AuthServerTestEnricher; +import org.keycloak.testsuite.util.OAuthClient.AccessTokenResponse; import java.security.PublicKey; import java.util.List; @@ -47,10 +47,9 @@ public abstract class AbstractGroupTest extends AbstractKeycloakTest { public AssertEvents events = new AssertEvents(this); AccessToken login(String login, String clientId, String clientSecret, String userId) throws Exception { + AccessTokenResponse tokenResponse = oauth.doGrantAccessTokenRequest("test", login, "password", null, clientId, clientSecret); - AccessTokenResponse tokenResponse = deleteMeOAuthClient.getToken("test", clientId, clientSecret, login, "password"); - - String accessToken = tokenResponse.getToken(); + String accessToken = tokenResponse.getAccessToken(); String refreshToken = tokenResponse.getRefreshToken(); PublicKey publicKey = PemUtils.decodePublicKey(adminClient.realm("test").toRepresentation().getPublicKey()); @@ -66,7 +65,6 @@ public abstract class AbstractGroupTest extends AbstractKeycloakTest { events.expectLogin() .client(clientId) .user(userId) - .session(tokenResponse.getSessionState()) .detail(Details.GRANT_TYPE, OAuth2Constants.PASSWORD) .detail(Details.TOKEN_ID, accessTokenRepresentation.getId()) .detail(Details.REFRESH_TOKEN_ID, refreshTokenRepresentation.getId()) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/AbstractClientRegistrationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/AbstractClientRegistrationTest.java index 8e4cfc3476..2ea1961041 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/AbstractClientRegistrationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/AbstractClientRegistrationTest.java @@ -120,7 +120,11 @@ public abstract class AbstractClientRegistrationTest extends AbstractKeycloakTes } private String getToken(String username, String password) { - return deleteMeOAuthClient.getToken(REALM_NAME, Constants.ADMIN_CLI_CLIENT_ID, null, username, password).getToken(); + try { + return oauth.doGrantAccessTokenRequest(REALM_NAME, username, password, null, Constants.ADMIN_CLI_CLIENT_ID, null).getAccessToken(); + } catch (Exception e) { + throw new RuntimeException(e); + } } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/ClientRegistrationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/ClientRegistrationTest.java index e8ccff9790..75acfac82e 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/ClientRegistrationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/ClientRegistrationTest.java @@ -59,10 +59,10 @@ public class ClientRegistrationTest extends AbstractClientRegistrationTest { } @Test - public void registerClientInMasterRealm() throws ClientRegistrationException { + public void registerClientInMasterRealm() throws Exception { ClientRegistration masterReg = ClientRegistration.create().url(suiteContext.getAuthServerInfo().getContextRoot() + "/auth", "master").build(); - String token = deleteMeOAuthClient.getToken("master", Constants.ADMIN_CLI_CLIENT_ID, null, "admin", "admin").getToken(); + String token = oauth.doGrantAccessTokenRequest("master", "admin", "admin", null, Constants.ADMIN_CLI_CLIENT_ID, null).getAccessToken(); masterReg.auth(Auth.token(token)); ClientRepresentation client = new ClientRepresentation();