From 08ebd7f881b8fb713dfa6def495e6fd6407efbdf Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 11 Dec 2015 11:10:53 +0530 Subject: [PATCH] Added DCR proxy endpoint & refactored code. --- .../dynamic-client-web-proxy/pom.xml | 133 ++++++++++++++++ .../client/web/proxy/OAuthEndpointProxy.java | 37 +++++ .../client/web/proxy/RegistrationProxy.java | 91 +++++++++++ .../client/web/proxy/util/Constants.java | 62 ++++++++ .../client/web/proxy/util/DCRProxyUtils.java | 76 +++++++++ .../web/proxy/util/RemoteDCRClient.java | 150 ++++++++++++++++++ .../webapp/META-INF/webapp-classloading.xml | 35 ++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 51 ++++++ .../src/main/webapp/WEB-INF/web.xml | 37 +++++ .../src/main/webapp/servicelist.css | 125 +++++++++++++++ .../src/test/resources/log4j.properties | 32 ++++ .../src/test/resources/testng.xml | 23 +++ .../dynamic-client-web/pom.xml | 5 - .../client/web/RegistrationService.java | 2 +- .../src/main/webapp/WEB-INF/web.xml | 4 +- .../src/test/resources/testng.xml | 7 +- ...amicClientWebAppRegistrationConstants.java | 3 +- .../DynamicClientWebAppRegistrationUtil.java | 2 +- .../registration/util/RemoteDCRClient.java | 13 +- .../dynamic-client-registration/pom.xml | 1 + .../pom.xml | 9 ++ .../src/main/resources/p2.inf | 3 +- 22 files changed, 879 insertions(+), 22 deletions(-) create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/pom.xml create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/OAuthEndpointProxy.java create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/RegistrationProxy.java create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/Constants.java create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/DCRProxyUtils.java create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/RemoteDCRClient.java create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/META-INF/webapp-classloading.xml create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/cxf-servlet.xml create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/web.xml create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/servicelist.css create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/log4j.properties create mode 100644 components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/testng.xml diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/pom.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/pom.xml new file mode 100644 index 00000000000..05c20176cd1 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/pom.xml @@ -0,0 +1,133 @@ + + + + + + dynamic-client-registration + org.wso2.carbon.devicemgt + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.mdm + dynamic-client-web-proxy + 0.9.2-SNAPSHOT + WSO2 Carbon - Proxy endpoint of Dynamic Client Registration Web Service + WSO2 Carbon - Dynamic Client Registration Web Proxy + war + + + + + maven-war-plugin + 2.2 + + ${project.artifactId} + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18 + + + file:src/test/resources/log4j.properties + + + src/test/resources/testng.xml + + + + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.dynamic.client.registration + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.apache.ws.commons.axiom + axiom-api + provided + + + org.apache.ws.commons.axiom + axiom-impl + provided + + + org.apache.ws.commons.axiom.wso2 + axiom + provided + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-transports-http + provided + + + org.apache.cxf + cxf-rt-bindings-http + provided + + + org.testng + testng + provided + + + org.codehaus.jackson + jackson-jaxrs + + + commons-logging + commons-logging + provided + + + org.apache.httpcomponents + httpclient + + + com.google.code.gson + gson + provided + + + org.wso2.carbon + org.wso2.carbon.core + provided + + + \ No newline at end of file diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/OAuthEndpointProxy.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/OAuthEndpointProxy.java new file mode 100644 index 00000000000..60ff66bddc9 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/OAuthEndpointProxy.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.dynamic.client.web.proxy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.ws.rs.POST; + +/** + * Created by harshan on 12/10/15. + */ +public class OAuthEndpointProxy { + + private static final Log log = LogFactory.getLog(OAuthEndpointProxy.class); + + @POST + public String getAccessToken() { + return ""; + } +} diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/RegistrationProxy.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/RegistrationProxy.java new file mode 100644 index 00000000000..556c62ef352 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/RegistrationProxy.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.dynamic.client.web.proxy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.util.EntityUtils; +import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; +import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; +import org.wso2.carbon.dynamic.client.web.proxy.util.Constants; +import org.wso2.carbon.dynamic.client.web.proxy.util.DCRProxyUtils; +import org.wso2.carbon.dynamic.client.web.proxy.util.RemoteDCRClient; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Created by harshan on 12/10/15. + */ + +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class RegistrationProxy { + + private static final Log log = LogFactory.getLog(RegistrationProxy.class); + + @POST + public Response register(RegistrationProfile profile) { + Response response; + try { + CloseableHttpResponse serverResponse = RemoteDCRClient.createOAuthApplication(profile); + HttpEntity responseData = serverResponse.getEntity(); + int status = serverResponse.getStatusLine().getStatusCode(); + String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF8); + response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build(); + } catch (DynamicClientRegistrationException e) { + String msg = "Server error occurred while registering client '" + profile.getClientName() + "'"; + log.error(msg, e); + response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (IOException e) { + String msg = "Service invoke error occurred while registering client '" + profile.getClientName() + "'"; + log.error(msg, e); + response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + return response; + } + + @DELETE + public Response unregister(@QueryParam("applicationName") String applicationName, + @QueryParam("userId") String userId, + @QueryParam("consumerKey") String consumerKey) { + Response response; + try { + CloseableHttpResponse serverResponse = RemoteDCRClient.deleteOAuthApplication(userId, applicationName, + consumerKey); + HttpEntity responseData = serverResponse.getEntity(); + int status = serverResponse.getStatusLine().getStatusCode(); + String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF8); + response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build(); + } catch (DynamicClientRegistrationException e) { + String msg = "Server error occurred while deleting the client '" + applicationName + "'"; + log.error(msg, e); + response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (IOException e) { + String msg = "Service invoke error occurred while deleting the client '" + applicationName + "'"; + log.error(msg, e); + response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + return response; + } +} \ No newline at end of file diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/Constants.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/Constants.java new file mode 100644 index 00000000000..74a491e1561 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/Constants.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.dynamic.client.web.proxy.util; + +/** + * Created by harshan on 12/10/15. + */ +public class Constants { + + public static final class ContentTypes { + private ContentTypes() { + throw new AssertionError(); + } + + public static final String CONTENT_TYPE_ANY = "*/*"; + public static final String CONTENT_TYPE_XML = "application/xml"; + public static final String CONTENT_TYPE_APPLICATION_JSON = "application/json"; + } + + public static final class CharSets { + private CharSets() { + throw new AssertionError(); + } + + public static final String CHARSET_UTF8 = "UTF8"; + } + + public static class ConfigurationProperties { + private ConfigurationProperties() { + throw new AssertionError(); + } + + public static final String AUTHENTICATOR_NAME = "OAuthAuthenticator"; + public static final String AUTHENTICATOR_CONFIG_IS_REMOTE = "isRemote"; + public static final String AUTHENTICATOR_CONFIG_HOST_URL = "hostURL"; + } + + public static class RemoteServiceProperties { + private RemoteServiceProperties() { + throw new AssertionError(); + } + + public static final String DYNAMIC_CLIENT_SERVICE_ENDPOINT = "/dynamic-client-web/register"; + public static final String DYNAMIC_CLIENT_SERVICE_PROTOCOL = "https"; + } +} diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/DCRProxyUtils.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/DCRProxyUtils.java new file mode 100644 index 00000000000..7cfa96f1ab0 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/DCRProxyUtils.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.dynamic.client.web.proxy.util; + +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.core.security.AuthenticatorsConfiguration; +import org.wso2.carbon.utils.ConfigurationContextService; + +import javax.ws.rs.core.Response; + +/** + * Created by harshan on 12/10/15. + */ +public class DCRProxyUtils { + + public static ConfigurationContextService getConfigurationContextService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + return (ConfigurationContextService) ctx.getOSGiService(ConfigurationContextService.class, null); + } + + public static Response.Status getResponseStatus(int statusCode) { + switch (statusCode) { + case 200 : + return Response.Status.OK; + case 201 : + return Response.Status.CREATED; + case 400 : + return Response.Status.BAD_REQUEST; + case 500 : + return Response.Status.INTERNAL_SERVER_ERROR; + } + return Response.Status.ACCEPTED; + } + + public static String getKeyManagerHost() + throws IllegalArgumentException { + AuthenticatorsConfiguration authenticatorsConfiguration = AuthenticatorsConfiguration.getInstance(); + AuthenticatorsConfiguration.AuthenticatorConfig authenticatorConfig = authenticatorsConfiguration. + getAuthenticatorConfig( + Constants.ConfigurationProperties.AUTHENTICATOR_NAME); + if (authenticatorConfig != null && authenticatorConfig.getParameters() != null) { + return getHostName(authenticatorConfig.getParameters().get(Constants.ConfigurationProperties. + AUTHENTICATOR_CONFIG_HOST_URL)); + + }else{ + throw new IllegalArgumentException("Configuration parameters need to be defined in Authenticators.xml."); + } + } + + private static String getHostName(String host) { + if (host != null && !host.isEmpty()) { + if (host.contains("https://")) { + return host.replace("https://",""); + } + } else { + throw new IllegalArgumentException("Remote Host parameter must defined in Authenticators.xml."); + } + return null; + } +} diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/RemoteDCRClient.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/RemoteDCRClient.java new file mode 100644 index 00000000000..1bf917bb789 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/RemoteDCRClient.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.dynamic.client.web.proxy.util; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.conn.ssl.X509HostnameVerifier; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.SingleClientConnManager; +import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException; +import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile; +import org.wso2.carbon.utils.CarbonUtils; +import org.wso2.carbon.utils.ConfigurationContextService; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * This class holds the necessary logic to create and delete service-providers by invoking the + * dynamic-client-registration endpoint. + */ +public class RemoteDCRClient { + + private static final String CONTENT_TYPE_APPLICATION_JSON = "application/json"; + private static final String CHARSET_UTF_8 = "UTF-8"; + + public static CloseableHttpResponse createOAuthApplication(RegistrationProfile registrationProfile) + throws DynamicClientRegistrationException { + DefaultHttpClient httpClient = new DefaultHttpClient(); + String clientName = registrationProfile.getClientName(); + String host = DCRProxyUtils.getKeyManagerHost(); + try { + // Setup the HTTPS settings to accept any certificate. + HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; + + SchemeRegistry registry = new SchemeRegistry(); + SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); + socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); + registry.register(new Scheme(Constants.RemoteServiceProperties. + DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, getServerHTTPSPort())); + SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); + httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); + + // Set verifier + HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); + + URI uri = new URIBuilder().setScheme(Constants.RemoteServiceProperties. + DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath( + Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT).build(); + Gson gson = new Gson(); + StringEntity entity = new StringEntity(gson.toJson(registrationProfile), CONTENT_TYPE_APPLICATION_JSON, + CHARSET_UTF_8); + HttpPost httpPost = new HttpPost(uri); + httpPost.setEntity(entity); + return httpClient.execute(httpPost); + } catch (URISyntaxException e) { + throw new DynamicClientRegistrationException("Exception occurred while constructing the URI for invoking " + + "DCR endpoint for registering service-provider for web-app : " + + clientName, e); + } catch (UnsupportedEncodingException e) { + throw new DynamicClientRegistrationException("Exception occurred while constructing the payload for invoking " + + "DCR endpoint for registering service-provider for web-app : " + + clientName, e); + } catch (IOException e) { + throw new DynamicClientRegistrationException("Connection error occurred while invoking DCR endpoint for" + + " registering service-provider for web-app : " + clientName, e); + } + } + + public static CloseableHttpResponse deleteOAuthApplication(String user, String appName, String clientid) + throws DynamicClientRegistrationException { + DefaultHttpClient httpClient = new DefaultHttpClient(); + String host = DCRProxyUtils.getKeyManagerHost(); + try { + // Setup the HTTPS settings to accept any certificate. + HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; + + SchemeRegistry registry = new SchemeRegistry(); + SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); + socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); + registry.register(new Scheme(Constants.RemoteServiceProperties. + DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, getServerHTTPSPort())); + SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); + httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); + + // Set verifier + HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); + + URI uri = new URIBuilder().setScheme(Constants.RemoteServiceProperties. + DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath( + Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT) + .setParameter("applicationName", appName) + .setParameter("userId", user) + .setParameter("consumerKey", clientid).build(); + HttpDelete httpDelete = new HttpDelete(uri); + return httpClient.execute(httpDelete); + } catch (IOException e) { + throw new DynamicClientRegistrationException("Connection error occurred while constructing the payload for " + + "invoking DCR endpoint for unregistering the web-app : " + appName, e); + } catch (URISyntaxException e) { + throw new DynamicClientRegistrationException("Exception occurred while constructing the URI for invoking " + + "DCR endpoint for unregistering the web-app : " + appName, e); + } + } + + private static int getServerHTTPSPort() { + // HTTPS port + String mgtConsoleTransport = CarbonUtils.getManagementTransport(); + ConfigurationContextService configContextService = DCRProxyUtils.getConfigurationContextService(); + int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport); + int httpsProxyPort = + CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(), + mgtConsoleTransport); + if (httpsProxyPort > 0) { + port = httpsProxyPort; + } + return port; + } +} \ No newline at end of file diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/META-INF/webapp-classloading.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 00000000000..38ac5358422 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,35 @@ + + + + + + + + + false + + + CXF,Carbon + diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 00000000000..3044b684e7b --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/web.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..091413931d0 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,37 @@ + + + + Dynamic-client-proxy-Webapp + + Dynamic-client-registration-proxy Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + 1 + + + CXFServlet + /* + + + 60 + + \ No newline at end of file diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/servicelist.css b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/servicelist.css new file mode 100644 index 00000000000..e6eacadbb0e --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/servicelist.css @@ -0,0 +1,125 @@ +@CHARSET "ISO-8859-1"; + +/* http://meyerweb.com/eric/tools/css/reset/ + v2.0 | 20110126 + License: none (public domain) +*/ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} + +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} + +html { + background: #efefef; +} + +body { + line-height: 1; + width: 960px; + margin: auto; + background: white; + padding: 10px; + box-shadow: 0px 0px 5px #CCC; + font-family: "Lucida Grande", "Lucida Sans", "Microsoft Sans Serif", "Lucida Sans Unicode", "Verdana", "Sans-serif", "trebuchet ms" !important; + +} + +ol, ul { + list-style: none; +} + +blockquote, q { + quotes: none; +} + +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} + +table { + border-collapse: collapse; + border-spacing: 0; + width: 960px; + border: solid 1px #ccc; +} + +table a { + font-size: 12px; + color: #1e90ff; + padding: 7px; + float: left;; +} + +.heading { + font-size: 18px; + margin-top: 20px; + float: left; + color: #0067B1; + margin-bottom: 20px; + padding-top: 20px; +} + +.field { + font-weight: normal; + width: 120px; + font-size: 12px; + float: left; + padding: 7px; + clear: left; +} + +.value { + font-weight: bold; + font-size: 12px; + float: left; + padding: 7px; + clear: right; +} + +.porttypename { + font-weight: bold; + font-size: 14px; +} + +UL { + margin-top: 0; +} + +LI { + font-weight: normal; + font-size: 12px; + margin-top: 10px; +} + +TD { + border: 1px solid #ccc; + vertical-align: text-top; + padding: 5px; +} + + diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/log4j.properties b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/log4j.properties new file mode 100644 index 00000000000..7da6d6c9e12 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright 2009 WSO2, Inc. (http://wso2.com) +# +# 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. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/testng.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/testng.xml new file mode 100644 index 00000000000..c0c21a40c31 --- /dev/null +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/test/resources/testng.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/pom.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/pom.xml index 9df732403c0..1df2b45ea17 100644 --- a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/pom.xml +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/pom.xml @@ -87,11 +87,6 @@ cxf-rt-transports-http provided - - org.apache.cxf - cxf-rt-bindings-soap - compile - org.apache.cxf cxf-rt-bindings-http diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java index 194d5e966d3..3c42d87bf88 100644 --- a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/RegistrationService.java @@ -63,7 +63,7 @@ public interface RegistrationService { * @return Status 200 if success. */ @DELETE - public Response unregister(@QueryParam("applicationName") String applicationName, + Response unregister(@QueryParam("applicationName") String applicationName, @QueryParam("userId") String userId, @QueryParam("consumerKey") String consumerKey); diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml index a89397675ad..57eb77536b3 100644 --- a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/webapp/WEB-INF/web.xml @@ -19,9 +19,9 @@ ~ */ --> - Admin-Webapp + dynamic-client-registration-Webapp - JAX-WS/JAX-RS Device Registration Agent Endpoint + Dynamic-client-registration Agent Endpoint JAX-WS/JAX-RS Servlet CXFServlet diff --git a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml index de65e3005d8..c25631e70a1 100644 --- a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml +++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/test/resources/testng.xml @@ -18,11 +18,6 @@ - + - - - - - \ No newline at end of file diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationConstants.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationConstants.java index 12697ceb316..ca5e9a0eb60 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationConstants.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationConstants.java @@ -36,7 +36,8 @@ public class DynamicClientWebAppRegistrationConstants { } public static final String CONTENT_TYPE_ANY = "*/*"; - public static final String MEDIA_TYPE_XML = "application/xml"; + public static final String CONTENT_TYPE_XML = "application/xml"; + public static final String CONTENT_TYPE_APPLICATION_JSON = "application/json"; } public static final class CharSets { diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java index 23729976558..ce6eaa50ee0 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java @@ -117,7 +117,7 @@ public class DynamicClientWebAppRegistrationUtil { Resource resource = DynamicClientWebAppRegistrationUtil.getGovernanceRegistry().newResource(); resource.setContent(writer.toString()); - resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); + resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.CONTENT_TYPE_XML); String resourcePath = DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + oAuthAppDetails.getClientName(); status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/RemoteDCRClient.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/RemoteDCRClient.java index 120b2f056fb..f8e97ed5c0f 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/RemoteDCRClient.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/RemoteDCRClient.java @@ -21,6 +21,8 @@ package org.wso2.carbon.dynamic.client.web.app.registration.util; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; @@ -54,8 +56,7 @@ import java.net.URISyntaxException; */ public class RemoteDCRClient { - private static final String CONTENT_TYPE_APPLICATION_JSON = "application/json"; - private static final String CHARSET_UTF_8 = "UTF-8"; + private static final Log log = LogFactory.getLog(RemoteDCRClient.class); public static OAuthApplicationInfo createOAuthApplication(RegistrationProfile registrationProfile, String host) throws DynamicClientRegistrationException { @@ -80,14 +81,16 @@ public class RemoteDCRClient { DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath( DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT).build(); Gson gson = new Gson(); - StringEntity entity = new StringEntity(gson.toJson(registrationProfile), CONTENT_TYPE_APPLICATION_JSON, - CHARSET_UTF_8); + StringEntity entity = new StringEntity(gson.toJson(registrationProfile), + DynamicClientWebAppRegistrationConstants.ContentTypes.CONTENT_TYPE_APPLICATION_JSON, + DynamicClientWebAppRegistrationConstants.CharSets.CHARSET_UTF8); HttpPost httpPost = new HttpPost(uri); httpPost.setEntity(entity); HttpResponse response = httpClient.execute(httpPost); int status = response.getStatusLine().getStatusCode(); HttpEntity responseData = response.getEntity(); - String responseString = EntityUtils.toString(responseData, CHARSET_UTF_8); + String responseString = EntityUtils.toString(responseData, DynamicClientWebAppRegistrationConstants. + CharSets.CHARSET_UTF8); if (status != 201) { throw new DynamicClientRegistrationException("Backend server error occurred while invoking DCR endpoint for " + "registering service-provider for web-app : " + clientName); diff --git a/components/identity-extensions/dynamic-client-registration/pom.xml b/components/identity-extensions/dynamic-client-registration/pom.xml index e568ea5e88d..54e68022ac6 100644 --- a/components/identity-extensions/dynamic-client-registration/pom.xml +++ b/components/identity-extensions/dynamic-client-registration/pom.xml @@ -36,6 +36,7 @@ dynamic-client-web + dynamic-client-web-proxy org.wso2.carbon.dynamic.client.registration org.wso2.carbon.dynamic.client.web.app.registration diff --git a/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/pom.xml b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/pom.xml index 3f553899898..44ae1e0e363 100644 --- a/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/pom.xml +++ b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/pom.xml @@ -105,6 +105,15 @@ ${basedir}/src/main/resources/ dynamic-client-web.war + + org.wso2.mdm + dynamic-client-web-proxy + ${carbon.device.mgt.version} + war + true + ${basedir}/src/main/resources/ + dynamic-client-web-proxy.war + diff --git a/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/src/main/resources/p2.inf b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/src/main/resources/p2.inf index 0f2ca3fd111..e25a76e1cfd 100644 --- a/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/src/main/resources/p2.inf +++ b/features/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration.server.feature/src/main/resources/p2.inf @@ -1,2 +1,3 @@ instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.dynamic.client.registration.server_${feature.version}/dynamic-client-web.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-web.war,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.dynamic.client.registration.server_${feature.version}/dynamic-client-web.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-web.war,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.dynamic.client.registration.server_${feature.version}/dynamic-client-web-proxy.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-web-proxy.war,overwrite:true);\ \ No newline at end of file