From ff69607f52e31e8a3ab788b78c030f96f3e56c89 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Tue, 6 May 2014 10:41:17 -0400 Subject: [PATCH] aerogear fix --- .../keycloak/example/BootstrapListener.java | 1 + .../services/CustomerDataProvider.java | 35 --------- .../services/CustomerDatabaseClient.java | 72 ------------------- .../example/services/CustomerService.java | 27 ------- .../example/services/DataApplication.java | 38 ---------- .../example/services/ProductService.java | 27 ------- 6 files changed, 1 insertion(+), 199 deletions(-) delete mode 100755 project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDataProvider.java delete mode 100755 project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDatabaseClient.java delete mode 100755 project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerService.java delete mode 100755 project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/DataApplication.java delete mode 100755 project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/ProductService.java diff --git a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/BootstrapListener.java b/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/BootstrapListener.java index f7284b931e..23c632abe3 100755 --- a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/BootstrapListener.java +++ b/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/BootstrapListener.java @@ -20,6 +20,7 @@ public class BootstrapListener implements ServletContextListener { config.setAuthServerUrl("/auth"); config.setSslNotRequired(true); config.setPublicClient(true); + config.setDisableTrustManager(true); deploymentContext.updateDeployment(config); } diff --git a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDataProvider.java b/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDataProvider.java deleted file mode 100755 index 3d6c6dc4eb..0000000000 --- a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDataProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * JBoss, Home of Professional Open Source - * Copyright Red Hat, Inc., and individual contributors. - * - * 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.example.services; - -import java.util.ArrayList; -import java.util.List; - -public class CustomerDataProvider { - - public List getCustomers() { - ArrayList rtn = new ArrayList(); - rtn.add("Bill Burke"); - rtn.add("Stian Thorgersen"); - rtn.add("Stan Silvert"); - rtn.add("Gabriel Cardoso"); - rtn.add("Viliam Rockai"); - rtn.add("Marek Posolda"); - rtn.add("Boleslaw Dawidowicz"); - return rtn; - } -} diff --git a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDatabaseClient.java b/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDatabaseClient.java deleted file mode 100755 index a775e56167..0000000000 --- a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerDatabaseClient.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.keycloak.example.services; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.keycloak.KeycloakSecurityContext; -import org.keycloak.adapters.HttpClientBuilder; -import org.keycloak.representations.IDToken; -import org.keycloak.util.JsonSerialization; - -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class CustomerDatabaseClient { - - static class TypedList extends ArrayList { - } - - public static class Failure extends Exception { - private int status; - - public Failure(int status) { - this.status = status; - } - - public int getStatus() { - return status; - } - } - - public static IDToken getIDToken(HttpServletRequest req) { - KeycloakSecurityContext session = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName()); - return session.getIdToken(); - - } - - public static List getCustomers(HttpServletRequest req) throws Failure { - KeycloakSecurityContext session = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName()); - - HttpClient client = new HttpClientBuilder() - .disableTrustManager().build(); - try { - HttpGet get = new HttpGet("http://localhost:8080/app/rest/customers"); - get.addHeader("Authorization", "Bearer " + session.getTokenString()); - try { - HttpResponse response = client.execute(get); - if (response.getStatusLine().getStatusCode() != 200) { - throw new Failure(response.getStatusLine().getStatusCode()); - } - HttpEntity entity = response.getEntity(); - InputStream is = entity.getContent(); - try { - return JsonSerialization.readValue(is, TypedList.class); - } finally { - is.close(); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } finally { - client.getConnectionManager().shutdown(); - } - } -} diff --git a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerService.java b/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerService.java deleted file mode 100755 index 3d412ab449..0000000000 --- a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/CustomerService.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.keycloak.example.services; - -import org.jboss.resteasy.annotations.cache.NoCache; - -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import java.util.List; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -@Path("customers") -public class CustomerService { - - @Inject - private CustomerDataProvider provider; - - @GET - @Produces("application/json") - @NoCache - public List getCustomers() { - return provider.getCustomers(); - } -} diff --git a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/DataApplication.java b/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/DataApplication.java deleted file mode 100755 index 86887097f7..0000000000 --- a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/DataApplication.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.keycloak.example.services; - -import org.keycloak.adapters.AdapterDeploymentContext; -import org.keycloak.representations.adapters.config.AdapterConfig; - -import javax.servlet.ServletContext; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; -import javax.ws.rs.core.Context; -import java.util.HashSet; -import java.util.Set; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -@ApplicationPath("/rest") -public class DataApplication extends Application -{ - public DataApplication(@Context ServletContext context) { - AdapterDeploymentContext deploymentContext = (AdapterDeploymentContext)context.getAttribute(AdapterDeploymentContext.class.getName()); - AdapterConfig config = new AdapterConfig(); - config.setDisableTrustManager(true); - } - - @Override - public Set> getClasses() { - HashSet> set = new HashSet>(); - set.add(CustomerService.class); - set.add(ProductService.class); - return set; - } - - @Override - public Set getSingletons() { - return super.getSingletons(); //To change body of overridden methods use File | Settings | File Templates. - } -} diff --git a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/ProductService.java b/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/ProductService.java deleted file mode 100755 index 1be0de8495..0000000000 --- a/project-integrations/aerogear-ups/app/src/main/java/org/keycloak/example/services/ProductService.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.keycloak.example.services; - -import org.jboss.resteasy.annotations.cache.NoCache; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -@Path("products") -public class ProductService { - @GET - @Produces("application/json") - @NoCache - public List getProducts() { - ArrayList rtn = new ArrayList(); - rtn.add("iphone"); - rtn.add("ipad"); - rtn.add("ipod"); - return rtn; - } -}