forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
commit
6a623f5657
@ -0,0 +1,147 @@
|
||||
<!-- ~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~ ~ WSO2 Inc. licenses this file to you under the Apache License, ~ Version
|
||||
2.0 (the "License"); you may not use this file except ~ in compliance with
|
||||
the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ ~ Unless required by applicable law or agreed to in writing, ~ software
|
||||
distributed under the License is distributed on an ~ "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the
|
||||
License for the ~ specific language governing permissions and limitations
|
||||
~ under the License. -->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.37-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
||||
<version>2.0.37-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Integration Client</name>
|
||||
<description>WSO2 Carbon - API Management Integration Client</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>APIM Integration</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.apimgt.integration.client.internal</Private-Package>
|
||||
<Export-Package>
|
||||
org.wso2.carbon.apimgt.integration.client.*,
|
||||
!org.wso2.carbon.apimgt.integration.client.internal
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
feign,
|
||||
feign.codec,
|
||||
feign.auth,
|
||||
feign.gson,
|
||||
feign.slf4j,
|
||||
org.wso2.carbon.apimgt.integration.generated.client.publisher.api,
|
||||
org.wso2.carbon.apimgt.integration.generated.client.store.api,
|
||||
javax.xml.bind,
|
||||
javax.xml.bind.annotation,
|
||||
javax.xml.parsers;resolution:=optional,
|
||||
org.apache.commons.logging,
|
||||
org.w3c.dom,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.identity.jwt.client.*,
|
||||
org.wso2.carbon.user.api,
|
||||
org.wso2.carbon.utils,
|
||||
com.fasterxml.jackson.annotation,
|
||||
io.swagger.annotations,
|
||||
org.wso2.carbon.core.util,
|
||||
javax.xml,
|
||||
org.wso2.carbon.base,
|
||||
javax.net.ssl,
|
||||
</Import-Package>
|
||||
<Embed-Dependency>
|
||||
jsr311-api,
|
||||
feign-jaxrs
|
||||
</Embed-Dependency>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-gson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.jwt.client.extension</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient;
|
||||
import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService;
|
||||
import org.wso2.carbon.apimgt.integration.client.store.StoreClient;
|
||||
|
||||
public class IntegrationClientServiceImpl implements IntegrationClientService {
|
||||
|
||||
private static StoreClient storeClient;
|
||||
private static PublisherClient publisherClient;
|
||||
|
||||
public IntegrationClientServiceImpl() {
|
||||
RequestInterceptor oAuthRequestInterceptor = new OAuthRequestInterceptor();
|
||||
storeClient = new StoreClient(oAuthRequestInterceptor);
|
||||
publisherClient = new PublisherClient(oAuthRequestInterceptor);
|
||||
}
|
||||
@Override
|
||||
public StoreClient getStoreClient() {
|
||||
return storeClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublisherClient getPublisherClient() {
|
||||
return publisherClient;
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import feign.auth.BasicAuthRequestInterceptor;
|
||||
import feign.gson.GsonDecoder;
|
||||
import feign.gson.GsonEncoder;
|
||||
import feign.jaxrs.JAXRSContract;
|
||||
import feign.slf4j.Slf4jLogger;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.apimgt.integration.client.configs.APIMConfigReader;
|
||||
import org.wso2.carbon.apimgt.integration.client.exception.APIMClientOAuthException;
|
||||
import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDataHolder;
|
||||
import org.wso2.carbon.apimgt.integration.client.model.ClientProfile;
|
||||
import org.wso2.carbon.apimgt.integration.client.model.DCRClient;
|
||||
import org.wso2.carbon.apimgt.integration.client.model.OAuthApplication;
|
||||
import org.wso2.carbon.apimgt.integration.client.util.Utils;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This is a request interceptor to add oauth token header.
|
||||
*/
|
||||
public class OAuthRequestInterceptor implements RequestInterceptor {
|
||||
|
||||
private static final String APPLICATION_NAME = "api_integration_client";
|
||||
private static final String GRANT_TYPES = "password refresh_token urn:ietf:params:oauth:grant-type:jwt-bearer";
|
||||
private static final String REQUIRED_SCOPE =
|
||||
"apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " +
|
||||
"apim:subscription_view apim:subscription_block";
|
||||
private static final String APIM_SUBSCRIBE_SCOPE = "apim:subscribe";
|
||||
private static final long DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS = 100000;
|
||||
private DCRClient dcrClient;
|
||||
private static OAuthApplication oAuthApplication;
|
||||
private static Map<String, AccessTokenInfo> tenantUserTokenMap = new HashMap<>();
|
||||
private static final Log log = LogFactory.getLog(OAuthRequestInterceptor.class);
|
||||
|
||||
/**
|
||||
* Creates an interceptor that authenticates all requests.
|
||||
*/
|
||||
public OAuthRequestInterceptor() {
|
||||
String username = APIMConfigReader.getInstance().getConfig().getUsername();
|
||||
String password = APIMConfigReader.getInstance().getConfig().getPassword();
|
||||
dcrClient = Feign.builder().client(Utils.getSSLClient()).logger(new Slf4jLogger()).logLevel(
|
||||
Logger.Level.FULL).requestInterceptor(new BasicAuthRequestInterceptor(username, password))
|
||||
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||
.target(DCRClient.class, Utils.replaceProperties(
|
||||
APIMConfigReader.getInstance().getConfig().getDcrEndpoint()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(RequestTemplate template) {
|
||||
if (oAuthApplication == null) {
|
||||
//had to do on demand initialization due to start up error.
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setClientName(APPLICATION_NAME);
|
||||
clientProfile.setCallbackUrl("");
|
||||
clientProfile.setGrantType(GRANT_TYPES);
|
||||
clientProfile.setOwner(APIMConfigReader.getInstance().getConfig().getUsername());
|
||||
clientProfile.setSaasApp(true);
|
||||
oAuthApplication = dcrClient.register(clientProfile);
|
||||
}
|
||||
try {
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
||||
username = username + "@" + tenantDomain;
|
||||
}
|
||||
AccessTokenInfo tenantBasedAccessTokenInfo = tenantUserTokenMap.get(username);
|
||||
if ((tenantBasedAccessTokenInfo == null ||
|
||||
((System.currentTimeMillis() + DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS) >
|
||||
tenantBasedAccessTokenInfo.getExpiresIn()))) {
|
||||
|
||||
JWTClient jwtClient = APIIntegrationClientDataHolder.getInstance().getJwtClientManagerService()
|
||||
.getJWTClient();
|
||||
tenantBasedAccessTokenInfo = jwtClient.getAccessToken(oAuthApplication.getClientId(),
|
||||
oAuthApplication.getClientSecret(), username,
|
||||
REQUIRED_SCOPE);
|
||||
tenantBasedAccessTokenInfo.setExpiresIn(
|
||||
System.currentTimeMillis() + (tenantBasedAccessTokenInfo.getExpiresIn() * 1000));
|
||||
if (tenantBasedAccessTokenInfo.getScopes().contains(APIM_SUBSCRIBE_SCOPE)) {
|
||||
tenantUserTokenMap.put(username, tenantBasedAccessTokenInfo);
|
||||
}
|
||||
|
||||
}
|
||||
if (tenantBasedAccessTokenInfo.getAccessToken() != null) {
|
||||
String headerValue = "Bearer " + tenantBasedAccessTokenInfo.getAccessToken();
|
||||
template.header("Authorization", headerValue);
|
||||
}
|
||||
} catch (JWTClientException e) {
|
||||
throw new APIMClientOAuthException("failed to retrieve oauth token using jwt", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.configs;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* This holds the configuration api manager integration.
|
||||
*/
|
||||
@XmlRootElement(name = "APIMConfiguration")
|
||||
public class APIMConfig {
|
||||
|
||||
String dcrEndpoint;
|
||||
String tokenEndpoint;
|
||||
String publisherEndpoint;
|
||||
String storeEndpoint;
|
||||
String username;
|
||||
String password;
|
||||
|
||||
@XmlElement(name = "DCREndpoint", required = true)
|
||||
public String getDcrEndpoint() {
|
||||
return dcrEndpoint;
|
||||
}
|
||||
|
||||
public void setDcrEndpoint(String dcrEndpoint) {
|
||||
this.dcrEndpoint = dcrEndpoint;
|
||||
}
|
||||
|
||||
@XmlElement(name = "TokenEndpoint", required = true)
|
||||
public String getTokenEndpoint() {
|
||||
return tokenEndpoint;
|
||||
}
|
||||
|
||||
public void setTokenEndpoint(String tokenEndpoint) {
|
||||
this.tokenEndpoint = tokenEndpoint;
|
||||
}
|
||||
|
||||
@XmlElement(name = "PublisherEndpoint", required = true)
|
||||
public String getPublisherEndpoint() {
|
||||
return publisherEndpoint;
|
||||
}
|
||||
|
||||
public void setPublisherEndpoint(String publisherEndpoint) {
|
||||
this.publisherEndpoint = publisherEndpoint;
|
||||
}
|
||||
|
||||
@XmlElement(name = "StoreEndpoint", required = true)
|
||||
public String getStoreEndpoint() {
|
||||
return storeEndpoint;
|
||||
}
|
||||
|
||||
public void setStoreEndpoint(String storeEndpoint) {
|
||||
this.storeEndpoint = storeEndpoint;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Username", required = true)
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Password", required = true)
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.configs;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.apimgt.integration.client.exception.APIMClientException;
|
||||
import org.wso2.carbon.apimgt.integration.client.exception.InvalidConfigurationStateException;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This holds the configuration parser for api integration.xml
|
||||
*/
|
||||
public class APIMConfigReader {
|
||||
|
||||
private static APIMConfig config;
|
||||
private static APIMConfigReader configReader= new APIMConfigReader();
|
||||
private static boolean isInitialized = false;
|
||||
private static final String API_INTEGRATION_CONFIG_PATH =
|
||||
CarbonUtils.getCarbonConfigDirPath() + File.separator + "apim-integration.xml";
|
||||
|
||||
private APIMConfigReader() {
|
||||
|
||||
}
|
||||
|
||||
private static String apimIntegrationXmlFilePath = "";
|
||||
|
||||
//TOD file may be a part of another file
|
||||
public static APIMConfigReader getInstance() {
|
||||
if (!isInitialized) {
|
||||
try {
|
||||
init();
|
||||
} catch (APIMClientException e) {
|
||||
throw new InvalidConfigurationStateException("Webapp Authenticator Configuration is not " +
|
||||
"initialized properly");
|
||||
}
|
||||
}
|
||||
return configReader;
|
||||
}
|
||||
|
||||
public static void init() throws APIMClientException {
|
||||
try {
|
||||
File apimConfigFile = new File(API_INTEGRATION_CONFIG_PATH);
|
||||
Document doc = convertToDocument(apimConfigFile);
|
||||
|
||||
JAXBContext ctx = JAXBContext.newInstance(APIMConfig.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
config = (APIMConfig) unmarshaller.unmarshal(doc);
|
||||
isInitialized = true;
|
||||
} catch (JAXBException e) {
|
||||
throw new APIMClientException("Error occurred while un-marshalling APIMConfig", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Document convertToDocument(File file) throws APIMClientException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new APIMClientException("Error occurred while parsing file 'apim-integration.xml' to a org.w3c.dom.Document", e);
|
||||
}
|
||||
}
|
||||
|
||||
public APIMConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.exception;
|
||||
|
||||
/**
|
||||
* This holds api client exception.
|
||||
*/
|
||||
public class APIMClientException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3976392476319079281L;
|
||||
private String responseReason;
|
||||
private int responseStatus;
|
||||
private String methodKey;
|
||||
|
||||
APIMClientException(String methodKey, String reason, int status) {
|
||||
super("Exception occured while invoking " + methodKey + " status = " + status + " reason = " + reason);
|
||||
this.methodKey = methodKey;
|
||||
this.responseReason = reason;
|
||||
this.responseStatus = status;
|
||||
}
|
||||
|
||||
APIMClientException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public APIMClientException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
||||
public String getResponseReason() {
|
||||
return responseReason;
|
||||
}
|
||||
|
||||
public int getResponseStatus() {
|
||||
return responseStatus;
|
||||
}
|
||||
|
||||
public String getMethodKey() {
|
||||
return methodKey;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.exception;
|
||||
|
||||
/**
|
||||
* This holds api client exception.
|
||||
*/
|
||||
public class APIMClientOAuthException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3976392476319079281L;
|
||||
private String responseReason;
|
||||
private int responseStatus;
|
||||
private String methodKey;
|
||||
|
||||
APIMClientOAuthException(String methodKey, String reason, int status) {
|
||||
super("Exception occured while invoking " + methodKey + " status = " + status + " reason = " + reason);
|
||||
this.methodKey = methodKey;
|
||||
this.responseReason = reason;
|
||||
this.responseStatus = status;
|
||||
}
|
||||
|
||||
APIMClientOAuthException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public APIMClientOAuthException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
||||
public String getResponseReason() {
|
||||
return responseReason;
|
||||
}
|
||||
|
||||
public int getResponseStatus() {
|
||||
return responseStatus;
|
||||
}
|
||||
|
||||
public String getMethodKey() {
|
||||
return methodKey;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.exception;
|
||||
|
||||
/**
|
||||
* This error is thrown when there is an issue with the client.
|
||||
*/
|
||||
public class InvalidConfigurationStateException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279311329070397L;
|
||||
|
||||
private String errorMessage;
|
||||
private int errorCode;
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.apimgt.integration.client.internal;
|
||||
|
||||
|
||||
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
||||
|
||||
/**
|
||||
* This holds the required service for this component
|
||||
*/
|
||||
public class APIIntegrationClientDataHolder {
|
||||
private static APIIntegrationClientDataHolder thisInstance = new APIIntegrationClientDataHolder();
|
||||
private JWTClientManagerService jwtClientManagerService;
|
||||
private APIIntegrationClientDataHolder() {
|
||||
}
|
||||
|
||||
|
||||
public static APIIntegrationClientDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public void setJwtClientManagerService(JWTClientManagerService jwtClientManagerService) {
|
||||
this.jwtClientManagerService = jwtClientManagerService;
|
||||
}
|
||||
|
||||
public JWTClientManagerService getJwtClientManagerService() {
|
||||
return jwtClientManagerService;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.apimgt.integration.client.internal;
|
||||
|
||||
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.apimgt.integration.client.IntegrationClientServiceImpl;
|
||||
import org.wso2.carbon.apimgt.integration.client.configs.APIMConfigReader;
|
||||
import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.api.integration.client" immediate="true"
|
||||
* @scr.reference name="api.integration.client.service"
|
||||
* interface="org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setJWTClientManagerService"
|
||||
* unbind="unsetJWTClientManagerService"
|
||||
*/
|
||||
public class APIIntegrationClientServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(APIIntegrationClientServiceComponent.class);
|
||||
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing apimgt client bundle");
|
||||
}
|
||||
|
||||
/* Initializing webapp publisher configuration */
|
||||
APIMConfigReader.init();
|
||||
BundleContext bundleContext = componentContext.getBundleContext();
|
||||
bundleContext.registerService(IntegrationClientService.class.getName(), new IntegrationClientServiceImpl(), null);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("apimgt client bundle has been successfully initialized");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while initializing apimgt client bundle", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
protected void setJWTClientManagerService(JWTClientManagerService jwtClientManagerService) {
|
||||
if (jwtClientManagerService != null) {
|
||||
log.debug("jwtClientManagerService service is initialized");
|
||||
}
|
||||
APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(jwtClientManagerService);
|
||||
}
|
||||
|
||||
protected void unsetJWTClientManagerService(JWTClientManagerService jwtClientManagerService) {
|
||||
APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.model;
|
||||
|
||||
/**
|
||||
* DTO fo DCR request.
|
||||
*/
|
||||
public class ClientProfile {
|
||||
|
||||
private String clientName;
|
||||
private String callbackUrl;
|
||||
private String tokenScope;
|
||||
private String owner;
|
||||
private String grantType;
|
||||
private boolean saasApp;
|
||||
|
||||
public String getClientName() {
|
||||
return clientName;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public String getCallbackUrl() {
|
||||
return callbackUrl;
|
||||
}
|
||||
|
||||
public void setCallbackUrl(String callbackUrl) {
|
||||
this.callbackUrl = callbackUrl;
|
||||
}
|
||||
|
||||
public String getTokenScope() {
|
||||
return tokenScope;
|
||||
}
|
||||
|
||||
public void setTokenScope(String tokenScope) {
|
||||
this.tokenScope = tokenScope;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getGrantType() {
|
||||
return grantType;
|
||||
}
|
||||
|
||||
public void setGrantType(String grantTypem) {
|
||||
this.grantType = grantTypem;
|
||||
}
|
||||
|
||||
public boolean isSaasApp() {
|
||||
return saasApp;
|
||||
}
|
||||
|
||||
public void setSaasApp(boolean saasApp) {
|
||||
this.saasApp = saasApp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
|
||||
sb.append(" clientName: ").append(clientName).append("\n");
|
||||
sb.append(" callbackUrl: ").append("callbackUrl").append("\n");
|
||||
sb.append(" grantType: ").append(grantType).append("\n");
|
||||
sb.append(" tokenScope: ").append(tokenScope).append("\n");
|
||||
sb.append(" owner: ").append(owner).append("\n");
|
||||
sb.append(" saasApp: ").append(saasApp).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
22
components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/grant/ExtendedPasswordGrantHandler.java → components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/model/DCRClient.java
22
components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/src/main/java/org/wso2/carbon/device/mgt/oauth/extensions/handlers/grant/ExtendedPasswordGrantHandler.java → components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/model/DCRClient.java
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.model;
|
||||
|
||||
public class OAuthApplication {
|
||||
|
||||
private String jsonString;
|
||||
private String appOwner;
|
||||
private String clientName;
|
||||
private String callBackURL;
|
||||
private String isSaasApplication;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
|
||||
public String getJsonString() {
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
public void setJsonString(String jsonString) {
|
||||
this.jsonString = jsonString;
|
||||
}
|
||||
|
||||
public String getAppOwner() {
|
||||
return appOwner;
|
||||
}
|
||||
|
||||
public void setAppOwner(String appOwner) {
|
||||
this.appOwner = appOwner;
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return clientName;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public String getCallBackURL() {
|
||||
return callBackURL;
|
||||
}
|
||||
|
||||
public void setCallBackURL(String callBackURL) {
|
||||
this.callBackURL = callBackURL;
|
||||
}
|
||||
|
||||
public String getIsSaasApplication() {
|
||||
return isSaasApplication;
|
||||
}
|
||||
|
||||
public void setIsSaasApplication(String isSaasApplication) {
|
||||
this.isSaasApplication = isSaasApplication;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class OAuthApplication {\n");
|
||||
|
||||
sb.append(" jsonString: ").append(jsonString).append("\n");
|
||||
sb.append(" appOwner: ").append(appOwner).append("\n");
|
||||
sb.append(" clientName: ").append(clientName).append("\n");
|
||||
sb.append(" callBackURL: ").append(callBackURL).append("\n");
|
||||
sb.append(" isSaasApplication: ").append(isSaasApplication).append("\n");
|
||||
sb.append(" clientId: ").append(isSaasApplication).append("\n");
|
||||
sb.append(" clientSecret: ").append(clientSecret).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.apimgt.integration.client.publisher;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.gson.GsonDecoder;
|
||||
import feign.gson.GsonEncoder;
|
||||
import feign.slf4j.Slf4jLogger;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.apimgt.integration.client.configs.APIMConfigReader;
|
||||
import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.*;
|
||||
import org.wso2.carbon.core.util.Utils;
|
||||
|
||||
/**
|
||||
* Publisher client generated using swagger.
|
||||
*/
|
||||
public class PublisherClient {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PublisherClient.class);
|
||||
private APIsApi api = null;
|
||||
private APIDocumentApi document = null;
|
||||
private ApplicationsApi application = null;
|
||||
private EnvironmentsApi environments = null;
|
||||
private SubscriptionsApi subscriptions = null;
|
||||
private TiersApi tiers = null;
|
||||
|
||||
|
||||
/**
|
||||
* PublisherClient constructor - Initialize a PublisherClient instance
|
||||
*
|
||||
*/
|
||||
public PublisherClient(RequestInterceptor requestInterceptor) {
|
||||
Feign.Builder builder = Feign.builder().client(
|
||||
org.wso2.carbon.apimgt.integration.client.util.Utils.getSSLClient()).logger(new Slf4jLogger())
|
||||
.logLevel(Logger.Level.FULL)
|
||||
.requestInterceptor(requestInterceptor).encoder(new GsonEncoder()).decoder(new GsonDecoder());
|
||||
String basePath = Utils.replaceSystemProperty(APIMConfigReader.getInstance().getConfig().getPublisherEndpoint());
|
||||
|
||||
api = builder.target(APIsApi.class, basePath);
|
||||
document = builder.target(APIDocumentApi.class, basePath);
|
||||
application = builder.target(ApplicationsApi.class, basePath);
|
||||
environments = builder.target(EnvironmentsApi.class, basePath);
|
||||
subscriptions = builder.target(SubscriptionsApi.class, basePath);
|
||||
tiers = builder.target(TiersApi.class, basePath);
|
||||
}
|
||||
|
||||
public APIsApi getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
public APIDocumentApi getDocument() {
|
||||
return document;
|
||||
}
|
||||
|
||||
public ApplicationsApi getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public EnvironmentsApi getEnvironments() {
|
||||
return environments;
|
||||
}
|
||||
|
||||
public SubscriptionsApi getSubscriptions() {
|
||||
return subscriptions;
|
||||
}
|
||||
|
||||
public TiersApi getTiers() {
|
||||
return tiers;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.apimgt.integration.client.service;
|
||||
|
||||
|
||||
import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient;
|
||||
import org.wso2.carbon.apimgt.integration.client.store.StoreClient;
|
||||
|
||||
/**
|
||||
* This is a service that can be called upon to access store and publisher.
|
||||
*/
|
||||
public interface IntegrationClientService {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API Store Client.
|
||||
*/
|
||||
StoreClient getStoreClient();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API Publisher Client.
|
||||
*/
|
||||
PublisherClient getPublisherClient();
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.apimgt.integration.client.store;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.gson.GsonDecoder;
|
||||
import feign.gson.GsonEncoder;
|
||||
import feign.slf4j.Slf4jLogger;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.apimgt.integration.client.configs.APIMConfigReader;
|
||||
import org.wso2.carbon.apimgt.integration.generated.client.store.api.*;
|
||||
import org.wso2.carbon.core.util.Utils;
|
||||
|
||||
/**
|
||||
* API Store client, created using swagger gen.
|
||||
*/
|
||||
public class StoreClient {
|
||||
|
||||
private static final org.apache.commons.logging.Log log = LogFactory.getLog(StoreClient.class);
|
||||
private APICollectionApi apis = null;
|
||||
private APIIndividualApi individualApi = null;
|
||||
private ApplicationCollectionApi applications = null;
|
||||
private ApplicationIndividualApi individualApplication = null;
|
||||
private SubscriptionCollectionApi subscriptions = null;
|
||||
private SubscriptionIndividualApi individualSubscription = null;
|
||||
private SubscriptionMultitpleApi subscriptionMultitpleApi = null;
|
||||
private ThrottlingTierIndividualApi individualTier = null;
|
||||
private TagCollectionApi tags = null;
|
||||
private ThrottlingTierCollectionApi tiers = null;
|
||||
|
||||
|
||||
public StoreClient(RequestInterceptor requestInterceptor) {
|
||||
|
||||
Feign.Builder builder = Feign.builder().client(
|
||||
org.wso2.carbon.apimgt.integration.client.util.Utils.getSSLClient()).logger(new Slf4jLogger())
|
||||
.logLevel(Logger.Level.FULL)
|
||||
.requestInterceptor(requestInterceptor).encoder(new GsonEncoder()).decoder(new GsonDecoder());
|
||||
String basePath = Utils.replaceSystemProperty(APIMConfigReader.getInstance().getConfig().getStoreEndpoint());
|
||||
|
||||
apis = builder.target(APICollectionApi.class, basePath);
|
||||
individualApi = builder.target(APIIndividualApi.class, basePath);
|
||||
applications = builder.target(ApplicationCollectionApi.class, basePath);
|
||||
individualApplication = builder.target(ApplicationIndividualApi.class, basePath);
|
||||
subscriptions = builder.target(SubscriptionCollectionApi.class, basePath);
|
||||
individualSubscription = builder.target(SubscriptionIndividualApi.class, basePath);
|
||||
subscriptionMultitpleApi = builder.target(SubscriptionMultitpleApi.class, basePath);
|
||||
tags = builder.target(TagCollectionApi.class, basePath);
|
||||
tiers = builder.target(ThrottlingTierCollectionApi.class, basePath);
|
||||
individualTier = builder.target(ThrottlingTierIndividualApi.class, basePath);
|
||||
|
||||
}
|
||||
|
||||
public APICollectionApi getApis() {
|
||||
return apis;
|
||||
}
|
||||
|
||||
public APIIndividualApi getIndividualApi() {
|
||||
return individualApi;
|
||||
}
|
||||
|
||||
public ApplicationCollectionApi getApplications() {
|
||||
return applications;
|
||||
}
|
||||
|
||||
public ApplicationIndividualApi getIndividualApplication() {
|
||||
return individualApplication;
|
||||
}
|
||||
|
||||
public SubscriptionCollectionApi getSubscriptions() {
|
||||
return subscriptions;
|
||||
}
|
||||
|
||||
public SubscriptionIndividualApi getIndividualSubscription() {
|
||||
return individualSubscription;
|
||||
}
|
||||
|
||||
public ThrottlingTierIndividualApi getIndividualTier() {
|
||||
return individualTier;
|
||||
}
|
||||
|
||||
public TagCollectionApi getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public ThrottlingTierCollectionApi getTiers() {
|
||||
return tiers;
|
||||
}
|
||||
|
||||
public SubscriptionMultitpleApi getSubscriptionMultitpleApi() {
|
||||
return subscriptionMultitpleApi;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.integration.client.util;
|
||||
|
||||
|
||||
import feign.Client;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import feign.Logger;
|
||||
import feign.Request;
|
||||
import feign.Response;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
public class Utils {
|
||||
|
||||
//This method is only used if the mb features are within DAS.
|
||||
public static String replaceProperties(String text) {
|
||||
String regex = "\\$\\{(.*?)\\}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matchPattern = pattern.matcher(text);
|
||||
while (matchPattern.find()) {
|
||||
String sysPropertyName = matchPattern.group(1);
|
||||
String sysPropertyValue = System.getProperty(sysPropertyName);
|
||||
if (sysPropertyValue != null && !sysPropertyName.isEmpty()) {
|
||||
text = text.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static Client getSSLClient() {
|
||||
return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String s, SSLSession sslSession) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static SSLSocketFactory getTrustedSSLSocketFactory() {
|
||||
try {
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(
|
||||
java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
public void checkServerTrusted(
|
||||
java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
}
|
||||
};
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
return sc.getSocketFactory();
|
||||
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
<!-- ~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~ ~ WSO2 Inc. licenses this file to you under the Apache License, ~ Version
|
||||
2.0 (the "License"); you may not use this file except ~ in compliance with
|
||||
the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ ~ Unless required by applicable law or agreed to in writing, ~ software
|
||||
distributed under the License is distributed on an ~ "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the
|
||||
License for the ~ specific language governing permissions and limitations
|
||||
~ under the License. -->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.37-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
|
||||
<version>2.0.37-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Integration Generated Client</name>
|
||||
<description>WSO2 Carbon - API Management Integration Client</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!--swagger yaml is used to generate code-->
|
||||
<plugin>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-resources</phase>
|
||||
<id>publisher</id>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>${project.basedir}/src/main/resources/publisher-api.yaml</inputSpec>
|
||||
<language>java</language>
|
||||
<configOptions>
|
||||
<apiPackage>${project.artifactId}.publisher.api</apiPackage>
|
||||
<modelPackage>${project.artifactId}.publisher.model</modelPackage>
|
||||
</configOptions>
|
||||
<library>feign</library>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<phase>process-resources</phase>
|
||||
<id>store</id>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>${project.basedir}/src/main/resources/store-api.yaml</inputSpec>
|
||||
<language>java</language>
|
||||
<configOptions>
|
||||
<apiPackage>${project.artifactId}.store.api</apiPackage>
|
||||
<modelPackage>${project.artifactId}.store.model</modelPackage>
|
||||
</configOptions>
|
||||
<library>feign</library>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||
<artifactId>replacer</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<executions>
|
||||
<!-- Replace java code that is generated from swagger to fix swagger client generation issues. -->
|
||||
<execution>
|
||||
<phase>process-resources</phase>
|
||||
<id>replace-for-swagger-genenerated-code-publisher</id>
|
||||
<goals>
|
||||
<goal>replace</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<file>${project.basedir}/target/generated-sources/swagger/src/main/java/org/wso2/carbon/apimgt/integration/generated/client/publisher/model/API.java</file>
|
||||
<replacements>
|
||||
<replacement>
|
||||
<token>CURRENT_TENANT</token>
|
||||
<value>current_tenant</value>
|
||||
</replacement>
|
||||
<replacement>
|
||||
<token>ALL_TENANTS</token>
|
||||
<value>all_tenants</value>
|
||||
</replacement>
|
||||
<replacement>
|
||||
<token>SPECIFIC_TENANTS</token>
|
||||
<value>specific_tenants</value>
|
||||
</replacement>
|
||||
</replacements>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>APIM Integration</Bundle-Description>
|
||||
<Export-Package>
|
||||
org.wso2.carbon.apimgt.integration.generated.client.publisher.api.*,
|
||||
org.wso2.carbon.apimgt.integration.generated.client.publisher.model.*,
|
||||
org.wso2.carbon.apimgt.integration.generated.client.store.api.*,
|
||||
org.wso2.carbon.apimgt.integration.generated.client.store.model.*
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
feign;version="${io.github.openfeign.version.range}",
|
||||
feign.jackson;version="${io.github.openfeign.version.range}",
|
||||
feign.codec;version="${io.github.openfeign.version.range}",
|
||||
feign.auth;version="${io.github.openfeign.version.range}",
|
||||
feign.gson;version="${io.github.openfeign.version.range}",
|
||||
feign.slf4j;version="${io.github.openfeign.version.range}",
|
||||
com.google.gson,
|
||||
com.fasterxml.jackson.core;resolution:=optional,
|
||||
com.fasterxml.jackson.annotation,
|
||||
com.fasterxml.jackson.databind;resolution:=optional,
|
||||
io.swagger.annotations,
|
||||
javax.net.ssl,
|
||||
com.fasterxml.jackson.datatype.joda;resolution:=optional,
|
||||
org.apache.oltu.oauth2.client.*;resolution:=optional,
|
||||
org.apache.oltu.oauth2.common.*;resolution:=optional,
|
||||
org.junit;resolution:=optional,
|
||||
</Import-Package>
|
||||
<Embed-Dependency>
|
||||
jsr311-api,
|
||||
feign-jaxrs
|
||||
</Embed-Dependency>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.oltu.oauth2</groupId>
|
||||
<artifactId>org.apache.oltu.oauth2.client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-slf4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-databind.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
</properties>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.webapp.publisher.dto;
|
||||
|
||||
public class ApiScope {
|
||||
|
||||
String key;
|
||||
String name;
|
||||
String roles;
|
||||
String description;
|
||||
int id;
|
||||
|
||||
public ApiScope() {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public void setRoles(String roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.webapp.publisher.dto;
|
||||
|
||||
/**
|
||||
* This hold the api uri template information.
|
||||
*/
|
||||
public class ApiUriTemplate {
|
||||
|
||||
private String authType;
|
||||
private String httpVerb;
|
||||
private String resourceURI;
|
||||
private String uriTemplate;
|
||||
private ApiScope scope;
|
||||
|
||||
public ApiUriTemplate() {}
|
||||
|
||||
public String getAuthType() {
|
||||
return authType;
|
||||
}
|
||||
|
||||
public void setAuthType(String authType) {
|
||||
this.authType = authType;
|
||||
}
|
||||
|
||||
public String getHttpVerb() {
|
||||
return httpVerb;
|
||||
}
|
||||
|
||||
public void setHttpVerb(String httpVerb) {
|
||||
this.httpVerb = httpVerb;
|
||||
}
|
||||
|
||||
public String getResourceURI() {
|
||||
return resourceURI;
|
||||
}
|
||||
|
||||
public void setResourceURI(String resourceURI) {
|
||||
this.resourceURI = resourceURI;
|
||||
}
|
||||
|
||||
public String getUriTemplate() {
|
||||
return uriTemplate;
|
||||
}
|
||||
|
||||
public void setUriTemplate(String uriTemplate) {
|
||||
this.uriTemplate = uriTemplate;
|
||||
}
|
||||
|
||||
public ApiScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(ApiScope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.apimgt.webapp.publisher.exception;
|
||||
|
||||
/**
|
||||
* Handles the exceptions related to API management.
|
||||
*/
|
||||
public class APIManagerPublisherException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -8933142342423122660L;
|
||||
|
||||
public APIManagerPublisherException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public APIManagerPublisherException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public APIManagerPublisherException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public APIManagerPublisherException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public APIManagerPublisherException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for DeviceDetails complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="DeviceDetails">
|
||||
* <simpleContent>
|
||||
* <extension base="<http://www.w3.org/2001/XMLSchema>string">
|
||||
* <attribute name="table-id" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* </extension>
|
||||
* </simpleContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "Claimable", propOrder = {
|
||||
"value"
|
||||
})
|
||||
public class Claimable {
|
||||
|
||||
@XmlValue
|
||||
protected String value;
|
||||
@XmlAttribute(name = "enabled")
|
||||
protected boolean enabled;
|
||||
|
||||
/**
|
||||
* Gets the value of the value property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the value property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the enabled property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the enabled property.
|
||||
*
|
||||
* @param enabled
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>Java class for InitialOperationConfig complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="InitialOperationConfig">
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="Operations" type="{http://www.w3.org/2001/XMLSchema}list"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "InitialOperationConfig")
|
||||
public class InitialOperationConfig {
|
||||
|
||||
private List<String> operations;
|
||||
|
||||
@XmlElementWrapper(name = "Operations", required = true)
|
||||
@XmlElement(name = "Operation", required = true)
|
||||
public List<String> getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
public void setOperationsll(List<String> operations) {
|
||||
this.operations = operations;
|
||||
}
|
||||
}
|
10
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java
10
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java
48
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
48
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
8
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMDataHolder.java
8
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMDataHolder.java
19
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMPushNotificationServiceComponent.java
19
components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java → components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMPushNotificationServiceComponent.java
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
|
||||
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "DeviceTypePublisherAdminService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/devicetype"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "device_management", description = "")
|
||||
}
|
||||
)
|
||||
@Path("/admin/devicetype")
|
||||
@Api(value = "Devicetype deployment Administrative Service", description = "This an API intended to be used to " +
|
||||
"deploy device type components" +
|
||||
"Further, this is strictly restricted to admin users only ")
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Devicetype deployment",
|
||||
description = "Deploy devicetype",
|
||||
key = "perm:devicetype:deployment",
|
||||
permissions = {"/device-mgt/devicetype/deploy"}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
public interface DeviceTypePublisherAdminService {
|
||||
|
||||
@POST
|
||||
@Path("/deploy/{type}")
|
||||
@ApiOperation(
|
||||
httpMethod = "POST",
|
||||
value = "Deploy device type\n",
|
||||
notes = "This is an API that can be used to deploy existing device type artifact for tenant",
|
||||
response = Response.class,
|
||||
tags = "Devicetype Deployment Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devicetype:deployment")
|
||||
})
|
||||
})
|
||||
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "OK. \n Successfully deployed the artifacts.",
|
||||
response = Response.class),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified resource does not exist."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while checking the authorization" +
|
||||
" for a specified set of devices.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
|
||||
Response doPublish(
|
||||
@ApiParam(name = "type",
|
||||
value = "The type of deployment." +
|
||||
"INFO: Deploy artifact with given type.",
|
||||
required = true)
|
||||
@PathParam("type") String type);
|
||||
|
||||
@GET
|
||||
@Path("/deploy/{type}/status")
|
||||
@ApiOperation(
|
||||
httpMethod = "GET",
|
||||
value = "Check the status of device type artifact\n",
|
||||
notes = "This is an API that can be used to check the status of the artifact",
|
||||
response = Response.class,
|
||||
tags = "Devicetype Status Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devicetype:deployment")
|
||||
})
|
||||
})
|
||||
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "OK. \n Successfully deployed the artifacts.",
|
||||
response = Response.class),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified resource does not exist."),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while checking the authorization" +
|
||||
" for a specified set of devices.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
|
||||
Response getStatus(@PathParam("type") String deviceType);
|
||||
|
||||
}
|
@ -0,0 +1,311 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
|
||||
|
||||
import org.apache.axis2.client.Options;
|
||||
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
|
||||
import org.apache.axis2.transport.http.HTTPConstants;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.protocol.Protocol;
|
||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.application.mgt.stub.upload.CarbonAppUploaderStub;
|
||||
import org.wso2.carbon.application.mgt.stub.upload.types.carbon.UploadedFileItem;
|
||||
import org.wso2.carbon.base.ServerConfiguration;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.core.util.Utils;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypePublisherAdminService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||
import org.wso2.carbon.registry.core.Registry;
|
||||
import org.wso2.carbon.registry.core.Resource;
|
||||
import org.wso2.carbon.registry.core.ResourceImpl;
|
||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.*;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/admin/devicetype")
|
||||
public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherAdminService {
|
||||
|
||||
/**
|
||||
* required soap header for authorization
|
||||
*/
|
||||
private static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
|
||||
/**
|
||||
* required soap header value for mutualSSL
|
||||
*/
|
||||
private static final String AUTHORIZATION_HEADER_VALUE = "Bearer";
|
||||
|
||||
private static final String KEY_STORE_TYPE = "JKS";
|
||||
/**
|
||||
* Default truststore type of the client
|
||||
*/
|
||||
private static final String TRUST_STORE_TYPE = "JKS";
|
||||
/**
|
||||
* Default keymanager type of the client
|
||||
*/
|
||||
private static final String KEY_MANAGER_TYPE = "SunX509"; //Default Key Manager Type
|
||||
/**
|
||||
* Default trustmanager type of the client
|
||||
*/
|
||||
private static final String TRUST_MANAGER_TYPE = "SunX509"; //Default Trust Manager Type
|
||||
|
||||
private static final String SSLV3 = "SSLv3";
|
||||
|
||||
private KeyStore keyStore;
|
||||
private KeyStore trustStore;
|
||||
private char[] keyStorePassword;
|
||||
private SSLContext sslContext;
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceTypePublisherAdminServiceImpl.class);
|
||||
private static final String DEFAULT_RESOURCE_LOCATION = "/resources/devicetypes";
|
||||
private static final String CAR_FILE_LOCATION = CarbonUtils.getCarbonHome() + File.separator + "repository" +
|
||||
File.separator + "resources" + File.separator + "devicetypes";
|
||||
private static final String DAS_PORT = "${iot.analytics.https.port}";
|
||||
private static final String DAS_HOST_NAME = "${iot.analytics.host}";
|
||||
private static final String DEFAULT_HTTP_PROTOCOL = "https";
|
||||
private static final String IOT_MGT_PORT = "${iot.manager.https.port}";
|
||||
private static final String IOT_MGT_HOST_NAME = "${iot.manager.host}";
|
||||
private static final String DAS_URL = DEFAULT_HTTP_PROTOCOL + "://" + DAS_HOST_NAME
|
||||
+ ":" + DAS_PORT + "/services/CarbonAppUploader" + "/";
|
||||
private static final String IOT_MGT_URL = DEFAULT_HTTP_PROTOCOL + "://" + IOT_MGT_HOST_NAME
|
||||
+ ":" + IOT_MGT_PORT + "/services/CarbonAppUploader" + "/";
|
||||
private static final String MEDIA_TYPE_XML = "application/xml";
|
||||
private static final String DEVICE_MANAGEMENT_TYPE = "device_management";
|
||||
|
||||
@Override
|
||||
@POST
|
||||
@Path("/deploy/{type}")
|
||||
public Response doPublish(@PathParam("type") String type) {
|
||||
|
||||
try {
|
||||
//Getting the tenant Domain
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
String tenantAdminUser = username + "@" + tenantDomain;
|
||||
|
||||
String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
|
||||
String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty(
|
||||
"Security.TrustStore.Password");
|
||||
String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location");
|
||||
String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty(
|
||||
"Security.TrustStore.Location");
|
||||
|
||||
//Call to load the keystore.
|
||||
loadKeyStore(keyStoreLocation, keyStorePassword);
|
||||
//Call to load the TrustStore.
|
||||
loadTrustStore(trustStoreLocation, trustStorePassword);
|
||||
//Create the SSL context with the loaded TrustStore/keystore.
|
||||
initSSLConnection();
|
||||
JWTClient jwtClient = DeviceMgtAPIUtils.getJWTClientManagerService().getJWTClient();
|
||||
|
||||
String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
|
||||
jwtClient.getJwtToken(tenantAdminUser).getBytes()));
|
||||
|
||||
List<Header> list = new ArrayList<Header>();
|
||||
Header httpHeader = new Header();
|
||||
httpHeader.setName(AUTHORIZATION_HEADER);
|
||||
httpHeader.setValue(authValue);
|
||||
list.add(httpHeader);//"https"
|
||||
|
||||
File directory = new File(CAR_FILE_LOCATION + File.separator + type);
|
||||
if (directory.isDirectory() && directory.exists()) {
|
||||
UploadedFileItem[] uploadedFileItems = loadCappFromFileSystem(type);
|
||||
if (uploadedFileItems.length > 0) {
|
||||
CarbonAppUploaderStub carbonAppUploaderStub = new CarbonAppUploaderStub(Utils.replaceSystemProperty(
|
||||
IOT_MGT_URL));
|
||||
Options appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions();
|
||||
if (appUploaderOptions == null) {
|
||||
appUploaderOptions = new Options();
|
||||
}
|
||||
appUploaderOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
|
||||
appUploaderOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
|
||||
, new Protocol(DEFAULT_HTTP_PROTOCOL, (ProtocolSocketFactory) new SSLProtocolSocketFactory
|
||||
(sslContext), Integer.parseInt(Utils.replaceSystemProperty(IOT_MGT_PORT))));
|
||||
|
||||
carbonAppUploaderStub._getServiceClient().setOptions(appUploaderOptions);
|
||||
carbonAppUploaderStub.uploadApp(uploadedFileItems);
|
||||
|
||||
if (!DEVICE_MANAGEMENT_TYPE.equals(type.toLowerCase())) {
|
||||
carbonAppUploaderStub = new CarbonAppUploaderStub(Utils.replaceSystemProperty(DAS_URL));
|
||||
appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions();
|
||||
if (appUploaderOptions == null) {
|
||||
appUploaderOptions = new Options();
|
||||
}
|
||||
appUploaderOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
|
||||
appUploaderOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
|
||||
, new Protocol(DEFAULT_HTTP_PROTOCOL
|
||||
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
||||
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
||||
|
||||
carbonAppUploaderStub._getServiceClient().setOptions(appUploaderOptions);
|
||||
carbonAppUploaderStub.uploadApp(uploadedFileItems);
|
||||
}
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Registry registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId);
|
||||
if (!registry.resourceExists(DEFAULT_RESOURCE_LOCATION + type + ".exist")) {
|
||||
Resource resource = new ResourceImpl();
|
||||
resource.setContent("</exist>");
|
||||
resource.setMediaType(MEDIA_TYPE_XML);
|
||||
registry.put(DEFAULT_RESOURCE_LOCATION + type + ".exist", resource);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity("\"Error, Artifact does not exist.\"").build();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Capp deployment failed due to " + e.getMessage(), e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
"\"Error, Artifact deployment has failed\"").build();
|
||||
}
|
||||
|
||||
return Response.status(Response.Status.CREATED).entity("\"OK. \\n Successfully uploaded the artifacts.\"")
|
||||
.build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/deploy/{type}/status")
|
||||
@Override
|
||||
public Response getStatus(@PathParam("type") String deviceType) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Registry registry = null;
|
||||
try {
|
||||
registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId);
|
||||
if (registry.resourceExists(DEFAULT_RESOURCE_LOCATION + deviceType + ".exist")) {
|
||||
return Response.status(Response.Status.OK).entity("Exist").build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NO_CONTENT).entity("Does not Exist").build();
|
||||
}
|
||||
} catch (RegistryException e) {
|
||||
log.error("Registry failed to load." + e.getMessage(), e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
"\"Error, Artifact status check has failed\"").build();
|
||||
}
|
||||
}
|
||||
|
||||
private UploadedFileItem[] loadCappFromFileSystem(String deviceType) throws IOException {
|
||||
|
||||
File directory = new File(CAR_FILE_LOCATION + File.separator + deviceType);
|
||||
File[] carFiles = directory.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.toLowerCase().endsWith(".car");
|
||||
}
|
||||
});
|
||||
List<UploadedFileItem> uploadedFileItemLis = new ArrayList<>();
|
||||
if (carFiles != null) {
|
||||
|
||||
for (File carFile : carFiles) {
|
||||
UploadedFileItem uploadedFileItem = new UploadedFileItem();
|
||||
DataHandler param = new DataHandler(carFile.toURI().toURL());
|
||||
uploadedFileItem.setDataHandler(param);
|
||||
uploadedFileItem.setFileName(carFile.getName());
|
||||
uploadedFileItem.setFileType("jar");
|
||||
uploadedFileItemLis.add(uploadedFileItem);
|
||||
}
|
||||
}
|
||||
UploadedFileItem[] fileItems = new UploadedFileItem[uploadedFileItemLis.size()];
|
||||
fileItems = uploadedFileItemLis.toArray(fileItems);
|
||||
return fileItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the keystore.
|
||||
*
|
||||
* @param keyStorePath - the path of the keystore
|
||||
* @param ksPassword - the keystore password
|
||||
*/
|
||||
private void loadKeyStore(String keyStorePath, String ksPassword)
|
||||
throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
|
||||
InputStream fis = null;
|
||||
try {
|
||||
keyStorePassword = ksPassword.toCharArray();
|
||||
keyStore = KeyStore.getInstance(KEY_STORE_TYPE);
|
||||
fis = new FileInputStream(keyStorePath);
|
||||
keyStore.load(fis, keyStorePassword);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the trustore
|
||||
*
|
||||
* @param trustStorePath - the trustore path in the filesystem.
|
||||
* @param tsPassword - the truststore password
|
||||
*/
|
||||
private void loadTrustStore(String trustStorePath, String tsPassword)
|
||||
throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
|
||||
|
||||
InputStream fis = null;
|
||||
try {
|
||||
trustStore = KeyStore.getInstance(TRUST_STORE_TYPE);
|
||||
fis = new FileInputStream(trustStorePath);
|
||||
trustStore.load(fis, tsPassword.toCharArray());
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the SSL Context
|
||||
*/
|
||||
private void initSSLConnection() throws NoSuchAlgorithmException, UnrecoverableKeyException,
|
||||
KeyStoreException, KeyManagementException {
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER_TYPE);
|
||||
keyManagerFactory.init(keyStore, keyStorePassword);
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TRUST_MANAGER_TYPE);
|
||||
trustManagerFactory.init(trustStore);
|
||||
|
||||
// Create and initialize SSLContext for HTTPS communication
|
||||
sslContext = SSLContext.getInstance(SSLV3);
|
||||
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
|
||||
SSLContext.setDefault(sslContext);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InitialOperationConfig {
|
||||
private List<String> operations;
|
||||
|
||||
public List<String> getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
public void setOperations(List<String> operations) {
|
||||
this.operations = operations;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common.scope.mgt;
|
||||
|
||||
/**
|
||||
* This exception is used to throw when there is an issue in scope management service.
|
||||
*/
|
||||
public class ScopeManagementException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -315127931137779899L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public ScopeManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public ScopeManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public ScopeManagementException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public ScopeManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ScopeManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.common.scope.mgt;
|
||||
|
||||
import java.util.List;
|
||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
||||
|
||||
/**
|
||||
* This interface contains the basic operations related to scope management.
|
||||
*/
|
||||
public interface ScopeManagementService {
|
||||
|
||||
/**
|
||||
* This method is used to update the given list of scopes.
|
||||
*
|
||||
* @param scopes List of scopes to be updated.
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
void updateScopes(List<Scope> scopes) throws ScopeManagementException;
|
||||
|
||||
/**
|
||||
* This method is used to update the given list of scopes keys with the role name.
|
||||
*
|
||||
* @param scopeKeys List of scopes to be updated.
|
||||
* @param roleName Role name
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
void updateScopes(List<String> scopeKeys, String roleName) throws ScopeManagementException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve all the scopes.
|
||||
*
|
||||
* @return List of scopes.
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
List<Scope> getAllScopes() throws ScopeManagementException;
|
||||
|
||||
/**
|
||||
* This method is to retrieve the roles of the given scope
|
||||
* @param scopeKey key of the scope
|
||||
* @return List of roles
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
String getRolesOfScope(String scopeKey) throws ScopeManagementException;
|
||||
|
||||
/**
|
||||
* This method is to retrieve the scopes of the given role
|
||||
* @param roleName key of the scope
|
||||
* @return List of scopes
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
List<Scope> getScopesOfRole(String roleName) throws ScopeManagementException;
|
||||
|
||||
/**
|
||||
* This method is used to remove the scopes of a given user role.
|
||||
*
|
||||
* @param roleName Role name
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
void removeScopes(String roleName) throws ScopeManagementException;
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Scope implements Serializable {
|
||||
String key;
|
||||
String name;
|
||||
String roles;
|
||||
String description;
|
||||
int id;
|
||||
|
||||
public Scope() {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public void setRoles(String roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue