commit
1013831507
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,212 @@
|
||||
<?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>device-mgt-extensions</artifactId>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<version>5.0.33-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>Entgra IoT - User store role mapping Module</name>
|
||||
<description>Entgra IoT - User store role mapping Module</description>
|
||||
<url>http://entgra.io</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
<version>2.3.2</version>
|
||||
</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>IOT - User store role mapping Module</Bundle-Description>
|
||||
<Private-Package>io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.internal</Private-Package>
|
||||
<Import-Package>
|
||||
org.osgi.framework.*;version="${imp.package.version.osgi.framework}",
|
||||
org.osgi.service.*;version="${imp.package.version.osgi.service}",
|
||||
org.apache.commons.logging,
|
||||
org.apache.axis2.*;version="${axis2.osgi.version.range}",
|
||||
org.wso2.carbon.core,
|
||||
org.wso2.carbon.utils.*,
|
||||
javax.xml.bind;resolution:=optional,
|
||||
javax.xml.bind.annotation,
|
||||
javax.xml.parsers,
|
||||
org.w3c.dom,
|
||||
org.wso2.carbon,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.user.api,
|
||||
org.wso2.carbon.user.core.common,
|
||||
org.wso2.carbon.user.core.service,
|
||||
org.wso2.carbon.user.mgt.common,
|
||||
io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service,
|
||||
io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.exception
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.internal,
|
||||
io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.*;version="${project.version}"
|
||||
</Export-Package>
|
||||
</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>
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-surefire-plugin</artifactId>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <systemPropertyVariables>-->
|
||||
<!-- <log4j.configuration>file:src/test/resources/carbon-home/repository/conf/log4j.properties-->
|
||||
<!-- </log4j.configuration>-->
|
||||
<!-- </systemPropertyVariables>-->
|
||||
<!-- <suiteXmlFiles>-->
|
||||
<!-- <file>src/test/resources/testng.xml</file>-->
|
||||
<!-- </suiteXmlFiles>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||
<artifactId>org.wso2.carbon.user.mgt</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.orbit.com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.wso2</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.securevault</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.securevault</groupId>
|
||||
<artifactId>org.wso2.securevault</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xerces.wso2</groupId>
|
||||
<artifactId>xercesImpl</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.queuing</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.entgra.device.mgt.core</groupId>
|
||||
<artifactId>io.entgra.device.mgt.core.server.bootup.heartbeat.beacon</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.userstore.role.mapper;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.bean.RoleMapping;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.bean.UserStoreRoleMappingConfig;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.internal.UserStoreRoleMappingDataHolder;
|
||||
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.core.ServerStartupObserver;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.api.UserStoreManager;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class UserStoreRoleMapper implements ServerStartupObserver {
|
||||
private static final Log log = LogFactory.getLog(UserStoreRoleMapper.class);
|
||||
|
||||
private UserStoreRoleMappingConfig config = null;
|
||||
@Override
|
||||
public void completingServerStartup() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completedServerStartup() {
|
||||
|
||||
config = UserStoreRoleMappingDataHolder.getInstance()
|
||||
.getUserStoreRoleMappingConfigManager().getUserStoreRoleMappingConfig();
|
||||
|
||||
try {
|
||||
if ((config.isEnabled() &&
|
||||
UserStoreRoleMappingDataHolder.getInstance().getHeartBeatService().isTaskPartitioningEnabled() &&
|
||||
UserStoreRoleMappingDataHolder.getInstance().getHeartBeatService().isQualifiedToExecuteTask())
|
||||
|| (config.isEnabled() &&
|
||||
!UserStoreRoleMappingDataHolder.getInstance().getHeartBeatService().isTaskPartitioningEnabled())) {
|
||||
Runnable periodicTask = new Runnable() {
|
||||
public void run() {
|
||||
updateRoleMapping();
|
||||
log.info("UserStoreRoleMapper executed....");
|
||||
}
|
||||
};
|
||||
|
||||
ScheduledExecutorService executor =
|
||||
Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
executor.scheduleAtFixedRate(periodicTask, config.getInitialDelayInSeconds(), config.getPeriodInSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (HeartBeatManagementException e) {
|
||||
log.error("Error while accessing heart beat service " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRoleMapping() {
|
||||
try {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(
|
||||
MultitenantConstants.SUPER_TENANT_ID);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
|
||||
List<RoleMapping> roleMappings = config.getMappings();
|
||||
|
||||
if (!roleMappings.isEmpty()) {
|
||||
UserStoreManager userStoreManager =
|
||||
UserStoreRoleMappingDataHolder.getInstance().getRealmService()
|
||||
.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getUserStoreManager();
|
||||
|
||||
for (RoleMapping mapping : roleMappings) {
|
||||
if (userStoreManager.isExistingRole(mapping.getSecondaryRole())) {
|
||||
String[] users = userStoreManager.getUserListOfRole(mapping.getSecondaryRole());
|
||||
if (users != null && users.length > 0) {
|
||||
List<String> primaryRoles = mapping.getInternalRoles();
|
||||
for (String role : primaryRoles) {
|
||||
if (userStoreManager.isExistingRole(role)) {
|
||||
String[] existingUsers = userStoreManager.getUserListOfRole(role);
|
||||
List<String> existingUserList = new ArrayList<>(Arrays.asList(existingUsers));
|
||||
List<String> newUserList = new ArrayList<>();
|
||||
for (String user : users) {
|
||||
if (existingUserList.contains(user)) {
|
||||
// if contains, remove from existing list
|
||||
existingUserList.remove(user);
|
||||
} else {
|
||||
// new user
|
||||
newUserList.add(user);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> deleteUserList = new ArrayList<>();
|
||||
if (!existingUserList.isEmpty()) {
|
||||
String domain = mapping.getSecondaryRole().substring(0, mapping.getSecondaryRole().indexOf("/"));
|
||||
for (String user : existingUserList) {
|
||||
if (user.startsWith(domain.toUpperCase())) {
|
||||
deleteUserList.add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update user list of given role
|
||||
if (!newUserList.isEmpty() || !deleteUserList.isEmpty()) {
|
||||
userStoreManager.updateUserListOfRole(role, deleteUserList.toArray(new String[0]), newUserList.toArray(new String[0]));
|
||||
log.info("update user role mapping executed.....");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (UserStoreException e) {
|
||||
log.error("Error while getting user store..." + e.getMessage());
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.userstore.role.mapper;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.bean.UserStoreRoleMappingConfig;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.exception.UserStoreRoleMapperException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
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;
|
||||
|
||||
public class UserStoreRoleMappingConfigManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(UserStoreRoleMappingConfigManager.class);
|
||||
private static final String USERSTORE_ROLE_MAPPING_CONFIG_PATH = CarbonUtils.getCarbonConfigDirPath() +
|
||||
File.separator + "user-store-role-mapping-config.xml";
|
||||
|
||||
private final UserStoreRoleMappingConfig userStoreRoleMappingConfig;
|
||||
|
||||
public UserStoreRoleMappingConfigManager() throws UserStoreRoleMapperException {
|
||||
try {
|
||||
File UserStoreRoleMappingConfig = new File(USERSTORE_ROLE_MAPPING_CONFIG_PATH);
|
||||
Document doc = convertToDocument(UserStoreRoleMappingConfig);
|
||||
JAXBContext smsContext = JAXBContext.newInstance(UserStoreRoleMappingConfig.class);
|
||||
Unmarshaller unmarshaller = smsContext.createUnmarshaller();
|
||||
this.userStoreRoleMappingConfig = (UserStoreRoleMappingConfig) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
String msg = "Error occurred while initializing config '" + USERSTORE_ROLE_MAPPING_CONFIG_PATH + "'";
|
||||
log.error(msg, e);
|
||||
throw new UserStoreRoleMapperException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Document convertToDocument(File file) throws UserStoreRoleMapperException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
factory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new UserStoreRoleMapperException("Error occurred while parsing " + USERSTORE_ROLE_MAPPING_CONFIG_PATH +
|
||||
" file, while converting to a org.w3c.dom.Document", e);
|
||||
}
|
||||
}
|
||||
|
||||
public UserStoreRoleMappingConfig getUserStoreRoleMappingConfig() {
|
||||
return this.userStoreRoleMappingConfig;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.userstore.role.mapper.bean;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(
|
||||
name = "mapping"
|
||||
)
|
||||
public class RoleMapping {
|
||||
private String secondaryRole;
|
||||
|
||||
private List<String> internalRoles;
|
||||
|
||||
@XmlAttribute(
|
||||
name = "secondaryRole"
|
||||
)
|
||||
public String getSecondaryRole() {
|
||||
return secondaryRole;
|
||||
}
|
||||
|
||||
public void setSecondaryRole(String secondaryRole) {
|
||||
this.secondaryRole = secondaryRole;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(
|
||||
name = "internalRoles"
|
||||
)
|
||||
@XmlElement(
|
||||
name = "role"
|
||||
)
|
||||
public List<String> getInternalRoles() {
|
||||
return internalRoles;
|
||||
}
|
||||
|
||||
public void setInternalRoles(List<String> internalRoles) {
|
||||
this.internalRoles = internalRoles;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.userstore.role.mapper.bean;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(
|
||||
name = "UserStoreRoleMappingConfig"
|
||||
)
|
||||
public class UserStoreRoleMappingConfig {
|
||||
|
||||
private boolean enabled;
|
||||
private List<RoleMapping> mappings;
|
||||
|
||||
private long initialDelayInSeconds;
|
||||
|
||||
private long periodInSeconds;
|
||||
|
||||
@XmlElement(
|
||||
name = "enabled"
|
||||
)
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(
|
||||
name = "mappings"
|
||||
)
|
||||
@XmlElement(
|
||||
name = "mapping"
|
||||
)
|
||||
public List<RoleMapping> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
public void setMappings(List<RoleMapping> mappings) {
|
||||
this.mappings = mappings;
|
||||
}
|
||||
|
||||
@XmlElement(
|
||||
name = "initialDelayInSeconds"
|
||||
)
|
||||
public long getInitialDelayInSeconds() {
|
||||
return initialDelayInSeconds;
|
||||
}
|
||||
|
||||
public void setInitialDelayInSeconds(long initialDelayInSeconds) {
|
||||
this.initialDelayInSeconds = initialDelayInSeconds;
|
||||
}
|
||||
|
||||
@XmlElement(
|
||||
name = "periodInSeconds"
|
||||
)
|
||||
public long getPeriodInSeconds() {
|
||||
return periodInSeconds;
|
||||
}
|
||||
|
||||
public void setPeriodInSeconds(long periodInSeconds) {
|
||||
this.periodInSeconds = periodInSeconds;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.userstore.role.mapper.exception;
|
||||
|
||||
public class UserStoreRoleMapperException extends Exception {
|
||||
|
||||
public UserStoreRoleMapperException(String msg, Exception e) {
|
||||
super(msg, e);
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.userstore.role.mapper.internal;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.UserStoreRoleMappingConfigManager;
|
||||
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.user.api.UserRealm;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.api.UserStoreManager;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
public class UserStoreRoleMappingDataHolder {
|
||||
|
||||
private ConfigurationContextService configurationContextService;
|
||||
private RealmService realmService;
|
||||
private UserStoreRoleMappingConfigManager userStoreRoleMappingConfigManager;
|
||||
private HeartBeatManagementService heartBeatService;
|
||||
private static final UserStoreRoleMappingDataHolder thisInstance = new UserStoreRoleMappingDataHolder();
|
||||
|
||||
private UserStoreRoleMappingDataHolder() {}
|
||||
|
||||
public static UserStoreRoleMappingDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public ConfigurationContextService getConfigurationContextService() {
|
||||
return configurationContextService;
|
||||
}
|
||||
|
||||
public void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
this.configurationContextService = configurationContextService;
|
||||
}
|
||||
|
||||
public UserStoreManager getUserStoreManager() throws UserStoreException {
|
||||
if (realmService == null) {
|
||||
String msg = "Realm service has not initialized.";
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
return realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||
}
|
||||
|
||||
public UserRealm getUserRealm() throws UserStoreException {
|
||||
UserRealm realm;
|
||||
if (realmService == null) {
|
||||
throw new IllegalStateException("Realm service not initialized");
|
||||
}
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
realm = realmService.getTenantUserRealm(tenantId);
|
||||
return realm;
|
||||
}
|
||||
|
||||
public RealmService getRealmService() {
|
||||
return realmService;
|
||||
}
|
||||
|
||||
public void setRealmService(RealmService realmService) {
|
||||
this.realmService = realmService;
|
||||
}
|
||||
|
||||
public UserStoreRoleMappingConfigManager getUserStoreRoleMappingConfigManager() {
|
||||
return userStoreRoleMappingConfigManager;
|
||||
}
|
||||
|
||||
public void setUserStoreRoleMappingConfigManager(UserStoreRoleMappingConfigManager userStoreRoleMappingConfigManager) {
|
||||
this.userStoreRoleMappingConfigManager = userStoreRoleMappingConfigManager;
|
||||
}
|
||||
|
||||
public HeartBeatManagementService getHeartBeatService() {
|
||||
return heartBeatService;
|
||||
}
|
||||
|
||||
public void setHeartBeatService(HeartBeatManagementService heartBeatService) {
|
||||
this.heartBeatService = heartBeatService;
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.userstore.role.mapper.internal;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.UserStoreRoleMapper;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.UserStoreRoleMappingConfigManager;
|
||||
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.core.ServerStartupObserver;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
/**
|
||||
* @scr.component name="io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.internal.UserStoreRoleMappingServiceComponent"
|
||||
* immediate="true"
|
||||
* @scr.reference name="user.realmservice.default"
|
||||
* interface="org.wso2.carbon.user.core.service.RealmService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setRealmService"
|
||||
* unbind="unsetRealmService"
|
||||
* @scr.reference name="config.context.service"
|
||||
* interface="org.wso2.carbon.utils.ConfigurationContextService"
|
||||
* cardinality="0..1"
|
||||
* policy="dynamic"
|
||||
* bind="setConfigurationContextService"
|
||||
* unbind="unsetConfigurationContextService"
|
||||
* @scr.reference name="entgra.heart.beat.service"
|
||||
* interface="io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService"
|
||||
* cardinality="0..1"
|
||||
* policy="dynamic"
|
||||
* bind="setHeartBeatService"
|
||||
* unbind="unsetHeartBeatService"
|
||||
*/
|
||||
public class UserStoreRoleMappingServiceComponent {
|
||||
|
||||
private static final Log log = LogFactory.getLog(UserStoreRoleMappingServiceComponent.class);
|
||||
|
||||
protected void activate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Activating Role Management Service Component");
|
||||
}
|
||||
try {
|
||||
BundleContext bundleContext = ctx.getBundleContext();
|
||||
UserStoreRoleMapper mapper = new UserStoreRoleMapper();
|
||||
bundleContext.registerService(ServerStartupObserver.class.getName(), mapper, null);
|
||||
UserStoreRoleMappingDataHolder.getInstance().setUserStoreRoleMappingConfigManager(new UserStoreRoleMappingConfigManager());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Role Management Service Component has been successfully activated");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while activating Role Management Service Component", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("De-activating Role Manager Service Component");
|
||||
}
|
||||
}
|
||||
|
||||
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting ConfigurationContextService");
|
||||
}
|
||||
|
||||
UserStoreRoleMappingDataHolder.getInstance().setConfigurationContextService(configurationContextService);
|
||||
}
|
||||
|
||||
protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Un-setting ConfigurationContextService");
|
||||
}
|
||||
UserStoreRoleMappingDataHolder.getInstance().setConfigurationContextService(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Realm Service.
|
||||
*
|
||||
* @param realmService An instance of RealmService
|
||||
*/
|
||||
protected void setRealmService(RealmService realmService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting Realm Service");
|
||||
}
|
||||
UserStoreRoleMappingDataHolder.getInstance().setRealmService(realmService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets Realm Service.
|
||||
*
|
||||
* @param realmService An instance of RealmService
|
||||
*/
|
||||
protected void unsetRealmService(RealmService realmService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unsetting Realm Service");
|
||||
}
|
||||
UserStoreRoleMappingDataHolder.getInstance().setRealmService(null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void setHeartBeatService(HeartBeatManagementService heartBeatService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting heart beat service");
|
||||
}
|
||||
UserStoreRoleMappingDataHolder.getInstance().setHeartBeatService(heartBeatService);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void unsetHeartBeatService(HeartBeatManagementService heartBeatManagementService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Removing heart beat service");
|
||||
}
|
||||
UserStoreRoleMappingDataHolder.getInstance().setHeartBeatService(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.device.mgt.api.jaxrs.service.impl.util;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApiModel(value = "DisenrollRequest", description = "Contains the multiple devices specified by device IDs")
|
||||
public class DisenrollRequest {
|
||||
@ApiModelProperty(name = "deviceTypeWithDeviceIds", value = "Contains the multiple devices specified by device IDs with type",
|
||||
required = true)
|
||||
private Map<String, List<String>> deviceTypeWithDeviceIds;
|
||||
|
||||
public Map<String, List<String>> getDeviceTypeWithDeviceIds() {
|
||||
return deviceTypeWithDeviceIds;
|
||||
}
|
||||
|
||||
public void setDeviceTypeWithDeviceIds(Map<String, List<String>> deviceTypeWithDeviceIds) {
|
||||
this.deviceTypeWithDeviceIds = deviceTypeWithDeviceIds;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.device.mgt.common.type.mgt;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "DeviceTypeMetaDetails", propOrder = {
|
||||
"storeVisibilityEnabled"
|
||||
})
|
||||
public class DeviceTypeMetaDetails {
|
||||
|
||||
@XmlElement(name = "storeVisibilityEnabled")
|
||||
private boolean storeVisibilityEnabled;
|
||||
|
||||
public boolean isStoreVisibilityEnabled() {
|
||||
return storeVisibilityEnabled;
|
||||
}
|
||||
|
||||
public void setStoreVisibilityEnabled(boolean storeVisibilityEnabled) {
|
||||
this.storeVisibilityEnabled = storeVisibilityEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue