Implementing a component to invoke APIM publisher REST API (Scope mapping) #104
Merged
charithag
merged 17 commits from pasindu/device-mgt-core:scopeMapAPILayer
into master
2 years ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'pasindu/device-mgt-core:scopeMapAPILayer'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Purpose
The purpose of this PR is to fix http://roadmap.entgra.net/issues/10031
Goals
Implement a component to invoke APIM publisher REST API
Approach
Implementing a component to invoke APIM publisher REST API (Scope maping)to WIP: Implementing a component to invoke APIM publisher REST API (Scope maping) 2 years agoWIP: Implementing a component to invoke APIM publisher REST API (Scope maping)to WIP: Implementing a component to invoke APIM publisher REST API (Scope mapping) 2 years ago9a2fea8b48
toee6d667345
2 years ago<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.devicemgt.apimgt.extension.rest.api</artifactId>
<packaging>bundle</packaging>
<name>Entgra - Device API Management Extension Publisher API</name>
Device Mgt extension for APIM REST API
<!-- </plugin>-->
</plugins>
</build>
<properties>
do not add this property
jsonObject.put("saasApp", true);
RequestBody requestBody = RequestBody.Companion.create(jsonObject.toString(), JSON);
String applicationEndpoint = "https://localhost:9443/client-registration/v0.17/register";
get url from api-manager xml
throws APIApplicationServicesException {
RequestBody requestBody = RequestBody.Companion.create(nameValuePairs.toString(), JSON);
String tokenEndPoint = "https://localhost:9443/oauth2/token";
need to fix url generation
public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIApplicationServicesException, BadRequestException {
String getScopesUrl = "https://localhost:9443/api/am/publisher/v2/scopes?limit=1000";
need to fix
try {
Response response = client.newCall(request).execute();
if (response.code() == HttpStatus.SC_OK) {
should swap the condition, other can throw null pointer exception
//TODO: max attempt count
return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
log.info(response);
give proper log message
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
throw new APIApplicationServicesException(msg);
pass e, when throwing otherwise real exception will not be able to find
package io.entgra.devicemgt.apimgt.extension.rest.api.constants;
no licence header
*/
package org.wso2.carbon.apimgt.webapp.publisher;
this fix not required for this PR , pls remove
throw new APIManagerPublisherException(e);
}
catch (APIApplicationServicesException e) {
log.error(e);
handle exceptions with proper messages
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
change the artificat id and device id according to this
https://docs.google.com/document/d/179pfBB2uglDSjCHMuKMPgCJ9AQlrCe0IFuRO3wOMqd0/edit#heading=h.2p4l6vczsdts
b020a82135
to3ef3310ca5
2 years ago3ef3310ca5
to2ccf1dd022
2 years ago6dc02dbc06
to3be9dd6bdc
2 years ago3be9dd6bdc
to6008976e20
2 years ago8a61dc802b
to7a79030421
2 years agoWIP: Implementing a component to invoke APIM publisher REST API (Scope mapping)to Implementing a component to invoke APIM publisher REST API (Scope mapping) 2 years agof856d0f1d6
tob7b3b1f203
2 years agoSSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
return sc.getSocketFactory();
} catch (KeyManagementException | NoSuchAlgorithmException e) {
We can use an error msg to handle exceptions here
public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIServicesException, BadRequestException {
String getAllScopesUrl = "https://" + host + ":" + port + Constants.GET_ALL_SCOPES;
Here we can store
https://
and:
in constants as well.throws APIServicesException, BadRequestException {
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", "");
String getScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + keyValue;
Here we can store
https://
and:
in constants as well.public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException {
String updateScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + scope.getId();
Here we can store
https://
and:
in constants as well.JSONArray scopeList = (JSONArray) scopeObject.get("list");
for (int i = 0; i < scopeList.length(); i++) {
JSONObject scopeObj = null;
scopeObj = scopeList.getJSONObject(i);
We can use an inline variable here
JSONObject scopeObj = scopeList.getJSONObject(i);
f2c429778d
to2ca425819e
2 years ago751c2cae72
to1ee66a860f
2 years ago}
protected static OkHttpClient getOkHttpClient() {
X509TrustManager trustAllCerts = new X509TrustManager() {
Why trusting all certs? This a security risk
private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() {
try {
TrustManager[] trustAllCerts = new TrustManager[]{
Why trusting all certs? This a security risk
log.error(msg);
throw new BadRequestException(msg);
} else {
return null;
If we get some other http status like bad gateway or internal server error, this can lead to incorrect state. Better to throw an exception (Ex: UnexpectedResponseException) and handle it in the other end.
log.error(msg);
throw new BadRequestException(msg);
} else {
return false;
If we got some other http status like bad gateway or internal server error, this will lead to incorrect state. Better to throw an exception (Ex: UnexpectedResponseException) and handle it in the other end.
log.error(msg);
throw new BadRequestException(msg);
} else {
return false;
If we get some other http status like bad gateway or internal server error, this will lead to incorrect state. Better to throw an exception (Ex: UnexpectedResponseException) and handle it in the other end.
1ee66a860f
to53798af576
2 years ago53798af576
to455917f21e
2 years ago99df875fb3
into master 2 years agoReviewers
99df875fb3
.