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
index 05c20176cd..2b03b808fb 100644
--- 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
@@ -44,20 +44,6 @@
${project.artifactId}
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.18
-
-
- file:src/test/resources/log4j.properties
-
-
- src/test/resources/testng.xml
-
-
-
@@ -101,11 +87,6 @@
cxf-rt-bindings-http
provided
-
- org.testng
- testng
- provided
-
org.codehaus.jackson
jackson-jaxrs
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
index 60ff66bddc..c738d8aec1 100644
--- 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
@@ -20,18 +20,61 @@ 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.HttpHost;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.wso2.carbon.dynamic.client.web.proxy.util.Constants;
+import org.wso2.carbon.dynamic.client.web.proxy.util.DCRProxyUtils;
+import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
-/**
- * Created by harshan on 12/10/15.
- */
public class OAuthEndpointProxy {
private static final Log log = LogFactory.getLog(OAuthEndpointProxy.class);
@POST
- public String getAccessToken() {
- return "";
+ @Consumes("application/x-www-form-urlencoded")
+ @Produces("application/json")
+ public Response issueAccessToken(MultivaluedMap paramMap) {
+ DefaultHttpClient httpClient = DCRProxyUtils.getHttpsClient();
+ String host = DCRProxyUtils.getKeyManagerHost();
+ Response response;
+ try {
+ URI uri = new URIBuilder().setScheme(Constants.RemoteServiceProperties.
+ DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath(
+ Constants.RemoteServiceProperties.OAUTH2_TOKEN_ENDPOINT).build();
+ HttpHost httpHost = new HttpHost(uri.toString());
+ CloseableHttpResponse serverResponse = httpClient.execute(httpHost, null);
+ HttpEntity responseData = serverResponse.getEntity();
+ int status = serverResponse.getStatusLine().getStatusCode();
+ String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF_8);
+ response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build();
+ } catch (URISyntaxException e) {
+ String msg = "Service invoke error occurred while registering client";
+ log.error(msg, e);
+ response = Response.status(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (UnsupportedEncodingException e) {
+ String msg = "Service invoke error occurred while registering client";
+ log.error(msg, e);
+ response = Response.status(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (IOException e) {
+ String msg = "Service invoke error occurred while registering client";
+ log.error(msg, e);
+ response = Response.status(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } finally {
+ httpClient.close();
+ }
+ return response;
}
}
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
index 556c62ef35..885530df77 100644
--- 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
@@ -18,73 +18,111 @@
package org.wso2.carbon.dynamic.client.web.proxy;
+import com.google.gson.Gson;
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.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
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;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
/**
- * Created by harshan on 12/10/15.
+ * This class implements the proxy-endpoint for Dynamic-client-registration web service endpoints.
*/
-
-@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) {
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response register(RegistrationProfile registrationProfile) {
+ DefaultHttpClient httpClient = DCRProxyUtils.getHttpsClient();
+ String host = DCRProxyUtils.getKeyManagerHost();
Response response;
try {
- CloseableHttpResponse serverResponse = RemoteDCRClient.createOAuthApplication(profile);
+ 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), MediaType.APPLICATION_JSON,
+ Constants.CharSets.CHARSET_UTF_8);
+ HttpPost httpPost = new HttpPost(uri);
+ httpPost.setEntity(entity);
+ CloseableHttpResponse serverResponse = httpClient.execute(httpPost);
HttpEntity responseData = serverResponse.getEntity();
int status = serverResponse.getStatusLine().getStatusCode();
- String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF8);
+ String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF_8);
response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build();
- } catch (DynamicClientRegistrationException e) {
- String msg = "Server error occurred while registering client '" + profile.getClientName() + "'";
+ } catch (URISyntaxException e) {
+ String msg = "Server error occurred while registering client '" + registrationProfile.getClientName() + "'";
log.error(msg, e);
- response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ response = Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ } catch (UnsupportedEncodingException e) {
+ String msg = "Request data encoding error occurred while registering client '" + registrationProfile.
+ getClientName() + "'";
+ log.error(msg, e);
+ response = Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity(msg).build();
} catch (IOException e) {
- String msg = "Service invoke error occurred while registering client '" + profile.getClientName() + "'";
+ String msg = "Service invoke error occurred while registering client.";
log.error(msg, e);
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } finally {
+ httpClient.close();
}
return response;
}
@DELETE
+ @Produces(MediaType.APPLICATION_JSON)
public Response unregister(@QueryParam("applicationName") String applicationName,
@QueryParam("userId") String userId,
@QueryParam("consumerKey") String consumerKey) {
Response response;
+ DefaultHttpClient httpClient = DCRProxyUtils.getHttpsClient();
+ String host = DCRProxyUtils.getKeyManagerHost();
try {
- CloseableHttpResponse serverResponse = RemoteDCRClient.deleteOAuthApplication(userId, applicationName,
- consumerKey);
+ URI uri = new URIBuilder().setScheme(Constants.RemoteServiceProperties.
+ DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath(
+ Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT)
+ .setParameter("applicationName", applicationName)
+ .setParameter("userId", userId)
+ .setParameter("consumerKey", consumerKey).build();
+ HttpDelete httpDelete = new HttpDelete(uri);
+ CloseableHttpResponse serverResponse = httpClient.execute(httpDelete);
HttpEntity responseData = serverResponse.getEntity();
int status = serverResponse.getStatusLine().getStatusCode();
- String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF8);
+ String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF_8);
response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build();
- } catch (DynamicClientRegistrationException e) {
+ } catch (URISyntaxException 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();
+ response = Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ } catch (UnsupportedEncodingException e) {
+ String msg = "Request data encoding error occurred while deleting the client '" + applicationName + "'";
+ log.error(msg, e);
+ response = Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).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();
+ } finally {
+ httpClient.close();
}
return response;
}
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
index 74a491e156..a63a530edb 100644
--- 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
@@ -19,26 +19,16 @@
package org.wso2.carbon.dynamic.client.web.proxy.util;
/**
- * Created by harshan on 12/10/15.
+ * Holds the constants used by DCR proxy app.
*/
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 final String CHARSET_UTF_8 = "UTF-8";
}
public static class ConfigurationProperties {
@@ -47,7 +37,6 @@ public class Constants {
}
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";
}
@@ -57,6 +46,7 @@ public class Constants {
}
public static final String DYNAMIC_CLIENT_SERVICE_ENDPOINT = "/dynamic-client-web/register";
+ public static final String OAUTH2_TOKEN_ENDPOINT = "/oauth2/token";
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
index 7cfa96f1ab..d9d1e549b2 100644
--- 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
@@ -18,14 +18,25 @@
package org.wso2.carbon.dynamic.client.web.proxy.util;
+import org.apache.http.HttpHost;
+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.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.SingleClientConnManager;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.security.AuthenticatorsConfiguration;
+import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
import javax.ws.rs.core.Response;
/**
- * Created by harshan on 12/10/15.
+ * Holds the utility methods used by DCR proxy app.
*/
public class DCRProxyUtils {
@@ -34,6 +45,24 @@ public class DCRProxyUtils {
return (ConfigurationContextService) ctx.getOSGiService(ConfigurationContextService.class, null);
}
+ public static DefaultHttpClient getHttpsClient() {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ // 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, DCRProxyUtils.getServerHTTPSPort()));
+ SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry);
+ httpClient = new DefaultHttpClient(mgr, httpClient.getParams());
+
+ // Set verifier
+ HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
+ return httpClient;
+ }
+
public static Response.Status getResponseStatus(int statusCode) {
switch (statusCode) {
case 200 :
@@ -42,6 +71,8 @@ public class DCRProxyUtils {
return Response.Status.CREATED;
case 400 :
return Response.Status.BAD_REQUEST;
+ case 415 :
+ return Response.Status.UNSUPPORTED_MEDIA_TYPE;
case 500 :
return Response.Status.INTERNAL_SERVER_ERROR;
}
@@ -73,4 +104,19 @@ public class DCRProxyUtils {
}
return null;
}
+
+
+ public 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;
+ }
}
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
deleted file mode 100644
index 1bf917bb78..0000000000
--- a/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/java/org/wso2/carbon/dynamic/client/web/proxy/util/RemoteDCRClient.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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/WEB-INF/cxf-servlet.xml b/components/identity-extensions/dynamic-client-registration/dynamic-client-web-proxy/src/main/webapp/WEB-INF/cxf-servlet.xml
index 3044b684e7..e057aebcd2 100644
--- 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
@@ -37,7 +37,7 @@
-
+
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 3c42d87bf8..ee5fa0ce74 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
@@ -27,8 +27,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
public interface RegistrationService {
enum ErrorCode {
@@ -52,6 +50,8 @@ public interface RegistrationService {
* @return Status 200 if success including consumerKey and consumerSecret.
*/
@POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
Response register(RegistrationProfile profile);
/**
@@ -63,6 +63,8 @@ public interface RegistrationService {
* @return Status 200 if success.
*/
@DELETE
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
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/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java
index 028b6df1f6..59539b7279 100644
--- a/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java
+++ b/components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/RegistrationServiceImpl.java
@@ -37,8 +37,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.QueryParam;
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
public class RegistrationServiceImpl implements RegistrationService {
private static final Log log = LogFactory.getLog(RegistrationServiceImpl.class);
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 f8e97ed5c0..9d5926db77 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
@@ -60,26 +60,17 @@ public class RemoteDCRClient {
public static OAuthApplicationInfo createOAuthApplication(RegistrationProfile registrationProfile, String host)
throws DynamicClientRegistrationException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ if (log.isDebugEnabled()) {
+ log.debug("Invoking DCR service to create OAuth application for web app : " + registrationProfile.
+ getClientName());
+ }
+ DefaultHttpClient httpClient = getHTTPSClient();
String clientName = registrationProfile.getClientName();
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(DynamicClientWebAppRegistrationConstants.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(DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.
DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath(
- DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT).build();
+ DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT)
+ .build();
Gson gson = new Gson();
StringEntity entity = new StringEntity(gson.toJson(registrationProfile),
DynamicClientWebAppRegistrationConstants.ContentTypes.CONTENT_TYPE_APPLICATION_JSON,
@@ -88,11 +79,12 @@ public class RemoteDCRClient {
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
int status = response.getStatusLine().getStatusCode();
- HttpEntity responseData = response.getEntity();
+ HttpEntity responseData = response.getEntity();
String responseString = EntityUtils.toString(responseData, DynamicClientWebAppRegistrationConstants.
CharSets.CHARSET_UTF8);
if (status != 201) {
- throw new DynamicClientRegistrationException("Backend server error occurred while invoking DCR endpoint for " +
+ throw new DynamicClientRegistrationException(
+ "Backend server error occurred while invoking DCR endpoint for " +
"registering service-provider for web-app : " + clientName);
}
return getOAuthApplicationInfo(gson.fromJson(responseString, JsonElement.class));
@@ -101,39 +93,32 @@ public class RemoteDCRClient {
"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);
+ 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);
+ " registering service-provider for web-app : " + clientName,
+ e);
+ } finally {
+ httpClient.close();
}
}
public static boolean deleteOAuthApplication(String user, String appName, String clientid, String host)
throws DynamicClientRegistrationException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ if (log.isDebugEnabled()) {
+ log.debug("Invoking DCR service to remove OAuth application created for web app : " + appName);
+ }
+ DefaultHttpClient httpClient = getHTTPSClient();
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(DynamicClientWebAppRegistrationConstants.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(DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.
- DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath(
- DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT)
- .setParameter("applicationName", appName)
- .setParameter("userId", user)
- .setParameter("consumerKey", clientid).build();
+ URI uri = new URIBuilder().setScheme(DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.
+ DYNAMIC_CLIENT_SERVICE_PROTOCOL).setHost(host).setPath(
+ DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_ENDPOINT)
+ .setParameter("applicationName", appName)
+ .setParameter("userId", user)
+ .setParameter("consumerKey", clientid).build();
HttpDelete httpDelete = new HttpDelete(uri);
HttpResponse response = httpClient.execute(httpDelete);
int status = response.getStatusLine().getStatusCode();
@@ -141,11 +126,14 @@ public class RemoteDCRClient {
return true;
}
} catch (IOException e) {
- throw new DynamicClientRegistrationException("Connection error occurred while constructing the payload for " +
- "invoking DCR endpoint for unregistering the web-app : " + appName, 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);
+ } finally {
+ httpClient.close();
}
return false;
}
@@ -162,7 +150,7 @@ public class RemoteDCRClient {
if (httpsProxyPort > 0) {
port = httpsProxyPort;
}
- return port;
+ return port;
}
private static OAuthApplicationInfo getOAuthApplicationInfo(JsonElement jsonData) {
@@ -182,4 +170,22 @@ public class RemoteDCRClient {
}
return oAuthApplicationInfo;
}
+
+ private static DefaultHttpClient getHTTPSClient() {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ // 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(DynamicClientWebAppRegistrationConstants.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);
+ return httpClient;
+ }
}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
index 1eb91150b8..54b284dcb2 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
@@ -106,6 +106,9 @@ public class MonitoringManagerImpl implements MonitoringManager {
complianceData.setPolicyId(policy.getId());
} catch (SQLException e) {
throw new PolicyComplianceException("Error occurred while opening a data source connection", e);
+ } catch (MonitoringDAOException e) {
+ throw new PolicyComplianceException("Unable to add the none compliance features to database for device " +
+ deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
} finally {
PolicyManagementDAOFactory.closeConnection();
}
@@ -124,6 +127,10 @@ public class MonitoringManagerImpl implements MonitoringManager {
complianceFeatures);
PolicyManagementDAOFactory.commitTransaction();
+ } catch (MonitoringDAOException e) {
+ PolicyManagementDAOFactory.rollbackTransaction();
+ throw new PolicyComplianceException("Unable to add the none compliance features to database for device " +
+ deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
} finally {
PolicyManagementDAOFactory.closeConnection();
}
@@ -143,6 +150,10 @@ public class MonitoringManagerImpl implements MonitoringManager {
.getId());
monitoringDAO.deleteNoneComplianceData(complianceData.getId());
PolicyManagementDAOFactory.commitTransaction();
+ } catch (MonitoringDAOException e) {
+ PolicyManagementDAOFactory.rollbackTransaction();
+ throw new PolicyComplianceException("Unable to remove the none compliance features from database for device " +
+ deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
} finally {
PolicyManagementDAOFactory.closeConnection();
}
@@ -153,17 +164,11 @@ public class MonitoringManagerImpl implements MonitoringManager {
}
}
} catch (DeviceManagementException e) {
- PolicyManagementDAOFactory.rollbackTransaction();
throw new PolicyComplianceException("Unable tor retrieve device data from DB for " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
} catch (PolicyManagerDAOException | PolicyManagementException e) {
- PolicyManagementDAOFactory.rollbackTransaction();
throw new PolicyComplianceException("Unable tor retrieve policy data from DB for device " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
- } catch (MonitoringDAOException e) {
- PolicyManagementDAOFactory.rollbackTransaction();
- throw new PolicyComplianceException("Unable to add the none compliance features to database for device " +
- deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
}
return complianceFeatures;
}
diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java
index 497fa3b3e2..c82a57646b 100644
--- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java
+++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java
@@ -99,13 +99,14 @@ public class OAuthAuthenticator implements WebappAuthenticator {
if (oAuthValidationResponse.isValid()) {
String username = oAuthValidationResponse.getUserName();
+ String tenantDomain = oAuthValidationResponse.getTenantDomain();
//Remove the userstore domain from username
/*if (username.contains("/")) {
username = username.substring(username.indexOf('/') + 1);
}*/
authenticationInfo.setUsername(username);
- authenticationInfo.setTenantDomain(oAuthValidationResponse.getTenantDomain());
- authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username));
+ authenticationInfo.setTenantDomain(tenantDomain);
+ authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username + "@" + tenantDomain));
if (oAuthValidationResponse.isValid()) {
authenticationInfo.setStatus(Status.CONTINUE);
}
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 44ae1e0e36..3f55389989 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,15 +105,6 @@
${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 e25a76e1cf..0f2ca3fd11 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,3 +1,2 @@
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);\
-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
+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