Merge branch 'master' of ssh://repository.entgra.net:222/community/device-mgt-core into device-apps-api-1
commit
4635e2bd14
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.APIInfo;
|
||||
|
||||
import org.wso2.carbon.apimgt.api.model.APIRevisionDeployment;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class APIRevision implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int id;
|
||||
private String apiUUID;
|
||||
private String revisionUUID;
|
||||
private String description;
|
||||
private String createdBy;
|
||||
private String createdTime;
|
||||
private List<APIRevisionDeployment> apiRevisionDeploymentList;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApiUUID() {
|
||||
return apiUUID;
|
||||
}
|
||||
|
||||
public void setApiUUID(String apiUUID) {
|
||||
this.apiUUID = apiUUID;
|
||||
}
|
||||
|
||||
public String getRevisionUUID() {
|
||||
return revisionUUID;
|
||||
}
|
||||
|
||||
public void setRevisionUUID(String revisionUUID) {
|
||||
this.revisionUUID = revisionUUID;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public String getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
public void setCreatedTime(String createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
}
|
||||
|
||||
public List<APIRevisionDeployment> getApiRevisionDeploymentList() {
|
||||
return apiRevisionDeploymentList;
|
||||
}
|
||||
|
||||
public void setApiRevisionDeploymentList(List<APIRevisionDeployment> apiRevisionDeploymentList) {
|
||||
this.apiRevisionDeploymentList = apiRevisionDeploymentList;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.APIInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class APIRevisionDeployment implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int id;
|
||||
private String revisionUUID;
|
||||
private String deployment;
|
||||
private String vhost;
|
||||
private boolean isDisplayOnDevportal;
|
||||
private String deployedTime;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRevisionUUID() {
|
||||
return revisionUUID;
|
||||
}
|
||||
|
||||
public void setRevisionUUID(String revisionUUID) {
|
||||
this.revisionUUID = revisionUUID;
|
||||
}
|
||||
|
||||
public String getDeployment() {
|
||||
return deployment;
|
||||
}
|
||||
|
||||
public void setDeployment(String deployment) {
|
||||
this.deployment = deployment;
|
||||
}
|
||||
|
||||
public String getVhost() {
|
||||
return vhost;
|
||||
}
|
||||
|
||||
public void setVhost(String vhost) {
|
||||
this.vhost = vhost;
|
||||
}
|
||||
|
||||
public boolean isDisplayOnDevportal() {
|
||||
return isDisplayOnDevportal;
|
||||
}
|
||||
|
||||
public void setDisplayOnDevportal(boolean displayOnDevportal) {
|
||||
isDisplayOnDevportal = displayOnDevportal;
|
||||
}
|
||||
|
||||
public String getDeployedTime() {
|
||||
return deployedTime;
|
||||
}
|
||||
|
||||
public void setDeployedTime(String deployedTime) {
|
||||
this.deployedTime = deployedTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.APIInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API CORS Configuration
|
||||
*/
|
||||
public class CORSConfiguration {
|
||||
|
||||
private boolean corsConfigurationEnabled;
|
||||
private List<String> accessControlAllowOrigins;
|
||||
private boolean accessControlAllowCredentials;
|
||||
private List<String> accessControlAllowHeaders;
|
||||
private List<String> accessControlAllowMethods;
|
||||
|
||||
public CORSConfiguration(boolean corsConfigurationEnabled, List<String> accessControlAllowOrigins,
|
||||
boolean accessControlAllowCredentials,
|
||||
List<String> accessControlAllowHeaders, List<String> accessControlAllowMethods) {
|
||||
this.corsConfigurationEnabled = corsConfigurationEnabled;
|
||||
this.accessControlAllowOrigins = accessControlAllowOrigins;
|
||||
this.accessControlAllowCredentials = accessControlAllowCredentials;
|
||||
this.accessControlAllowHeaders = accessControlAllowHeaders;
|
||||
this.accessControlAllowMethods = accessControlAllowMethods;
|
||||
}
|
||||
|
||||
public boolean isCorsConfigurationEnabled() {
|
||||
return corsConfigurationEnabled;
|
||||
}
|
||||
|
||||
public void setCorsConfigurationEnabled(boolean corsConfigurationEnabled) {
|
||||
this.corsConfigurationEnabled = corsConfigurationEnabled;
|
||||
}
|
||||
|
||||
public List<String> getAccessControlAllowOrigins() {
|
||||
return accessControlAllowOrigins;
|
||||
}
|
||||
|
||||
public void setAccessControlAllowOrigins(List<String> accessControlAllowOrigins) {
|
||||
this.accessControlAllowOrigins = accessControlAllowOrigins;
|
||||
}
|
||||
|
||||
public boolean isAccessControlAllowCredentials() {
|
||||
return accessControlAllowCredentials;
|
||||
}
|
||||
|
||||
public void setAccessControlAllowCredentials(boolean accessControlAllowCredentials) {
|
||||
this.accessControlAllowCredentials = accessControlAllowCredentials;
|
||||
}
|
||||
|
||||
public List<String> getAccessControlAllowHeaders() {
|
||||
return accessControlAllowHeaders;
|
||||
}
|
||||
|
||||
public void setAccessControlAllowHeaders(List<String> accessControlAllowHeaders) {
|
||||
this.accessControlAllowHeaders = accessControlAllowHeaders;
|
||||
}
|
||||
|
||||
public List<String> getAccessControlAllowMethods() {
|
||||
return accessControlAllowMethods;
|
||||
}
|
||||
|
||||
public void setAccessControlAllowMethods(List<String> accessControlAllowMethods) {
|
||||
this.accessControlAllowMethods = accessControlAllowMethods;
|
||||
}
|
||||
}
|
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* 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.APIInfo;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Documentation {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String id;
|
||||
private String documentId;
|
||||
private DocumentationType type;
|
||||
private String name;
|
||||
private String summary;
|
||||
private DocumentSourceType sourceType;
|
||||
private String sourceUrl;
|
||||
private DocumentVisibility visibility;
|
||||
private Date lastUpdated;
|
||||
private String filePath;
|
||||
private Date createdDate;
|
||||
private String otherTypeName;
|
||||
|
||||
public String getOtherTypeName() {
|
||||
return this.otherTypeName;
|
||||
}
|
||||
|
||||
public void setOtherTypeName(String otherTypeName) {
|
||||
this.otherTypeName = otherTypeName;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return this.filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getSourceUrl() {
|
||||
return this.sourceUrl;
|
||||
}
|
||||
|
||||
public void setSourceUrl(String sourceUrl) {
|
||||
this.sourceUrl = sourceUrl;
|
||||
}
|
||||
|
||||
public Documentation(DocumentationType type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o != null && this.getClass() == o.getClass()) {
|
||||
Documentation that = (Documentation)o;
|
||||
return this.name.equals(that.name) && this.type == that.type;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public DocumentationType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return this.summary;
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
public DocumentVisibility getVisibility() {
|
||||
return this.visibility;
|
||||
}
|
||||
|
||||
public void setVisibility(DocumentVisibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
public DocumentSourceType getSourceType() {
|
||||
return this.sourceType;
|
||||
}
|
||||
|
||||
public void setSourceType(DocumentSourceType sourceType) {
|
||||
this.sourceType = sourceType;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = this.type.hashCode();
|
||||
result = 31 * result + this.name.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return this.lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(Date lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDocumentId() {
|
||||
return documentId;
|
||||
}
|
||||
|
||||
public void setDocumentId(String documentId) {
|
||||
this.documentId = documentId;
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return this.createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Date createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public static enum DocumentVisibility {
|
||||
OWNER_ONLY("owner_only"),
|
||||
PRIVATE("private"),
|
||||
API_LEVEL("api_level");
|
||||
|
||||
private String visibility;
|
||||
|
||||
private DocumentVisibility(String visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum DocumentSourceType {
|
||||
INLINE("In line"),
|
||||
MARKDOWN("Markdown"),
|
||||
URL("URL"),
|
||||
FILE("File");
|
||||
|
||||
private String type;
|
||||
|
||||
private DocumentSourceType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum DocumentationType {
|
||||
HOWTO("How To"),
|
||||
SAMPLES("Samples"),
|
||||
PUBLIC_FORUM("Public Forum"),
|
||||
SUPPORT_FORUM("Support Forum"),
|
||||
API_MESSAGE_FORMAT("API Message Format"),
|
||||
SWAGGER_DOC("Swagger API Definition"),
|
||||
OTHER("Other");
|
||||
|
||||
private String type;
|
||||
|
||||
private DocumentationType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.APIInfo;
|
||||
|
||||
public class Mediation {
|
||||
|
||||
private String uuid;
|
||||
private String name;
|
||||
private String type;
|
||||
private String config;
|
||||
private boolean isGlobal;
|
||||
|
||||
public Mediation(){}
|
||||
|
||||
public void setUuid(String id){
|
||||
this.uuid=id;
|
||||
}
|
||||
public String getUuid(){return uuid;}
|
||||
|
||||
public void setName(String name){this.name=name;}
|
||||
|
||||
public String getName(){return name;}
|
||||
|
||||
public void setType(String mType){this.type=mType;}
|
||||
|
||||
public String getType(){return type;}
|
||||
|
||||
public void setConfig(String mConfig){this.config=mConfig;}
|
||||
|
||||
public String getConfig(){return config;}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return isGlobal;
|
||||
}
|
||||
|
||||
public void setGlobal(boolean isGlobal) {
|
||||
this.isGlobal = isGlobal;
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.APIInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Scope implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
String key;
|
||||
String name;
|
||||
String roles;
|
||||
String description;
|
||||
String id;
|
||||
int usageCount;
|
||||
|
||||
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 String getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(String roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getUsageCount() {
|
||||
return usageCount;
|
||||
}
|
||||
|
||||
public void setUsageCount(int usageCount) {
|
||||
this.usageCount = usageCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Scope scope = (Scope) o;
|
||||
|
||||
if (id != null ? !id.equals(scope.id) : scope.id != null) return false;
|
||||
if (!key.equals(scope.key)) return false;
|
||||
if (!name.equals(scope.name)) return false;
|
||||
if (roles != null ? !roles.equals(scope.roles) : scope.roles != null) return false;
|
||||
return description != null ? description.equals(scope.description) : scope.description == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(key, name, roles, description, id);
|
||||
}
|
||||
}
|
@ -0,0 +1,440 @@
|
||||
/*
|
||||
* 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.APIInfo;
|
||||
|
||||
import org.json.simple.JSONValue;
|
||||
import org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO;
|
||||
import org.wso2.carbon.apimgt.api.model.APIProductIdentifier;
|
||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
||||
import org.wso2.carbon.apimgt.api.model.policy.PolicyConstants;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
public class URITemplate implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String uriTemplate;
|
||||
private String resourceURI;
|
||||
private String resourceSandboxURI;
|
||||
private String httpVerb;
|
||||
private String authType;
|
||||
private LinkedHashSet<String> httpVerbs = new LinkedHashSet<String>();
|
||||
private List<String> authTypes = new ArrayList<String>();
|
||||
private List<String> throttlingConditions = new ArrayList<String>();
|
||||
private String applicableLevel;
|
||||
private String throttlingTier;
|
||||
private List<String> throttlingTiers = new ArrayList<String>();
|
||||
private org.wso2.carbon.apimgt.api.model.Scope scope;
|
||||
private String mediationScript;
|
||||
private List<org.wso2.carbon.apimgt.api.model.Scope> scopes = new ArrayList<org.wso2.carbon.apimgt.api.model.Scope>();
|
||||
private Map<String, String> mediationScripts = new HashMap<String, String>();
|
||||
private ConditionGroupDTO[] conditionGroups;
|
||||
private int id;
|
||||
private Set<APIProductIdentifier> usedByProducts = new HashSet<>();
|
||||
private String amznResourceName;
|
||||
private int amznResourceTimeout;
|
||||
|
||||
public ConditionGroupDTO[] getConditionGroups() {
|
||||
return conditionGroups;
|
||||
}
|
||||
|
||||
public void setConditionGroups(ConditionGroupDTO[] conditionGroups) {
|
||||
this.conditionGroups = conditionGroups;
|
||||
}
|
||||
|
||||
public String getMediationScript() {
|
||||
return mediationScript;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getThrottlingConditions() {
|
||||
return throttlingConditions;
|
||||
}
|
||||
|
||||
public void setThrottlingConditions(List<String> throttlingConditions) {
|
||||
this.throttlingConditions = throttlingConditions;
|
||||
}
|
||||
|
||||
public void setMediationScript(String mediationScript) {
|
||||
this.mediationScript = mediationScript;
|
||||
}
|
||||
/**
|
||||
* Set mediation script for a given http method
|
||||
* @param method http method name
|
||||
* @param mediationScript mediation script content
|
||||
*/
|
||||
public void setMediationScripts(String method, String mediationScript){
|
||||
if (mediationScript != null && !mediationScript.trim().equals("") && !mediationScript.trim().equals("null")){
|
||||
mediationScripts.put(method, mediationScript);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating the script by aggregating scripts of each http method to form a single script in to be
|
||||
* used when generating synapse configuration file.
|
||||
*
|
||||
* @return aggregated script in the following format,
|
||||
* if (http-method = 'GET'){
|
||||
* //script for GET
|
||||
* }
|
||||
* ....
|
||||
* ....
|
||||
* if (http-method = 'POST'){
|
||||
* //script for POST
|
||||
* }
|
||||
*/
|
||||
public String getAggregatedMediationScript(){
|
||||
if (mediationScripts.isEmpty()){
|
||||
return "null";
|
||||
}else if (mediationScripts.size() == 1 && httpVerbs.size() == 1){
|
||||
return mediationScript;
|
||||
}else{
|
||||
StringBuilder aggregatedScript = new StringBuilder();
|
||||
|
||||
for (Map.Entry<String, String> entry : mediationScripts.entrySet()){
|
||||
String httpMethod = entry.getKey();
|
||||
String mediationScript = entry.getValue();
|
||||
|
||||
aggregatedScript.append("if (mc.getProperty('REST_METHOD') == '").append(httpMethod).append("'){");
|
||||
aggregatedScript.append(mediationScript);
|
||||
aggregatedScript.append("}");
|
||||
|
||||
}
|
||||
|
||||
return aggregatedScript.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public String getThrottlingTier() {
|
||||
return throttlingTier;
|
||||
}
|
||||
|
||||
public void setThrottlingTier(String throttlingTier) {
|
||||
this.throttlingTier = throttlingTier;
|
||||
}
|
||||
|
||||
public List<String> getThrottlingTiers(){
|
||||
return throttlingTiers;
|
||||
}
|
||||
|
||||
public void setThrottlingTiers(List<String> throttlingTiers) {
|
||||
this.throttlingTiers = throttlingTiers;
|
||||
}
|
||||
|
||||
public String getHTTPVerb() {
|
||||
return httpVerb;
|
||||
}
|
||||
|
||||
public void setHTTPVerb(String httpVerb) {
|
||||
this.httpVerb = httpVerb;
|
||||
}
|
||||
|
||||
public String getAuthType() {
|
||||
return authType;
|
||||
}
|
||||
|
||||
public void setAuthType(String authType) {
|
||||
this.authType = authType;
|
||||
|
||||
}
|
||||
|
||||
public String getResourceURI() {
|
||||
return resourceURI;
|
||||
}
|
||||
|
||||
public void setResourceURI(String resourceURI) {
|
||||
this.resourceURI = resourceURI;
|
||||
}
|
||||
|
||||
public boolean isResourceURIExist(){
|
||||
return this.resourceURI != null;
|
||||
}
|
||||
|
||||
public String getResourceSandboxURI() {
|
||||
return resourceSandboxURI;
|
||||
}
|
||||
|
||||
public void setResourceSandboxURI(String resourceSandboxURI) {
|
||||
this.resourceSandboxURI = resourceSandboxURI;
|
||||
}
|
||||
|
||||
public boolean isResourceSandboxURIExist(){
|
||||
return this.resourceSandboxURI != null;
|
||||
}
|
||||
|
||||
public String getUriTemplate() {
|
||||
return uriTemplate;
|
||||
}
|
||||
|
||||
public void setUriTemplate(String template) {
|
||||
this.uriTemplate = template;
|
||||
}
|
||||
|
||||
public void setHttpVerbs(String httpVerb) {
|
||||
|
||||
httpVerbs.add(httpVerb);
|
||||
}
|
||||
|
||||
public LinkedHashSet<String> getHttpVerbs() {
|
||||
|
||||
return httpVerbs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setAuthTypes(String authType) {
|
||||
|
||||
authTypes.add(authType);
|
||||
}
|
||||
|
||||
public String getAuthTypes() {
|
||||
|
||||
return authType;
|
||||
}
|
||||
|
||||
|
||||
public String getMethodsAsString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String method : httpVerbs) {
|
||||
stringBuilder.append(method).append(" ");
|
||||
}
|
||||
return stringBuilder.toString().trim();
|
||||
}
|
||||
|
||||
public String getAuthTypeAsString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String authType : authTypes) {
|
||||
stringBuilder.append(authType).append(" ");
|
||||
}
|
||||
return stringBuilder.toString().trim();
|
||||
}
|
||||
|
||||
public String getThrottlingConditionsAsString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String authType : throttlingConditions) {
|
||||
stringBuilder.append(authType).append(" ");
|
||||
}
|
||||
return stringBuilder.toString().trim();
|
||||
}
|
||||
|
||||
public void setThrottlingTiers(String tier) {
|
||||
throttlingTiers.add(tier);
|
||||
}
|
||||
|
||||
public String getThrottlingTiersAsString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String tier : throttlingTiers) {
|
||||
if (tier.contains(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR)) {
|
||||
stringBuilder.append(tier.substring(0,
|
||||
tier.indexOf(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR)).trim()).append(" ");
|
||||
} else {
|
||||
stringBuilder.append(tier.trim()).append(" ");
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString().trim();
|
||||
}
|
||||
|
||||
public boolean checkContentAwareFromThrottlingTiers() {
|
||||
// use the content aware property appended to throttling tiers
|
||||
if (!throttlingTiers.isEmpty()) {
|
||||
String throttlingTierWithContentAware = throttlingTiers.get(0);
|
||||
if (throttlingTierWithContentAware != null &&
|
||||
throttlingTierWithContentAware.contains(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR)) {
|
||||
String[] splitThrottlingTiers =
|
||||
throttlingTierWithContentAware.split(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR);
|
||||
return Boolean.valueOf(splitThrottlingTiers[splitThrottlingTiers.length - 1]);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public org.wso2.carbon.apimgt.api.model.Scope getScope() {
|
||||
return scope;
|
||||
}
|
||||
public List<org.wso2.carbon.apimgt.api.model.Scope> getScopes() {
|
||||
return scopes;
|
||||
}
|
||||
|
||||
public void setScope(org.wso2.carbon.apimgt.api.model.Scope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public void setScopes(org.wso2.carbon.apimgt.api.model.Scope scope){
|
||||
this.scopes.add(scope);
|
||||
}
|
||||
|
||||
public String getResourceMap(){
|
||||
Map verbs = new LinkedHashMap();
|
||||
int i = 0;
|
||||
for (String method : httpVerbs) {
|
||||
Map verb = new LinkedHashMap();
|
||||
verb.put("auth_type",authTypes.get(i));
|
||||
verb.put("throttling_tier",throttlingTiers.get(i));
|
||||
//Following parameter is not required as it not need to reflect UI level. If need please enable it.
|
||||
// /verb.put("throttling_conditions", throttlingConditions.get(i));
|
||||
try{
|
||||
org.wso2.carbon.apimgt.api.model.Scope tmpScope = scopes.get(i);
|
||||
if(tmpScope != null){
|
||||
verb.put("scope",tmpScope.getKey());
|
||||
}
|
||||
}catch(IndexOutOfBoundsException e){
|
||||
//todo need to rewrite to prevent this type of exceptions
|
||||
}
|
||||
verbs.put(method,verb);
|
||||
i++;
|
||||
}
|
||||
//todo this is a hack to make key validation service stub from braking need to rewrite.
|
||||
return JSONValue.toJSONString(verbs);
|
||||
}
|
||||
|
||||
public String getApplicableLevel() {
|
||||
return applicableLevel;
|
||||
}
|
||||
|
||||
public void setApplicableLevel(String applicableLevel) {
|
||||
this.applicableLevel = applicableLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
URITemplate that = (URITemplate) o;
|
||||
|
||||
if (!uriTemplate.equals(that.uriTemplate)) {
|
||||
return false;
|
||||
}
|
||||
if (resourceURI != null ? !resourceURI.equals(that.resourceURI) : that.resourceURI != null) {
|
||||
return false;
|
||||
}
|
||||
if (resourceSandboxURI != null ? !resourceSandboxURI.equals(that.resourceSandboxURI) : that
|
||||
.resourceSandboxURI != null) {
|
||||
return false;
|
||||
}
|
||||
if (!httpVerb.equals(that.httpVerb)) {
|
||||
return false;
|
||||
}
|
||||
if (!authType.equals(that.authType)) {
|
||||
return false;
|
||||
}
|
||||
if (!httpVerbs.equals(that.httpVerbs)) {
|
||||
return false;
|
||||
}
|
||||
if (!authTypes.equals(that.authTypes)) {
|
||||
return false;
|
||||
}
|
||||
if (throttlingConditions != null ? !throttlingConditions.equals(that.throttlingConditions) : that
|
||||
.throttlingConditions != null) {
|
||||
return false;
|
||||
}
|
||||
if (applicableLevel != null ? !applicableLevel.equals(that.applicableLevel) : that.applicableLevel != null) {
|
||||
return false;
|
||||
}
|
||||
if (!throttlingTier.equals(that.throttlingTier)) {
|
||||
return false;
|
||||
}
|
||||
if (!throttlingTiers.equals(that.throttlingTiers)) {
|
||||
return false;
|
||||
}
|
||||
if (scope != null ? !scope.equals(that.scope) : that.scope != null) {
|
||||
return false;
|
||||
}
|
||||
if (mediationScript != null ? !mediationScript.equals(that.mediationScript) : that.mediationScript != null) {
|
||||
return false;
|
||||
}
|
||||
if (scopes != null ? !scopes.equals(that.scopes) : that.scopes != null) {
|
||||
return false;
|
||||
}
|
||||
if (mediationScripts != null ? !mediationScripts.equals(that.mediationScripts) : that.mediationScripts !=
|
||||
null) {
|
||||
return false;
|
||||
}
|
||||
// Probably incorrect - comparing Object[] arrays with Arrays.equals
|
||||
return Arrays.equals(conditionGroups, that.conditionGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = uriTemplate.hashCode();
|
||||
result = 31 * result + (resourceURI != null ? resourceURI.hashCode() : 0);
|
||||
result = 31 * result + (resourceSandboxURI != null ? resourceSandboxURI.hashCode() : 0);
|
||||
result = 31 * result + (httpVerb != null ? httpVerb.hashCode() : 0);
|
||||
result = 31 * result + (authType != null ? authType.hashCode() : 0);
|
||||
result = 31 * result + (httpVerbs != null ? httpVerbs.hashCode() : 0);
|
||||
result = 31 * result + (authTypes != null ? authTypes.hashCode() : 0);
|
||||
result = 31 * result + (throttlingConditions != null ? throttlingConditions.hashCode() : 0);
|
||||
result = 31 * result + (applicableLevel != null ? applicableLevel.hashCode() : 0);
|
||||
result = 31 * result + (throttlingTier != null ? throttlingTier.hashCode() : 0);
|
||||
result = 31 * result + (throttlingTiers != null ? throttlingTiers.hashCode() : 0);
|
||||
result = 31 * result + (scope != null ? scope.hashCode() : 0);
|
||||
result = 31 * result + (mediationScript != null ? mediationScript.hashCode() : 0);
|
||||
result = 31 * result + (scopes != null ? scopes.hashCode() : 0);
|
||||
result = 31 * result + (mediationScripts != null ? mediationScripts.hashCode() : 0);
|
||||
result = 31 * result + Arrays.hashCode(conditionGroups);
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<org.wso2.carbon.apimgt.api.model.Scope> retrieveAllScopes() {
|
||||
return this.scopes;
|
||||
}
|
||||
|
||||
public void addAllScopes(List<Scope> scopes) {
|
||||
|
||||
this.scopes = scopes;
|
||||
}
|
||||
|
||||
public Set<APIProductIdentifier> retrieveUsedByProducts() {
|
||||
return usedByProducts;
|
||||
}
|
||||
|
||||
public void addUsedByProduct(APIProductIdentifier usedByProduct) {
|
||||
usedByProducts.add(usedByProduct);
|
||||
}
|
||||
|
||||
public void setAmznResourceName(String amznResourceName) {
|
||||
this.amznResourceName = amznResourceName;
|
||||
}
|
||||
|
||||
public String getAmznResourceName() {
|
||||
return amznResourceName;
|
||||
}
|
||||
|
||||
public void setAmznResourceTimeout(int amznResourceTimeout) {
|
||||
this.amznResourceTimeout = amznResourceTimeout;
|
||||
}
|
||||
|
||||
public int getAmznResourceTimeout() {
|
||||
return amznResourceTimeout;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.server.bootup.heartbeat.beacon.service;
|
||||
|
||||
public interface ClusterFormationChangedNotifier {
|
||||
|
||||
String getType();
|
||||
|
||||
void notifyClusterFormationChanged(int hashIndex, int activeServerCount);
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.server.bootup.heartbeat.beacon.service;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ClusterFormationChangedNotifierRepository {
|
||||
|
||||
private Map<String, ClusterFormationChangedNotifier> notifiers;
|
||||
private static final Log log = LogFactory.getLog(ClusterFormationChangedNotifierRepository.class);
|
||||
|
||||
public ClusterFormationChangedNotifierRepository() {
|
||||
this.notifiers = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public void addNotifier(ClusterFormationChangedNotifier notifier) {
|
||||
notifiers.put(notifier.getType(), notifier);
|
||||
}
|
||||
|
||||
public void addNotifier(String className) {
|
||||
try {
|
||||
if (!StringUtils.isEmpty(className)) {
|
||||
Class<?> clz = Class.forName(className);
|
||||
ClusterFormationChangedNotifier notifier = (ClusterFormationChangedNotifier) clz.newInstance();
|
||||
notifiers.put(notifier.getType(), notifier);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error("Provided ClusterFormationChangedNotifier implementation '" + className + "' cannot be found", e);
|
||||
} catch (InstantiationException e) {
|
||||
log.error("Error occurred while instantiating ClusterFormationChangedNotifier implementation '" +
|
||||
className + "'", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("Error occurred while adding ClusterFormationChangedNotifier implementation '" + className + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
public ClusterFormationChangedNotifier getNotifier(String type) {
|
||||
return notifiers.get(type);
|
||||
}
|
||||
|
||||
public Map<String, ClusterFormationChangedNotifier> getNotifiers() {
|
||||
return notifiers;
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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.ui.request.interceptor;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.entgra.device.mgt.core.ui.request.interceptor.beans.AuthData;
|
||||
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerConstants;
|
||||
import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import io.entgra.device.mgt.core.ui.request.interceptor.beans.ProxyResponse;
|
||||
|
||||
import javax.servlet.annotation.MultipartConfig;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
@MultipartConfig
|
||||
@WebServlet("/default-oauth2-credentials")
|
||||
public class DefaultOauth2TokenHandler extends HttpServlet {
|
||||
private static final Log log = LogFactory.getLog(DefaultTokenHandler.class);
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
HttpSession httpSession = req.getSession(false);
|
||||
|
||||
if (httpSession != null) {
|
||||
AuthData authData = (AuthData) httpSession.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY);
|
||||
if (authData == null) {
|
||||
HandlerUtil.sendUnAuthorizeResponse(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
AuthData defaultAuthData = (AuthData) httpSession
|
||||
.getAttribute(HandlerConstants.SESSION_DEFAULT_AUTH_DATA_KEY);
|
||||
if (defaultAuthData != null) {
|
||||
HandlerUtil.handleSuccess(resp, constructSuccessProxyResponse(defaultAuthData.getAccessToken()));
|
||||
return;
|
||||
}
|
||||
|
||||
String clientId = authData.getClientId();
|
||||
String clientSecret = authData.getClientSecret();
|
||||
|
||||
String queryString = req.getQueryString();
|
||||
String scopeString = "";
|
||||
if (StringUtils.isNotEmpty(queryString)) {
|
||||
scopeString = req.getParameter("scopes");
|
||||
if (scopeString != null) {
|
||||
scopeString = "?scopes=" + scopeString;
|
||||
}
|
||||
}
|
||||
|
||||
String iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR
|
||||
+ System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
|
||||
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
|
||||
String tokenUrl = iotsCoreUrl + "/api/device-mgt/v1.0/devices/" + clientId
|
||||
+ "/" + clientSecret + "/default-token" + scopeString;
|
||||
|
||||
HttpGet defaultTokenRequest = new HttpGet(tokenUrl);
|
||||
defaultTokenRequest
|
||||
.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken());
|
||||
defaultTokenRequest
|
||||
.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString());
|
||||
ProxyResponse tokenResultResponse = HandlerUtil.execute(defaultTokenRequest);
|
||||
|
||||
if (tokenResultResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
||||
log.error("Error occurred while invoking the API to get default token data.");
|
||||
HandlerUtil.handleError(resp, tokenResultResponse);
|
||||
return;
|
||||
}
|
||||
String tokenResult = tokenResultResponse.getData();
|
||||
if (tokenResult == null) {
|
||||
log.error("Invalid default token response is received.");
|
||||
HandlerUtil.handleError(resp, tokenResultResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
JsonParser jsonParser = new JsonParser();
|
||||
JsonElement jTokenResult = jsonParser.parse(tokenResult);
|
||||
if (jTokenResult.isJsonObject()) {
|
||||
JsonObject jTokenResultAsJsonObject = jTokenResult.getAsJsonObject();
|
||||
AuthData newDefaultAuthData = new AuthData();
|
||||
newDefaultAuthData.setClientId(clientId);
|
||||
newDefaultAuthData.setClientSecret(clientSecret);
|
||||
|
||||
String defaultToken = jTokenResultAsJsonObject.get("accessToken").getAsString();
|
||||
newDefaultAuthData.setAccessToken(defaultToken);
|
||||
newDefaultAuthData.setRefreshToken(jTokenResultAsJsonObject.get("refreshToken").getAsString());
|
||||
newDefaultAuthData.setScope(jTokenResultAsJsonObject.get("scopes").getAsString());
|
||||
httpSession.setAttribute(HandlerConstants.SESSION_DEFAULT_AUTH_DATA_KEY, newDefaultAuthData);
|
||||
|
||||
HandlerUtil.handleSuccess(resp, constructSuccessProxyResponse(defaultToken));
|
||||
}
|
||||
} else {
|
||||
HandlerUtil.sendUnAuthorizeResponse(resp);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error occurred when processing GET request to get default token.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Success Proxy Response
|
||||
* @param defaultAccessToken Access token which has default scope
|
||||
* @return {@link ProxyResponse}
|
||||
*/
|
||||
private ProxyResponse constructSuccessProxyResponse (String defaultAccessToken) {
|
||||
|
||||
URIBuilder ub = new URIBuilder();
|
||||
ub.setScheme(HandlerConstants.WSS_PROTOCOL);
|
||||
ub.setHost(System.getProperty(HandlerConstants.IOT_REMOTE_SESSION_HOST_ENV_VAR));
|
||||
ub.setPort(Integer.parseInt(System.getProperty(HandlerConstants.IOT_REMOTE_SESSION_HTTPS_PORT_ENV_VAR)));
|
||||
ub.setPath(HandlerConstants.REMOTE_SESSION_CONTEXT);
|
||||
|
||||
URIBuilder ub2 = new URIBuilder();
|
||||
ub2.setScheme(HandlerConstants.WSS_PROTOCOL);
|
||||
ub2.setHost(System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR));
|
||||
ub2.setPort(Integer.parseInt(System.getProperty(HandlerConstants.IOT_GATEWAY_WEBSOCKET_WSS_PORT_ENV_VAR)));
|
||||
|
||||
URIBuilder ub3 = new URIBuilder();
|
||||
ub3.setScheme(HandlerConstants.WS_PROTOCOL);
|
||||
ub3.setHost(System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR));
|
||||
ub3.setPort(Integer.parseInt(System.getProperty(HandlerConstants.IOT_GATEWAY_WEBSOCKET_WS_PORT_ENV_VAR)));
|
||||
|
||||
JsonObject responseJsonObj = new JsonObject();
|
||||
responseJsonObj.addProperty("default-access-token", defaultAccessToken);
|
||||
responseJsonObj.addProperty("remote-session-base-url", ub.toString());
|
||||
responseJsonObj.addProperty("secured-websocket-gateway-url", ub2.toString());
|
||||
responseJsonObj.addProperty("unsecured-websocket-gateway-url", ub3.toString());
|
||||
|
||||
Gson gson = new Gson();
|
||||
String payload = gson.toJson(responseJsonObj);
|
||||
|
||||
ProxyResponse proxyResponse = new ProxyResponse();
|
||||
proxyResponse.setCode(HttpStatus.SC_OK);
|
||||
proxyResponse.setStatus(ProxyResponse.Status.SUCCESS);
|
||||
proxyResponse.setData(payload);
|
||||
return proxyResponse;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue