forked from community/device-mgt-core
usage-11591
commit
70f5a99e60
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
||||
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.*;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.ApiApplicationInfo;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ConsumerRESTAPIServices {
|
||||
|
||||
Application[] getAllApplications(ApiApplicationInfo apiApplicationInfo, String appName)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
Application getDetailsOfAnApplication(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
Application createApplication(ApiApplicationInfo apiApplicationInfo, Application application)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
Boolean deleteApplication(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
Subscription[] getAllSubscriptions(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
APIInfo[] getAllApis(ApiApplicationInfo apiApplicationInfo, Map<String, String> queryParams, Map<String, String> headerParams)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
Subscription createSubscription(ApiApplicationInfo apiApplicationInfo, Subscription subscriptions)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
Subscription[] createSubscriptions(ApiApplicationInfo apiApplicationInfo, List<Subscription> subscriptions)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
ApplicationKey generateApplicationKeys(ApiApplicationInfo apiApplicationInfo, String applicationId, String keyManager,
|
||||
String validityTime, String keyType)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
ApplicationKey mapApplicationKeys(ApiApplicationInfo apiApplicationInfo, Application application, String keyManager, String keyType)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
ApplicationKey getKeyDetails(ApiApplicationInfo apiApplicationInfo, String applicationId, String keyMapId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
ApplicationKey updateGrantType(ApiApplicationInfo apiApplicationInfo, String applicationId, String keyMapId, String keyManager,
|
||||
List<String> supportedGrantTypes, String callbackUrl)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
|
||||
KeyManager[] getAllKeyManagers(ApiApplicationInfo apiApplicationInfo)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||
}
|
@ -0,0 +1,674 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.*;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.ApiApplicationInfo;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils;
|
||||
import okhttp3.*;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ConsumerRESTAPIServicesImpl.class);
|
||||
private static final OkHttpClient client = new OkHttpClient(HttpsTrustManagerUtils.getSSLClient().newBuilder());
|
||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
private static final Gson gson = new Gson();
|
||||
private static final String host = System.getProperty(Constants.IOT_CORE_HOST);
|
||||
private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT);
|
||||
private static final String endPointPrefix = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
|
||||
+ Constants.COLON + port;
|
||||
|
||||
@Override
|
||||
public Application[] getAllApplications(ApiApplicationInfo apiApplicationInfo, String appName)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getAllApplicationsUrl = endPointPrefix + Constants.APPLICATIONS_API + "?query=" + appName;
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getAllApplicationsUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.get();
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
JSONArray applicationList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||
return gson.fromJson(applicationList.toString(), Application[].class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return getAllApplications(refreshedApiApplicationInfo, appName);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Application getDetailsOfAnApplication(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getDetailsOfAPPUrl = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH + applicationId;
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getDetailsOfAPPUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.get();
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
return gson.fromJson(response.body().string(), Application.class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return getDetailsOfAnApplication(refreshedApiApplicationInfo, applicationId);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Application createApplication(ApiApplicationInfo apiApplicationInfo, Application application)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getAllScopesUrl = endPointPrefix + Constants.APPLICATIONS_API;
|
||||
|
||||
JSONArray groups = new JSONArray();
|
||||
JSONArray subscriptionScope = new JSONArray();
|
||||
|
||||
if (application.getGroups() != null && application.getSubscriptionScopes() != null) {
|
||||
for (String string : application.getGroups()) {
|
||||
groups.put(string);
|
||||
}
|
||||
for (Scopes string : application.getSubscriptionScopes()) {
|
||||
subscriptionScope.put(string);
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject applicationInfo = new JSONObject();
|
||||
applicationInfo.put("name", application.getName());
|
||||
applicationInfo.put("throttlingPolicy", application.getThrottlingPolicy());
|
||||
applicationInfo.put("description", application.getDescription());
|
||||
applicationInfo.put("tokenType", application.getTokenType());
|
||||
applicationInfo.put("groups", groups);
|
||||
applicationInfo.put("attributes", new JSONObject());
|
||||
applicationInfo.put("subscriptionScopes", subscriptionScope);
|
||||
|
||||
RequestBody requestBody = RequestBody.create(JSON, applicationInfo.toString());
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getAllScopesUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.post(requestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_CREATED == response.code()) {
|
||||
return gson.fromJson(response.body().string(), Application.class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return createApplication(refreshedApiApplicationInfo, application);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request body";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteApplication(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String deleteScopesUrl = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH + applicationId;
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(deleteScopesUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.delete();
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
return true;
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return deleteApplication(refreshedApiApplicationInfo, applicationId);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request body";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subscription[] getAllSubscriptions(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "?applicationId=" + applicationId + "&limit=1000";
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getAllScopesUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.get();
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
JSONArray subscriptionList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||
return gson.fromJson(subscriptionList.toString(), Subscription[].class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return getAllSubscriptions(refreshedApiApplicationInfo, applicationId);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public APIInfo[] getAllApis(ApiApplicationInfo apiApplicationInfo, Map<String, String> queryParams, Map<String, String> headerParams)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
StringBuilder getAPIsURL = new StringBuilder(endPointPrefix + Constants.DEV_PORTAL_API);
|
||||
|
||||
for (Map.Entry<String, String> query : queryParams.entrySet()) {
|
||||
getAPIsURL.append(Constants.AMPERSAND).append(query.getKey()).append(Constants.EQUAL).append(query.getValue());
|
||||
}
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getAPIsURL.toString());
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
|
||||
for (Map.Entry<String, String> header : headerParams.entrySet()) {
|
||||
builder.addHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
builder.get();
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
JSONArray apiList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||
return gson.fromJson(apiList.toString(), APIInfo[].class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return getAllApis(refreshedApiApplicationInfo, queryParams, headerParams);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subscription createSubscription(ApiApplicationInfo apiApplicationInfo, Subscription subscriptions)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String createSubscriptionUrl = endPointPrefix + Constants.SUBSCRIPTION_API;
|
||||
|
||||
JSONObject subscriptionObject = new JSONObject();
|
||||
subscriptionObject.put("applicationId", subscriptions.getApplicationId());
|
||||
subscriptionObject.put("apiId", subscriptions.getApiId());
|
||||
subscriptionObject.put("throttlingPolicy", subscriptions.getThrottlingPolicy());
|
||||
subscriptionObject.put("requestedThrottlingPolicy", subscriptions.getRequestedThrottlingPolicy());
|
||||
|
||||
RequestBody requestBody = RequestBody.create(JSON, subscriptionObject.toString());
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(createSubscriptionUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
|
||||
builder.post(requestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_CREATED == response.code()) {
|
||||
return gson.fromJson(response.body().string(), Subscription.class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return createSubscription(refreshedApiApplicationInfo, subscriptions);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request body";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subscription[] createSubscriptions(ApiApplicationInfo apiApplicationInfo, List<Subscription> subscriptions)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String createSubscriptionsUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "/multiple";
|
||||
|
||||
String subscriptionsList = gson.toJson(subscriptions);
|
||||
RequestBody requestBody = RequestBody.create(JSON, subscriptionsList);
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(createSubscriptionsUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
|
||||
builder.post(requestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
return gson.fromJson(response.body().string(), Subscription[].class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return createSubscriptions(refreshedApiApplicationInfo, subscriptions);
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request body";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationKey generateApplicationKeys(ApiApplicationInfo apiApplicationInfo, String applicationId, String keyManager,
|
||||
String validityTime, String keyType)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String generateApplicationKeysUrl = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH +
|
||||
applicationId + "/generate-keys";
|
||||
|
||||
JSONArray grantTypesToBeSupported = new JSONArray();
|
||||
grantTypesToBeSupported.put("password");
|
||||
grantTypesToBeSupported.put("client_credentials");
|
||||
|
||||
JSONArray scopes = new JSONArray();
|
||||
scopes.put("am_application_scope");
|
||||
scopes.put("default");
|
||||
|
||||
JSONObject keyInfo = new JSONObject();
|
||||
keyInfo.put("keyType", keyType);
|
||||
keyInfo.put("keyManager", keyManager);
|
||||
keyInfo.put("grantTypesToBeSupported", grantTypesToBeSupported);
|
||||
keyInfo.put("callbackUrl", "");
|
||||
keyInfo.put("scopes", scopes);
|
||||
keyInfo.put("validityTime", 3600);
|
||||
keyInfo.put("additionalProperties", new JSONObject());
|
||||
|
||||
RequestBody requestBody = RequestBody.create(JSON, keyInfo.toString());
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(generateApplicationKeysUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.post(requestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
return gson.fromJson(response.body().string(), ApplicationKey.class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return generateApplicationKeys(refreshedApiApplicationInfo, applicationId, keyManager, validityTime, keyType);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request body";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationKey mapApplicationKeys(ApiApplicationInfo apiApplicationInfo, Application application, String keyManager, String keyType)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getAllScopesUrl = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH +
|
||||
application.getApplicationId() + "/map-keys";
|
||||
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("consumerKey", apiApplicationInfo.getClientId());
|
||||
payload.put("consumerSecret", apiApplicationInfo.getClientSecret());
|
||||
payload.put("keyManager", keyManager);
|
||||
payload.put("keyType", keyType);
|
||||
|
||||
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getAllScopesUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.post(requestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
return gson.fromJson(response.body().string(), ApplicationKey.class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return mapApplicationKeys(refreshedApiApplicationInfo, application, keyManager, keyType);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request body";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationKey getKeyDetails(ApiApplicationInfo apiApplicationInfo, String applicationId, String keyMapId)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getKeyDetails = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH + applicationId + "/oauth-keys/" + keyMapId;
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getKeyDetails);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.get();
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
return gson.fromJson(response.body().string(), ApplicationKey.class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return getKeyDetails(refreshedApiApplicationInfo, applicationId, keyMapId);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationKey updateGrantType(ApiApplicationInfo apiApplicationInfo, String applicationId, String keyMapId, String keyManager,
|
||||
List<String> supportedGrantTypes, String callbackUrl)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getKeyDetails = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH + applicationId + "/oauth-keys/" + keyMapId;
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getKeyDetails);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
|
||||
JSONArray supportedGrantTypeList = new JSONArray();
|
||||
for (String string : supportedGrantTypes) {
|
||||
supportedGrantTypeList.put(string);
|
||||
}
|
||||
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("keyMappingId", keyMapId);
|
||||
payload.put("keyManager", keyManager);
|
||||
payload.put("supportedGrantTypes", supportedGrantTypeList);
|
||||
payload.put("callbackUrl", (callbackUrl != null ? callbackUrl : ""));
|
||||
payload.put("additionalProperties", new JSONObject());
|
||||
|
||||
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||
|
||||
builder.put(requestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
return gson.fromJson(response.body().string(), ApplicationKey.class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return updateGrantType(refreshedApiApplicationInfo, applicationId, keyMapId, keyManager, supportedGrantTypes, callbackUrl);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyManager[] getAllKeyManagers(ApiApplicationInfo apiApplicationInfo)
|
||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||
|
||||
String getAllKeyManagersUrl = endPointPrefix + Constants.KEY_MANAGERS_API;
|
||||
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(getAllKeyManagersUrl);
|
||||
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||
+ apiApplicationInfo.getAccess_token());
|
||||
builder.get();
|
||||
Request request = builder.build();
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (HttpStatus.SC_OK == response.code()) {
|
||||
JSONArray keyManagerList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||
return gson.fromJson(keyManagerList.toString(), KeyManager[].class);
|
||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
||||
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
||||
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
||||
return getAllKeyManagers(refreshedApiApplicationInfo);
|
||||
//TODO: max attempt count
|
||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||
String msg = "Bad Request, Invalid request";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
String msg = "Response : " + response.code() + response.body();
|
||||
throw new UnexpectedResponseException(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error occurred while processing the response";
|
||||
log.error(msg, e);
|
||||
throw new APIServicesException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private ApiApplicationInfo returnApplicationInfo(ApiApplicationInfo apiApplicationInfo, AccessTokenInfo refreshedToken) {
|
||||
|
||||
ApiApplicationInfo applicationInfo = new ApiApplicationInfo();
|
||||
applicationInfo.setClientId(apiApplicationInfo.getClientId());
|
||||
applicationInfo.setClientSecret(apiApplicationInfo.getClientSecret());
|
||||
applicationInfo.setAccess_token(refreshedToken.getAccess_token());
|
||||
applicationInfo.setRefresh_token(refreshedToken.getRefresh_token());
|
||||
return applicationInfo;
|
||||
}
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class represents the Consumer API Information.
|
||||
*/
|
||||
|
||||
public class APIInfo {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String context;
|
||||
private String version;
|
||||
private String provider;
|
||||
private String lifeCycleStatus;
|
||||
private String thumbnailUri;
|
||||
private String avgRating;
|
||||
private List<String> throttlingPolicies;
|
||||
private JSONObject advertiseInfo;
|
||||
private JSONObject businessInformation;
|
||||
private boolean isSubscriptionAvailable;
|
||||
private String monetizationLabel;
|
||||
private String gatewayVendor;
|
||||
private List<String> additionalProperties;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public void setProvider(String provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public String getLifeCycleStatus() {
|
||||
return lifeCycleStatus;
|
||||
}
|
||||
|
||||
public void setLifeCycleStatus(String lifeCycleStatus) {
|
||||
this.lifeCycleStatus = lifeCycleStatus;
|
||||
}
|
||||
|
||||
public String getThumbnailUri() {
|
||||
return thumbnailUri;
|
||||
}
|
||||
|
||||
public void setThumbnailUri(String thumbnailUri) {
|
||||
this.thumbnailUri = thumbnailUri;
|
||||
}
|
||||
|
||||
public String getAvgRating() {
|
||||
return avgRating;
|
||||
}
|
||||
|
||||
public void setAvgRating(String avgRating) {
|
||||
this.avgRating = avgRating;
|
||||
}
|
||||
|
||||
public List<String> getThrottlingPolicies() {
|
||||
return throttlingPolicies;
|
||||
}
|
||||
|
||||
public void setThrottlingPolicies(List<String> throttlingPolicies) {
|
||||
this.throttlingPolicies = throttlingPolicies;
|
||||
}
|
||||
|
||||
public JSONObject getAdvertiseInfo() {
|
||||
return advertiseInfo;
|
||||
}
|
||||
|
||||
public void setAdvertiseInfo(JSONObject advertiseInfo) {
|
||||
this.advertiseInfo = advertiseInfo;
|
||||
}
|
||||
|
||||
public JSONObject getBusinessInformation() {
|
||||
return businessInformation;
|
||||
}
|
||||
|
||||
public void setBusinessInformation(JSONObject businessInformation) {
|
||||
this.businessInformation = businessInformation;
|
||||
}
|
||||
|
||||
public boolean isSubscriptionAvailable() {
|
||||
return isSubscriptionAvailable;
|
||||
}
|
||||
|
||||
public void setSubscriptionAvailable(boolean subscriptionAvailable) {
|
||||
isSubscriptionAvailable = subscriptionAvailable;
|
||||
}
|
||||
|
||||
public String getMonetizationLabel() {
|
||||
return monetizationLabel;
|
||||
}
|
||||
|
||||
public void setMonetizationLabel(String monetizationLabel) {
|
||||
this.monetizationLabel = monetizationLabel;
|
||||
}
|
||||
|
||||
public String getGatewayVendor() {
|
||||
return gatewayVendor;
|
||||
}
|
||||
|
||||
public void setGatewayVendor(String gatewayVendor) {
|
||||
this.gatewayVendor = gatewayVendor;
|
||||
}
|
||||
|
||||
public List<String> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
public void setAdditionalProperties(List<String> additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
/**
|
||||
* This class represents the Consumer API Key Information.
|
||||
*/
|
||||
|
||||
public class APIKey {
|
||||
|
||||
private String apikey;
|
||||
private int validityTime;
|
||||
|
||||
public String getApikey() {
|
||||
return apikey;
|
||||
}
|
||||
|
||||
public void setApikey(String apikey) {
|
||||
this.apikey = apikey;
|
||||
}
|
||||
|
||||
public int getValidityTime() {
|
||||
return validityTime;
|
||||
}
|
||||
|
||||
public void setValidityTime(int validityTime) {
|
||||
this.validityTime = validityTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import org.wso2.carbon.apimgt.api.model.APIKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class represents the Consumer Application Information.
|
||||
*/
|
||||
|
||||
public class Application {
|
||||
private String applicationId;
|
||||
private String name;
|
||||
private String throttlingPolicy;
|
||||
private String description;
|
||||
private String tokenType;
|
||||
private String status;
|
||||
private List<String> groups;
|
||||
private int subscriptionCount;
|
||||
private List<String> keys;
|
||||
private Map<String, String> attributes;
|
||||
private List<Scopes> subscriptionScopes;
|
||||
private String owner;
|
||||
private boolean hashEnabled;
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public void setApplicationId(String applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getThrottlingPolicy() {
|
||||
return throttlingPolicy;
|
||||
}
|
||||
|
||||
public void setThrottlingPolicy(String throttlingPolicy) {
|
||||
this.throttlingPolicy = throttlingPolicy;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
public void setTokenType(String tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<String> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void setGroups(List<String> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
public int getSubscriptionCount() {
|
||||
return subscriptionCount;
|
||||
}
|
||||
|
||||
public void setSubscriptionCount(int subscriptionCount) {
|
||||
this.subscriptionCount = subscriptionCount;
|
||||
}
|
||||
|
||||
public List<String> getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public void setKeys(List<String> keys) {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(Map<String, String> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public List<Scopes> getSubscriptionScopes() {
|
||||
return subscriptionScopes;
|
||||
}
|
||||
|
||||
public void setSubscriptionScopes(List<Scopes> subscriptionScopes) {
|
||||
this.subscriptionScopes = subscriptionScopes;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public boolean isHashEnabled() {
|
||||
return hashEnabled;
|
||||
}
|
||||
|
||||
public void setHashEnabled(boolean hashEnabled) {
|
||||
this.hashEnabled = hashEnabled;
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import io.apicurio.datamodels.asyncapi.v2.visitors.Aai20Traverser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the Consumer Application configuration Information.
|
||||
*/
|
||||
public class ApplicationConfigurations {
|
||||
|
||||
private String name;
|
||||
private String label;
|
||||
private String type;
|
||||
private boolean required;
|
||||
private boolean mask;
|
||||
private boolean multiple;
|
||||
private String tooltip;
|
||||
private List<String> values;
|
||||
private String defaults;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public void setRequired(boolean required) {
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public boolean isMask() {
|
||||
return mask;
|
||||
}
|
||||
|
||||
public void setMask(boolean mask) {
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
public boolean isMultiple() {
|
||||
return multiple;
|
||||
}
|
||||
|
||||
public void setMultiple(boolean multiple) {
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
public String getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
public void setTooltip(String tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public List<String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(List<String> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public String getDefaults() {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public void setDefaults(String defaults) {
|
||||
this.defaults = defaults;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ApplicationGrantTypeUpdater {
|
||||
|
||||
private String callbackUrl;
|
||||
|
||||
private ArrayList<String> supportedGrantTypes;
|
||||
|
||||
public String getCallbackUrl() {
|
||||
return callbackUrl;
|
||||
}
|
||||
|
||||
public void setCallbackUrl(String callbackUrl) {
|
||||
this.callbackUrl = callbackUrl;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSupportedGrantTypes() {
|
||||
return supportedGrantTypes;
|
||||
}
|
||||
|
||||
public void setSupportedGrantTypes(ArrayList<String> supportedGrantTypes) {
|
||||
this.supportedGrantTypes = supportedGrantTypes;
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the Consumer Application key Information.
|
||||
*/
|
||||
public class ApplicationKey {
|
||||
|
||||
private String keyMappingId;
|
||||
private String keyManager;
|
||||
private String consumerKey;
|
||||
private String consumerSecret;
|
||||
private List<String> supportedGrantTypes;
|
||||
private String callbackUrl;
|
||||
private String keyState;
|
||||
private String keyType;
|
||||
private String mode;
|
||||
private String groupId;
|
||||
private JSONObject token;
|
||||
private JSONObject additionalProperties;
|
||||
|
||||
public String getKeyMappingId() {
|
||||
return keyMappingId;
|
||||
}
|
||||
|
||||
public void setKeyMappingId(String keyMappingId) {
|
||||
this.keyMappingId = keyMappingId;
|
||||
}
|
||||
|
||||
public String getKeyManager() {
|
||||
return keyManager;
|
||||
}
|
||||
|
||||
public void setKeyManager(String keyManager) {
|
||||
this.keyManager = keyManager;
|
||||
}
|
||||
|
||||
public String getConsumerKey() {
|
||||
return consumerKey;
|
||||
}
|
||||
|
||||
public void setConsumerKey(String consumerKey) {
|
||||
this.consumerKey = consumerKey;
|
||||
}
|
||||
|
||||
public String getConsumerSecret() {
|
||||
return consumerSecret;
|
||||
}
|
||||
|
||||
public void setConsumerSecret(String consumerSecret) {
|
||||
this.consumerSecret = consumerSecret;
|
||||
}
|
||||
|
||||
public List<String> getSupportedGrantTypes() {
|
||||
return supportedGrantTypes;
|
||||
}
|
||||
|
||||
public void setSupportedGrantTypes(List<String> supportedGrantTypes) {
|
||||
this.supportedGrantTypes = supportedGrantTypes;
|
||||
}
|
||||
|
||||
public String getCallbackUrl() {
|
||||
return callbackUrl;
|
||||
}
|
||||
|
||||
public void setCallbackUrl(String callbackUrl) {
|
||||
this.callbackUrl = callbackUrl;
|
||||
}
|
||||
|
||||
public String getKeyState() {
|
||||
return keyState;
|
||||
}
|
||||
|
||||
public void setKeyState(String keyState) {
|
||||
this.keyState = keyState;
|
||||
}
|
||||
|
||||
public String getKeyType() {
|
||||
return keyType;
|
||||
}
|
||||
|
||||
public void setKeyType(String keyType) {
|
||||
this.keyType = keyType;
|
||||
}
|
||||
|
||||
public String getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(String mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public JSONObject getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(JSONObject token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public JSONObject getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
public void setAdditionalProperties(JSONObject additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the Consumer Key manager Information.
|
||||
*/
|
||||
|
||||
public class KeyManager {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String type;
|
||||
private String displayName;
|
||||
private String description;
|
||||
private boolean enabled;
|
||||
private List<String> availableGrantTypes;
|
||||
private String tokenEndpoint;
|
||||
private String revokeEndpoint;
|
||||
private String userInfoEndpoint;
|
||||
private String enableTokenGeneration;
|
||||
private String enableTokenEncryption;
|
||||
private String enableTokenHashing;
|
||||
private String enableOAuthAppCreation;
|
||||
private String enableMapOAuthConsumerApps;
|
||||
private List<ApplicationConfigurations> applicationConfiguration;
|
||||
private JSONObject additionalProperties;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public List<String> getAvailableGrantTypes() {
|
||||
return availableGrantTypes;
|
||||
}
|
||||
|
||||
public void setAvailableGrantTypes(List<String> availableGrantTypes) {
|
||||
this.availableGrantTypes = availableGrantTypes;
|
||||
}
|
||||
|
||||
public String getTokenEndpoint() {
|
||||
return tokenEndpoint;
|
||||
}
|
||||
|
||||
public void setTokenEndpoint(String tokenEndpoint) {
|
||||
this.tokenEndpoint = tokenEndpoint;
|
||||
}
|
||||
|
||||
public String getRevokeEndpoint() {
|
||||
return revokeEndpoint;
|
||||
}
|
||||
|
||||
public void setRevokeEndpoint(String revokeEndpoint) {
|
||||
this.revokeEndpoint = revokeEndpoint;
|
||||
}
|
||||
|
||||
public String getUserInfoEndpoint() {
|
||||
return userInfoEndpoint;
|
||||
}
|
||||
|
||||
public void setUserInfoEndpoint(String userInfoEndpoint) {
|
||||
this.userInfoEndpoint = userInfoEndpoint;
|
||||
}
|
||||
|
||||
public String getEnableTokenGeneration() {
|
||||
return enableTokenGeneration;
|
||||
}
|
||||
|
||||
public void setEnableTokenGeneration(String enableTokenGeneration) {
|
||||
this.enableTokenGeneration = enableTokenGeneration;
|
||||
}
|
||||
|
||||
public String getEnableTokenEncryption() {
|
||||
return enableTokenEncryption;
|
||||
}
|
||||
|
||||
public void setEnableTokenEncryption(String enableTokenEncryption) {
|
||||
this.enableTokenEncryption = enableTokenEncryption;
|
||||
}
|
||||
|
||||
public String getEnableTokenHashing() {
|
||||
return enableTokenHashing;
|
||||
}
|
||||
|
||||
public void setEnableTokenHashing(String enableTokenHashing) {
|
||||
this.enableTokenHashing = enableTokenHashing;
|
||||
}
|
||||
|
||||
public String getEnableOAuthAppCreation() {
|
||||
return enableOAuthAppCreation;
|
||||
}
|
||||
|
||||
public void setEnableOAuthAppCreation(String enableOAuthAppCreation) {
|
||||
this.enableOAuthAppCreation = enableOAuthAppCreation;
|
||||
}
|
||||
|
||||
public String getEnableMapOAuthConsumerApps() {
|
||||
return enableMapOAuthConsumerApps;
|
||||
}
|
||||
|
||||
public void setEnableMapOAuthConsumerApps(String enableMapOAuthConsumerApps) {
|
||||
this.enableMapOAuthConsumerApps = enableMapOAuthConsumerApps;
|
||||
}
|
||||
|
||||
public List<ApplicationConfigurations> getApplicationConfiguration() {
|
||||
return applicationConfiguration;
|
||||
}
|
||||
|
||||
public void setApplicationConfiguration(List<ApplicationConfigurations> applicationConfiguration) {
|
||||
this.applicationConfiguration = applicationConfiguration;
|
||||
}
|
||||
|
||||
public JSONObject getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
public void setAdditionalProperties(JSONObject additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the scope data.
|
||||
*/
|
||||
|
||||
public class Scopes {
|
||||
|
||||
private String key;
|
||||
private String name;
|
||||
private List<String> roles;
|
||||
private String description;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(List<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Subscription {
|
||||
|
||||
private String subscriptionId;
|
||||
private String applicationId;
|
||||
private String apiId;
|
||||
private APIInfo apiInfo;
|
||||
private JSONObject applicationInfo;
|
||||
private String throttlingPolicy;
|
||||
private String requestedThrottlingPolicy;
|
||||
private String status;
|
||||
private String redirectionParams;
|
||||
|
||||
public String getSubscriptionId() {
|
||||
return subscriptionId;
|
||||
}
|
||||
|
||||
public void setSubscriptionId(String subscriptionId) {
|
||||
this.subscriptionId = subscriptionId;
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public void setApplicationId(String applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
|
||||
public String getApiId() {
|
||||
return apiId;
|
||||
}
|
||||
|
||||
public void setApiId(String apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
|
||||
public APIInfo getApiInfo() {
|
||||
return apiInfo;
|
||||
}
|
||||
|
||||
public void setApiInfo(APIInfo apiInfo) {
|
||||
this.apiInfo = apiInfo;
|
||||
}
|
||||
|
||||
public JSONObject getApplicationInfo() {
|
||||
return applicationInfo;
|
||||
}
|
||||
|
||||
public void setApplicationInfo(JSONObject applicationInfo) {
|
||||
this.applicationInfo = applicationInfo;
|
||||
}
|
||||
|
||||
public String getThrottlingPolicy() {
|
||||
return throttlingPolicy;
|
||||
}
|
||||
|
||||
public void setThrottlingPolicy(String throttlingPolicy) {
|
||||
this.throttlingPolicy = throttlingPolicy;
|
||||
}
|
||||
|
||||
public String getRequestedThrottlingPolicy() {
|
||||
return requestedThrottlingPolicy;
|
||||
}
|
||||
|
||||
public void setRequestedThrottlingPolicy(String requestedThrottlingPolicy) {
|
||||
this.requestedThrottlingPolicy = requestedThrottlingPolicy;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRedirectionParams() {
|
||||
return redirectionParams;
|
||||
}
|
||||
|
||||
public void setRedirectionParams(String redirectionParams) {
|
||||
this.redirectionParams = redirectionParams;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.dto;
|
||||
|
||||
/**
|
||||
* This holds the API application client information and token information.
|
||||
*/
|
||||
public class ApiApplicationInfo {
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String refresh_token;
|
||||
private String access_token;
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getRefresh_token() {
|
||||
return refresh_token;
|
||||
}
|
||||
|
||||
public void setRefresh_token(String refresh_token) {
|
||||
this.refresh_token = refresh_token;
|
||||
}
|
||||
|
||||
public String getAccess_token() {
|
||||
return access_token;
|
||||
}
|
||||
|
||||
public void setAccess_token(String access_token) {
|
||||
this.access_token = access_token;
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.handlers</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Security Handler Component</name>
|
||||
<description>WSO2 Carbon - API Management Security Handler Module</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.synapse</groupId>
|
||||
<artifactId>synapse-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.security.wso2</groupId>
|
||||
<artifactId>wss4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.certificate.mgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json.wso2</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${io.entgra.device.mgt.core.version}</Bundle-Version>
|
||||
<Bundle-Description>WSO2 Carbon - API Security Handler Component</Bundle-Description>
|
||||
<Import-Package>
|
||||
org.apache.axiom.*,
|
||||
javax.security.cert.*,
|
||||
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
|
||||
javax.xml.*,
|
||||
org.apache.axis2.*,
|
||||
org.apache.commons.*,
|
||||
org.apache.http.*,
|
||||
org.apache.http.util,
|
||||
org.apache.ws.*;version="${org.apache.ws.security.wso2.version}",
|
||||
org.json,
|
||||
org.wso2.carbon.utils,
|
||||
org.wso2.carbon.context,
|
||||
com.google.gson,
|
||||
org.w3c.dom,
|
||||
org.apache.synapse,
|
||||
org.apache.synapse.core.axis2,
|
||||
org.apache.synapse.rest,
|
||||
io.entgra.device.mgt.core.certificate.mgt.core.*
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
|
||||
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs..carbon.apimgt.handlers;
|
||||
|
||||
/**
|
||||
* Error handling class for the apimgt handler.
|
||||
*/
|
||||
public class APIMCertificateMGTException extends Exception{
|
||||
|
||||
private static final long serialVersionUID = -37676242646464497L;
|
||||
|
||||
public APIMCertificateMGTException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
}
|
||||
|
@ -1,235 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.axis2.context.MessageContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.synapse.core.axis2.Axis2MessageContext;
|
||||
import org.apache.synapse.rest.AbstractHandler;
|
||||
import org.wso2.carbon.apimgt.handlers.beans.Certificate;
|
||||
import org.wso2.carbon.apimgt.handlers.beans.ValidationResponce;
|
||||
import org.wso2.carbon.apimgt.handlers.config.IOTServerConfiguration;
|
||||
import org.wso2.carbon.apimgt.handlers.invoker.RESTInvoker;
|
||||
import org.wso2.carbon.apimgt.handlers.invoker.RESTResponse;
|
||||
import org.wso2.carbon.apimgt.handlers.utils.AuthConstants;
|
||||
import org.wso2.carbon.apimgt.handlers.utils.Utils;
|
||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
||||
import io.entgra.device.mgt.core.certificate.mgt.core.exception.KeystoreException;
|
||||
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import javax.security.cert.CertificateEncodingException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Synapse gateway handler for API authentication.
|
||||
*/
|
||||
public class AuthenticationHandler extends AbstractHandler {
|
||||
private static final Log log = LogFactory.getLog(AuthenticationHandler.class);
|
||||
private RESTInvoker restInvoker;
|
||||
|
||||
private static final String X_JWT_ASSERTION = "X-JWT-Assertion";
|
||||
private static final String JWTTOKEN = "JWTToken";
|
||||
private static final String AUTHORIZATION = "Authorization";
|
||||
private static final String BEARER = "Basic ";
|
||||
private static final String CONTENT_TYPE = "Content-Type";
|
||||
private static final boolean USE_INTERNAL_CERT_VERIFIER = true;
|
||||
|
||||
private IOTServerConfiguration iotServerConfiguration;
|
||||
|
||||
/**
|
||||
* Setting up configurations at the constructor
|
||||
*/
|
||||
public AuthenticationHandler() {
|
||||
log.info("Engaging API Security Handler..........");
|
||||
restInvoker = new RESTInvoker();
|
||||
this.iotServerConfiguration = Utils.initConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling the message and checking the security.
|
||||
*
|
||||
* @param messageContext Request message context.
|
||||
* @return Boolean value of the result of the processing the request.
|
||||
*/
|
||||
@Override
|
||||
public boolean handleRequest(org.apache.synapse.MessageContext messageContext) {
|
||||
org.apache.axis2.context.MessageContext axisMC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
|
||||
|
||||
String ctxPath = messageContext.getTo().getAddress().trim();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Authentication handler invoked by: " + ctxPath);
|
||||
}
|
||||
Map<String, String> headers = (Map<String, String>) axisMC.getProperty(MessageContext.TRANSPORT_HEADERS);
|
||||
try {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
RESTResponse response = null;
|
||||
if (headers.containsKey(AuthConstants.MDM_SIGNATURE)) {
|
||||
|
||||
String mdmSignature = headers.get(AuthConstants.MDM_SIGNATURE);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Verify Cert:\n" + mdmSignature);
|
||||
}
|
||||
URI certVerifyUrl = new URI(iotServerConfiguration.getVerificationEndpoint() + "ios");
|
||||
Map<String, String> certVerifyHeaders = this.setHeaders();
|
||||
|
||||
Certificate certificate = new Certificate();
|
||||
certificate.setPem(mdmSignature);
|
||||
certificate.setTenantId(tenantId);
|
||||
certificate.setSerial("");
|
||||
|
||||
Gson gson = new Gson();
|
||||
String certVerifyContent = gson.toJson(certificate);
|
||||
response = restInvoker.invokePOST(certVerifyUrl, certVerifyHeaders, certVerifyContent);
|
||||
|
||||
String str = response.getContent();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Verify response:" + response.getContent());
|
||||
log.debug("Response String : " + str);
|
||||
}
|
||||
if (response.getHttpStatus() == 200 && str.contains(JWTTOKEN)) {
|
||||
ValidationResponce validationResponce = gson.fromJson(str, ValidationResponce.class);
|
||||
headers.put(X_JWT_ASSERTION, validationResponce.getJWTToken());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
} else if (headers.containsKey(AuthConstants.PROXY_MUTUAL_AUTH_HEADER)) {
|
||||
String subjectDN = headers.get(AuthConstants.PROXY_MUTUAL_AUTH_HEADER);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Verify subject DN: " + subjectDN);
|
||||
}
|
||||
|
||||
if (USE_INTERNAL_CERT_VERIFIER) {
|
||||
CertificateResponse certificateResponse = Utils.getCertificateManagementService()
|
||||
.verifySubjectDN(subjectDN);
|
||||
if (certificateResponse != null && certificateResponse.getCommonName() != null
|
||||
&& !certificateResponse.getCommonName().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
String deviceType = this.getDeviceType(messageContext.getTo().getAddress().trim());
|
||||
URI certVerifyUrl = new URI(iotServerConfiguration.getVerificationEndpoint() + deviceType);
|
||||
Map<String, String> certVerifyHeaders = this.setHeaders();
|
||||
|
||||
Certificate certificate = new Certificate();
|
||||
certificate.setPem(subjectDN);
|
||||
certificate.setTenantId(tenantId);
|
||||
certificate.setSerial(AuthConstants.PROXY_MUTUAL_AUTH_HEADER);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String certVerifyContent = gson.toJson(certificate);
|
||||
response = restInvoker.invokePOST(certVerifyUrl, certVerifyHeaders, certVerifyContent);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Verify response:" + response.getContent());
|
||||
}
|
||||
}
|
||||
} else if (headers.containsKey(AuthConstants.MUTUAL_AUTH_HEADER)) {
|
||||
javax.security.cert.X509Certificate[] certs =
|
||||
(javax.security.cert.X509Certificate[]) axisMC.getProperty(AuthConstants.CLIENT_CERTIFICATE);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(certs[0].getEncoded());
|
||||
X509Certificate x509 = (X509Certificate) cf.generateCertificate(bais);
|
||||
bais.close();
|
||||
if (x509 != null) {
|
||||
headers.put(AuthConstants.PROXY_MUTUAL_AUTH_HEADER, CertificateGenerator.getCommonName(x509));
|
||||
return true;
|
||||
}
|
||||
} else if (headers.containsKey(AuthConstants.ENCODED_PEM)) {
|
||||
String encodedPem = headers.get(AuthConstants.ENCODED_PEM);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Verify Cert:\n" + encodedPem);
|
||||
}
|
||||
String deviceType = this.getDeviceType(messageContext.getTo().getAddress().trim());
|
||||
URI certVerifyUrl = new URI(iotServerConfiguration.getVerificationEndpoint() + deviceType);
|
||||
Map<String, String> certVerifyHeaders = this.setHeaders();
|
||||
|
||||
Certificate certificate = new Certificate();
|
||||
certificate.setPem(encodedPem);
|
||||
certificate.setTenantId(tenantId);
|
||||
certificate.setSerial("");
|
||||
Gson gson = new Gson();
|
||||
String certVerifyContent = gson.toJson(certificate);
|
||||
response = restInvoker.invokePOST(certVerifyUrl, certVerifyHeaders, certVerifyContent);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Verify response:" + response.getContent());
|
||||
}
|
||||
} else {
|
||||
log.warn("Unauthorized request for api: " + ctxPath);
|
||||
return false;
|
||||
}
|
||||
if (response != null && !response.getContent().contains("invalid")) {
|
||||
return true;
|
||||
}
|
||||
log.warn("Unauthorized request for api: " + ctxPath);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
log.error("Error while processing certificate.", e);
|
||||
return false;
|
||||
} catch (URISyntaxException e) {
|
||||
log.error("Error while processing certificate.", e);
|
||||
return false;
|
||||
} catch (CertificateException e) {
|
||||
log.error("Certificate issue occurred when generating converting PEM to x509Certificate", e);
|
||||
return false;
|
||||
} catch (CertificateEncodingException e) {
|
||||
log.error("Error while attempting to encode certificate.", e);
|
||||
return false;
|
||||
} catch (KeystoreException e) {
|
||||
log.error("Error while attempting to validate certificate.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleResponse(org.apache.synapse.MessageContext messageContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private String getDeviceType(String url) {
|
||||
StringTokenizer parts = new StringTokenizer(url, "/");
|
||||
while (parts.hasMoreElements()) {
|
||||
if (parts.nextElement().equals("device-mgt")) {
|
||||
return (String) parts.nextElement();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, String> setHeaders() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
String accessToken = Utils.getBase64EncodedToken(iotServerConfiguration);
|
||||
map.put(AUTHORIZATION, BEARER + accessToken);
|
||||
map.put(CONTENT_TYPE, "application/json");
|
||||
return map;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers.beans;
|
||||
|
||||
/**
|
||||
* This class keeps the certificate data.
|
||||
*/
|
||||
public class Certificate {
|
||||
|
||||
// public key of the certificate
|
||||
private String pem;
|
||||
// Tenant id
|
||||
private int tenantId;
|
||||
// Serial of the certificate.
|
||||
private String serial;
|
||||
|
||||
public String getPem() {
|
||||
return pem;
|
||||
}
|
||||
|
||||
public void setPem(String pem) {
|
||||
this.pem = pem;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public String getSerial() {
|
||||
return serial;
|
||||
}
|
||||
|
||||
public void setSerial(String serial) {
|
||||
this.serial = serial;
|
||||
}
|
||||
}
|
||||
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers.beans;
|
||||
|
||||
/**
|
||||
* This class holds the DCR endpoints data to create an application.
|
||||
*/
|
||||
public class DCR {
|
||||
|
||||
private String callbackUrl;
|
||||
private String owner;
|
||||
private String clientName;
|
||||
private String grantType;
|
||||
private String tokenScope;
|
||||
private boolean isSaasApp;
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return clientName;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public String getGrantType() {
|
||||
return grantType;
|
||||
}
|
||||
|
||||
public void setGrantType(String grantType) {
|
||||
this.grantType = grantType;
|
||||
}
|
||||
|
||||
public String getTokenScope() {
|
||||
return tokenScope;
|
||||
}
|
||||
|
||||
public void setTokenScope(String tokenScope) {
|
||||
this.tokenScope = tokenScope;
|
||||
}
|
||||
|
||||
public boolean getIsSaasApp() {
|
||||
return isSaasApp;
|
||||
}
|
||||
|
||||
public void setIsSaasApp(boolean isSaasApp) {
|
||||
this.isSaasApp = isSaasApp;
|
||||
}
|
||||
|
||||
public String getCallbackUrl() {
|
||||
return callbackUrl;
|
||||
}
|
||||
|
||||
public void setCallbackUrl(String callbackUrl) {
|
||||
this.callbackUrl = callbackUrl;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
return "{\"callbackUrl\": \"" + callbackUrl + "\",\"clientName\": \"" + clientName + "\", \"tokenScope\": " +
|
||||
"\"" + tokenScope + "\", \"owner\": \"" + owner + "\"," + "\"grantType\": \"" + grantType +
|
||||
"\", \"saasApp\" :" + isSaasApp + " }\n";
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.handlers.beans;
|
||||
|
||||
/**
|
||||
* This class holds the data returned from the backend after the certificate was authenticated.
|
||||
*/
|
||||
public class ValidationResponce {
|
||||
|
||||
private String JWTToken; // X-JWT-Assertion
|
||||
private String deviceId;
|
||||
private String deviceType;
|
||||
private int tenantId;
|
||||
|
||||
public String getJWTToken() {
|
||||
return JWTToken;
|
||||
}
|
||||
|
||||
public void setJWTToken(String JWTToken) {
|
||||
this.JWTToken = JWTToken;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
}
|
||||
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class initialize the iot-api-config.xml and hold the values, in order to be read from the relevant classes. This
|
||||
* get initialized at the start of the server when apis get loaded.
|
||||
*/
|
||||
@XmlRootElement(name = "ServerConfiguration")
|
||||
public class IOTServerConfiguration {
|
||||
|
||||
private String hostname;
|
||||
private String verificationEndpoint;
|
||||
private String username;
|
||||
private String password;
|
||||
private String dynamicClientRegistrationEndpoint;
|
||||
private String oauthTokenEndpoint;
|
||||
private List<ContextPath> apis;
|
||||
|
||||
@XmlElement(name = "Hostname", required = true)
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
@XmlElement(name = "VerificationEndpoint", required = true)
|
||||
public String getVerificationEndpoint() {
|
||||
return verificationEndpoint;
|
||||
}
|
||||
|
||||
public void setVerificationEndpoint(String verificationEndpoint) {
|
||||
this.verificationEndpoint = verificationEndpoint;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Username", required = true)
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Password", required = true)
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DynamicClientRegistrationEndpoint", required = true)
|
||||
public String getDynamicClientRegistrationEndpoint() {
|
||||
return dynamicClientRegistrationEndpoint;
|
||||
}
|
||||
|
||||
public void setDynamicClientRegistrationEndpoint(String dynamicClientRegistrationEndpoint) {
|
||||
this.dynamicClientRegistrationEndpoint = dynamicClientRegistrationEndpoint;
|
||||
}
|
||||
|
||||
@XmlElement(name = "OauthTokenEndpoint", required = true)
|
||||
public String getOauthTokenEndpoint() {
|
||||
return oauthTokenEndpoint;
|
||||
}
|
||||
|
||||
public void setOauthTokenEndpoint(String oauthTokenEndpoint) {
|
||||
this.oauthTokenEndpoint = oauthTokenEndpoint;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="APIS")
|
||||
@XmlElement(name = "ContextPath", required = true)
|
||||
public List<ContextPath> getApis() {
|
||||
return apis;
|
||||
}
|
||||
|
||||
public void setApis(List<ContextPath> apis) {
|
||||
this.apis = apis;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "ContextPath")
|
||||
public static class ContextPath {
|
||||
|
||||
private String contextPath;
|
||||
|
||||
@XmlValue()
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers.invoker;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class RESTInvoker {
|
||||
|
||||
private static final Log log = LogFactory.getLog(RESTInvoker.class);
|
||||
|
||||
private CloseableHttpClient client = null;
|
||||
|
||||
public RESTInvoker() {
|
||||
configureHttpClient();
|
||||
}
|
||||
|
||||
private void configureHttpClient() {
|
||||
int connectionTimeout = 120000;
|
||||
int socketTimeout = 120000;
|
||||
int maxTotalConnectionsPerRoute = 100;
|
||||
int maxTotalConnections = 100;
|
||||
RequestConfig defaultRequestConfig = RequestConfig.custom()
|
||||
.setExpectContinueEnabled(true)
|
||||
.setConnectTimeout(connectionTimeout)
|
||||
.setSocketTimeout(socketTimeout)
|
||||
.build();
|
||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
|
||||
connectionManager.setDefaultMaxPerRoute(maxTotalConnectionsPerRoute);
|
||||
connectionManager.setMaxTotal(maxTotalConnections);
|
||||
client = HttpClients.custom()
|
||||
.setConnectionManager(connectionManager)
|
||||
.setDefaultRequestConfig(defaultRequestConfig)
|
||||
.build();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("REST client initialized with " +
|
||||
"maxTotalConnection = " + maxTotalConnections +
|
||||
"maxConnectionsPerRoute = " + maxTotalConnectionsPerRoute +
|
||||
"connectionTimeout = " + connectionTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public RESTResponse invokePOST(URI uri, Map<String, String> requestHeaders, String payload) throws IOException {
|
||||
|
||||
HttpPost httpPost = null;
|
||||
CloseableHttpResponse response = null;
|
||||
int httpStatus;
|
||||
String output;
|
||||
try {
|
||||
httpPost = new HttpPost(uri);
|
||||
httpPost.setEntity(new StringEntity(payload));
|
||||
if (requestHeaders != null && !requestHeaders.isEmpty()) {
|
||||
Set<String> keys = requestHeaders.keySet();
|
||||
for (String header : keys) {
|
||||
httpPost.setHeader(header, requestHeaders.get(header));
|
||||
}
|
||||
}
|
||||
response = sendReceiveRequest(httpPost);
|
||||
output = IOUtils.toString(response.getEntity().getContent());
|
||||
httpStatus = response.getStatusLine().getStatusCode();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Invoked POST " + uri.toString() +
|
||||
" - Input payload: " + payload + " - Response message: " + output);
|
||||
}
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
if (response != null) {
|
||||
IOUtils.closeQuietly(response);
|
||||
}
|
||||
if (httpPost != null) {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
}
|
||||
return new RESTResponse(output, httpStatus);
|
||||
}
|
||||
|
||||
private CloseableHttpResponse sendReceiveRequest(HttpRequestBase requestBase)
|
||||
throws IOException {
|
||||
return client.execute(requestBase);
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers.invoker;
|
||||
|
||||
|
||||
/**
|
||||
* RESTResponse class holds the data retrieved from the HTTP invoke response.
|
||||
*/
|
||||
public class RESTResponse {
|
||||
private String content;
|
||||
private int httpStatus;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param content from the REST invoke response
|
||||
* @param httpStatus from the REST invoke response
|
||||
*/
|
||||
RESTResponse(String content, int httpStatus) {
|
||||
this.content = content;
|
||||
this.httpStatus = httpStatus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get contents of the REST invoke response
|
||||
*
|
||||
* @return contents of the REST invoke response
|
||||
*/
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP Status code from REST invoke response
|
||||
*
|
||||
* @return int HTTP status code
|
||||
*/
|
||||
public int getHttpStatus() {
|
||||
return httpStatus;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers.utils;
|
||||
|
||||
/**
|
||||
* This initializes the constance.
|
||||
*/
|
||||
public class AuthConstants {
|
||||
public static final String MDM_SIGNATURE = "mdm-signature";
|
||||
public static final String PROXY_MUTUAL_AUTH_HEADER = "proxy-mutual-auth-header";
|
||||
public static final String MUTUAL_AUTH_HEADER = "mutual-auth-header";
|
||||
public static final String ONE_TIME_TOKEN_HEADER = "one-time-token";
|
||||
public static final String ENCODED_PEM = "encoded-pem";
|
||||
public static final String CALLBACK_URL = "";
|
||||
public static final String CLIENT_NAME = "IOT-API-MANAGER";
|
||||
public static final String GRANT_TYPE = "refresh_token password client_credentials";
|
||||
public static final String TOKEN_SCOPE = "default";
|
||||
public static final String CONTENT_TYPE_HEADER = "Content-Type";
|
||||
public static final String CONTENT_TYPE = "application/json";
|
||||
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
public static final String BASIC_AUTH_PREFIX = "Basic ";
|
||||
public static final String CLIENT_ID = "clientId";
|
||||
public static final String CLIENT_SECRET = "clientSecret";
|
||||
public static final String CLIENT_CERTIFICATE = "ssl.client.auth.cert.X509";
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.apimgt.handlers.utils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ws.security.util.Base64;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.apimgt.handlers.APIMCertificateMGTException;
|
||||
import org.wso2.carbon.apimgt.handlers.beans.DCR;
|
||||
import org.wso2.carbon.apimgt.handlers.config.IOTServerConfiguration;
|
||||
import org.wso2.carbon.apimgt.handlers.invoker.RESTInvoker;
|
||||
import org.wso2.carbon.apimgt.handlers.invoker.RESTResponse;
|
||||
import io.entgra.device.mgt.core.certificate.mgt.core.service.CertificateManagementService;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Contains util methods for synapse gateway authentication handler
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(Utils.class);
|
||||
private static final String IOT_APIS_CONFIG_FILE = "iot-api-config.xml";
|
||||
private static String clientId;
|
||||
private static String clientSecret;
|
||||
|
||||
/**
|
||||
* This method initializes the iot-api-config.xml file.
|
||||
*
|
||||
* @return IoTServerConfiguration Object based on the configuration file.
|
||||
*/
|
||||
public static IOTServerConfiguration initConfig() {
|
||||
return initConfig(CarbonUtils.getCarbonConfigDirPath() + File.separator + IOT_APIS_CONFIG_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This methods initialized the iot-api-config.xml from provided path.
|
||||
*
|
||||
* @param path The actual file path of iot-api-config.xml
|
||||
* @return The instance of the IOTServerConfiguration based on the configuration.
|
||||
*/
|
||||
public static IOTServerConfiguration initConfig(String path) {
|
||||
try {
|
||||
File file = new File(path);
|
||||
Document doc = Utils.convertToDocument(file);
|
||||
|
||||
JAXBContext fileContext = JAXBContext.newInstance(IOTServerConfiguration.class);
|
||||
Unmarshaller unmarshaller = fileContext.createUnmarshaller();
|
||||
|
||||
IOTServerConfiguration iotServerConfiguration = (IOTServerConfiguration) unmarshaller.unmarshal(
|
||||
doc);
|
||||
iotServerConfiguration.setHostname(replaceProperties(iotServerConfiguration.getHostname()));
|
||||
iotServerConfiguration.setVerificationEndpoint(
|
||||
replaceProperties(iotServerConfiguration.getVerificationEndpoint()));
|
||||
iotServerConfiguration.setDynamicClientRegistrationEndpoint(
|
||||
replaceProperties(iotServerConfiguration.getDynamicClientRegistrationEndpoint()));
|
||||
iotServerConfiguration.setOauthTokenEndpoint(
|
||||
replaceProperties(iotServerConfiguration.getOauthTokenEndpoint()));
|
||||
return iotServerConfiguration;
|
||||
} catch (JAXBException | APIMCertificateMGTException e) {
|
||||
log.error("Error occurred while initializing Data Source config", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the values from system variables and sets to xml.
|
||||
*/
|
||||
private static String replaceProperties(String text) {
|
||||
String regex = "\\$\\{(.*?)\\}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matchPattern = pattern.matcher(text);
|
||||
while (matchPattern.find()) {
|
||||
String sysPropertyName = matchPattern.group(1);
|
||||
String sysPropertyValue = System.getProperty(sysPropertyName);
|
||||
if (sysPropertyValue != null && !sysPropertyName.isEmpty()) {
|
||||
text = text.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class build the iot-api-config.xml file.
|
||||
*
|
||||
* @param file The file object of iot-api-config.xml.
|
||||
* @return Document instance of the file
|
||||
* @throws APIMCertificateMGTException
|
||||
*/
|
||||
private static Document convertToDocument(File file) throws APIMCertificateMGTException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new APIMCertificateMGTException("Error occurred while parsing file, while converting " +
|
||||
"to a org.w3c.dom.Document", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the base64 encoded token.
|
||||
*
|
||||
* @param iotServerConfiguration Instance of the IoTsererConfiguration.
|
||||
* @return Access token will be returned.
|
||||
*/
|
||||
public static String getBase64EncodedToken(IOTServerConfiguration iotServerConfiguration) {
|
||||
return Base64.encode((iotServerConfiguration.getUsername() + ":" + iotServerConfiguration.getPassword()).
|
||||
getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method register an application to get the client key and secret.
|
||||
*
|
||||
* @param iotServerConfiguration Instance of the IoTServerConfiguration.
|
||||
* @throws APIMCertificateMGTException
|
||||
*/
|
||||
private static void getClientSecretes(IOTServerConfiguration iotServerConfiguration, RESTInvoker restInvoker)
|
||||
throws APIMCertificateMGTException {
|
||||
try {
|
||||
String username = iotServerConfiguration.getUsername();
|
||||
String password = iotServerConfiguration.getPassword();
|
||||
DCR dcr = new DCR();
|
||||
dcr.setOwner(iotServerConfiguration.getUsername());
|
||||
dcr.setClientName(AuthConstants.CLIENT_NAME);
|
||||
dcr.setGrantType(AuthConstants.GRANT_TYPE);
|
||||
dcr.setTokenScope(AuthConstants.TOKEN_SCOPE);
|
||||
dcr.setCallbackUrl(AuthConstants.CALLBACK_URL);
|
||||
dcr.setIsSaasApp(true);
|
||||
String dcrContent = dcr.toJSON();
|
||||
Map<String, String> dcrHeaders = new HashMap<>();
|
||||
String basicAuth = Base64.encode((username + ":" + password).getBytes());
|
||||
dcrHeaders.put(AuthConstants.CONTENT_TYPE_HEADER, AuthConstants.CONTENT_TYPE);
|
||||
dcrHeaders.put(AuthConstants.AUTHORIZATION_HEADER, AuthConstants.BASIC_AUTH_PREFIX + basicAuth);
|
||||
URI dcrUrl = new URI(iotServerConfiguration.getDynamicClientRegistrationEndpoint());
|
||||
RESTResponse response = restInvoker.invokePOST(dcrUrl, dcrHeaders, dcrContent);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("DCR response :" + response.getContent());
|
||||
}
|
||||
JSONObject jsonResponse = new JSONObject(response.getContent());
|
||||
clientId = jsonResponse.getString(AuthConstants.CLIENT_ID);
|
||||
clientSecret = jsonResponse.getString(AuthConstants.CLIENT_SECRET);
|
||||
} catch (JSONException e) {
|
||||
throw new APIMCertificateMGTException("Error occurred while converting the json to object", e);
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
throw new APIMCertificateMGTException("Error occurred while trying to call DCR endpoint", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static CertificateManagementService getCertificateManagementService() {
|
||||
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
CertificateManagementService certificateManagementService = (CertificateManagementService)
|
||||
ctx.getOSGiService(CertificateManagementService.class, null);
|
||||
|
||||
if (certificateManagementService == null) {
|
||||
String msg = "CertificateManagementAdminServiceImpl Management service not initialized.";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
|
||||
return certificateManagementService;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
|
||||
<ServerConfiguration>
|
||||
<!-- IoT server host name, this is referred from APIM gateway to call to IoT server for certificate validation-->
|
||||
<Hostname>https://${iot.core.host}:${iot.core.https.port}/</Hostname>
|
||||
|
||||
<!--End point to verify the certificate-->
|
||||
<VerificationEndpoint>https://${iot.core.host}:${iot.core.https.port}/api/certificate-mgt/v1.0/admin/certificates/verify/</VerificationEndpoint>
|
||||
|
||||
<!--Admin username/password - this is to use for oauth token generation-->
|
||||
<Username>admin</Username>
|
||||
<Password>admin</Password>
|
||||
|
||||
<!--Dynamic client registration endpoint-->
|
||||
<DynamicClientRegistrationEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.12/register</DynamicClientRegistrationEndpoint>
|
||||
|
||||
<!--Oauth token endpoint-->
|
||||
<OauthTokenEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/oauth2/token</OauthTokenEndpoint>
|
||||
|
||||
<APIS>
|
||||
<ContextPath>/services</ContextPath>
|
||||
</APIS>
|
||||
</ServerConfiguration>
|
@ -1,296 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.handlers;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import junit.framework.Assert;
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.om.OMDocument;
|
||||
import org.apache.axiom.soap.SOAPEnvelope;
|
||||
import org.apache.axis2.addressing.EndpointReference;
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.axis2.engine.AxisConfiguration;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.apache.synapse.MessageContext;
|
||||
import org.apache.synapse.config.SynapseConfigUtils;
|
||||
import org.apache.synapse.config.SynapseConfiguration;
|
||||
import org.apache.synapse.core.SynapseEnvironment;
|
||||
import org.apache.synapse.core.axis2.Axis2MessageContext;
|
||||
import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.apimgt.handlers.beans.ValidationResponce;
|
||||
import org.wso2.carbon.apimgt.handlers.invoker.RESTInvoker;
|
||||
import org.wso2.carbon.apimgt.handlers.mock.MockClient;
|
||||
import org.wso2.carbon.apimgt.handlers.mock.MockHttpResponse;
|
||||
import org.wso2.carbon.apimgt.handlers.utils.AuthConstants;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import javax.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* This testcase will focus on covering the methods of {@link AuthenticationHandler}
|
||||
*/
|
||||
public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
|
||||
|
||||
private AuthenticationHandler handler;
|
||||
private SynapseConfiguration synapseConfiguration;
|
||||
private MockClient mockClient;
|
||||
|
||||
@BeforeClass
|
||||
public void initTest() {
|
||||
TestUtils.setSystemProperties();
|
||||
this.handler = new AuthenticationHandler();
|
||||
this.synapseConfiguration = new SynapseConfiguration();
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with empty transport headers")
|
||||
public void testHandleRequestWithEmptyTransportHeader() throws Exception {
|
||||
boolean response = this.handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
new HashMap<>(), "https://test.com/testservice"));
|
||||
Assert.assertFalse(response);
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with without device type",
|
||||
dependsOnMethods = "testHandleRequestWithEmptyTransportHeader")
|
||||
public void testHandleRequestWithoutDeviceType() throws Exception {
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.MDM_SIGNATURE, "some cert");
|
||||
boolean response = this.handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice"));
|
||||
Assert.assertFalse(response);
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with device type URI with MDM ceritificate",
|
||||
dependsOnMethods = "testHandleRequestWithoutDeviceType")
|
||||
public void testHandleSuccessfulRequestMDMCertificate() throws Exception {
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.MDM_SIGNATURE, "some cert");
|
||||
setMockClient();
|
||||
this.mockClient.setResponse(getValidationResponse());
|
||||
boolean response = this.handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice/device-mgt/testdevice"));
|
||||
Assert.assertTrue(response);
|
||||
this.mockClient.reset();
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with device type URI with Mutual Auth Header",
|
||||
dependsOnMethods = "testHandleSuccessfulRequestMDMCertificate")
|
||||
public void testHandleSuccessRequestMutualAuthHeader() throws Exception {
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.MUTUAL_AUTH_HEADER, "Test Header");
|
||||
setMockClient();
|
||||
this.mockClient.setResponse(getValidationResponse());
|
||||
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
|
||||
org.apache.axis2.context.MessageContext axisMC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
|
||||
String certStr = getContent(TestUtils.getAbsolutePathOfConfig("ra_cert.pem"));
|
||||
X509Certificate cert = X509Certificate.getInstance(new ByteArrayInputStream(certStr.
|
||||
getBytes(StandardCharsets.UTF_8.name())));
|
||||
axisMC.setProperty(AuthConstants.CLIENT_CERTIFICATE, new X509Certificate[]{cert});
|
||||
boolean response = this.handler.handleRequest(messageContext);
|
||||
Assert.assertTrue(response);
|
||||
this.mockClient.reset();
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with device type URI with Encoded Pem",
|
||||
dependsOnMethods = "testHandleSuccessRequestMutualAuthHeader")
|
||||
public void testHandleSuccessRequestEncodedPem() throws Exception {
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.ENCODED_PEM, "encoded pem");
|
||||
setMockClient();
|
||||
this.mockClient.setResponse(getValidationResponse());
|
||||
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
|
||||
boolean response = this.handler.handleRequest(messageContext);
|
||||
Assert.assertTrue(response);
|
||||
this.mockClient.reset();
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with device type URI with Encoded Pem with invalid response",
|
||||
dependsOnMethods = "testHandleSuccessRequestEncodedPem")
|
||||
public void testHandleSuccessRequestEncodedPemInvalidResponse() throws Exception {
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.ENCODED_PEM, "encoded pem");
|
||||
setMockClient();
|
||||
this.mockClient.setResponse(getInvalidResponse());
|
||||
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
|
||||
boolean response = this.handler.handleRequest(messageContext);
|
||||
Assert.assertFalse(response);
|
||||
this.mockClient.reset();
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with cert management exception ",
|
||||
dependsOnMethods = "testHandleSuccessRequestEncodedPem")
|
||||
public void testHandleRequestWithCertMgmtException() throws Exception {
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.ENCODED_PEM, "encoded pem");
|
||||
setMockClient();
|
||||
this.mockClient.setResponse(null);
|
||||
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
|
||||
boolean response = this.handler.handleRequest(messageContext);
|
||||
Assert.assertFalse(response);
|
||||
this.mockClient.reset();
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with IO exception",
|
||||
dependsOnMethods = "testHandleRequestWithCertMgmtException")
|
||||
public void testHandleRequestWithIOException() throws Exception {
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.ENCODED_PEM, "encoded pem");
|
||||
setMockClient();
|
||||
this.mockClient.setResponse(null);
|
||||
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
|
||||
boolean response = this.handler.handleRequest(messageContext);
|
||||
Assert.assertFalse(response);
|
||||
this.mockClient.reset();
|
||||
}
|
||||
|
||||
@Test(description = "Handle request with URI exception",
|
||||
dependsOnMethods = "testHandleRequestWithIOException")
|
||||
public void testHandleRequestWithURIException() throws Exception {
|
||||
TestUtils.resetSystemProperties();
|
||||
HashMap<String, String> transportHeaders = new HashMap<>();
|
||||
transportHeaders.put(AuthConstants.MDM_SIGNATURE, "some cert");
|
||||
AuthenticationHandler handler = new AuthenticationHandler();
|
||||
boolean response = handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration,
|
||||
transportHeaders, "https://test.com/testservice/device-mgt/testdevice"));
|
||||
Assert.assertFalse(response);
|
||||
TestUtils.setSystemProperties();
|
||||
}
|
||||
|
||||
@Test(description = "Handle response")
|
||||
public void testHandleResponse() throws Exception {
|
||||
boolean response = this.handler.handleResponse(null);
|
||||
Assert.assertTrue(response);
|
||||
}
|
||||
|
||||
|
||||
private static MessageContext createSynapseMessageContext(
|
||||
String payload, SynapseConfiguration config, HashMap<String, String> transportHeaders,
|
||||
String address) throws Exception {
|
||||
org.apache.axis2.context.MessageContext mc =
|
||||
new org.apache.axis2.context.MessageContext();
|
||||
AxisConfiguration axisConfig = config.getAxisConfiguration();
|
||||
if (axisConfig == null) {
|
||||
axisConfig = new AxisConfiguration();
|
||||
config.setAxisConfiguration(axisConfig);
|
||||
}
|
||||
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
|
||||
SynapseEnvironment env = new Axis2SynapseEnvironment(cfgCtx, config);
|
||||
MessageContext synMc = new Axis2MessageContext(mc, config, env);
|
||||
SOAPEnvelope envelope =
|
||||
OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
|
||||
OMDocument omDoc =
|
||||
OMAbstractFactory.getSOAP11Factory().createOMDocument();
|
||||
omDoc.addChild(envelope);
|
||||
envelope.getBody().addChild(SynapseConfigUtils.stringToOM(payload));
|
||||
synMc.setEnvelope(envelope);
|
||||
synMc.setTo(new EndpointReference(address));
|
||||
org.apache.axis2.context.MessageContext axis2MessageContext =
|
||||
((Axis2MessageContext) synMc).getAxis2MessageContext();
|
||||
axis2MessageContext.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, transportHeaders);
|
||||
return synMc;
|
||||
}
|
||||
|
||||
private void setMockClient() throws NoSuchFieldException, IllegalAccessException {
|
||||
Field restInvokerField = this.handler.getClass().getDeclaredField("restInvoker");
|
||||
restInvokerField.setAccessible(true);
|
||||
RESTInvoker restInvoker = (RESTInvoker) restInvokerField.get(this.handler);
|
||||
Field clientField = restInvoker.getClass().getDeclaredField("client");
|
||||
clientField.setAccessible(true);
|
||||
this.mockClient = new MockClient();
|
||||
clientField.set(restInvoker, this.mockClient);
|
||||
}
|
||||
|
||||
private CloseableHttpResponse getDCRResponse() throws IOException {
|
||||
CloseableHttpResponse mockDCRResponse = new MockHttpResponse();
|
||||
String dcrResponseFile = TestUtils.getAbsolutePathOfConfig("dcr-response.json");
|
||||
BasicHttpEntity responseEntity = new BasicHttpEntity();
|
||||
responseEntity.setContent(new ByteArrayInputStream(getContent(dcrResponseFile).
|
||||
getBytes(StandardCharsets.UTF_8.name())));
|
||||
responseEntity.setContentType(TestUtils.CONTENT_TYPE);
|
||||
mockDCRResponse.setEntity(responseEntity);
|
||||
mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK"));
|
||||
return mockDCRResponse;
|
||||
}
|
||||
|
||||
private CloseableHttpResponse getAccessTokenReponse() throws IOException {
|
||||
CloseableHttpResponse mockDCRResponse = new MockHttpResponse();
|
||||
String dcrResponseFile = TestUtils.getAbsolutePathOfConfig("accesstoken-response.json");
|
||||
BasicHttpEntity responseEntity = new BasicHttpEntity();
|
||||
responseEntity.setContent(new ByteArrayInputStream(getContent(dcrResponseFile).
|
||||
getBytes(StandardCharsets.UTF_8.name())));
|
||||
responseEntity.setContentType(TestUtils.CONTENT_TYPE);
|
||||
mockDCRResponse.setEntity(responseEntity);
|
||||
mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK"));
|
||||
return mockDCRResponse;
|
||||
}
|
||||
|
||||
private CloseableHttpResponse getValidationResponse() throws UnsupportedEncodingException {
|
||||
ValidationResponce response = new ValidationResponce();
|
||||
response.setDeviceId("1234");
|
||||
response.setDeviceType("testdevice");
|
||||
response.setJWTToken("1234567788888888");
|
||||
response.setTenantId(-1234);
|
||||
Gson gson = new Gson();
|
||||
String jsonReponse = gson.toJson(response);
|
||||
CloseableHttpResponse mockDCRResponse = new MockHttpResponse();
|
||||
BasicHttpEntity responseEntity = new BasicHttpEntity();
|
||||
responseEntity.setContent(new ByteArrayInputStream(jsonReponse.getBytes(StandardCharsets.UTF_8.name())));
|
||||
responseEntity.setContentType(TestUtils.CONTENT_TYPE);
|
||||
mockDCRResponse.setEntity(responseEntity);
|
||||
mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK"));
|
||||
return mockDCRResponse;
|
||||
}
|
||||
|
||||
private CloseableHttpResponse getInvalidResponse() throws UnsupportedEncodingException {
|
||||
CloseableHttpResponse mockDCRResponse = new MockHttpResponse();
|
||||
BasicHttpEntity responseEntity = new BasicHttpEntity();
|
||||
responseEntity.setContent(new ByteArrayInputStream("invalid response".getBytes(StandardCharsets.UTF_8.name())));
|
||||
responseEntity.setContentType(TestUtils.CONTENT_TYPE);
|
||||
mockDCRResponse.setEntity(responseEntity);
|
||||
mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 400, "Bad Request"));
|
||||
return mockDCRResponse;
|
||||
}
|
||||
|
||||
private String getContent(String filePath) throws IOException {
|
||||
FileReader fileReader = new FileReader(filePath);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
String content = "";
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
content += line + "\n";
|
||||
}
|
||||
bufferedReader.close();
|
||||
return content;
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.handlers;
|
||||
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This is the base test case for API Handler tests.
|
||||
*/
|
||||
public class BaseAPIHandlerTest {
|
||||
|
||||
@BeforeSuite
|
||||
public void init() {
|
||||
setUpCarbonHome();
|
||||
}
|
||||
|
||||
private void setUpCarbonHome() {
|
||||
if (System.getProperty("carbon.home") == null) {
|
||||
File file = new File("src/test/resources/carbon-home");
|
||||
if (file.exists()) {
|
||||
System.setProperty("carbon.home", file.getAbsolutePath());
|
||||
}
|
||||
file = new File("carbon-home");
|
||||
if (file.exists()) {
|
||||
System.setProperty("carbon.home", file.getAbsolutePath());
|
||||
}
|
||||
file = new File("../../resources/carbon-home");
|
||||
if (file.exists()) {
|
||||
System.setProperty("carbon.home", file.getAbsolutePath());
|
||||
}
|
||||
file = new File("../../../resources/carbon-home");
|
||||
if (file.exists()) {
|
||||
System.setProperty("carbon.home", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants
|
||||
.SUPER_TENANT_DOMAIN_NAME);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.handlers;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.apimgt.handlers.config.IOTServerConfiguration;
|
||||
import org.wso2.carbon.apimgt.handlers.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This class validates the behaviour of {@link IOTServerConfiguration}
|
||||
*/
|
||||
public class IOTServerConfigurationTest extends BaseAPIHandlerTest {
|
||||
private static final String CONFIG_DIR = "carbon-home" + File.separator + "repository" + File.separator +
|
||||
"conf" + File.separator;
|
||||
|
||||
@BeforeClass
|
||||
public void initTest(){
|
||||
TestUtils.resetSystemProperties();
|
||||
}
|
||||
|
||||
@Test(description = "Validating the IoT Server configuration initialization without system properties")
|
||||
public void initConfigWithoutSystemProps() {
|
||||
IOTServerConfiguration serverConfiguration = Utils.initConfig();
|
||||
Assert.assertTrue(serverConfiguration != null);
|
||||
Assert.assertEquals(serverConfiguration.getHostname(), "https://${iot.core.host}:${iot.core.https.port}/");
|
||||
Assert.assertEquals(serverConfiguration.getVerificationEndpoint(),
|
||||
"https://${iot.core.host}:${iot.core.https.port}/api/certificate-mgt/v1.0/admin/certificates/verify/");
|
||||
Assert.assertEquals(serverConfiguration.getUsername(), "testuser");
|
||||
Assert.assertEquals(serverConfiguration.getPassword(), "testuserpwd");
|
||||
Assert.assertEquals(serverConfiguration.getDynamicClientRegistrationEndpoint(),
|
||||
"https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.12/register");
|
||||
Assert.assertEquals(serverConfiguration.getOauthTokenEndpoint(),
|
||||
"https://${iot.keymanager.host}:${iot.keymanager.https.port}/oauth2/token");
|
||||
Assert.assertEquals(serverConfiguration.getApis().size(), 1);
|
||||
Assert.assertEquals(serverConfiguration.getApis().get(0).getContextPath(), "/services");
|
||||
}
|
||||
|
||||
@Test(description = "Initializing IoT server config with invalid configuration",
|
||||
dependsOnMethods = "initConfigWithoutSystemProps")
|
||||
public void initConfigWithInvalidConfig() {
|
||||
IOTServerConfiguration serverConfig = Utils.initConfig(TestUtils.getAbsolutePathOfConfig(CONFIG_DIR
|
||||
+ "iot-api-config-invalid.xml"));
|
||||
Assert.assertEquals(serverConfig, null);
|
||||
}
|
||||
|
||||
@Test(description = "Initializing IoT server config with invalid xml",
|
||||
dependsOnMethods = "initConfigWithInvalidConfig")
|
||||
public void initConfigWithInvalidXMLConfig() {
|
||||
IOTServerConfiguration serverConfig = Utils.initConfig(TestUtils.getAbsolutePathOfConfig(CONFIG_DIR +
|
||||
"iot-api-config-invalid-xml.xml"));
|
||||
Assert.assertEquals(serverConfig, null);
|
||||
}
|
||||
|
||||
@Test(description = "Initializing IoT server config with system configs",
|
||||
dependsOnMethods = "initConfigWithInvalidXMLConfig")
|
||||
public void initConfigWithSystemProps() {
|
||||
TestUtils.setSystemProperties();
|
||||
IOTServerConfiguration serverConfiguration = Utils.initConfig();
|
||||
Assert.assertTrue(serverConfiguration != null);
|
||||
Assert.assertEquals(serverConfiguration.getHostname(), "https://" + TestUtils.IOT_CORE_HOST + ":"
|
||||
+ TestUtils.IOT_CORE_HTTPS_PORT
|
||||
+ "/");
|
||||
Assert.assertEquals(serverConfiguration.getVerificationEndpoint(),
|
||||
"https://" + TestUtils.IOT_CORE_HOST + ":" + TestUtils.IOT_CORE_HTTPS_PORT +
|
||||
"/api/certificate-mgt/v1.0/admin/certificates/" +
|
||||
"verify/");
|
||||
Assert.assertEquals(serverConfiguration.getUsername(), "testuser");
|
||||
Assert.assertEquals(serverConfiguration.getPassword(), "testuserpwd");
|
||||
Assert.assertEquals(serverConfiguration.getDynamicClientRegistrationEndpoint(),
|
||||
"https://" + TestUtils.IOT_KEYMANAGER_HOST + ":" + TestUtils.IOT_KEYMANAGER_PORT
|
||||
+ "/client-registration/v0.12/register");
|
||||
Assert.assertEquals(serverConfiguration.getOauthTokenEndpoint(),
|
||||
"https://" + TestUtils.IOT_KEYMANAGER_HOST + ":" + TestUtils.IOT_KEYMANAGER_PORT
|
||||
+ "/oauth2/token");
|
||||
Assert.assertEquals(serverConfiguration.getApis().size(), 1);
|
||||
Assert.assertEquals(serverConfiguration.getApis().get(0).getContextPath(), "/services");
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.handlers;
|
||||
|
||||
import org.testng.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Utils class which provides utility methods for other testcases.
|
||||
*/
|
||||
public class TestUtils {
|
||||
static final String IOT_CORE_HOST = "iot.core.wso2.com";
|
||||
static final String IOT_CORE_HTTPS_PORT = "9443";
|
||||
static final String IOT_KEYMANAGER_HOST = "iot.keymanager.wso2.com";
|
||||
static final String IOT_KEYMANAGER_PORT = "9443";
|
||||
static final String CONTENT_TYPE = "application/json";
|
||||
|
||||
private static final String IOT_HOST_PROPERTY = "iot.core.host";
|
||||
private static final String IOT_PORT_PROPERTY = "iot.core.https.port";
|
||||
private static final String IOT_KEY_MANAGER_HOST_PROPERTY = "iot.keymanager.host";
|
||||
private static final String IOT_KEY_MANAGER_PORT_PROPERTY = "iot.keymanager.https.port";
|
||||
|
||||
static String getAbsolutePathOfConfig(String configFilePath) {
|
||||
ClassLoader classLoader = TestUtils.class.getClassLoader();
|
||||
URL invalidConfig = classLoader.getResource(configFilePath);
|
||||
Assert.assertTrue(invalidConfig != null);
|
||||
File file = new File(invalidConfig.getFile());
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
static void setSystemProperties() {
|
||||
System.setProperty(IOT_HOST_PROPERTY, IOT_CORE_HOST);
|
||||
System.setProperty(IOT_PORT_PROPERTY, IOT_CORE_HTTPS_PORT);
|
||||
System.setProperty(IOT_KEY_MANAGER_HOST_PROPERTY, IOT_KEYMANAGER_HOST);
|
||||
System.setProperty(IOT_KEY_MANAGER_PORT_PROPERTY, IOT_KEYMANAGER_PORT);
|
||||
}
|
||||
|
||||
static void resetSystemProperties() {
|
||||
System.clearProperty(IOT_HOST_PROPERTY);
|
||||
System.clearProperty(IOT_PORT_PROPERTY);
|
||||
System.clearProperty(IOT_KEY_MANAGER_HOST_PROPERTY);
|
||||
System.clearProperty(IOT_KEY_MANAGER_PORT_PROPERTY);
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.handlers.mock;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mock implementation for CloseableHttpClient to be used in test cases.
|
||||
*/
|
||||
public class MockClient extends CloseableHttpClient {
|
||||
private List<CloseableHttpResponse> responses = new ArrayList<>();
|
||||
private int responseCount = 0;
|
||||
|
||||
@Override
|
||||
protected CloseableHttpResponse doExecute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext)
|
||||
throws IOException {
|
||||
if (this.responseCount < this.responses.size()) {
|
||||
this.responseCount++;
|
||||
CloseableHttpResponse response = this.responses.get(this.responseCount - 1);
|
||||
if (response == null) {
|
||||
throw new IOException("test exception");
|
||||
}
|
||||
return response;
|
||||
} else {
|
||||
return new MockHttpResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpParams getParams() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientConnectionManager getConnectionManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setResponse(CloseableHttpResponse reponse) {
|
||||
this.responses.add(reponse);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.responses.clear();
|
||||
this.responseCount = 0;
|
||||
}
|
||||
}
|
@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.handlers.mock;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderIterator;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Mock http response to be used in the test cases.
|
||||
*
|
||||
*/
|
||||
public class MockHttpResponse implements CloseableHttpResponse {
|
||||
private HttpEntity httpEntity;
|
||||
private StatusLine statusLine;
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatusLine getStatusLine() {
|
||||
return this.statusLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatusLine(StatusLine statusLine) {
|
||||
this.statusLine = statusLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatusLine(ProtocolVersion protocolVersion, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatusLine(ProtocolVersion protocolVersion, int i, String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatusCode(int i) throws IllegalStateException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReasonPhrase(String s) throws IllegalStateException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpEntity getEntity() {
|
||||
return this.httpEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(HttpEntity httpEntity) {
|
||||
this.httpEntity = httpEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(Locale locale) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsHeader(String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header[] getHeaders(String s) {
|
||||
return new Header[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header getFirstHeader(String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header getLastHeader(String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header[] getAllHeaders() {
|
||||
return new Header[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHeader(Header header) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHeader(String s, String s1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeader(Header header) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeader(String s, String s1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaders(Header[] headers) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHeader(Header header) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHeaders(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeaderIterator headerIterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeaderIterator headerIterator(String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpParams getParams() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParams(HttpParams httpParams) {
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"scope": "API_SUBSCRIBER_SCOPE",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 3600,
|
||||
"refresh_token": "33c3be152ebf0030b3fb76f2c1f80bf8",
|
||||
"access_token": "292ff0fd256814536baca0926f483c8d"
|
||||
}
|
@ -1,658 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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 is the main server configuration file
|
||||
|
||||
${carbon.home} represents the carbon.home system property.
|
||||
Other system properties can be specified in a similar manner.
|
||||
-->
|
||||
<Server xmlns="http://wso2.org/projects/carbon/carbon.xml">
|
||||
|
||||
<!--
|
||||
Product Name
|
||||
-->
|
||||
<Name>${product.name}</Name>
|
||||
|
||||
<!--
|
||||
machine readable unique key to identify each product
|
||||
-->
|
||||
<ServerKey>${product.key}</ServerKey>
|
||||
|
||||
<!--
|
||||
Product Version
|
||||
-->
|
||||
<Version>${product.version}</Version>
|
||||
|
||||
<!--
|
||||
Host name or IP address of the machine hosting this server
|
||||
e.g. www.wso2.org, 192.168.1.10
|
||||
This is will become part of the End Point Reference of the
|
||||
services deployed on this server instance.
|
||||
-->
|
||||
<!--HostName>www.wso2.org</HostName-->
|
||||
|
||||
<!--
|
||||
Host name to be used for the Carbon management console
|
||||
-->
|
||||
<!--MgtHostName>mgt.wso2.org</MgtHostName-->
|
||||
|
||||
<!--
|
||||
The URL of the back end server. This is where the admin services are hosted and
|
||||
will be used by the clients in the front end server.
|
||||
This is required only for the Front-end server. This is used when seperating BE server from FE server
|
||||
-->
|
||||
<ServerURL>local:/${carbon.context}/services/</ServerURL>
|
||||
<!--
|
||||
<ServerURL>https://${carbon.local.ip}:${carbon.management.port}${carbon.context}/services/</ServerURL>
|
||||
-->
|
||||
<!--
|
||||
The URL of the index page. This is where the user will be redirected after signing in to the
|
||||
carbon server.
|
||||
-->
|
||||
<!-- IndexPageURL>/carbon/admin/index.jsp</IndexPageURL-->
|
||||
|
||||
<!--
|
||||
For cApp deployment, we have to identify the roles that can be acted by the current server.
|
||||
The following property is used for that purpose. Any number of roles can be defined here.
|
||||
Regular expressions can be used in the role.
|
||||
Ex : <Role>.*</Role> means this server can act any role
|
||||
-->
|
||||
<ServerRoles>
|
||||
<Role>${default.server.role}</Role>
|
||||
</ServerRoles>
|
||||
|
||||
<!-- uncommnet this line to subscribe to a bam instance automatically -->
|
||||
<!--<BamServerURL>https://bamhost:bamport/services/</BamServerURL>-->
|
||||
|
||||
<!--
|
||||
The fully qualified name of the server
|
||||
-->
|
||||
<Package>org.wso2.carbon</Package>
|
||||
|
||||
<!--
|
||||
Webapp context root of WSO2 Carbon management console.
|
||||
-->
|
||||
<WebContextRoot>/</WebContextRoot>
|
||||
|
||||
<!--
|
||||
Proxy context path is a useful parameter to add a proxy path when a Carbon server is fronted by reverse proxy. In addtion
|
||||
to the proxy host and proxy port this parameter allows you add a path component to external URLs. e.g.
|
||||
URL of the Carbon server -> https://10.100.1.1:9443/carbon
|
||||
URL of the reverse proxy -> https://prod.abc.com/appserver/carbon
|
||||
|
||||
appserver - proxy context path. This specially required whenever you are generating URLs to displace in
|
||||
Carbon UI components.
|
||||
-->
|
||||
<!--
|
||||
<MgtProxyContextPath></MgtProxyContextPath>
|
||||
<ProxyContextPath></ProxyContextPath>
|
||||
-->
|
||||
|
||||
<!-- In-order to get the registry http Port from the back-end when the default http transport is not the same-->
|
||||
<!--RegistryHttpPort>9763</RegistryHttpPort-->
|
||||
|
||||
<!--
|
||||
Number of items to be displayed on a management console page. This is used at the
|
||||
backend server for pagination of various items.
|
||||
-->
|
||||
<ItemsPerPage>15</ItemsPerPage>
|
||||
|
||||
<!-- The endpoint URL of the cloud instance management Web service -->
|
||||
<!--<InstanceMgtWSEndpoint>https://ec2.amazonaws.com/</InstanceMgtWSEndpoint>-->
|
||||
|
||||
<!--
|
||||
Ports used by this server
|
||||
-->
|
||||
<Ports>
|
||||
|
||||
<!-- Ports offset. This entry will set the value of the ports defined below to
|
||||
the define value + Offset.
|
||||
e.g. Offset=2 and HTTPS port=9443 will set the effective HTTPS port to 9445
|
||||
-->
|
||||
<Offset>0</Offset>
|
||||
|
||||
<!-- The JMX Ports -->
|
||||
<JMX>
|
||||
<!--The port RMI registry is exposed-->
|
||||
<RMIRegistryPort>9999</RMIRegistryPort>
|
||||
<!--The port RMI server should be exposed-->
|
||||
<RMIServerPort>11111</RMIServerPort>
|
||||
</JMX>
|
||||
|
||||
<!-- Embedded LDAP server specific ports -->
|
||||
<EmbeddedLDAP>
|
||||
<!-- Port which embedded LDAP server runs -->
|
||||
<LDAPServerPort>10389</LDAPServerPort>
|
||||
<!-- Port which KDC (Kerberos Key Distribution Center) server runs -->
|
||||
<KDCServerPort>8000</KDCServerPort>
|
||||
</EmbeddedLDAP>
|
||||
|
||||
<!--
|
||||
Override datasources JNDIproviderPort defined in bps.xml and datasources.properties files
|
||||
-->
|
||||
<!--<JNDIProviderPort>2199</JNDIProviderPort>-->
|
||||
<!--Override receive port of thrift based entitlement service.-->
|
||||
<ThriftEntitlementReceivePort>10500</ThriftEntitlementReceivePort>
|
||||
|
||||
</Ports>
|
||||
|
||||
<!--
|
||||
JNDI Configuration
|
||||
-->
|
||||
<JNDI>
|
||||
<!--
|
||||
The fully qualified name of the default initial context factory
|
||||
-->
|
||||
<DefaultInitialContextFactory>org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory</DefaultInitialContextFactory>
|
||||
<!--
|
||||
The restrictions that are done to various JNDI Contexts in a Multi-tenant environment
|
||||
-->
|
||||
<Restrictions>
|
||||
<!--
|
||||
Contexts that will be available only to the super-tenant
|
||||
-->
|
||||
<!-- <SuperTenantOnly>
|
||||
<UrlContexts>
|
||||
<UrlContext>
|
||||
<Scheme>foo</Scheme>
|
||||
</UrlContext>
|
||||
<UrlContext>
|
||||
<Scheme>bar</Scheme>
|
||||
</UrlContext>
|
||||
</UrlContexts>
|
||||
</SuperTenantOnly> -->
|
||||
<!--
|
||||
Contexts that are common to all tenants
|
||||
-->
|
||||
<AllTenants>
|
||||
<UrlContexts>
|
||||
<UrlContext>
|
||||
<Scheme>java</Scheme>
|
||||
</UrlContext>
|
||||
<!-- <UrlContext>
|
||||
<Scheme>foo</Scheme>
|
||||
</UrlContext> -->
|
||||
</UrlContexts>
|
||||
</AllTenants>
|
||||
<!--
|
||||
All other contexts not mentioned above will be available on a per-tenant basis
|
||||
(i.e. will not be shared among tenants)
|
||||
-->
|
||||
</Restrictions>
|
||||
</JNDI>
|
||||
|
||||
<!--
|
||||
Property to determine if the server is running an a cloud deployment environment.
|
||||
This property should only be used to determine deployment specific details that are
|
||||
applicable only in a cloud deployment, i.e when the server deployed *-as-a-service.
|
||||
-->
|
||||
<IsCloudDeployment>false</IsCloudDeployment>
|
||||
|
||||
<!--
|
||||
Property to determine whether usage data should be collected for metering purposes
|
||||
-->
|
||||
<EnableMetering>false</EnableMetering>
|
||||
|
||||
<!-- The Max time a thread should take for execution in seconds -->
|
||||
<MaxThreadExecutionTime>600</MaxThreadExecutionTime>
|
||||
|
||||
<!--
|
||||
A flag to enable or disable Ghost Deployer. By default this is set to false. That is
|
||||
because the Ghost Deployer works only with the HTTP/S transports. If you are using
|
||||
other transports, don't enable Ghost Deployer.
|
||||
-->
|
||||
<GhostDeployment>
|
||||
<Enabled>false</Enabled>
|
||||
</GhostDeployment>
|
||||
|
||||
|
||||
<!--
|
||||
Eager loading or lazy loading is a design pattern commonly used in computer programming which
|
||||
will initialize an object upon creation or load on-demand. In carbon, lazy loading is used to
|
||||
load tenant when a request is received only. Similarly Eager loading is used to enable load
|
||||
existing tenants after carbon server starts up. Using this feature, you will be able to include
|
||||
or exclude tenants which are to be loaded when server startup.
|
||||
|
||||
We can enable only one LoadingPolicy at a given time.
|
||||
|
||||
1. Tenant Lazy Loading
|
||||
This is the default behaviour and enabled by default. With this policy, tenants are not loaded at
|
||||
server startup, but loaded based on-demand (i.e when a request is received for a tenant).
|
||||
The default tenant idle time is 30 minutes.
|
||||
|
||||
2. Tenant Eager Loading
|
||||
This is by default not enabled. It can be be enabled by un-commenting the <EagerLoading> section.
|
||||
The eager loading configurations supported are as below. These configurations can be given as the
|
||||
value for <Include> element with eager loading.
|
||||
(i)Load all tenants when server startup - *
|
||||
(ii)Load all tenants except foo.com & bar.com - *,!foo.com,!bar.com
|
||||
(iii)Load only foo.com & bar.com to be included - foo.com,bar.com
|
||||
-->
|
||||
<Tenant>
|
||||
<LoadingPolicy>
|
||||
<LazyLoading>
|
||||
<IdleTime>30</IdleTime>
|
||||
</LazyLoading>
|
||||
<!-- <EagerLoading>
|
||||
<Include>*,!foo.com,!bar.com</Include>
|
||||
</EagerLoading>-->
|
||||
</LoadingPolicy>
|
||||
</Tenant>
|
||||
|
||||
<!--
|
||||
Caching related configurations
|
||||
-->
|
||||
<Cache>
|
||||
<!-- Default cache timeout in minutes -->
|
||||
<DefaultCacheTimeout>15</DefaultCacheTimeout>
|
||||
</Cache>
|
||||
|
||||
<!--
|
||||
Axis2 related configurations
|
||||
-->
|
||||
<Axis2Config>
|
||||
<!--
|
||||
Location of the Axis2 Services & Modules repository
|
||||
|
||||
This can be a directory in the local file system, or a URL.
|
||||
|
||||
e.g.
|
||||
1. /home/wso2wsas/repository/ - An absolute path
|
||||
2. repository - In this case, the path is relative to CARBON_HOME
|
||||
3. file:///home/wso2wsas/repository/
|
||||
4. http://wso2wsas/repository/
|
||||
-->
|
||||
<RepositoryLocation>${carbon.home}/repository/deployment/server/</RepositoryLocation>
|
||||
|
||||
<!--
|
||||
Deployment update interval in seconds. This is the interval between repository listener
|
||||
executions.
|
||||
-->
|
||||
<DeploymentUpdateInterval>15</DeploymentUpdateInterval>
|
||||
|
||||
<!--
|
||||
Location of the main Axis2 configuration descriptor file, a.k.a. axis2.xml file
|
||||
|
||||
This can be a file on the local file system, or a URL
|
||||
|
||||
e.g.
|
||||
1. /home/repository/axis2.xml - An absolute path
|
||||
2. conf/axis2.xml - In this case, the path is relative to CARBON_HOME
|
||||
3. file:///home/carbon/repository/axis2.xml
|
||||
4. http://repository/conf/axis2.xml
|
||||
-->
|
||||
<ConfigurationFile>${carbon.home}/repository/conf/axis2/axis2.xml</ConfigurationFile>
|
||||
|
||||
<!--
|
||||
ServiceGroupContextIdleTime, which will be set in ConfigurationContex
|
||||
for multiple clients which are going to access the same ServiceGroupContext
|
||||
Default Value is 30 Sec.
|
||||
-->
|
||||
<ServiceGroupContextIdleTime>30000</ServiceGroupContextIdleTime>
|
||||
|
||||
<!--
|
||||
This repository location is used to crete the client side configuration
|
||||
context used by the server when calling admin services.
|
||||
-->
|
||||
<ClientRepositoryLocation>${carbon.home}/repository/deployment/client/</ClientRepositoryLocation>
|
||||
<!-- This axis2 xml is used in createing the configuration context by the FE server
|
||||
calling to BE server -->
|
||||
<clientAxis2XmlLocation>${carbon.home}/repository/conf/axis2/axis2_client.xml</clientAxis2XmlLocation>
|
||||
<!-- If this parameter is set, the ?wsdl on an admin service will not give the admin service wsdl. -->
|
||||
<HideAdminServiceWSDLs>true</HideAdminServiceWSDLs>
|
||||
|
||||
<!--WARNING-Use With Care! Uncommenting bellow parameter would expose all AdminServices in HTTP transport.
|
||||
With HTTP transport your credentials and data routed in public channels are vulnerable for sniffing attacks.
|
||||
Use bellow parameter ONLY if your communication channels are confirmed to be secured by other means -->
|
||||
<!--HttpAdminServices>*</HttpAdminServices-->
|
||||
|
||||
</Axis2Config>
|
||||
|
||||
<!--
|
||||
The default user roles which will be created when the server
|
||||
is started up for the first time.
|
||||
-->
|
||||
<ServiceUserRoles>
|
||||
<Role>
|
||||
<Name>admin</Name>
|
||||
<Description>Default Administrator Role</Description>
|
||||
</Role>
|
||||
<Role>
|
||||
<Name>user</Name>
|
||||
<Description>Default User Role</Description>
|
||||
</Role>
|
||||
</ServiceUserRoles>
|
||||
|
||||
<!--
|
||||
Enable following config to allow Emails as usernames.
|
||||
-->
|
||||
<!--EnableEmailUserName>true</EnableEmailUserName-->
|
||||
|
||||
<!--
|
||||
Security configurations
|
||||
-->
|
||||
<Security>
|
||||
<!--
|
||||
KeyStore which will be used for encrypting/decrypting passwords
|
||||
and other sensitive information.
|
||||
-->
|
||||
<KeyStore>
|
||||
<!-- Keystore file location-->
|
||||
<Location>${carbon.home}/repository/resources/security/wso2carbon.jks</Location>
|
||||
<!-- Keystore type (JKS/PKCS12 etc.)-->
|
||||
<Type>JKS</Type>
|
||||
<!-- Keystore password-->
|
||||
<Password>wso2carbon</Password>
|
||||
<!-- Private Key alias-->
|
||||
<KeyAlias>wso2carbon</KeyAlias>
|
||||
<!-- Private Key password-->
|
||||
<KeyPassword>wso2carbon</KeyPassword>
|
||||
</KeyStore>
|
||||
|
||||
<!--
|
||||
System wide trust-store which is used to maintain the certificates of all
|
||||
the trusted parties.
|
||||
-->
|
||||
<TrustStore>
|
||||
<!-- trust-store file location -->
|
||||
<Location>${carbon.home}/repository/resources/security/client-truststore.jks</Location>
|
||||
<!-- trust-store type (JKS/PKCS12 etc.) -->
|
||||
<Type>JKS</Type>
|
||||
<!-- trust-store password -->
|
||||
<Password>wso2carbon</Password>
|
||||
</TrustStore>
|
||||
|
||||
<!--
|
||||
The Authenticator configuration to be used at the JVM level. We extend the
|
||||
java.net.Authenticator to make it possible to authenticate to given servers and
|
||||
proxies.
|
||||
-->
|
||||
<NetworkAuthenticatorConfig>
|
||||
<!--
|
||||
Below is a sample configuration for a single authenticator. Please note that
|
||||
all child elements are mandatory. Not having some child elements would lead to
|
||||
exceptions at runtime.
|
||||
-->
|
||||
<!-- <Credential> -->
|
||||
<!--
|
||||
the pattern that would match a subset of URLs for which this authenticator
|
||||
would be used
|
||||
-->
|
||||
<!-- <Pattern>regularExpression</Pattern> -->
|
||||
<!--
|
||||
the type of this authenticator. Allowed values are:
|
||||
1. server
|
||||
2. proxy
|
||||
-->
|
||||
<!-- <Type>proxy</Type> -->
|
||||
<!-- the username used to log in to server/proxy -->
|
||||
<!-- <Username>username</Username> -->
|
||||
<!-- the password used to log in to server/proxy -->
|
||||
<!-- <Password>password</Password> -->
|
||||
<!-- </Credential> -->
|
||||
</NetworkAuthenticatorConfig>
|
||||
|
||||
<!--
|
||||
The Tomcat realm to be used for hosted Web applications. Allowed values are;
|
||||
1. UserManager
|
||||
2. Memory
|
||||
|
||||
If this is set to 'UserManager', the realm will pick users & roles from the system's
|
||||
WSO2 User Manager. If it is set to 'memory', the realm will pick users & roles from
|
||||
CARBON_HOME/repository/conf/tomcat/tomcat-users.xml
|
||||
-->
|
||||
<TomcatRealm>UserManager</TomcatRealm>
|
||||
|
||||
<!--Option to disable storing of tokens issued by STS-->
|
||||
<DisableTokenStore>false</DisableTokenStore>
|
||||
|
||||
<!--
|
||||
Security token store class name. If this is not set, default class will be
|
||||
org.wso2.carbon.security.util.SecurityTokenStore
|
||||
-->
|
||||
<!--TokenStoreClassName>org.wso2.carbon.identity.sts.store.DBTokenStore</TokenStoreClassName-->
|
||||
</Security>
|
||||
|
||||
<!--
|
||||
The temporary work directory
|
||||
-->
|
||||
<WorkDirectory>${carbon.home}/tmp/work</WorkDirectory>
|
||||
|
||||
<!--
|
||||
House-keeping configuration
|
||||
-->
|
||||
<HouseKeeping>
|
||||
|
||||
<!--
|
||||
true - Start House-keeping thread on server startup
|
||||
false - Do not start House-keeping thread on server startup.
|
||||
The user will run it manually as and when he wishes.
|
||||
-->
|
||||
<AutoStart>true</AutoStart>
|
||||
|
||||
<!--
|
||||
The interval in *minutes*, between house-keeping runs
|
||||
-->
|
||||
<Interval>10</Interval>
|
||||
|
||||
<!--
|
||||
The maximum time in *minutes*, temp files are allowed to live
|
||||
in the system. Files/directories which were modified more than
|
||||
"MaxTempFileLifetime" minutes ago will be removed by the
|
||||
house-keeping task
|
||||
-->
|
||||
<MaxTempFileLifetime>30</MaxTempFileLifetime>
|
||||
</HouseKeeping>
|
||||
|
||||
<!--
|
||||
Configuration for handling different types of file upload & other file uploading related
|
||||
config parameters.
|
||||
To map all actions to a particular FileUploadExecutor, use
|
||||
<Action>*</Action>
|
||||
-->
|
||||
<FileUploadConfig>
|
||||
<!--
|
||||
The total file upload size limit in MB
|
||||
-->
|
||||
<TotalFileSizeLimit>100</TotalFileSizeLimit>
|
||||
|
||||
<Mapping>
|
||||
<Actions>
|
||||
<Action>keystore</Action>
|
||||
<Action>certificate</Action>
|
||||
<Action>*</Action>
|
||||
</Actions>
|
||||
<Class>org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor</Class>
|
||||
</Mapping>
|
||||
|
||||
<Mapping>
|
||||
<Actions>
|
||||
<Action>jarZip</Action>
|
||||
</Actions>
|
||||
<Class>org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor</Class>
|
||||
</Mapping>
|
||||
<Mapping>
|
||||
<Actions>
|
||||
<Action>dbs</Action>
|
||||
</Actions>
|
||||
<Class>org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor</Class>
|
||||
</Mapping>
|
||||
<Mapping>
|
||||
<Actions>
|
||||
<Action>tools</Action>
|
||||
</Actions>
|
||||
<Class>org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor</Class>
|
||||
</Mapping>
|
||||
<Mapping>
|
||||
<Actions>
|
||||
<Action>toolsAny</Action>
|
||||
</Actions>
|
||||
<Class>org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor</Class>
|
||||
</Mapping>
|
||||
</FileUploadConfig>
|
||||
|
||||
<!--
|
||||
Processors which process special HTTP GET requests such as ?wsdl, ?policy etc.
|
||||
|
||||
In order to plug in a processor to handle a special request, simply add an entry to this
|
||||
section.
|
||||
|
||||
The value of the Item element is the first parameter in the query string(e.g. ?wsdl)
|
||||
which needs special processing
|
||||
|
||||
The value of the Class element is a class which implements
|
||||
org.wso2.carbon.transport.HttpGetRequestProcessor
|
||||
-->
|
||||
<HttpGetRequestProcessors>
|
||||
<Processor>
|
||||
<Item>info</Item>
|
||||
<Class>org.wso2.carbon.core.transports.util.InfoProcessor</Class>
|
||||
</Processor>
|
||||
<Processor>
|
||||
<Item>wsdl</Item>
|
||||
<Class>org.wso2.carbon.core.transports.util.Wsdl11Processor</Class>
|
||||
</Processor>
|
||||
<Processor>
|
||||
<Item>wsdl2</Item>
|
||||
<Class>org.wso2.carbon.core.transports.util.Wsdl20Processor</Class>
|
||||
</Processor>
|
||||
<Processor>
|
||||
<Item>xsd</Item>
|
||||
<Class>org.wso2.carbon.core.transports.util.XsdProcessor</Class>
|
||||
</Processor>
|
||||
</HttpGetRequestProcessors>
|
||||
|
||||
<!-- Deployment Synchronizer Configuration. t Enabled value to true when running with "svn based" dep sync.
|
||||
In master nodes you need to set both AutoCommit and AutoCheckout to true
|
||||
and in worker nodes set only AutoCheckout to true.
|
||||
-->
|
||||
<DeploymentSynchronizer>
|
||||
<Enabled>false</Enabled>
|
||||
<AutoCommit>false</AutoCommit>
|
||||
<AutoCheckout>true</AutoCheckout>
|
||||
<RepositoryType>svn</RepositoryType>
|
||||
<SvnUrl>http://svnrepo.example.com/repos/</SvnUrl>
|
||||
<SvnUser>username</SvnUser>
|
||||
<SvnPassword>password</SvnPassword>
|
||||
<SvnUrlAppendTenantId>true</SvnUrlAppendTenantId>
|
||||
</DeploymentSynchronizer>
|
||||
|
||||
<!-- Deployment Synchronizer Configuration. Uncomment the following section when running with "registry based" dep sync.
|
||||
In master nodes you need to set both AutoCommit and AutoCheckout to true
|
||||
and in worker nodes set only AutoCheckout to true.
|
||||
-->
|
||||
<!--<DeploymentSynchronizer>
|
||||
<Enabled>true</Enabled>
|
||||
<AutoCommit>false</AutoCommit>
|
||||
<AutoCheckout>true</AutoCheckout>
|
||||
</DeploymentSynchronizer>-->
|
||||
|
||||
<!-- Mediation persistence configurations. Only valid if mediation features are available i.e. ESB -->
|
||||
<!--<MediationConfig>
|
||||
<LoadFromRegistry>false</LoadFromRegistry>
|
||||
<SaveToFile>false</SaveToFile>
|
||||
<Persistence>enabled</Persistence>
|
||||
<RegistryPersistence>enabled</RegistryPersistence>
|
||||
</MediationConfig>-->
|
||||
|
||||
<!--
|
||||
Server intializing code, specified as implementation classes of org.wso2.carbon.core.ServerInitializer.
|
||||
This code will be run when the Carbon server is initialized
|
||||
-->
|
||||
<ServerInitializers>
|
||||
<!--<Initializer></Initializer>-->
|
||||
</ServerInitializers>
|
||||
|
||||
<!--
|
||||
Indicates whether the Carbon Servlet is required by the system, and whether it should be
|
||||
registered
|
||||
-->
|
||||
<RequireCarbonServlet>${require.carbon.servlet}</RequireCarbonServlet>
|
||||
|
||||
<!--
|
||||
Carbon H2 OSGI Configuration
|
||||
By default non of the servers start.
|
||||
name="web" - Start the web server with the H2 Console
|
||||
name="webPort" - The port (default: 8082)
|
||||
name="webAllowOthers" - Allow other computers to connect
|
||||
name="webSSL" - Use encrypted (HTTPS) connections
|
||||
name="tcp" - Start the TCP server
|
||||
name="tcpPort" - The port (default: 9092)
|
||||
name="tcpAllowOthers" - Allow other computers to connect
|
||||
name="tcpSSL" - Use encrypted (SSL) connections
|
||||
name="pg" - Start the PG server
|
||||
name="pgPort" - The port (default: 5435)
|
||||
name="pgAllowOthers" - Allow other computers to connect
|
||||
name="trace" - Print additional trace information; for all servers
|
||||
name="baseDir" - The base directory for H2 databases; for all servers
|
||||
-->
|
||||
<!--H2DatabaseConfiguration>
|
||||
<property name="web" />
|
||||
<property name="webPort">8082</property>
|
||||
<property name="webAllowOthers" />
|
||||
<property name="webSSL" />
|
||||
<property name="tcp" />
|
||||
<property name="tcpPort">9092</property>
|
||||
<property name="tcpAllowOthers" />
|
||||
<property name="tcpSSL" />
|
||||
<property name="pg" />
|
||||
<property name="pgPort">5435</property>
|
||||
<property name="pgAllowOthers" />
|
||||
<property name="trace" />
|
||||
<property name="baseDir">${carbon.home}</property>
|
||||
</H2DatabaseConfiguration-->
|
||||
<!--Disabling statistics reporter by default-->
|
||||
<StatisticsReporterDisabled>true</StatisticsReporterDisabled>
|
||||
|
||||
<!-- Enable accessing Admin Console via HTTP -->
|
||||
<!-- EnableHTTPAdminConsole>true</EnableHTTPAdminConsole -->
|
||||
|
||||
<!--
|
||||
Default Feature Repository of WSO2 Carbon.
|
||||
-->
|
||||
<FeatureRepository>
|
||||
<RepositoryName>default repository</RepositoryName>
|
||||
<RepositoryURL>${p2.repo.url}</RepositoryURL>
|
||||
</FeatureRepository>
|
||||
|
||||
<!--
|
||||
Configure API Management
|
||||
-->
|
||||
<APIManagement>
|
||||
|
||||
<!--Uses the embedded API Manager by default. If you want to use an external
|
||||
API Manager instance to manage APIs, configure below externalAPIManager-->
|
||||
|
||||
<Enabled>true</Enabled>
|
||||
|
||||
<!--Uncomment and configure API Gateway and
|
||||
Publisher URLs to use external API Manager instance-->
|
||||
|
||||
<!--ExternalAPIManager>
|
||||
|
||||
<APIGatewayURL>http://localhost:8281</APIGatewayURL>
|
||||
<APIPublisherURL>http://localhost:8281/publisher</APIPublisherURL>
|
||||
|
||||
</ExternalAPIManager-->
|
||||
|
||||
<LoadAPIContextsInServerStartup>true</LoadAPIContextsInServerStartup>
|
||||
</APIManagement>
|
||||
</Server>
|
@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
|
||||
<ServerConfig>
|
||||
<!-- IoT server host name, this is referred from APIM gateway to call to IoT server for certificate validation-->
|
||||
<Hostname>https://${iot.core.host}:${iot.core.https.port}/</Hostname>
|
||||
|
||||
<!--End point to verify the certificate-->
|
||||
<VerificationEndpoint>https://${iot.core.host}:${iot.core.https.port}/api/certificate-mgt/v1.0/admin/certificates/verify/</VerificationEndpoint>
|
||||
|
||||
<!--Admin username/password - this is to use for oauth token generation-->
|
||||
<Username>testuser</Username>
|
||||
<Password>testuserpwd</Password>
|
||||
|
||||
<!--Dynamic client registration endpoint-->
|
||||
<DynamicClientRegistrationEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.12/register</DynamicClientRegistrationEndpoint>
|
||||
|
||||
<!--Oauth token endpoint-->
|
||||
<OauthTokenEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/oauth2/token</OauthTokenEndpoint>
|
||||
|
||||
<APIS>
|
||||
<ContextPath>/services</ContextPath>
|
||||
</APIS>
|
||||
</ServerConfig
|
@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
|
||||
<ServerConfig>
|
||||
<!-- IoT server host name, this is referred from APIM gateway to call to IoT server for certificate validation-->
|
||||
<Hostname>https://${iot.core.host}:${iot.core.https.port}/</Hostname>
|
||||
|
||||
<!--End point to verify the certificate-->
|
||||
<VerificationEndpoint>https://${iot.core.host}:${iot.core.https.port}/api/certificate-mgt/v1.0/admin/certificates/verify/</VerificationEndpoint>
|
||||
|
||||
<!--Admin username/password - this is to use for oauth token generation-->
|
||||
<Username>testuser</Username>
|
||||
<Password>testuserpwd</Password>
|
||||
|
||||
<!--Dynamic client registration endpoint-->
|
||||
<DynamicClientRegistrationEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.12/register</DynamicClientRegistrationEndpoint>
|
||||
|
||||
<!--Oauth token endpoint-->
|
||||
<OauthTokenEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/oauth2/token</OauthTokenEndpoint>
|
||||
|
||||
<APIS>
|
||||
<ContextPath>/services</ContextPath>
|
||||
</APIS>
|
||||
</ServerConfig>
|
@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
|
||||
<ServerConfiguration>
|
||||
<!-- IoT server host name, this is referred from APIM gateway to call to IoT server for certificate validation-->
|
||||
<Hostname>https://${iot.core.host}:${iot.core.https.port}/</Hostname>
|
||||
|
||||
<!--End point to verify the certificate-->
|
||||
<VerificationEndpoint>https://${iot.core.host}:${iot.core.https.port}/api/certificate-mgt/v1.0/admin/certificates/verify/</VerificationEndpoint>
|
||||
|
||||
<!--Admin username/password - this is to use for oauth token generation-->
|
||||
<Username>testuser</Username>
|
||||
<Password>testuserpwd</Password>
|
||||
|
||||
<!--Dynamic client registration endpoint-->
|
||||
<DynamicClientRegistrationEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.12/register</DynamicClientRegistrationEndpoint>
|
||||
|
||||
<!--Oauth token endpoint-->
|
||||
<OauthTokenEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/oauth2/token</OauthTokenEndpoint>
|
||||
|
||||
<APIS>
|
||||
<ContextPath>/services</ContextPath>
|
||||
</APIS>
|
||||
</ServerConfiguration>
|
@ -1,52 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
<wso2registry>
|
||||
|
||||
<!--
|
||||
For details on configuring different config & governance registries see;
|
||||
http://wso2.org/library/tutorials/2010/04/sharing-registry-space-across-multiple-product-instances
|
||||
-->
|
||||
|
||||
<currentDBConfig>wso2registry</currentDBConfig>
|
||||
<readOnly>false</readOnly>
|
||||
<enableCache>true</enableCache>
|
||||
<registryRoot>/</registryRoot>
|
||||
|
||||
<dbConfig name="wso2registry">
|
||||
<url>jdbc:h2:./target/databasetest/CARBON_TEST</url>
|
||||
<!--userName>sa</userName>
|
||||
<password>sa</password-->
|
||||
<driverName>org.h2.Driver</driverName>
|
||||
<maxActive>80</maxActive>
|
||||
<maxWait>60000</maxWait>
|
||||
<minIdle>5</minIdle>
|
||||
</dbConfig>
|
||||
|
||||
<versionResourcesOnChange>false</versionResourcesOnChange>
|
||||
|
||||
<!-- NOTE: You can edit the options under "StaticConfiguration" only before the
|
||||
startup. -->
|
||||
<staticConfiguration>
|
||||
<versioningProperties>true</versioningProperties>
|
||||
<versioningComments>true</versioningComments>
|
||||
<versioningTags>true</versioningTags>
|
||||
<versioningRatings>true</versioningRatings>
|
||||
</staticConfiguration>
|
||||
</wso2registry>
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"callBackURL": "www.google.lk",
|
||||
"clientName": null,
|
||||
"clientId": "HfEl1jJPdg5tbtrxhAwybN05QGoa",
|
||||
"clientSecret": "l6c0aoLcWR3fwezHhc7XoGOht5Aa"
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFqDCCA5CgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
|
||||
DTALBgNVBAgTBFRlc3QxDTALBgNVBAcTBFRlc3QxETAPBgNVBAoTCFRlc3QgT3Jn
|
||||
MRYwFAYDVQQLEw1UZXN0IG9yZyB1bml0MRUwEwYDVQQDEwxXU08yIFJvb3QgQ0Ex
|
||||
HDAaBgkqhkiG9w0BCQEWDXJvb3RAd3NvMi5jb20wHhcNMTUwMTI3MTI1MzAxWhcN
|
||||
MTcxMDIzMTI1MzAxWjCBgzELMAkGA1UEBhMCVVMxGTAXBgNVBAgTEFRlc3QgUkEg
|
||||
UHJvdmluY2UxFTATBgNVBAcTDFRlc3QgUkEgQ2l0eTEUMBIGA1UEChMLVGVzdCBS
|
||||
QSBPcmcxGTAXBgNVBAsTEFRlc3QgUkEgb3JnIHVuaXQxETAPBgNVBAMTCFdTTzIg
|
||||
UkEgMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtUMgUlYYU3/TPfEe
|
||||
zNAvBaiOi/jUjfZ9IbxvMl7obDT17/5vU68TCGkZRjyfYUEiGNBisUEFWjSk/sGL
|
||||
/ofYKUAxw33cd456FLMjaJX/4Zk4y8eYB1m1GGlHejoDyjPhq8S6GDmy+PXbJr8n
|
||||
lSTROR2mQHkGwYrCreWeU4AYWzdctIFk7U2DKeIvZYSidIIjfSpDXURxrt9LPvig
|
||||
fMzr5l/WkZfjvk5S+W7rgMtpllxlEPgyDc07pNAdNSq5FB990oaUsVX8o6l6wdCw
|
||||
grYz83edPOKwZa04fsVztz2oF3ZYSGGjD3lwh0KS/jUL+awRyhMx5p/O1hySg6PP
|
||||
pJjeqRuobNTuwSAXxp3nsNSY0DkGW04pSxWoDQqhnpaqBbAf71l6ya2e3so1SHm/
|
||||
jouWSYTHncq5bmGE4AN7ZGVGZvfx84+UR8fNxJxxLo+DFFE0oJNzpPGNxILpHxgT
|
||||
V7IOII6mhfkrQk+AFQiW2Y5FXLVYv8r+SPXW8pYsjaWl971XZeM/HC3L9IZkCrrr
|
||||
a0ID5oT6vt+xTmdo4yiBqIP5TBYm+1a9YzMAy7XGtPih9k6cufMLcfzvUZdOXw9x
|
||||
3T05nM5ZtcDq0gHvUzQ7sfHTguWVnuHVEdb2ox4x2L5NzEA475fbSdXpMok9z/z7
|
||||
Xa71vIZi28InDAFBQehUlJnFtf0CAwEAAaMdMBswDAYDVR0TBAUwAwEB/zALBgNV
|
||||
HQ8EBAMCBaAwDQYJKoZIhvcNAQEFBQADggIBAAO0TwnQBMJvL8wbfsnTqAGCCHM4
|
||||
x1cpW+KgTmflPEliYGOn/dJYDz/dUowCgoj5mrSxjQ3G1/qL+9Y7E33h0tyw37vH
|
||||
YDL1p2Tn+fwmXRHrk+CHoPHNcImEfSIDWbbG7ehBR6erVfbQSZjmj4fwPkItp8rP
|
||||
nyUtXHOLpfFYoAxYkNP9+C8vpC9W/H1pj3rzmQFA1z+EZAKVV7vDAxbe6sun84nf
|
||||
YAaMSIzHx1B+XLHokgChmnZr3wV7EypBEmmKp4ITvJqK7WsIG9t1M6hI7OTPCURR
|
||||
mdy+DJtIoIUbZxHyIyC9nPcVJFkdBusnfXq4uMb0KMaWYCU8ESqZPySukF2qZ5KA
|
||||
acB+0ZhY+EGQ6QF/hB6iiUj96BlQ7XAPXFU6xUt6nRjDiJmb3vW1IEv0hpbs7PRl
|
||||
UMlbOwQk37rXpFqQc6ZW7lsxI2RmfkD4DOkQIGH3q5foVr+PEp0uSPWrFX62eBet
|
||||
1S4c/opVv6BcuUgilYABHTYxb45GfYwJAI9Qw2uQWT8DmhtVbcYu6GLYGlnRyaOC
|
||||
EPzc0z0KQTjhsgHWzi60IYBBh+fy+Z7w5X1rTTvhFOoU5J7kedGEqiBatIZmhF5t
|
||||
UFbT0u350ET5a0Kg83gu5aLwXdoIP9o7bp3XzLBMVNny2RX3tOHUA2HBe/p0h0OU
|
||||
Ggt3G6oD0gBe9pZI
|
||||
-----END CERTIFICATE-----
|
@ -1,30 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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="DeviceManagementExtensions">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
|
||||
<test name="API Management Auth Handlers" preserve-order="true">
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.apimgt.handlers.IOTServerConfigurationTest"/>
|
||||
<class name="org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
@ -1,202 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Integration Client</name>
|
||||
<description>WSO2 Carbon - API Management Integration Client</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>APIM Integration</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.apimgt.integration.client.internal</Private-Package>
|
||||
<Export-Package>
|
||||
org.wso2.carbon.apimgt.integration.client.*,
|
||||
!org.wso2.carbon.apimgt.integration.client.internal
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
feign,
|
||||
feign.codec,
|
||||
feign.auth,
|
||||
feign.gson,
|
||||
feign.slf4j,
|
||||
org.wso2.carbon.apimgt.integration.generated.client.publisher.api,
|
||||
org.wso2.carbon.apimgt.integration.generated.client.store.api,
|
||||
javax.xml.bind,
|
||||
javax.xml.bind.annotation,
|
||||
javax.xml.parsers;resolution:=optional,
|
||||
org.apache.commons.logging,
|
||||
org.w3c.dom,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.identity.jwt.client.*,
|
||||
org.wso2.carbon.user.api,
|
||||
org.wso2.carbon.utils,
|
||||
com.fasterxml.jackson.annotation,
|
||||
io.swagger.annotations,
|
||||
org.wso2.carbon.core.util,
|
||||
javax.xml,
|
||||
org.wso2.carbon.base,
|
||||
javax.net.ssl,
|
||||
org.apache.commons.lang,
|
||||
android.util;resolution:=optional,
|
||||
javax.annotation;resolution:=optional,
|
||||
javax.net;resolution:=optional,
|
||||
javax.security.auth.x500;resolution:=optional,
|
||||
javax.crypto;resolution:=optional,
|
||||
javax.crypto.spec;resolution:=optional
|
||||
</Import-Package>
|
||||
<Embed-Dependency>
|
||||
jsr311-api,
|
||||
feign-jaxrs,
|
||||
feign-okhttp,
|
||||
okhttp,
|
||||
okio
|
||||
</Embed-Dependency>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
|
||||
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okio</groupId>
|
||||
<artifactId>okio</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-gson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.identity.jwt.client.extension</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.apimgt.integration.client;
|
||||
|
||||
import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient;
|
||||
import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService;
|
||||
import org.wso2.carbon.apimgt.integration.client.store.StoreClient;
|
||||
|
||||
public class IntegrationClientServiceImpl implements IntegrationClientService {
|
||||
|
||||
private static volatile IntegrationClientServiceImpl instance;
|
||||
private StoreClient storeClient;
|
||||
private PublisherClient publisherClient;
|
||||
private OAuthRequestInterceptor oAuthRequestInterceptor;
|
||||
|
||||
private IntegrationClientServiceImpl() {
|
||||
oAuthRequestInterceptor = new OAuthRequestInterceptor();
|
||||
storeClient = new StoreClient(oAuthRequestInterceptor);
|
||||
publisherClient = new PublisherClient(oAuthRequestInterceptor);
|
||||
}
|
||||
|
||||
public IntegrationClientServiceImpl(OAuthRequestInterceptor oAuthRequestInterceptor) {
|
||||
this.oAuthRequestInterceptor = oAuthRequestInterceptor;
|
||||
storeClient = new StoreClient(oAuthRequestInterceptor);
|
||||
publisherClient = new PublisherClient(oAuthRequestInterceptor);
|
||||
}
|
||||
|
||||
public static IntegrationClientServiceImpl getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (IntegrationClientService.class) {
|
||||
if (instance == null) {
|
||||
instance = new IntegrationClientServiceImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void resetUserInfo(String userName, String tenantDomain) {
|
||||
oAuthRequestInterceptor.removeToken(userName, tenantDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoreClient getStoreClient() {
|
||||
return storeClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublisherClient getPublisherClient() {
|
||||
return publisherClient;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue