From d5b28013d132f82e0f5364fadc1c5f2639769c91 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 1 Mar 2019 09:50:52 +0100 Subject: [PATCH] KEYCLOAK-8523 Remove jaxrs package from old testsuite and deprecate jaxrs filter --- .../jaxrs/JaxrsBearerTokenFilter.java | 4 + .../jaxrs/JaxrsBearerTokenFilterImpl.java | 4 + .../org/keycloak/jaxrs/JaxrsHttpFacade.java | 4 + .../org/keycloak/jaxrs/JaxrsOAuthClient.java | 4 + .../jaxrs/OsgiJaxrsBearerTokenFilterImpl.java | 4 + .../testsuite/jaxrs/JaxrsBasicAuthTest.java | 161 --------- .../testsuite/jaxrs/JaxrsFilterTest.java | 322 ------------------ .../testsuite/jaxrs/JaxrsTestApplication.java | 54 --- .../testsuite/jaxrs/JaxrsTestResource.java | 109 ------ .../jaxrs-test/jaxrs-keycloak-basicauth.json | 12 - .../jaxrs-test/jaxrs-keycloak-relative.json | 7 - .../jaxrs-keycloak-resource-mappings.json | 10 - .../jaxrs-test/jaxrs-keycloak-ssl.json | 8 - .../resources/jaxrs-test/jaxrs-keycloak.json | 9 - 14 files changed, 20 insertions(+), 692 deletions(-) delete mode 100755 testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsBasicAuthTest.java delete mode 100644 testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsFilterTest.java delete mode 100644 testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestApplication.java delete mode 100644 testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestResource.java delete mode 100755 testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-basicauth.json delete mode 100644 testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-relative.json delete mode 100644 testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-resource-mappings.json delete mode 100644 testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-ssl.json delete mode 100644 testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak.json diff --git a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilter.java b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilter.java index 6387f61aac..9e66bc0ee0 100644 --- a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilter.java +++ b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilter.java @@ -24,8 +24,12 @@ import javax.ws.rs.container.PreMatching; /** * @author Marek Posolda + * @deprecated Class is deprecated and may be removed in the future. If you want to maintain this class for Keycloak community, please + * contact Keycloak team on keycloak-dev mailing list. You can fork it into your github repository and + * Keycloak team will reference it from "Keycloak Extensions" page. */ @PreMatching @Priority(Priorities.AUTHENTICATION) +@Deprecated public interface JaxrsBearerTokenFilter extends ContainerRequestFilter { } diff --git a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilterImpl.java b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilterImpl.java index bec9875a60..a44a4e5660 100755 --- a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilterImpl.java +++ b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsBearerTokenFilterImpl.java @@ -52,9 +52,13 @@ import java.util.logging.Logger; /** * @author Bill Burke * @version $Revision: 1 $ + * @deprecated Class is deprecated and may be removed in the future. If you want to maintain this class for Keycloak community, please + * contact Keycloak team on keycloak-dev mailing list. You can fork it into your github repository and + * Keycloak team will reference it from "Keycloak Extensions" page. */ @PreMatching @Priority(Priorities.AUTHENTICATION) +@Deprecated public class JaxrsBearerTokenFilterImpl implements JaxrsBearerTokenFilter { private final static Logger log = Logger.getLogger("" + JaxrsBearerTokenFilterImpl.class); diff --git a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsHttpFacade.java b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsHttpFacade.java index 0d984eb24d..66599c45d9 100755 --- a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsHttpFacade.java +++ b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsHttpFacade.java @@ -37,7 +37,11 @@ import java.util.Map; /** * @author Marek Posolda + * @deprecated Class is deprecated and may be removed in the future. If you want to maintain this class for Keycloak community, please + * contact Keycloak team on keycloak-dev mailing list. You can fork it into your github repository and + * Keycloak team will reference it from "Keycloak Extensions" page. */ +@Deprecated public class JaxrsHttpFacade implements OIDCHttpFacade { protected final ContainerRequestContext requestContext; diff --git a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsOAuthClient.java b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsOAuthClient.java index ae305e2a39..2ec416d179 100755 --- a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsOAuthClient.java +++ b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/JaxrsOAuthClient.java @@ -42,7 +42,11 @@ import java.util.logging.Logger; * * @author Bill Burke * @version $Revision: 1 $ + * @deprecated Class is deprecated and may be removed in the future. If you want to maintain this class for Keycloak community, please + * contact Keycloak team on keycloak-dev mailing list. You can fork it into your github repository and + * Keycloak team will reference it from "Keycloak Extensions" page. */ +@Deprecated public class JaxrsOAuthClient extends AbstractOAuthClient { private final static Logger logger = Logger.getLogger("" + JaxrsOAuthClient.class); protected Client client; diff --git a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/OsgiJaxrsBearerTokenFilterImpl.java b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/OsgiJaxrsBearerTokenFilterImpl.java index b19fc7a9fe..fca53d87f7 100644 --- a/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/OsgiJaxrsBearerTokenFilterImpl.java +++ b/adapters/oidc/jaxrs-oauth-client/src/main/java/org/keycloak/jaxrs/OsgiJaxrsBearerTokenFilterImpl.java @@ -33,9 +33,13 @@ import java.util.logging.Logger; * Variant of JaxrsBearerTokenFilter, which can be used to properly use resources from current osgi bundle * * @author Marek Posolda + * @deprecated Class is deprecated and may be removed in the future. If you want to maintain this class for Keycloak community, please + * contact Keycloak team on keycloak-dev mailing list. You can fork it into your github repository and + * Keycloak team will reference it from "Keycloak Extensions" page. */ @PreMatching @Priority(Priorities.AUTHENTICATION) +@Deprecated public class OsgiJaxrsBearerTokenFilterImpl extends JaxrsBearerTokenFilterImpl { private final static Logger log = Logger.getLogger("" + JaxrsBearerTokenFilterImpl.class); diff --git a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsBasicAuthTest.java b/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsBasicAuthTest.java deleted file mode 100755 index afe72f52c4..0000000000 --- a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsBasicAuthTest.java +++ /dev/null @@ -1,161 +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.jaxrs; - -import org.apache.http.impl.client.DefaultHttpClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExternalResource; -import org.keycloak.adapters.HttpClientBuilder; -import org.keycloak.common.util.Base64; -import org.keycloak.models.ClientModel; -import org.keycloak.models.RealmModel; -import org.keycloak.models.utils.KeycloakModelUtils; -import org.keycloak.services.managers.RealmManager; -import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.KeycloakRule; -import org.keycloak.testsuite.rule.WebResource; -import org.keycloak.testsuite.rule.WebRule; -import org.openqa.selenium.WebDriver; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Form; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import java.util.Map; -import java.util.TreeMap; -import java.util.UUID; - -/** - * Test for basic authentication. - */ -public class JaxrsBasicAuthTest { - - private static final String JAXRS_APP_URL = Constants.SERVER_ROOT + "/jaxrs-simple/res"; - - public static final String CONFIG_FILE_INIT_PARAM = "config-file"; - - @ClassRule - public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - ClientModel app = KeycloakModelUtils.createClient(appRealm, "jaxrs-app"); - app.setEnabled(true); - app.setSecret("password"); - app.setFullScopeAllowed(true); - app.setDirectAccessGrantsEnabled(true); - - JaxrsBasicAuthTest.appRealm = appRealm; - } - }); - - @ClassRule - public static ExternalResource clientRule = new ExternalResource() { - - @Override - protected void before() throws Throwable { - DefaultHttpClient httpClient = (DefaultHttpClient) new HttpClientBuilder().build(); - ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient); - client = new ResteasyClientBuilder().httpEngine(engine).build(); - } - - @Override - protected void after() { - client.close(); - } - }; - - private static ResteasyClient client; - - @Rule - public WebRule webRule = new WebRule(this); - - @WebResource - protected WebDriver driver; - - // Used for signing admin action - protected static RealmModel appRealm; - - - @Test - public void testBasic() { - keycloakRule.update(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - Map initParams = new TreeMap(); - initParams.put(CONFIG_FILE_INIT_PARAM, "classpath:jaxrs-test/jaxrs-keycloak-basicauth.json"); - keycloakRule.deployJaxrsApplication("JaxrsSimpleApp", "/jaxrs-simple", JaxrsTestApplication.class, initParams); - } - - }); - - // Send GET request without credentials, it should fail - Response getResp = client.target(JAXRS_APP_URL).request().get(); - Assert.assertEquals(getResp.getStatus(), 401); - getResp.close(); - - // Send POST request without credentials, it should fail - Response postResp = client.target(JAXRS_APP_URL).request().post(Entity.form(new Form())); - Assert.assertEquals(postResp.getStatus(), 401); - postResp.close(); - - // Retrieve token - String incorrectAuthHeader = "Basic "+encodeCredentials("invalid-user", "password"); - - // Send GET request with incorrect credentials, it shojuld fail - getResp = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, incorrectAuthHeader) - .get(); - Assert.assertEquals(getResp.getStatus(), 401); - getResp.close(); - - // Retrieve token - String authHeader = "Basic "+encodeCredentials("test-user@localhost", "password"); - - // Send GET request with token and assert it's passing - JaxrsTestResource.SimpleRepresentation getRep = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .get(JaxrsTestResource.SimpleRepresentation.class); - Assert.assertEquals("get", getRep.getMethod()); - - Assert.assertTrue(getRep.getHasUserRole()); - Assert.assertFalse(getRep.getHasAdminRole()); - Assert.assertFalse(getRep.getHasJaxrsAppRole()); - // Assert that principal is ID of user (should be in UUID format) - UUID.fromString(getRep.getPrincipal()); - - // Send POST request with token and assert it's passing - JaxrsTestResource.SimpleRepresentation postRep = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .post(Entity.form(new Form()), JaxrsTestResource.SimpleRepresentation.class); - Assert.assertEquals("post", postRep.getMethod()); - Assert.assertEquals(getRep.getPrincipal(), postRep.getPrincipal()); - } - - private String encodeCredentials(String username, String password) { - String text=username+":"+password; - return (Base64.encodeBytes(text.getBytes())); - } -} diff --git a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsFilterTest.java b/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsFilterTest.java deleted file mode 100644 index 3a257fd8e7..0000000000 --- a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsFilterTest.java +++ /dev/null @@ -1,322 +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.jaxrs; - -import org.apache.http.impl.client.DefaultHttpClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExternalResource; -import org.keycloak.OAuth2Constants; -import org.keycloak.TokenIdGenerator; -import org.keycloak.adapters.CorsHeaders; -import org.keycloak.adapters.HttpClientBuilder; -import org.keycloak.common.util.Time; -import org.keycloak.constants.AdapterConstants; -import org.keycloak.models.ClientModel; -import org.keycloak.models.RealmModel; -import org.keycloak.models.RoleModel; -import org.keycloak.models.UserModel; -import org.keycloak.protocol.oidc.TokenManager; -import org.keycloak.representations.adapters.action.PushNotBeforeAction; -import org.keycloak.services.managers.RealmManager; -import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.OAuthClient; -import org.keycloak.testsuite.rule.KeycloakRule; -import org.keycloak.testsuite.rule.WebResource; -import org.keycloak.testsuite.rule.WebRule; -import org.openqa.selenium.WebDriver; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Form; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import java.util.Map; -import java.util.TreeMap; -import java.util.UUID; - -/** - * @author Marek Posolda - */ -public class JaxrsFilterTest { - - private static final String JAXRS_APP_URL = Constants.SERVER_ROOT + "/jaxrs-simple/res"; - private static final String JAXRS_APP_PUSN_NOT_BEFORE_URL = Constants.SERVER_ROOT + "/jaxrs-simple/" + AdapterConstants.K_PUSH_NOT_BEFORE; - - public static final String CONFIG_FILE_INIT_PARAM = "config-file"; - - @ClassRule - public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - ClientModel app = appRealm.addClient("jaxrs-app"); - app.setEnabled(true); - RoleModel role = app.addRole("jaxrs-app-user"); - UserModel user = manager.getSession().users().getUserByUsername("test-user@localhost", appRealm); - user.grantRole(role); - - JaxrsFilterTest.appRealm = appRealm; - } - }); - - @ClassRule - public static ExternalResource clientRule = new ExternalResource() { - - @Override - protected void before() throws Throwable { - DefaultHttpClient httpClient = (DefaultHttpClient) new HttpClientBuilder().build(); - ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient); - client = new ResteasyClientBuilder().httpEngine(engine).build(); - } - - @Override - protected void after() { - client.close(); - } - }; - - private static ResteasyClient client; - - @Rule - public WebRule webRule = new WebRule(this); - - @WebResource - protected WebDriver driver; - - // Used for signing admin action - protected static RealmModel appRealm; - - - @Test - public void testBasic() { - keycloakRule.update(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - Map initParams = new TreeMap(); - initParams.put(CONFIG_FILE_INIT_PARAM, "classpath:jaxrs-test/jaxrs-keycloak.json"); - keycloakRule.deployJaxrsApplication("JaxrsSimpleApp", "/jaxrs-simple", JaxrsTestApplication.class, initParams); - } - - }); - - // Send GET request without token, it should fail - Response getResp = client.target(JAXRS_APP_URL).request().get(); - Assert.assertEquals(getResp.getStatus(), 401); - getResp.close(); - - // Send POST request without token, it should fail - Response postResp = client.target(JAXRS_APP_URL).request().post(Entity.form(new Form())); - Assert.assertEquals(postResp.getStatus(), 401); - postResp.close(); - - // Retrieve token - OAuthClient.AccessTokenResponse accessTokenResp = retrieveAccessToken(); - String authHeader = "Bearer " + accessTokenResp.getAccessToken(); - - // Send GET request with token and assert it's passing - JaxrsTestResource.SimpleRepresentation getRep = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .get(JaxrsTestResource.SimpleRepresentation.class); - Assert.assertEquals("get", getRep.getMethod()); - Assert.assertTrue(getRep.getHasUserRole()); - Assert.assertFalse(getRep.getHasAdminRole()); - Assert.assertFalse(getRep.getHasJaxrsAppRole()); - // Assert that principal is ID of user (should be in UUID format) - UUID.fromString(getRep.getPrincipal()); - - // Send POST request with token and assert it's passing - JaxrsTestResource.SimpleRepresentation postRep = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .post(Entity.form(new Form()), JaxrsTestResource.SimpleRepresentation.class); - Assert.assertEquals("post", postRep.getMethod()); - Assert.assertEquals(getRep.getPrincipal(), postRep.getPrincipal()); - } - - @Test - public void testRelativeUriAndPublicKey() { - keycloakRule.update(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - Map initParams = new TreeMap(); - initParams.put(CONFIG_FILE_INIT_PARAM, "classpath:jaxrs-test/jaxrs-keycloak-relative.json"); - keycloakRule.deployJaxrsApplication("JaxrsSimpleApp", "/jaxrs-simple", JaxrsTestApplication.class, initParams); - } - - }); - - // Send GET request without token, it should fail - Response getResp = client.target(JAXRS_APP_URL).request().get(); - Assert.assertEquals(getResp.getStatus(), 401); - getResp.close(); - - // Retrieve token - OAuthClient.AccessTokenResponse accessTokenResp = retrieveAccessToken(); - String authHeader = "Bearer " + accessTokenResp.getAccessToken(); - - // Send GET request with token and assert it's passing - JaxrsTestResource.SimpleRepresentation getRep = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .get(JaxrsTestResource.SimpleRepresentation.class); - Assert.assertEquals("get", getRep.getMethod()); - Assert.assertTrue(getRep.getHasUserRole()); - Assert.assertFalse(getRep.getHasAdminRole()); - Assert.assertFalse(getRep.getHasJaxrsAppRole()); - // Assert that principal is ID of user (should be in UUID format) - UUID.fromString(getRep.getPrincipal()); - } - - @Test - public void testSslRequired() { - keycloakRule.update(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - Map initParams = new TreeMap(); - initParams.put(CONFIG_FILE_INIT_PARAM, "classpath:jaxrs-test/jaxrs-keycloak-ssl.json"); - keycloakRule.deployJaxrsApplication("JaxrsSimpleApp", "/jaxrs-simple", JaxrsTestApplication.class, initParams); - } - - }); - - // Retrieve token - OAuthClient.AccessTokenResponse accessTokenResp = retrieveAccessToken(); - String authHeader = "Bearer " + accessTokenResp.getAccessToken(); - - // Fail due to non-https - Response getResp = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .get(); - Assert.assertEquals(getResp.getStatus(), 403); - getResp.close(); - } - - @Test - public void testResourceRoleMappings() { - keycloakRule.update(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - Map initParams = new TreeMap(); - initParams.put(CONFIG_FILE_INIT_PARAM, "classpath:jaxrs-test/jaxrs-keycloak-resource-mappings.json"); - keycloakRule.deployJaxrsApplication("JaxrsSimpleApp", "/jaxrs-simple", JaxrsTestApplication.class, initParams); - } - - }); - - // Retrieve token - OAuthClient.AccessTokenResponse accessTokenResp = retrieveAccessToken(); - String authHeader = "Bearer " + accessTokenResp.getAccessToken(); - - // Send GET request with token and assert it's passing - JaxrsTestResource.SimpleRepresentation getRep = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .get(JaxrsTestResource.SimpleRepresentation.class); - Assert.assertEquals("get", getRep.getMethod()); - - // principal is username - Assert.assertEquals("test-user@localhost", getRep.getPrincipal()); - - // User is in jaxrs-app-user role thanks to use-resource-role-mappings - Assert.assertFalse(getRep.getHasUserRole()); - Assert.assertFalse(getRep.getHasAdminRole()); - Assert.assertTrue(getRep.getHasJaxrsAppRole()); - } - - @Test - public void testCors() { - keycloakRule.update(new KeycloakRule.KeycloakSetup() { - - @Override - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { - Map initParams = new TreeMap(); - initParams.put(CONFIG_FILE_INIT_PARAM, "classpath:jaxrs-test/jaxrs-keycloak.json"); - keycloakRule.deployJaxrsApplication("JaxrsSimpleApp", "/jaxrs-simple", JaxrsTestApplication.class, initParams); - } - - }); - - // Send OPTIONS request - Response optionsResp = client.target(JAXRS_APP_URL).request() - .header(CorsHeaders.ORIGIN, "http://localhost:8081") - .options(); - Assert.assertEquals("true", optionsResp.getHeaderString(CorsHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)); - Assert.assertEquals("http://localhost:8081", optionsResp.getHeaderString(CorsHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); - optionsResp.close(); - - // Retrieve token - OAuthClient.AccessTokenResponse accessTokenResp = retrieveAccessToken(); - String authHeader = "Bearer " + accessTokenResp.getAccessToken(); - - // Send GET request with token but bad origin - Response badOriginResp = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .header(CorsHeaders.ORIGIN, "http://evil.org") - .get(); - Assert.assertEquals(403, badOriginResp.getStatus()); - badOriginResp.close(); - - // Send GET request with token and good origin - Response goodResp = client.target(JAXRS_APP_URL).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .header(CorsHeaders.ORIGIN, "http://localhost:8081") - .get(); - Assert.assertEquals(200, goodResp.getStatus()); - Assert.assertEquals("true", optionsResp.getHeaderString(CorsHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)); - Assert.assertEquals("http://localhost:8081", optionsResp.getHeaderString(CorsHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); - JaxrsTestResource.SimpleRepresentation getRep = goodResp.readEntity(JaxrsTestResource.SimpleRepresentation.class); - Assert.assertEquals("get", getRep.getMethod()); - goodResp.close(); - } - - // @Test - public void testCxfExample() { - //String uri = "http://localhost:9000/customerservice/customers/123"; - String uri = "http://localhost:8080/jax_rs_basic_servlet/services/service1/customerservice/customers/123"; - Response resp = client.target(uri).request() - .get(); - Assert.assertEquals(resp.getStatus(), 401); - resp.close(); - - // Retrieve token - OAuthClient.AccessTokenResponse accessTokenResp = retrieveAccessToken(); - String authHeader = "Bearer " + accessTokenResp.getAccessToken(); - - String resp2 = client.target(uri).request() - .header(HttpHeaders.AUTHORIZATION, authHeader) - .get(String.class); - System.out.println(resp2); - } - - - private OAuthClient.AccessTokenResponse retrieveAccessToken() { - OAuthClient oauth = new OAuthClient(driver); - oauth.doLogin("test-user@localhost", "password"); - String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE); - OAuthClient.AccessTokenResponse response = oauth.doAccessTokenRequest(code, "password"); - Assert.assertEquals(200, response.getStatusCode()); - return response; - } - -} diff --git a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestApplication.java b/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestApplication.java deleted file mode 100644 index c577ab219a..0000000000 --- a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestApplication.java +++ /dev/null @@ -1,54 +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.jaxrs; - -import org.keycloak.jaxrs.JaxrsBearerTokenFilterImpl; - -import javax.servlet.ServletContext; -import javax.ws.rs.core.Application; -import javax.ws.rs.core.Context; -import java.util.HashSet; -import java.util.Set; - -/** - * @author Marek Posolda - */ -public class JaxrsTestApplication extends Application { - - protected Set> classes = new HashSet>(); - protected Set singletons = new HashSet(); - - public JaxrsTestApplication(@Context ServletContext context) throws Exception { - singletons.add(new JaxrsTestResource()); - - String configFile = context.getInitParameter(JaxrsFilterTest.CONFIG_FILE_INIT_PARAM); - JaxrsBearerTokenFilterImpl filter = new JaxrsBearerTokenFilterImpl(); - filter.setKeycloakConfigFile(configFile); - singletons.add(filter); - } - - @Override - public Set> getClasses() { - return classes; - } - - @Override - public Set getSingletons() { - return singletons; - } -} diff --git a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestResource.java b/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestResource.java deleted file mode 100644 index 8bf2d7be19..0000000000 --- a/testsuite/integration-deprecated/src/test/java/org/keycloak/testsuite/jaxrs/JaxrsTestResource.java +++ /dev/null @@ -1,109 +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.jaxrs; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.SecurityContext; - -/** - * @author Marek Posolda - */ -@Path("res") -public class JaxrsTestResource { - - @Context - protected SecurityContext securityContext; - - @GET - @Produces("application/json") - public SimpleRepresentation get() { - return new SimpleRepresentation("get", securityContext.getUserPrincipal().getName(), securityContext.isUserInRole("user"), - securityContext.isUserInRole("admin"), securityContext.isUserInRole("jaxrs-app-user")); - } - - @POST - @Produces("application/json") - public SimpleRepresentation post() { - return new SimpleRepresentation("post", securityContext.getUserPrincipal().getName(), securityContext.isUserInRole("user"), - securityContext.isUserInRole("admin"), securityContext.isUserInRole("jaxrs-app-user")); - } - - public static class SimpleRepresentation { - private String method; - private String principal; - private Boolean hasUserRole; - private Boolean hasAdminRole; - private Boolean hasJaxrsAppRole; - - public SimpleRepresentation() { - } - - public SimpleRepresentation(String method, String principal, boolean hasUserRole, boolean hasAdminRole, - boolean hasJaxrsAppRole) { - this.method = method; - this.principal = principal; - this.hasUserRole = hasUserRole; - this.hasAdminRole = hasAdminRole; - this.hasJaxrsAppRole = hasJaxrsAppRole; - } - - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method; - } - - public String getPrincipal() { - return principal; - } - - public void setPrincipal(String principal) { - this.principal = principal; - } - - public Boolean getHasUserRole() { - return hasUserRole; - } - - public void setHasUserRole(Boolean hasUserRole) { - this.hasUserRole = hasUserRole; - } - - public Boolean getHasAdminRole() { - return hasAdminRole; - } - - public void setHasAdminRole(Boolean hasAdminRole) { - this.hasAdminRole = hasAdminRole; - } - - public Boolean getHasJaxrsAppRole() { - return hasJaxrsAppRole; - } - - public void setHasJaxrsAppRole(Boolean hasJaxrsAppRole) { - this.hasJaxrsAppRole = hasJaxrsAppRole; - } - } -} diff --git a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-basicauth.json b/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-basicauth.json deleted file mode 100755 index c6c72e967f..0000000000 --- a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-basicauth.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "realm": "test", - "resource": "jaxrs-app", - "realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url": "http://localhost:8081/auth", - "ssl-required" : "external", - "enable-basic-auth": true, - "bearer-only": true, - "credentials": { - "secret": "password" - } -} \ No newline at end of file diff --git a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-relative.json b/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-relative.json deleted file mode 100644 index a17933ec9e..0000000000 --- a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-relative.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "realm": "test", - "resource": "jaxrs-app", - "auth-server-url": "/auth", - "ssl-required" : "external", - "bearer-only": true -} \ No newline at end of file diff --git a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-resource-mappings.json b/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-resource-mappings.json deleted file mode 100644 index 924e4ad1ef..0000000000 --- a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-resource-mappings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "realm": "test", - "resource": "jaxrs-app", - "realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url": "http://localhost:8081/auth", - "ssl-required" : "external", - "bearer-only": true, - "principal-attribute": "preferred_username", - "use-resource-role-mappings": true -} diff --git a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-ssl.json b/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-ssl.json deleted file mode 100644 index 666ddb9f78..0000000000 --- a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak-ssl.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "realm": "test", - "resource": "jaxrs-app", - "realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url": "http://localhost:8081/auth", - "ssl-required" : "all", - "bearer-only": true -} \ No newline at end of file diff --git a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak.json b/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak.json deleted file mode 100644 index 5a836688c1..0000000000 --- a/testsuite/integration-deprecated/src/test/resources/jaxrs-test/jaxrs-keycloak.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "realm": "test", - "resource": "jaxrs-app", - "realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url": "http://localhost:8081/auth", - "ssl-required" : "external", - "bearer-only": true, - "enable-cors": true -} \ No newline at end of file