Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sp provision api feature #357

Open
wants to merge 65 commits into
base: sp-provision-api-feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
bfa9205
created sp-provision-service module
gayanch Jun 26, 2018
d777b72
initial commit: API implementation
gayanch Jun 28, 2018
2e1bb56
changed property file based config method to mobile-connect.xml method
gayanch Jun 28, 2018
6e88f43
created basic functionalties of service provision api
gayanch Jun 29, 2018
f61296c
[IDSDEV-945] Add Self Service Portal Code to master
Lakini Jul 2, 2018
581316c
[IDSDEV-945] Add angular component to Self Service portal feature
madushak Apr 27, 2017
1dcea92
IDSDEV-553 - Fixing error on npm Build Production
sahantelco May 5, 2017
7308cb8
adding anjular build files
sahantelco May 5, 2017
49987bb
Added cross origin filter
madushak May 5, 2017
5cfdb5e
Changed the ngfor
madushak May 5, 2017
2528aeb
Added login count API method
madushak May 8, 2017
9a4fb70
Added Pin reset swagger
madushak May 8, 2017
e51a74e
[IDSDEV-553] build anjular files
sahantelco May 5, 2017
55ce98f
[IDSDEV-559] Create PIN reset page with form validation
sahantelco May 9, 2017
dac1a53
[IDSDEV-500] activity widget modification
sahantelco May 9, 2017
215e150
Added PIN reset API method and get current LOA api - IDSDEV-557
madushak May 9, 2017
95491e9
PIN reset UI - IDSDEV-557
madushak May 15, 2017
b64bb1c
Added login summary chart and pin reset IDSDEV-557
madushak May 19, 2017
9bb78e7
Code cleanup IDSDEV-557
madushak May 22, 2017
d72aa01
Footer modification
sahantelco May 23, 2017
42f204e
Added profile upgrade flow - IDSDEV-557
madushak May 24, 2017
7004625
Rename README to README.md
madushak May 30, 2017
48cdc52
Update README.md
madushak May 30, 2017
c18fc79
[IDSDEV-945] Added build scripts and hashed pin reset
madushak May 30, 2017
2780cfb
Changed login history sort order - IDSDEV-557
madushak May 30, 2017
ff79163
[IDSDEV-564] Theme change accourding to mobileconnect color schema
sahantelco May 30, 2017
ced4a5b
Fixing Undefined param usage for common service call
sahantelco Jun 13, 2017
5437ca7
Fixing URL path(pin reset/signout) issue
sahantelco Jun 14, 2017
626e596
[IDSDEV-605] UI Improvements
sahantelco Jul 4, 2017
aa11d18
[IDSDEV-604] User can not log into self service portal after login ou…
sahantelco Jul 5, 2017
f09c440
[IDSDEV-619] Fix the issue in After changing the offset value of MIG …
Jul 11, 2017
2307d03
[IDSDEV-619] Fixed the issue : unable to log into self service Portal…
Jul 11, 2017
7266c4f
sp provision api feature
gayanch Jul 5, 2018
9091a05
[IDSDEV-971] rebase the master with mig-release-2.2.0-m3 to add Self …
Lakini Jul 5, 2018
3632c46
implemented service provider provision API
gayanch Jul 9, 2018
049b087
feature generation
gayanch Jul 10, 2018
8e6f587
[IDSDEV-984] Fix bugs in login history
Lakini Jul 10, 2018
18de31d
Retrieve MIG host URL from carbon
gayanch Jul 10, 2018
2c8528b
feature generation
gayanch Jul 10, 2018
6c78d57
PR review modifications
gayanch Jul 10, 2018
a63e610
PR review modifications - 2
gayanch Jul 10, 2018
5a1a1f0
changed stored procedures to handle operator name and scope values pr…
gayanch Jul 11, 2018
f28f2d6
created sp-provision-service module
gayanch Jun 26, 2018
f20f1db
initial commit: API implementation
gayanch Jun 28, 2018
2111664
changed property file based config method to mobile-connect.xml method
gayanch Jun 28, 2018
9cc47a0
created basic functionalties of service provision api
gayanch Jun 29, 2018
dc65d97
sp provision api feature
gayanch Jul 5, 2018
1b95a62
implemented service provider provision API
gayanch Jul 9, 2018
ce3f870
feature generation
gayanch Jul 10, 2018
aae9b28
Retrieve MIG host URL from carbon
gayanch Jul 10, 2018
6b90680
feature generation
gayanch Jul 10, 2018
012421e
PR review modifications
gayanch Jul 10, 2018
3f347c1
PR review modifications - 2
gayanch Jul 10, 2018
4e021b5
changed stored procedures to handle operator name and scope values pr…
gayanch Jul 11, 2018
fb33566
rebase with Lakini/selfServicePortal
gayanch Jul 11, 2018
0086b31
added error messages
gayanch Jul 11, 2018
ce1ef6a
changed log4j ConversionPattern for SPProvision API logs
gayanch Jul 12, 2018
920f233
Selfcareportal UI v1
gayanch Jul 24, 2018
96ca309
selfserviceportal endpoint changes
gayanch Jul 24, 2018
ae8d049
added some error messages
gayanch Jul 24, 2018
56d113b
removed react unused imports and added .gitignore entries for react f…
gayanch Jul 25, 2018
1fc8120
changed selfserviceportal web app path
gayanch Jul 25, 2018
1146231
fixed an issue in recent activities paging mechanism
gayanch Jul 25, 2018
76d204c
Removed debug console.log statements
gayanch Jul 25, 2018
3a9d099
UI improvements
gayanch Jul 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions components/sp-provision-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2015-2016, WSO2.Telco Inc. (http://www.wso2telco.com)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use correct year

All Rights Reserved. WSO2.Telco Inc. licences 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>
<groupId>com.wso2telco.ids</groupId>
<artifactId>component-ids</artifactId>
<version>2.4.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>sp-provision-service</artifactId>
<packaging>war</packaging>
<name>Service Provider Provisioning Service</name>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
<version>5.1.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.wso2telco.core</groupId>
<artifactId>config-util</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.application.mgt.stub</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>com.wso2telco.core</groupId>
<artifactId>dbutils</artifactId>
</dependency>
</dependencies>

<build>
<finalName>service-provider-provision</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven-compiler-plugin.version}</source>
<target>${maven-compiler-plugin.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp</directory>
</resource>
</webResources>
<warName>service-provider-provision</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>


Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/**
* ****************************************************************************
* Copyright (c) 2015-2018, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved.
* <p>
* WSO2.Telco Inc. licences 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 com.wso2telco.spprovisionapp.api;

import com.google.gson.Gson;
import com.wso2telco.core.config.model.MobileConnectConfig;
import com.wso2telco.core.config.service.ConfigurationService;
import com.wso2telco.core.config.service.ConfigurationServiceImpl;
import com.wso2telco.spprovisionapp.exception.HttpResponseIsEmptyException;
import com.wso2telco.spprovisionapp.model.TokenResponse;
import com.wso2telco.spprovisionapp.utils.HttpClientUtil;
import net.iharder.Base64;
import okhttp3.*;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
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.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.security.KeyStore;
import java.util.List;

public class ApiCallsInAM {
static final Logger logInstance = Logger.getLogger(ApiCallsInAM.class);

private String amUserCreationAPI, amLoginAPI, amAppCreationAPI, addSubscriptionAPI, password, appName, tokenUrlAm,
tokenEndpoint;
private List<Cookie> cookies;
private CookieStore cookieStore;
private static ConfigurationService configurationService = new ConfigurationServiceImpl();
private static MobileConnectConfig mobileConnectConfigs;

static {
mobileConnectConfigs = configurationService.getDataHolder().getMobileConnectConfig();
}


public ApiCallsInAM() {
String host;
host = mobileConnectConfigs.getSpProvisionConfig().getApiManagerUrl();
tokenUrlAm = mobileConnectConfigs.getSpProvisionConfig().getAmTokenUrl();
tokenEndpoint = mobileConnectConfigs.getSpProvisionConfig().getTokenUrl();

amUserCreationAPI = host + "/store/site/blocks/user/sign-up/ajax/user-add.jag";
amLoginAPI = host + "/store/site/blocks/user/login/ajax/login.jag";
amAppCreationAPI = host + "/store/site/blocks/application/application-add/ajax/application-add.jag";
addSubscriptionAPI = host + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag";
password = mobileConnectConfigs.getSpProvisionConfig().getDefaultUserPassword();
}

private static String postToURLjson(String url, HttpClient httpClient) {
try {
HttpPost postRequest = new HttpPost(url);

postRequest.addHeader("Content-Type", "application/json");
HttpResponse response = httpClient.execute(postRequest);

BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));

String output;
StringBuffer totalOutput = new StringBuffer();
String postResponse;

while ((output = br.readLine()) != null) {
totalOutput.append(output);
}

postResponse = "{\"httpCode\": " + response.getStatusLine().getStatusCode() + ",\"output\": "
+ totalOutput.toString() + "}";
return postResponse;
} catch (IOException ex) {
logInstance.error("IOException occured in reading responce from AM APIs:" + ex.toString(), ex);
String postResponse = "{\"exception\": " + ex.toString() + "\"}";
return postResponse;
}
}

/*
* Create new User in AM
*/
public String createNewUserInAm(String appName, String firstName, String lastName, String devEmail) throws
IOException {

String url = amUserCreationAPI + "?allFieldsValues=" + firstName + "%7C" + lastName + "%7C" + devEmail
+ "&username=" + appName + "&password=" + password + "&action=addUser";
HttpClient httpClient = getNewHttpClient();
String response = postToURLjson(url, httpClient);
httpClient.getConnectionManager().shutdown();
return response;
}

/*
* Login the new User to API
*/
public String loginToAm(String appName) throws IOException {
cookieStore = null;


String url = amLoginAPI + "?username=" + appName + "&password="
+ URLEncoder.encode(password, "UTF-8") + "&action=login";
DefaultHttpClient httpClient = getNewHttpClient();
String response = postToURLjson(url, httpClient);
httpClient.getConnectionManager().shutdown();
cookieStore = httpClient.getCookieStore();
return response;
}

/*
* add subscriptions to the newly created app
*/
/*
* Service provider get scope
*/

/*
* Create application in AM
*/
public String createApplication(String appName, String description, String callback, String tier)
throws IOException {

String url = amAppCreationAPI + "?action=addApplication&application=" + appName + "&tier=" + tier
+ "&description=" + description + "&callbackUrl=" + callback + "";
DefaultHttpClient httpClient = getNewHttpClient();
httpClient.setCookieStore(cookieStore);
String response = postToURLjson(url, httpClient);
httpClient.getConnectionManager().shutdown();
return response;
}

public String addSubscritions(String userName, String appName, String apiName, String apiVersion,
String apiProvider, String tier) {

try {
loginToAm(userName);
} catch (IOException ex) {
logInstance.error("IO Exception occured when trying to login to the user in Add subscription " +
"process" + ex.toString(), ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llogInstance.error("IO Exception occured when trying to login to the user in Add subscription " +

  •                "process" + ex.getMessage(), ex);
    

}
String url = addSubscriptionAPI + "?action=addAPISubscription&name=" + apiName + "&version=" + apiVersion
+ "&provider=" + apiProvider + "&tier=" + tier + "&applicationName=" + appName + "";
DefaultHttpClient httpClient = getNewHttpClient();
httpClient.setCookieStore(cookieStore);
String response = postToURLjson(url, httpClient);
httpClient.getConnectionManager().shutdown();
return response;
}

public String getAccessToken(String consumerKey, String consumerSecret) throws IOException {

return getTokenWithOkHttpClient(consumerKey, consumerSecret);
}

private String getTokenWithOkHttpClient(String consumerKey, String consumerSecret) throws IOException {
OkHttpClient client = HttpClientUtil.getUnsafeOkHttpClient();//HttpClientUtil.getUnsecureHttpClient();//null;//new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "grant_type=client_credentials");
String encoding = Base64.encodeBytes((consumerKey + ":" + consumerSecret).getBytes());
Request request = new Request.Builder()
.url(tokenEndpoint)
.post(body)
.addHeader("authorization", "Basic " + encoding)
.addHeader("content-type", "application/x-www-form-urlencoded")
.addHeader("cache-control", "no-cache")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "37e6d409-ba6d-b94d-50d2-273b7d671a84")

.addHeader("postman-token", "37e6d409-ba6d-b94d-50d2-273b7d671a84")
.build();

Response response = client.newCall(request).execute();
if (response != null && response.body() != null) {
TokenResponse tokenResponse = new Gson().fromJson(response.body().string(), TokenResponse.class);

return tokenResponse.getAccessToken();
} else {
throw new HttpResponseIsEmptyException("Response is empty");
}
}


public DefaultHttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);

SslSocketFactory sf = new SslSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

HttpParams parameters = new BasicHttpParams();
HttpProtocolParams.setVersion(parameters, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(parameters, HTTP.UTF_8);

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));

ClientConnectionManager ccm = new ThreadSafeClientConnManager(parameters,
registry);

return new DefaultHttpClient(ccm, parameters);
} catch (Exception exception) {
logInstance.error("Exception" + exception.getMessage(), exception);
return new DefaultHttpClient();
}
}

private String convertStringToJson(String value) throws JSONException {
JSONObject jObject = new JSONObject(value);
String accessToken = jObject.getString("access_token");
return accessToken;
}
}
Loading