forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
commit
eaca364b0e
@ -0,0 +1,114 @@
|
|||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>dynamic-client-registration</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.wso2.mdm</groupId>
|
||||||
|
<artifactId>dynamic-client-web-proxy</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - Proxy endpoint of Dynamic Client Registration Web Service</name>
|
||||||
|
<description>WSO2 Carbon - Dynamic Client Registration Web Proxy</description>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
<configuration>
|
||||||
|
<warName>${project.artifactId}</warName>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||||
|
<artifactId>axiom-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||||
|
<artifactId>axiom-impl</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
|
||||||
|
<artifactId>axiom</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-transports-http</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-bindings-http</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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.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;
|
||||||
|
|
||||||
|
public class OAuthEndpointProxy {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(OAuthEndpointProxy.class);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes("application/x-www-form-urlencoded")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response issueAccessToken(MultivaluedMap<String, String> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* 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 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.profile.RegistrationProfile;
|
||||||
|
import org.wso2.carbon.dynamic.client.web.proxy.util.Constants;
|
||||||
|
import org.wso2.carbon.dynamic.client.web.proxy.util.DCRProxyUtils;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class implements the proxy-endpoint for Dynamic-client-registration web service endpoints.
|
||||||
|
*/
|
||||||
|
public class RegistrationProxy {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(RegistrationProxy.class);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response register(RegistrationProfile registrationProfile) {
|
||||||
|
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.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_UTF_8);
|
||||||
|
response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
String msg = "Server error occurred while registering client '" + registrationProfile.getClientName() + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
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.";
|
||||||
|
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 {
|
||||||
|
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_UTF_8);
|
||||||
|
response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
String msg = "Server error occurred while deleting the client '" + applicationName + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the constants used by DCR proxy app.
|
||||||
|
*/
|
||||||
|
public class Constants {
|
||||||
|
|
||||||
|
public static final class CharSets {
|
||||||
|
private CharSets() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String CHARSET_UTF_8 = "UTF-8";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ConfigurationProperties {
|
||||||
|
private ConfigurationProperties() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String AUTHENTICATOR_NAME = "OAuthAuthenticator";
|
||||||
|
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 OAUTH2_TOKEN_ENDPOINT = "/oauth2/token";
|
||||||
|
public static final String DYNAMIC_CLIENT_SERVICE_PROTOCOL = "https";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* 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.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the utility methods used by DCR proxy app.
|
||||||
|
*/
|
||||||
|
public class DCRProxyUtils {
|
||||||
|
|
||||||
|
public static ConfigurationContextService getConfigurationContextService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
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 :
|
||||||
|
return Response.Status.OK;
|
||||||
|
case 201 :
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
||||||
|
-->
|
||||||
|
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
||||||
|
|
||||||
|
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
||||||
|
<ParentFirst>false</ParentFirst>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
||||||
|
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
||||||
|
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
||||||
|
-->
|
||||||
|
<Environments>CXF,Carbon</Environments>
|
||||||
|
</Classloading>
|
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||||
|
|
||||||
|
<import resource="classpath:META-INF/cxf/cxf.xml"/>
|
||||||
|
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
|
||||||
|
|
||||||
|
<!-- Registration Service Proxy Endpoint -->
|
||||||
|
<jaxrs:server id="RegistrationService" address="/register">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="RegistrationServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
|
||||||
|
<!-- OAuth Service Proxy Endpoint -->
|
||||||
|
<jaxrs:server id="OAuthService" address="/token">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="OAuthServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers></jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
|
||||||
|
<bean id="RegistrationServiceBean" class="org.wso2.carbon.dynamic.client.web.proxy.RegistrationProxy"/>
|
||||||
|
<bean id="OAuthServiceBean" class="org.wso2.carbon.dynamic.client.web.proxy.OAuthEndpointProxy"/>
|
||||||
|
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
||||||
|
</beans>
|
||||||
|
|
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
|
||||||
|
<display-name>Dynamic-client-proxy-Webapp</display-name>
|
||||||
|
<servlet>
|
||||||
|
<description>Dynamic-client-registration-proxy Endpoint</description>
|
||||||
|
<display-name>JAX-WS/JAX-RS Servlet</display-name>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
|
<servlet-class>
|
||||||
|
org.apache.cxf.transport.servlet.CXFServlet
|
||||||
|
</servlet-class>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<session-config>
|
||||||
|
<session-timeout>60</session-timeout>
|
||||||
|
</session-config>
|
||||||
|
</web-app>
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -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
|
@ -0,0 +1,23 @@
|
|||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
|
|
||||||
|
<suite name="DCR-Proxy-Tests">
|
||||||
|
<parameter name="useDefaultListeners" value="false"/>
|
||||||
|
</suite>
|
@ -1,33 +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;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@Path("/connect")
|
|
||||||
public interface ConfigurationService {
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/register")
|
|
||||||
Response getProfile(@PathParam("client_id") String clientId);
|
|
||||||
|
|
||||||
}
|
|
6
components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java → components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/util/DCRConstants.java
6
components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/ApplicationConstants.java → components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/util/DCRConstants.java
6
components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationUtil.java → components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/util/DynamicClientRegistrationUtil.java
6
components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/DynamicClientRegistrationUtil.java → components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/util/DynamicClientRegistrationUtil.java
28
components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java → 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/dto/DynamicClientRegistrationSettings.java
28
components/identity-extensions/dynamic-client-registration/dynamic-client-web/src/main/java/org/wso2/carbon/dynamic/client/web/impl/ConfigurationServiceImpl.java → 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/dto/DynamicClientRegistrationSettings.java
@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* 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.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;
|
||||||
|
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.apache.http.util.EntityUtils;
|
||||||
|
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException;
|
||||||
|
import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo;
|
||||||
|
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
|
||||||
|
import org.wso2.carbon.dynamic.client.web.app.registration.internal.DynamicClientWebAppRegistrationDataHolder;
|
||||||
|
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 Log log = LogFactory.getLog(RemoteDCRClient.class);
|
||||||
|
|
||||||
|
public static OAuthApplicationInfo createOAuthApplication(RegistrationProfile registrationProfile, String host)
|
||||||
|
throws DynamicClientRegistrationException {
|
||||||
|
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 {
|
||||||
|
URI uri = new URIBuilder().setScheme(DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.
|
||||||
|
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),
|
||||||
|
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, 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);
|
||||||
|
}
|
||||||
|
return getOAuthApplicationInfo(gson.fromJson(responseString, JsonElement.class));
|
||||||
|
} 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);
|
||||||
|
} finally {
|
||||||
|
httpClient.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean deleteOAuthApplication(String user, String appName, String clientid, String host)
|
||||||
|
throws DynamicClientRegistrationException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Invoking DCR service to remove OAuth application created for web app : " + appName);
|
||||||
|
}
|
||||||
|
DefaultHttpClient httpClient = getHTTPSClient();
|
||||||
|
try {
|
||||||
|
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();
|
||||||
|
if (status == 200) {
|
||||||
|
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);
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getServerHTTPSPort() {
|
||||||
|
// HTTPS port
|
||||||
|
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
|
||||||
|
ConfigurationContextService configContextService =
|
||||||
|
DynamicClientWebAppRegistrationDataHolder.getInstance().getConfigurationContextService();
|
||||||
|
int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
|
||||||
|
int httpsProxyPort =
|
||||||
|
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
|
||||||
|
mgtConsoleTransport);
|
||||||
|
if (httpsProxyPort > 0) {
|
||||||
|
port = httpsProxyPort;
|
||||||
|
}
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OAuthApplicationInfo getOAuthApplicationInfo(JsonElement jsonData) {
|
||||||
|
JsonObject jsonObject = jsonData.getAsJsonObject();
|
||||||
|
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
|
||||||
|
JsonElement property = jsonObject.get("client_id");
|
||||||
|
if (property != null) {
|
||||||
|
oAuthApplicationInfo.setClientId(property.getAsString());
|
||||||
|
}
|
||||||
|
property = jsonObject.get("client_name");
|
||||||
|
if (property != null) {
|
||||||
|
oAuthApplicationInfo.setClientName(property.getAsString());
|
||||||
|
}
|
||||||
|
property = jsonObject.get("client_secret");
|
||||||
|
if (property != null) {
|
||||||
|
oAuthApplicationInfo.setClientSecret(property.getAsString());
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue