mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
520529f474
@ -22,13 +22,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - API Management Annotations</name>
|
<name>WSO2 Carbon - API Management Annotations</name>
|
||||||
<description>WSO2 Carbon - API Management Custom Annotation Module</description>
|
<description>WSO2 Carbon - API Management Custom Annotation Module</description>
|
||||||
|
|||||||
@ -21,12 +21,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<artifactId>org.wso2.carbon.apimgt.application.extension.api</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.application.extension.api</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>WSO2 Carbon - API Application Management API</name>
|
<name>WSO2 Carbon - API Application Management API</name>
|
||||||
|
|||||||
@ -22,12 +22,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - API Application Management</name>
|
<name>WSO2 Carbon - API Application Management</name>
|
||||||
|
|||||||
@ -21,13 +21,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.handlers</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.handlers</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - API Security Handler Component</name>
|
<name>WSO2 Carbon - API Security Handler Component</name>
|
||||||
<description>WSO2 Carbon - API Management Security Handler Module</description>
|
<description>WSO2 Carbon - API Management Security Handler Module</description>
|
||||||
|
|||||||
@ -13,13 +13,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - API Management Integration Client</name>
|
<name>WSO2 Carbon - API Management Integration Client</name>
|
||||||
<description>WSO2 Carbon - API Management Integration Client</description>
|
<description>WSO2 Carbon - API Management Integration Client</description>
|
||||||
|
|||||||
@ -13,13 +13,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - API Management Integration Generated Client</name>
|
<name>WSO2 Carbon - API Management Integration Generated Client</name>
|
||||||
<description>WSO2 Carbon - API Management Integration Client</description>
|
<description>WSO2 Carbon - API Management Integration Client</description>
|
||||||
|
|||||||
@ -22,13 +22,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - API Management Webapp Publisher</name>
|
<name>WSO2 Carbon - API Management Webapp Publisher</name>
|
||||||
<description>WSO2 Carbon - API Management Webapp Publisher</description>
|
<description>WSO2 Carbon - API Management Webapp Publisher</description>
|
||||||
|
|||||||
@ -276,7 +276,7 @@ public class APIPublisherUtil {
|
|||||||
if(null != resourcesList) {
|
if(null != resourcesList) {
|
||||||
for (ApiUriTemplate template : templates) {
|
for (ApiUriTemplate template : templates) {
|
||||||
String fullPaath = "";
|
String fullPaath = "";
|
||||||
if( template.getUriTemplate() != AnnotationProcessor.WILD_CARD ) {
|
if (!template.getUriTemplate().equals(AnnotationProcessor.WILD_CARD)) {
|
||||||
fullPaath = apiConfig.getContext() + template.getUriTemplate();
|
fullPaath = apiConfig.getContext() + template.getUriTemplate();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
@ -23,53 +23,7 @@ public class InvalidConfigurationStateException extends RuntimeException {
|
|||||||
|
|
||||||
private static final long serialVersionUID = -3151279311329070397L;
|
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) {
|
public InvalidConfigurationStateException(String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidConfigurationStateException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvalidConfigurationStateException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,20 +25,4 @@ public class WebappPublisherConfigurationFailedException extends Exception {
|
|||||||
public WebappPublisherConfigurationFailedException(String msg, Exception nestedEx) {
|
public WebappPublisherConfigurationFailedException(String msg, Exception nestedEx) {
|
||||||
super(msg, nestedEx);
|
super(msg, nestedEx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebappPublisherConfigurationFailedException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebappPublisherConfigurationFailedException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebappPublisherConfigurationFailedException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebappPublisherConfigurationFailedException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,38 +1,10 @@
|
|||||||
package org.wso2.carbon.apimgt.webapp.publisher.config;
|
package org.wso2.carbon.apimgt.webapp.publisher.config;
|
||||||
|
|
||||||
public class APIResourceManagementException extends Exception{
|
public class APIResourceManagementException extends Exception {
|
||||||
private static final long serialVersionUID = -3151279311929070297L;
|
private static final long serialVersionUID = -3151279311929070297L;
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
public APIResourceManagementException(String msg, Exception nestedEx) {
|
||||||
return errorMessage;
|
super(msg, nestedEx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public APIResourceManagementException(String msg, Exception nestedEx) {
|
|
||||||
super(msg, nestedEx);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public APIResourceManagementException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
setErrorMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public APIResourceManagementException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public APIResourceManagementException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public APIResourceManagementException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,24 +25,7 @@ public class APIManagerPublisherException extends Exception {
|
|||||||
|
|
||||||
private static final long serialVersionUID = -8933142342423122660L;
|
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) {
|
public APIManagerPublisherException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,10 +33,10 @@ import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIIn
|
|||||||
import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIList;
|
import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIList;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiScope;
|
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiScope;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiUriTemplate;
|
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException;
|
import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.utils.Api;
|
import org.wso2.carbon.apimgt.webapp.publisher.utils.MockApi;
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.utils.TestUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -46,8 +46,7 @@ import static org.mockito.Mockito.doReturn;
|
|||||||
/**
|
/**
|
||||||
* This is the test class for {@link APIPublisherServiceImpl}
|
* This is the test class for {@link APIPublisherServiceImpl}
|
||||||
*/
|
*/
|
||||||
public class
|
public class APIPublisherServiceTest extends BaseAPIPublisherTest {
|
||||||
APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|
||||||
private static final Log log = LogFactory.getLog(APIPublisherServiceTest.class);
|
private static final Log log = LogFactory.getLog(APIPublisherServiceTest.class);
|
||||||
private APIPublisherServiceImpl apiPublisherService = new APIPublisherServiceImpl();
|
private APIPublisherServiceImpl apiPublisherService = new APIPublisherServiceImpl();
|
||||||
|
|
||||||
@ -78,7 +77,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|||||||
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
|
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
|
||||||
getPublisherClient();
|
getPublisherClient();
|
||||||
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
||||||
APIsApi apIsApi = Mockito.mock(Api.class, Mockito.CALLS_REAL_METHODS);
|
APIsApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
|
||||||
doReturn(apIsApi).when(publisherClient).getApi();
|
doReturn(apIsApi).when(publisherClient).getApi();
|
||||||
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
|
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
|
||||||
api.setStatus("CREATED");
|
api.setStatus("CREATED");
|
||||||
@ -87,7 +86,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "createAPIListWithNoApi | will fail if there are any exceptions")
|
@Test(description = "createAPIListWithNoApi | will fail if there are any exceptions")
|
||||||
private void publishWithNoAPIListCreated() throws APIManagerPublisherException {
|
public void publishWithNoAPIListCreated() throws APIManagerPublisherException {
|
||||||
APIConfig apiConfig = new APIConfig();
|
APIConfig apiConfig = new APIConfig();
|
||||||
setApiConfigs(apiConfig, "testAPI-2");
|
setApiConfigs(apiConfig, "testAPI-2");
|
||||||
APIPublisherDataHolder apiPublisherDataHolder = Mockito.mock(APIPublisherDataHolder.getInstance().
|
APIPublisherDataHolder apiPublisherDataHolder = Mockito.mock(APIPublisherDataHolder.getInstance().
|
||||||
@ -98,7 +97,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|||||||
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
|
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
|
||||||
getPublisherClient();
|
getPublisherClient();
|
||||||
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
||||||
APIsApi apIsApi = Mockito.mock(Api.class, Mockito.CALLS_REAL_METHODS);
|
APIsApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
|
||||||
doReturn(apIsApi).when(publisherClient).getApi();
|
doReturn(apIsApi).when(publisherClient).getApi();
|
||||||
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
|
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
|
||||||
api.setStatus("CREATED");
|
api.setStatus("CREATED");
|
||||||
@ -116,7 +115,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "createAPIList | will fail if there are any exceptions")
|
@Test(description = "createAPIList | will fail if there are any exceptions")
|
||||||
private void publishWithAPIListCreated() throws APIManagerPublisherException {
|
public void publishWithAPIListCreated() throws APIManagerPublisherException {
|
||||||
APIConfig apiConfig = new APIConfig();
|
APIConfig apiConfig = new APIConfig();
|
||||||
setApiConfigs(apiConfig, "testAPI-3");
|
setApiConfigs(apiConfig, "testAPI-3");
|
||||||
APIPublisherDataHolder apiPublisherDataHolder = Mockito.mock(APIPublisherDataHolder.getInstance().
|
APIPublisherDataHolder apiPublisherDataHolder = Mockito.mock(APIPublisherDataHolder.getInstance().
|
||||||
@ -127,7 +126,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|||||||
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
|
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
|
||||||
getPublisherClient();
|
getPublisherClient();
|
||||||
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
||||||
APIsApi apIsApi = Mockito.mock(Api.class, Mockito.CALLS_REAL_METHODS);
|
APIsApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
|
||||||
doReturn(apIsApi).when(publisherClient).getApi();
|
doReturn(apIsApi).when(publisherClient).getApi();
|
||||||
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
|
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
|
||||||
api.setStatus("CREATED");
|
api.setStatus("CREATED");
|
||||||
@ -149,7 +148,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "publish API with scope added | will fail if there are any exceptions")
|
@Test(description = "publish API with scope added | will fail if there are any exceptions")
|
||||||
private void publishWithAPIScope() throws APIManagerPublisherException {
|
public void publishWithAPIScope() throws APIManagerPublisherException {
|
||||||
APIConfig apiConfig = new APIConfig();
|
APIConfig apiConfig = new APIConfig();
|
||||||
setApiConfigs(apiConfig, "testAPI-4");
|
setApiConfigs(apiConfig, "testAPI-4");
|
||||||
Set<ApiScope> scopes = new HashSet<>();
|
Set<ApiScope> scopes = new HashSet<>();
|
||||||
@ -175,24 +174,8 @@ APIPublisherServiceTest extends BaseAPIPublisherTest {
|
|||||||
Map<String, ApiScope> apiScopes = new HashMap<>();
|
Map<String, ApiScope> apiScopes = new HashMap<>();
|
||||||
Set<ApiScope> scopes = new HashSet<>(apiScopes.values());
|
Set<ApiScope> scopes = new HashSet<>(apiScopes.values());
|
||||||
apiConfig.setScopes(scopes);
|
apiConfig.setScopes(scopes);
|
||||||
setAPIURITemplates(apiConfig);
|
TestUtils util = new TestUtils();
|
||||||
}
|
util.setAPIURITemplates(apiConfig, "/reboot");
|
||||||
|
|
||||||
private void setAPIURITemplates(APIConfig apiConfig) {
|
|
||||||
Set<ApiUriTemplate> uriTemplates = new LinkedHashSet<>();
|
|
||||||
ApiUriTemplate template = new ApiUriTemplate();
|
|
||||||
template.setAuthType("Application & Application User");
|
|
||||||
template.setHttpVerb("POST");
|
|
||||||
template.setResourceURI("https://localhost:9443/api/device-mgt/windows/v1.0/admin/devices/reboot");
|
|
||||||
template.setUriTemplate("/reboot");
|
|
||||||
ApiScope scope = new ApiScope();
|
|
||||||
scope.setKey("perm:windows:reboot");
|
|
||||||
scope.setName("Reboot");
|
|
||||||
scope.setRoles("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot");
|
|
||||||
scope.setDescription("Lock reset on Windows devices");
|
|
||||||
template.setScope(scope);
|
|
||||||
uriTemplates.add(template);
|
|
||||||
apiConfig.setUriTemplates(uriTemplates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeOAuthApplication() throws NoSuchFieldException, IllegalAccessException {
|
private void initializeOAuthApplication() throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
|||||||
@ -18,35 +18,40 @@
|
|||||||
package org.wso2.carbon.apimgt.webapp.publisher;
|
package org.wso2.carbon.apimgt.webapp.publisher;
|
||||||
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.AfterClass;
|
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiScope;
|
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiScope;
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiUriTemplate;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException;
|
import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.utils.MockServletContext;
|
import org.wso2.carbon.apimgt.webapp.publisher.utils.MockServletContext;
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.utils.TestUtils;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
||||||
import org.wso2.carbon.user.api.RealmConfiguration;
|
import org.wso2.carbon.user.api.RealmConfiguration;
|
||||||
import org.wso2.carbon.user.api.UserRealm;
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil.buildApiConfig;
|
import static org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil.buildApiConfig;
|
||||||
|
import static org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil.getApiEndpointUrl;
|
||||||
|
import static org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil.setResourceAuthTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the test class for {@link APIPublisherUtil}
|
* This is the test class for {@link APIPublisherUtil}
|
||||||
*/
|
*/
|
||||||
public class APIPublisherUtilTest extends BaseAPIPublisherTest {
|
public class APIPublisherUtilTest extends BaseAPIPublisherTest {
|
||||||
|
|
||||||
|
private static final String AUTH_TYPE_NON_SECURED = "None";
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
public void initialConfigs() throws WebappPublisherConfigurationFailedException,
|
public void initialConfigs() throws WebappPublisherConfigurationFailedException,
|
||||||
org.wso2.carbon.user.core.UserStoreException, RegistryException {
|
org.wso2.carbon.user.core.UserStoreException, RegistryException {
|
||||||
@ -55,7 +60,7 @@ public class APIPublisherUtilTest extends BaseAPIPublisherTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "test buildAPIConfig method and ensures an APIConfig is created")
|
@Test(description = "test buildAPIConfig method and ensures an APIConfig is created")
|
||||||
private void buildApiConfigTest() throws UserStoreException, RegistryException {
|
public void buildApiConfigTest() throws UserStoreException, RegistryException {
|
||||||
try {
|
try {
|
||||||
startTenantFlowAsTestTenant();
|
startTenantFlowAsTestTenant();
|
||||||
ServletContext servletContext = new MockServletContext();
|
ServletContext servletContext = new MockServletContext();
|
||||||
@ -71,7 +76,7 @@ public class APIPublisherUtilTest extends BaseAPIPublisherTest {
|
|||||||
|
|
||||||
@Test(description = "test buildAPIConfig method as SuperTenant and ensures" +
|
@Test(description = "test buildAPIConfig method as SuperTenant and ensures" +
|
||||||
" an APIConfig is created")
|
" an APIConfig is created")
|
||||||
private void buildApiConfigAsSuperTenat() throws UserStoreException {
|
public void buildApiConfigAsSuperTenant() throws UserStoreException {
|
||||||
ServletContext servletContext = new MockServletContext();
|
ServletContext servletContext = new MockServletContext();
|
||||||
APIResourceConfiguration apiDef = new APIResourceConfiguration();
|
APIResourceConfiguration apiDef = new APIResourceConfiguration();
|
||||||
List<APIResource> resources = new ArrayList<>();
|
List<APIResource> resources = new ArrayList<>();
|
||||||
@ -82,7 +87,7 @@ public class APIPublisherUtilTest extends BaseAPIPublisherTest {
|
|||||||
|
|
||||||
@Test(description = "test buildAPIConfig with API tags specified and ensures " +
|
@Test(description = "test buildAPIConfig with API tags specified and ensures " +
|
||||||
"an APIConfig is created")
|
"an APIConfig is created")
|
||||||
private void buildApiConfigTestWithTags() throws UserStoreException {
|
public void buildApiConfigTestWithTags() throws UserStoreException {
|
||||||
ServletContext servletContext = new MockServletContext();
|
ServletContext servletContext = new MockServletContext();
|
||||||
APIResourceConfiguration apiDef = new APIResourceConfiguration();
|
APIResourceConfiguration apiDef = new APIResourceConfiguration();
|
||||||
List<APIResource> resources = new ArrayList<>();
|
List<APIResource> resources = new ArrayList<>();
|
||||||
@ -96,7 +101,7 @@ public class APIPublisherUtilTest extends BaseAPIPublisherTest {
|
|||||||
|
|
||||||
@Test(description = "test buildAPIConfig method with API scopes specified and " +
|
@Test(description = "test buildAPIConfig method with API scopes specified and " +
|
||||||
"ensures an APIConfig is created")
|
"ensures an APIConfig is created")
|
||||||
private void buildApiConfigTestWithScope() throws UserStoreException, APIManagerPublisherException {
|
public void buildApiConfigTestWithScope() throws UserStoreException, APIManagerPublisherException {
|
||||||
ServletContext servletContext = new MockServletContext();
|
ServletContext servletContext = new MockServletContext();
|
||||||
APIResourceConfiguration apiDef = new APIResourceConfiguration();
|
APIResourceConfiguration apiDef = new APIResourceConfiguration();
|
||||||
List<APIResource> resources = new ArrayList<>();
|
List<APIResource> resources = new ArrayList<>();
|
||||||
@ -111,6 +116,38 @@ public class APIPublisherUtilTest extends BaseAPIPublisherTest {
|
|||||||
Assert.assertNotNull(apiConfig, "API configuration is null.");
|
Assert.assertNotNull(apiConfig, "API configuration is null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(description = "test method for setResourceAuthTypes")
|
||||||
|
public void testSetResourceAuthTypes() throws UserStoreException {
|
||||||
|
ServletContext servletContext = new MockServletContext();
|
||||||
|
APIResourceConfiguration apiDef = new APIResourceConfiguration();
|
||||||
|
List<APIResource> resources = new ArrayList<>();
|
||||||
|
apiDef.setResources(resources);
|
||||||
|
APIConfig apiConfig = buildApiConfig(servletContext, apiDef);
|
||||||
|
apiConfig.setContext("/*");
|
||||||
|
TestUtils util = new TestUtils();
|
||||||
|
util.setAPIURITemplates(apiConfig, "/*");
|
||||||
|
Assert.assertNotNull(apiConfig, "API configuration is null.");
|
||||||
|
setResourceAuthTypes(servletContext, apiConfig);
|
||||||
|
Set<ApiUriTemplate> templates = apiConfig.getUriTemplates();
|
||||||
|
Assert.assertEquals(templates.iterator().next().getAuthType(), AUTH_TYPE_NON_SECURED, "Resource " +
|
||||||
|
"auth type is not properly set");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "test the method getApiEndpointUrl")
|
||||||
|
public void testGetApiEndpointUrl() {
|
||||||
|
String context = "/reboot";
|
||||||
|
String url = getApiEndpointUrl(context);
|
||||||
|
Assert.assertEquals(url, "https://localhost:9445/reboot", "Expected url " +
|
||||||
|
"is not same as actual url");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = WebappPublisherConfigurationFailedException.class, description =
|
||||||
|
"this tests the method convertToDocument with a undefined file name and ensures an " +
|
||||||
|
"exception occurs ")
|
||||||
|
public void testConvertToDocumentForException() throws WebappPublisherConfigurationFailedException {
|
||||||
|
WebappPublisherUtil.convertToDocument(null);
|
||||||
|
}
|
||||||
|
|
||||||
private void setUserRealm() throws RegistryException, org.wso2.carbon.user.core.UserStoreException {
|
private void setUserRealm() throws RegistryException, org.wso2.carbon.user.core.UserStoreException {
|
||||||
RealmConfiguration configuration = new RealmConfiguration();
|
RealmConfiguration configuration = new RealmConfiguration();
|
||||||
UserRealm userRealm = new InMemoryRealmService().getUserRealm(configuration);
|
UserRealm userRealm = new InMemoryRealmService().getUserRealm(configuration);
|
||||||
|
|||||||
@ -28,7 +28,7 @@ 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.service.IntegrationClientService;
|
||||||
import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIsApi;
|
import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIsApi;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.utils.Api;
|
import org.wso2.carbon.apimgt.webapp.publisher.utils.MockApi;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.context.internal.OSGiDataHolder;
|
import org.wso2.carbon.context.internal.OSGiDataHolder;
|
||||||
@ -87,7 +87,7 @@ public abstract class BaseAPIPublisherTest {
|
|||||||
PublisherClient publisherClient = Mockito.mock(PublisherClient.class, Mockito.CALLS_REAL_METHODS);
|
PublisherClient publisherClient = Mockito.mock(PublisherClient.class, Mockito.CALLS_REAL_METHODS);
|
||||||
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
|
||||||
|
|
||||||
APIsApi api = new Api();
|
APIsApi api = new MockApi();
|
||||||
Field field = PublisherClient.class.getDeclaredField("api");
|
Field field = PublisherClient.class.getDeclaredField("api");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(publisherClient, api);
|
field.set(publisherClient, api);
|
||||||
|
|||||||
@ -25,9 +25,9 @@ import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.FileI
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to create Api for testing.
|
* Class to create MockApi for testing.
|
||||||
*/
|
*/
|
||||||
public class Api implements APIsApi {
|
public class MockApi implements APIsApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apisApiIdDelete(String apiId, String ifMatch, String ifUnmodifiedSince) {
|
public void apisApiIdDelete(String apiId, String ifMatch, String ifUnmodifiedSince) {
|
||||||
@ -130,7 +130,7 @@ public class MockServletContext implements ServletContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInitParameter(String s) {
|
public String getInitParameter(String s) {
|
||||||
return "true";
|
return "/*";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.publisher.utils;
|
||||||
|
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.APIConfig;
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiScope;
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiUriTemplate;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains util methods for webAppPublisher tests.
|
||||||
|
*/
|
||||||
|
public class TestUtils {
|
||||||
|
|
||||||
|
public void setAPIURITemplates(APIConfig apiConfig, String uriTemplate) {
|
||||||
|
Set<ApiUriTemplate> uriTemplates = new LinkedHashSet<>();
|
||||||
|
ApiUriTemplate template = new ApiUriTemplate();
|
||||||
|
template.setAuthType("Application & Application User");
|
||||||
|
template.setHttpVerb("POST");
|
||||||
|
template.setResourceURI("https://localhost:9443/api/device-mgt/windows/v1.0/admin/devices/reboot");
|
||||||
|
template.setUriTemplate(uriTemplate);
|
||||||
|
ApiScope scope = new ApiScope();
|
||||||
|
scope.setKey("perm:windows:reboot");
|
||||||
|
scope.setName("Reboot");
|
||||||
|
scope.setRoles("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot");
|
||||||
|
scope.setDescription("Lock reset on Windows devices");
|
||||||
|
template.setScope(scope);
|
||||||
|
uriTemplates.add(template);
|
||||||
|
apiConfig.setUriTemplates(uriTemplates);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,7 +24,7 @@
|
|||||||
<WebappPublisherConfigs>
|
<WebappPublisherConfigs>
|
||||||
|
|
||||||
<!-- This host is used to define the host address which is used to publish APIs -->
|
<!-- This host is used to define the host address which is used to publish APIs -->
|
||||||
<Host>https://${iot.core.host}:${iot.core.https.port}</Host>
|
<Host>https://localhost:9445</Host>
|
||||||
|
|
||||||
<!-- If it is true, the APIs of this instance will be published to the defined host -->
|
<!-- If it is true, the APIs of this instance will be published to the defined host -->
|
||||||
<PublishAPI>true</PublishAPI>
|
<PublishAPI>true</PublishAPI>
|
||||||
|
|||||||
@ -22,13 +22,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>WSO2 Carbon - API Management Extensions Component</name>
|
<name>WSO2 Carbon - API Management Extensions Component</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,13 +21,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - Certificate Management Core</name>
|
<name>WSO2 Carbon - Certificate Management Core</name>
|
||||||
<description>WSO2 Carbon - Certificate Management Core</description>
|
<description>WSO2 Carbon - Certificate Management Core</description>
|
||||||
@ -94,7 +94,8 @@
|
|||||||
io.swagger.annotations.*;resolution:=optional,
|
io.swagger.annotations.*;resolution:=optional,
|
||||||
org.wso2.carbon.device.mgt.core.*,
|
org.wso2.carbon.device.mgt.core.*,
|
||||||
org.wso2.carbon.registry.indexing.*,
|
org.wso2.carbon.registry.indexing.*,
|
||||||
javax.cache.*
|
javax.cache.*,
|
||||||
|
javax.naming.ldap
|
||||||
<!--org.bouncycastle.pkcs.jcajce-->
|
<!--org.bouncycastle.pkcs.jcajce-->
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
<Export-Package>
|
<Export-Package>
|
||||||
|
|||||||
@ -61,6 +61,9 @@ import org.wso2.carbon.certificate.mgt.core.util.CommonUtil;
|
|||||||
import org.wso2.carbon.certificate.mgt.core.util.Serializer;
|
import org.wso2.carbon.certificate.mgt.core.util.Serializer;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
|
import javax.naming.InvalidNameException;
|
||||||
|
import javax.naming.ldap.LdapName;
|
||||||
|
import javax.naming.ldap.Rdn;
|
||||||
import javax.security.auth.x500.X500Principal;
|
import javax.security.auth.x500.X500Principal;
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -112,7 +115,7 @@ public class CertificateGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException | IOException e) {
|
} catch (ClassNotFoundException | IOException e) {
|
||||||
String errorMsg = "Error while deserializing the certificate.";
|
String errorMsg = "Error while during deserialization of the certificate.";
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,10 +323,20 @@ public class CertificateGenerator {
|
|||||||
CertificateResponse lookUpCertificate = null;
|
CertificateResponse lookUpCertificate = null;
|
||||||
KeyStoreReader keyStoreReader = new KeyStoreReader();
|
KeyStoreReader keyStoreReader = new KeyStoreReader();
|
||||||
if (distinguishedName != null && !distinguishedName.isEmpty()) {
|
if (distinguishedName != null && !distinguishedName.isEmpty()) {
|
||||||
String[] dnSplits = distinguishedName.split("/CN=");
|
LdapName ldapName;
|
||||||
if (dnSplits != null) {
|
try {
|
||||||
String commonNameExtracted = dnSplits[dnSplits.length - 1];
|
ldapName = new LdapName(distinguishedName);
|
||||||
lookUpCertificate = keyStoreReader.getCertificateBySerial(commonNameExtracted);
|
} catch (InvalidNameException e) {
|
||||||
|
throw new KeystoreException(
|
||||||
|
"Invalid name exception while trying to create a LDAP name using the distinguished name ", e);
|
||||||
|
}
|
||||||
|
for (Rdn relativeDistinuguishedNames : ldapName.getRdns()) {
|
||||||
|
if (relativeDistinuguishedNames.getType().equalsIgnoreCase("CN")) {
|
||||||
|
System.err.println("CN is: " + relativeDistinuguishedNames.getValue());
|
||||||
|
lookUpCertificate = keyStoreReader
|
||||||
|
.getCertificateBySerial(String.valueOf(relativeDistinuguishedNames.getValue()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lookUpCertificate;
|
return lookUpCertificate;
|
||||||
@ -409,21 +422,8 @@ public class CertificateGenerator {
|
|||||||
Date validityEndDate = commonUtil.getValidityEndDate();
|
Date validityEndDate = commonUtil.getValidityEndDate();
|
||||||
|
|
||||||
X500Name certSubject = new X500Name(CertificateManagementConstants.DEFAULT_PRINCIPAL);
|
X500Name certSubject = new X500Name(CertificateManagementConstants.DEFAULT_PRINCIPAL);
|
||||||
//X500Name certSubject = request.getSubject();
|
|
||||||
|
|
||||||
Attribute attributes[] = request.getAttributes();
|
Attribute attributes[] = request.getAttributes();
|
||||||
|
|
||||||
// if (certSubject == null) {
|
|
||||||
// certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
|
|
||||||
// } else {
|
|
||||||
// org.bouncycastle.asn1.x500.RDN[] rdn = certSubject.getRDNs();
|
|
||||||
//
|
|
||||||
// if (rdn == null || rdn.length == 0) {
|
|
||||||
// certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
RDN[] certUniqueIdRDN;
|
RDN[] certUniqueIdRDN;
|
||||||
BigInteger certUniqueIdentifier;
|
BigInteger certUniqueIdentifier;
|
||||||
|
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>WSO2 Carbon - Certificate Management Component</name>
|
<name>WSO2 Carbon - Certificate Management Component</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -150,7 +150,15 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<suiteXmlFiles>
|
||||||
|
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||||
|
</suiteXmlFiles>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -75,6 +75,18 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
<suiteXmlFiles>
|
||||||
|
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||||
|
</suiteXmlFiles>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@ -148,11 +160,6 @@
|
|||||||
<artifactId>cxf-rt-transports-http</artifactId>
|
<artifactId>cxf-rt-transports-http</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-httpclient.wso2</groupId>
|
<groupId>commons-httpclient.wso2</groupId>
|
||||||
<artifactId>commons-httpclient</artifactId>
|
<artifactId>commons-httpclient</artifactId>
|
||||||
@ -212,6 +219,14 @@
|
|||||||
<groupId>org.apache.axis2.wso2</groupId>
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
<artifactId>axis2-client</artifactId>
|
<artifactId>axis2-client</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>javassist</groupId>
|
||||||
|
<artifactId>javassist</artifactId>
|
||||||
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -223,6 +238,14 @@
|
|||||||
<groupId>org.apache.axis2.wso2</groupId>
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
<artifactId>axis2-client</artifactId>
|
<artifactId>axis2-client</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -249,6 +272,12 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
@ -378,6 +407,15 @@
|
|||||||
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-module-testng</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-api-mockito</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
|
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementAdminService;
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementAdminService;
|
||||||
@ -89,8 +88,6 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
|
|||||||
String msg = "Error occurred at server side while adding a device type.";
|
String msg = "Error occurred at server side while adding a device type.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(msg).build();
|
return Response.serverError().entity(msg).build();
|
||||||
} catch (InvalidConfigurationException e) {
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
@ -114,8 +111,6 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
|
|||||||
String msg = "Error occurred at server side while updating the device type.";
|
String msg = "Error occurred at server side while updating the device type.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(msg).build();
|
return Response.serverError().entity(msg).build();
|
||||||
} catch (InvalidConfigurationException e) {
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
|||||||
@ -101,7 +101,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class DeviceMgtAPIUtils {
|
public class DeviceMgtAPIUtils {
|
||||||
|
|
||||||
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON_TYPE;
|
|
||||||
private static final String NOTIFIER_FREQUENCY = "notifierFrequency";
|
private static final String NOTIFIER_FREQUENCY = "notifierFrequency";
|
||||||
private static final String STREAM_DEFINITION_PREFIX = "iot.per.device.stream.";
|
private static final String STREAM_DEFINITION_PREFIX = "iot.per.device.stream.";
|
||||||
private static final String DEFAULT_HTTP_PROTOCOL = "https";
|
private static final String DEFAULT_HTTP_PROTOCOL = "https";
|
||||||
|
|||||||
@ -0,0 +1,315 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.IObjectFactory;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.ObjectFactory;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import static org.mockito.MockitoAnnotations.initMocks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class includes unit tests for testing the functionality of {@link DeviceManagementServiceImpl}
|
||||||
|
*/
|
||||||
|
@PowerMockIgnore("javax.ws.rs.*")
|
||||||
|
@SuppressStaticInitializationFor({"org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils",
|
||||||
|
"org.wso2.carbon.context.CarbonContext"})
|
||||||
|
@PrepareForTest({DeviceMgtAPIUtils.class, MultitenantUtils.class, CarbonContext.class})
|
||||||
|
public class DeviceManagementServiceImplTest {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceManagementServiceImplTest.class);
|
||||||
|
private static final String TEST_DEVICE_TYPE = "TEST-DEVICE-TYPE";
|
||||||
|
private static final String TEST_DEVICE_NAME = "TEST-DEVICE";
|
||||||
|
private static final String DEFAULT_USERNAME = "admin";
|
||||||
|
private static final String TENANT_AWARE_USERNAME = "admin@carbon.super";
|
||||||
|
private static final String DEFAULT_ROLE = "admin";
|
||||||
|
private static final String DEFAULT_OWNERSHIP = "BYOD";
|
||||||
|
private static final String DEFAULT_STATUS = "ACTIVE";
|
||||||
|
private static final String DEFAULT_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||||
|
private DeviceManagementService deviceManagementService;
|
||||||
|
private DeviceAccessAuthorizationService deviceAccessAuthorizationService;
|
||||||
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
|
||||||
|
@ObjectFactory
|
||||||
|
public IObjectFactory getObjectFactory() {
|
||||||
|
return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() throws Exception {
|
||||||
|
log.info("Initializing DeviceManagementServiceImpl tests");
|
||||||
|
initMocks(this);
|
||||||
|
this.deviceManagementProviderService = Mockito
|
||||||
|
.mock(DeviceManagementProviderServiceImpl.class, Mockito.RETURNS_MOCKS);
|
||||||
|
this.deviceManagementService = new DeviceManagementServiceImpl();
|
||||||
|
this.deviceAccessAuthorizationService = Mockito.mock(DeviceAccessAuthorizationServiceImpl.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing if the device is enrolled when the device is enrolled.")
|
||||||
|
public void testIsEnrolledWhenDeviceIsEnrolled() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
||||||
|
.thenReturn(true);
|
||||||
|
Response response = this.deviceManagementService.isEnrolled(TEST_DEVICE_TYPE, UUID.randomUUID().toString());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
Mockito.reset(this.deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing if the device is enrolled when the device is not enrolled.",
|
||||||
|
dependsOnMethods = "testIsEnrolledWhenDeviceIsEnrolled")
|
||||||
|
public void testIsEnrolledWhenDeviceIsNotEnrolled() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
||||||
|
.thenReturn(false);
|
||||||
|
Response response = this.deviceManagementService.isEnrolled(TEST_DEVICE_TYPE, UUID.randomUUID().toString());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
|
||||||
|
Mockito.reset(this.deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing if the device enrolled api when exception occurred.",
|
||||||
|
dependsOnMethods = "testIsEnrolledWhenDeviceIsNotEnrolled")
|
||||||
|
public void testIsEnrolledError() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
||||||
|
.thenThrow(new DeviceManagementException());
|
||||||
|
Response response = this.deviceManagementService.isEnrolled(TEST_DEVICE_TYPE, UUID.randomUUID().toString());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
Mockito.reset(this.deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices when request exists both name and role.")
|
||||||
|
public void testGetDevicesWhenBothNameAndRoleAvailable() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices with correct request.")
|
||||||
|
public void testGetDevices() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
|
||||||
|
.toReturn(TENANT_AWARE_USERNAME);
|
||||||
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
||||||
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
||||||
|
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, null, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, null, null, null, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, null, null, null, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, true, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices when DeviceAccessAuthorizationService is not available")
|
||||||
|
public void testGetDevicesWithErroneousDeviceAccessAuthorizationService() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(null);
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices when user is the device admin")
|
||||||
|
public void testGetDevicesWhenUserIsAdmin() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
|
||||||
|
.toReturn(TENANT_AWARE_USERNAME);
|
||||||
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
||||||
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
||||||
|
Mockito.when(deviceAccessAuthorizationService.isDeviceAdminUser()).thenReturn(true);
|
||||||
|
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, null, DEFAULT_USERNAME, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices when user is unauthorized.")
|
||||||
|
public void testGetDevicesWhenUserIsUnauthorized() throws Exception {
|
||||||
|
PowerMockito.spy(MultitenantUtils.class);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
||||||
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
||||||
|
PowerMockito.doReturn(TENANT_AWARE_USERNAME)
|
||||||
|
.when(MultitenantUtils.class, "getTenantAwareUsername", DEFAULT_USERNAME);
|
||||||
|
PowerMockito.doReturn("newuser@carbon.super").when(MultitenantUtils.class, "getTenantAwareUsername", "newuser");
|
||||||
|
Mockito.when(this.deviceAccessAuthorizationService.isDeviceAdminUser()).thenReturn(false);
|
||||||
|
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, "newuser", null, DEFAULT_ROLE, DEFAULT_OWNERSHIP, DEFAULT_STATUS, 1,
|
||||||
|
null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
Mockito.reset(this.deviceAccessAuthorizationService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices with IF-Modified-Since")
|
||||||
|
public void testGetDevicesWithModifiedSince() throws Exception {
|
||||||
|
String ifModifiedSince = new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(new Date());
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
|
||||||
|
.toReturn(TENANT_AWARE_USERNAME);
|
||||||
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
||||||
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
||||||
|
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, ifModifiedSince, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, ifModifiedSince, true, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, "ErrorModifiedSince", false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices with Since")
|
||||||
|
public void testGetDevicesWithSince() throws Exception {
|
||||||
|
String since = new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(new Date());
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
|
||||||
|
.toReturn(TENANT_AWARE_USERNAME);
|
||||||
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
||||||
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
||||||
|
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, since, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, since, null, true, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, "ErrorSince", null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices when unable to retrieve devices")
|
||||||
|
public void testGetDeviceServerErrorWhenGettingDeviceList() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
|
||||||
|
.toReturn(TENANT_AWARE_USERNAME);
|
||||||
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
||||||
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getAllDevices(Mockito.any(PaginationRequest.class), Mockito.anyBoolean()))
|
||||||
|
.thenThrow(new DeviceManagementException());
|
||||||
|
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
Mockito.reset(this.deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get devices when unable to check if the user is the admin user")
|
||||||
|
public void testGetDevicesServerErrorWhenCheckingAdminUser() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
||||||
|
.toReturn(this.deviceAccessAuthorizationService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
|
||||||
|
.toReturn(TENANT_AWARE_USERNAME);
|
||||||
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
||||||
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
||||||
|
Mockito.when(this.deviceAccessAuthorizationService.isDeviceAdminUser())
|
||||||
|
.thenThrow(new DeviceAccessAuthorizationException());
|
||||||
|
|
||||||
|
Response response = this.deviceManagementService
|
||||||
|
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
|
||||||
|
DEFAULT_STATUS, 1, null, null, false, 10, 5);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
Mockito.reset(this.deviceAccessAuthorizationService);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,252 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.IObjectFactory;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.ObjectFactory;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeGeneratorServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementAdminService;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceTypeManagementAdminServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.DeviceMgtAPITestHelper;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import static org.mockito.MockitoAnnotations.initMocks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds the unit tests for the class {@link DeviceTypeManagementAdminService}
|
||||||
|
*/
|
||||||
|
@PowerMockIgnore("javax.ws.rs.*")
|
||||||
|
@SuppressStaticInitializationFor({"org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils"})
|
||||||
|
@PrepareForTest({DeviceMgtAPIUtils.class, DeviceManagementProviderService.class})
|
||||||
|
public class DeviceTypeManagementAdminServiceTest {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceTypeManagementAdminService.class);
|
||||||
|
private static final String TEST_DEVICE_TYPE = "TEST-DEVICE-TYPE";
|
||||||
|
private static final String TEST_DEVICE_TYPE_1 = "DUMMY-DEVICE-TYPE-1";
|
||||||
|
private static final String TEST_DEVICE_TYPE_2 = "DUMMY DEVICE TYPE";
|
||||||
|
private static final int TEST_DEVICE_TYPE_ID = 12345;
|
||||||
|
private static final int TEST_DEVICE_TYPE_ID_1 = 123452;
|
||||||
|
private static final int TEST_DEVICE_TYPE_ID_2 = 121233452;
|
||||||
|
private DeviceTypeManagementAdminService deviceTypeManagementAdminService;
|
||||||
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
private DeviceTypeGeneratorService deviceTypeGeneratorService;
|
||||||
|
|
||||||
|
@ObjectFactory
|
||||||
|
public IObjectFactory getObjectFactory() {
|
||||||
|
return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() throws DeviceManagementException {
|
||||||
|
log.info("Initializing DeviceTypeManagementAdmin tests");
|
||||||
|
initMocks(this);
|
||||||
|
this.deviceManagementProviderService = Mockito
|
||||||
|
.mock(DeviceManagementProviderServiceImpl.class, Mockito.RETURNS_MOCKS);
|
||||||
|
this.deviceTypeGeneratorService = Mockito.mock(DeviceTypeGeneratorServiceImpl.class, Mockito.RETURNS_MOCKS);
|
||||||
|
this.deviceTypeManagementAdminService = new DeviceTypeManagementAdminServiceImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test get all the device types.")
|
||||||
|
public void testGetDeviceTypes() {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementAdminService.getDeviceTypes();
|
||||||
|
|
||||||
|
log.info(response.getEntity());
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "The Response status code " +
|
||||||
|
"should be 200.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the error scenario of getting all the device types.")
|
||||||
|
public void testGetDeviceTypesError() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
Mockito.when(deviceManagementProviderService.getDeviceTypes()).thenThrow(new DeviceManagementException());
|
||||||
|
Response response = this.deviceTypeManagementAdminService.getDeviceTypes();
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
|
"The expected status code is 500.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the new device type creation scenario.")
|
||||||
|
public void testAddDeviceTypeWithExistingName() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE_1, TEST_DEVICE_TYPE_ID_1);
|
||||||
|
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
|
||||||
|
|
||||||
|
log.info(response.getEntity());
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CONFLICT.getStatusCode(),
|
||||||
|
"The Response Status code should be 409.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the new device type creation scenario when device type name is unqualified.")
|
||||||
|
public void testAddDeviceTypeWithUnqualifiedName() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE_2, TEST_DEVICE_TYPE_ID_2);
|
||||||
|
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
|
||||||
|
|
||||||
|
log.info(response.getEntity());
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
|
"The Response Status code should be 400.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test creating a new device type success scenario.")
|
||||||
|
public void testAddDeviceType() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
|
||||||
|
.toReturn(this.deviceTypeGeneratorService);
|
||||||
|
|
||||||
|
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
|
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
|
"The Response Status code should be 200.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the create device type scenario when the device type is null.")
|
||||||
|
public void testAddDeviceTypeWithNoDeviceType() {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementAdminService.addDeviceType(null);
|
||||||
|
|
||||||
|
log.info(response.getEntity());
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
|
"The Response Status code should be 409.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the device type creation scenario with Device Management exception.")
|
||||||
|
public void testAddDeviceTypeWithException() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenThrow(new
|
||||||
|
DeviceManagementException());
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
|
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
|
"The Response Status code should be 500.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the update device type scenario.")
|
||||||
|
public void testUpdateDeviceType() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
|
||||||
|
.toReturn(this.deviceTypeGeneratorService);
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
|
"The Response Status code should be 200.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the update device type scenario.")
|
||||||
|
public void testUpdateNonExistingDeviceType() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
|
||||||
|
.toReturn(this.deviceTypeGeneratorService);
|
||||||
|
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
|
"The Response Status code should be 400.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test update device Type when device type is null")
|
||||||
|
public void testUpdateDeviceTypeWithNullDeviceType() {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(null);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
|
"The Response Status code should be 400.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test update device Type with DeviceManagementException")
|
||||||
|
public void testUpdateDeviceTypeWithException() throws DeviceManagementException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString()))
|
||||||
|
.thenThrow(new DeviceManagementException());
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
|
"The Response Status code should be 500.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,236 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.IObjectFactory;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.ObjectFactory;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceTypeManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.DeviceMgtAPITestHelper;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mockito.MockitoAnnotations.initMocks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds the unit tests for the class {@link DeviceTypeManagementService}
|
||||||
|
*/
|
||||||
|
@PowerMockIgnore("javax.ws.rs.*")
|
||||||
|
@SuppressStaticInitializationFor({"org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils"})
|
||||||
|
@PrepareForTest({DeviceMgtAPIUtils.class, DeviceManagementProviderService.class})
|
||||||
|
public class DeviceTypeManagementServiceTest {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceManagementServiceImplTest.class);
|
||||||
|
private static final String TEST_DEVICE_TYPE = "TEST-DEVICE-TYPE";
|
||||||
|
private static final int TEST_DEVICE_TYPE_ID = 12345;
|
||||||
|
private static final String MODIFIED_SINCE = "1234503934242";
|
||||||
|
private DeviceTypeManagementService deviceTypeManagementService;
|
||||||
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
|
||||||
|
@ObjectFactory
|
||||||
|
public IObjectFactory getObjectFactory() {
|
||||||
|
return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() throws DeviceManagementException {
|
||||||
|
log.info("Initializing DeviceTypeManagement tests");
|
||||||
|
initMocks(this);
|
||||||
|
this.deviceManagementProviderService = Mockito
|
||||||
|
.mock(DeviceManagementProviderServiceImpl.class, Mockito.RETURNS_MOCKS);
|
||||||
|
this.deviceTypeManagementService = new DeviceTypeManagementServiceImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing for existing device types.")
|
||||||
|
public void testExistingDeviceType() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypes("");
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
|
"The response states should be 200.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get existing device types error")
|
||||||
|
public void testExistingDeviceTypesError() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenThrow(new DeviceManagementException());
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypes();
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
|
"The response status should be 500.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Testing get existing device types error")
|
||||||
|
public void testExistingDeviceTypesModifiedError() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenThrow(new
|
||||||
|
DeviceManagementException());
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypes(MODIFIED_SINCE);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
|
"The response status should be 500.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test case to retrieve the Features of specified device type.")
|
||||||
|
public void testGetDeviceTypeFeatures() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
|
"The response status should be 200.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test case to test the error scenario when retrieving the Features of specified device type.")
|
||||||
|
public void testGetDeviceTypeFeaturesError() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
FeatureManager featureManager = Mockito.mock(FeatureManager.class);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn
|
||||||
|
(featureManager);
|
||||||
|
Mockito.when((featureManager).getFeatures()).thenThrow(new DeviceManagementException());
|
||||||
|
Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
|
"The response status should be 500.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
Mockito.reset(featureManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test getting device type features when feature manager is null.")
|
||||||
|
public void testGetDeviceTypeFeaturesWithNoFeatureManager() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn(null);
|
||||||
|
Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||||
|
"The response status should be 404.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test to get all the device types.")
|
||||||
|
public void testGetDeviceTypes() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypes();
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
|
"The response status should be 200.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test to get all the device types.")
|
||||||
|
public void testGetDeviceTypesWithDeviceTypes() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
|
||||||
|
List<DeviceType> deviceTypes = DeviceMgtAPITestHelper.getDummyDeviceTypeList(5);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenReturn(deviceTypes);
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypes();
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
|
"The response state should be 200");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test to get all the device types for the given name")
|
||||||
|
public void testGetDeviceTypeByName() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypeByName(TEST_DEVICE_TYPE);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
|
"The response status should be 200.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the scenario when there are no device types for the given name.")
|
||||||
|
public void testGetDeviceTypeByNameError() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypeByName(TEST_DEVICE_TYPE);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode(),
|
||||||
|
"The response status should be 204.");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test the scenario when there are no device types for the given name.")
|
||||||
|
public void testGetDeviceTypeByNameException() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString()))
|
||||||
|
.thenThrow(new DeviceManagementException());
|
||||||
|
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypeByName(TEST_DEVICE_TYPE);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
|
"The response status should be 500");
|
||||||
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test to get all the device types when given name is null")
|
||||||
|
public void testGetDeviceTypeByNameBadRequest() throws Exception {
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Response response = this.deviceTypeManagementService.getDeviceTypeByName(null);
|
||||||
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
|
"The response status should be 400");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test to clear the sensitive metadata information of device type")
|
||||||
|
public void testClearMetaEntryInfo() throws NoSuchMethodException, InvocationTargetException,
|
||||||
|
IllegalAccessException {
|
||||||
|
Method clearMetaEntryInfo = DeviceTypeManagementServiceImpl.class.getDeclaredMethod("clearMetaEntryInfo",
|
||||||
|
DeviceType.class);
|
||||||
|
clearMetaEntryInfo.setAccessible(true);
|
||||||
|
|
||||||
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
|
DeviceType returned = (DeviceType) clearMetaEntryInfo.invoke(this.deviceTypeManagementService, deviceType);
|
||||||
|
|
||||||
|
Assert.assertNotNull(returned.getDeviceTypeMetaDefinition(), "The response object is null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for Device Management API test cases.
|
||||||
|
* */
|
||||||
|
public class DeviceMgtAPITestHelper {
|
||||||
|
|
||||||
|
private static final String DEVICE_TYPE_DESCRIPTION = "Dummy Description";
|
||||||
|
private static final String DEVICE_TYPE = "TEST_DEVICE_TYPE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Device Type with given name and given id.
|
||||||
|
* If the name is null, the TEST_DEVICE_TYPE will be used as the name.
|
||||||
|
*
|
||||||
|
* @param name : Name of the device type.
|
||||||
|
* @param deviceTypeId : The Id of the device type.
|
||||||
|
* @return DeviceType
|
||||||
|
*/
|
||||||
|
public static DeviceType getDummyDeviceType(String name, int deviceTypeId) {
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
deviceType.setId(deviceTypeId);
|
||||||
|
deviceType.setName(name != null ? name : DEVICE_TYPE);
|
||||||
|
|
||||||
|
DeviceTypeMetaDefinition deviceTypeMetaDefinition = new DeviceTypeMetaDefinition();
|
||||||
|
deviceTypeMetaDefinition.setClaimable(true);
|
||||||
|
deviceTypeMetaDefinition.setDescription(DEVICE_TYPE_DESCRIPTION);
|
||||||
|
|
||||||
|
PushNotificationConfig pushNotificationConfig =
|
||||||
|
new PushNotificationConfig(name, true, null);
|
||||||
|
deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig);
|
||||||
|
|
||||||
|
deviceType.setDeviceTypeMetaDefinition(deviceTypeMetaDefinition);
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a list of device types.
|
||||||
|
*
|
||||||
|
* @param count: The number of device types that is needed.
|
||||||
|
* @return List<DeviceType> : A list of device types.
|
||||||
|
*/
|
||||||
|
public static List<DeviceType> getDummyDeviceTypeList(int count) {
|
||||||
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
DeviceType deviceType = getDummyDeviceType(DEVICE_TYPE + count, count);
|
||||||
|
deviceTypes.add(deviceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deviceTypes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# This is the log4j configuration file used by WSO2 Carbon
|
||||||
|
#
|
||||||
|
# IMPORTANT : Please do not remove or change the names of any
|
||||||
|
# of the Appender defined here. The layout pattern & log file
|
||||||
|
# can be changed using the WSO2 Carbon Management Console, and those
|
||||||
|
# settings will override the settings in this file.
|
||||||
|
#
|
||||||
|
|
||||||
|
log4j.rootLogger=DEBUG, STD_OUT
|
||||||
|
|
||||||
|
# Redirect log messages to console
|
||||||
|
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.STD_OUT.Target=System.out
|
||||||
|
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
|
|
||||||
|
<suite name="DeviceManagementAPI">
|
||||||
|
<parameter name="useDefaultListeners" value="false"/>
|
||||||
|
|
||||||
|
<test name="API Unit Tests" preserve-order="true">
|
||||||
|
<classes>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceManagementServiceImplTest"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceTypeManagementServiceTest"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceTypeManagementAdminServiceTest"/>
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
|
</suite>
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -1062,9 +1062,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
||||||
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
"e.DATE_OF_ENROLMENT, e.ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e" +
|
||||||
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
".OWNERSHIP, e.STATUS, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS " +
|
||||||
"WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
"ENROLMENT_ID FROM DM_ENROLMENT e WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
||||||
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
|
|||||||
@ -95,7 +95,7 @@ public class TestDeviceManager implements DeviceManager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -388,6 +388,17 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|||||||
Assert.assertTrue(device != null);
|
Assert.assertTrue(device != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
||||||
|
public void testUpdateDeviceInfo() throws DeviceManagementException,
|
||||||
|
TransactionManagementException, DeviceDetailsMgtDAOException {
|
||||||
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
|
||||||
|
DEVICE_TYPE));
|
||||||
|
|
||||||
|
boolean status = deviceMgtService.updateDeviceInfo(new DeviceIdentifier(DEVICE_ID,
|
||||||
|
DEVICE_TYPE), device);
|
||||||
|
Assert.assertTrue(status);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
||||||
public void testDeviceByDateWithNonExistentDevice() throws DeviceManagementException,
|
public void testDeviceByDateWithNonExistentDevice() throws DeviceManagementException,
|
||||||
TransactionManagementException, DeviceDetailsMgtDAOException {
|
TransactionManagementException, DeviceDetailsMgtDAOException {
|
||||||
@ -466,6 +477,12 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|||||||
|
|
||||||
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
||||||
public void testGetAllDevicesByStatus() throws DeviceManagementException {
|
public void testGetAllDevicesByStatus() throws DeviceManagementException {
|
||||||
|
List<Device> devices = deviceMgtService.getDevicesByStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
Assert.assertTrue(!devices.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
||||||
|
public void testGetDevicesByStatus() throws DeviceManagementException {
|
||||||
PaginationRequest request = new PaginationRequest(0, 100);
|
PaginationRequest request = new PaginationRequest(0, 100);
|
||||||
request.setStatus(EnrolmentInfo.Status.ACTIVE.toString());
|
request.setStatus(EnrolmentInfo.Status.ACTIVE.toString());
|
||||||
PaginationResult result = deviceMgtService.getDevicesByStatus(request, true);
|
PaginationResult result = deviceMgtService.getDevicesByStatus(request, true);
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>email-sender</artifactId>
|
<artifactId>email-sender</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,13 +22,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>identity-extensions</artifactId>
|
<artifactId>identity-extensions</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.device.mgt.oauth.extensions</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.oauth.extensions</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - OAuth Extensions</name>
|
<name>WSO2 Carbon - OAuth Extensions</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>identity-extensions</artifactId>
|
<artifactId>identity-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>identity-extensions</artifactId>
|
<artifactId>identity-extensions</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>policy-mgt</artifactId>
|
<artifactId>policy-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.complex.policy.decision.point</artifactId>
|
<artifactId>org.wso2.carbon.complex.policy.decision.point</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - Policy Decision Point</name>
|
<name>WSO2 Carbon - Policy Decision Point</name>
|
||||||
<description>WSO2 Carbon - Policy Decision Point</description>
|
<description>WSO2 Carbon - Policy Decision Point</description>
|
||||||
|
|||||||
@ -3,14 +3,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>policy-mgt</artifactId>
|
<artifactId>policy-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.decision.point</artifactId>
|
<artifactId>org.wso2.carbon.policy.decision.point</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - Policy Decision Point</name>
|
<name>WSO2 Carbon - Policy Decision Point</name>
|
||||||
<description>WSO2 Carbon - Policy Decision Point</description>
|
<description>WSO2 Carbon - Policy Decision Point</description>
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>policy-mgt</artifactId>
|
<artifactId>policy-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -11,7 +11,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.information.point</artifactId>
|
<artifactId>org.wso2.carbon.policy.information.point</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - Policy Information Point</name>
|
<name>WSO2 Carbon - Policy Information Point</name>
|
||||||
<description>WSO2 Carbon - Policy Information Point</description>
|
<description>WSO2 Carbon - Policy Information Point</description>
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>policy-mgt</artifactId>
|
<artifactId>policy-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - Policy Management Common</name>
|
<name>WSO2 Carbon - Policy Management Common</name>
|
||||||
<description>WSO2 Carbon - Policy Management Common</description>
|
<description>WSO2 Carbon - Policy Management Common</description>
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>policy-mgt</artifactId>
|
<artifactId>policy-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - Policy Management Core</name>
|
<name>WSO2 Carbon - Policy Management Core</name>
|
||||||
<description>WSO2 Carbon - Policy Management Core</description>
|
<description>WSO2 Carbon - Policy Management Core</description>
|
||||||
@ -223,9 +223,14 @@
|
|||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.powermock</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>powermock-api-mockito</artifactId>
|
||||||
<version>2.10.0</version>
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-module-testng</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@ -180,7 +180,7 @@ public class ProfileDAOImpl implements ProfileDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
Profile profile = new Profile();
|
Profile profile = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_PROFILE WHERE ID = ?";
|
String query = "SELECT * FROM DM_PROFILE WHERE ID = ?";
|
||||||
@ -189,7 +189,7 @@ public class ProfileDAOImpl implements ProfileDAO {
|
|||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
|
profile = new Profile();
|
||||||
profile.setProfileId(profileId);
|
profile.setProfileId(profileId);
|
||||||
profile.setProfileName(resultSet.getString("PROFILE_NAME"));
|
profile.setProfileName(resultSet.getString("PROFILE_NAME"));
|
||||||
profile.setTenantId(resultSet.getInt("TENANT_ID"));
|
profile.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
|||||||
@ -20,12 +20,17 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -143,6 +148,9 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
profile = profileDAO.getProfile(profileId);
|
profile = profileDAO.getProfile(profileId);
|
||||||
|
if (profile == null) {
|
||||||
|
throw new ProfileManagementException("Profile is not available with profile id (" + profileId + ")");
|
||||||
|
}
|
||||||
featureList = featureDAO.getFeaturesForProfile(profileId);
|
featureList = featureDAO.getFeaturesForProfile(profileId);
|
||||||
profile.setProfileFeaturesList(featureList);
|
profile.setProfileFeaturesList(featureList);
|
||||||
} catch (ProfileManagerDAOException e) {
|
} catch (ProfileManagerDAOException e) {
|
||||||
|
|||||||
@ -21,45 +21,107 @@ package org.wso2.carbon.policy.mgt.core;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.BeforeSuite;
|
import org.testng.annotations.BeforeSuite;
|
||||||
|
import org.testng.internal.collections.Pair;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
||||||
|
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.ntask.common.TaskException;
|
import org.wso2.carbon.ntask.common.TaskException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.core.common.DataSourceConfig;
|
import org.wso2.carbon.policy.mgt.core.common.DataSourceConfig;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
import org.wso2.carbon.registry.core.config.RegistryContext;
|
||||||
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
|
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
|
||||||
|
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
||||||
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public abstract class BasePolicyManagementDAOTest {
|
public abstract class BasePolicyManagementDAOTest {
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
private static final Log log = LogFactory.getLog(BasePolicyManagementDAOTest.class);
|
private static final Log log = LogFactory.getLog(BasePolicyManagementDAOTest.class);
|
||||||
|
|
||||||
|
protected DeviceManagementProviderService deviceMgtService;
|
||||||
|
protected GroupManagementProviderService groupMgtService;
|
||||||
|
protected ProfileManager profileManager;
|
||||||
|
|
||||||
|
private static final String ADMIN_USER = "admin";
|
||||||
|
|
||||||
@BeforeSuite
|
@BeforeSuite
|
||||||
public void setupDataSource() throws Exception {
|
public void setupDataSource() throws Exception {
|
||||||
this.initDatSource();
|
this.initDatSource();
|
||||||
this.initSQLScript();
|
this.initSQLScript();
|
||||||
this.initialize();
|
|
||||||
this.initiatePrivilegedCaronContext();
|
this.initiatePrivilegedCaronContext();
|
||||||
DeviceConfigurationManager.getInstance().initConfig();
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws TaskException {
|
protected void initializeServices() throws Exception{
|
||||||
|
initDatSource();
|
||||||
|
initSQLScript();
|
||||||
|
|
||||||
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
|
|
||||||
|
deviceMgtService = new DeviceManagementProviderServiceImpl();
|
||||||
|
groupMgtService = new GroupManagementProviderServiceImpl();
|
||||||
|
|
||||||
|
DeviceManagementServiceComponent.notifyStartupListeners();
|
||||||
|
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
|
||||||
|
DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
|
||||||
|
DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(
|
||||||
|
new DeviceAccessAuthorizationServiceImpl());
|
||||||
|
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(groupMgtService);
|
||||||
|
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
||||||
|
|
||||||
|
PolicyEvaluationPoint policyEvaluationPoint = new SimplePolicyEvaluationTest();
|
||||||
|
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint("Simple", policyEvaluationPoint);
|
||||||
|
PolicyManagementDataHolder.getInstance().setDeviceManagementService(deviceMgtService);
|
||||||
|
|
||||||
|
profileManager = new ProfileManagerImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initDatSource() throws Exception {
|
public void initDatSource() throws Exception {
|
||||||
@ -98,9 +160,6 @@ public abstract class BasePolicyManagementDAOTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public abstract void init() throws Exception;
|
|
||||||
|
|
||||||
private DataSource getDataSource(DataSourceConfig config) {
|
private DataSource getDataSource(DataSourceConfig config) {
|
||||||
PoolProperties properties = new PoolProperties();
|
PoolProperties properties = new PoolProperties();
|
||||||
properties.setUrl(config.getUrl());
|
properties.setUrl(config.getUrl());
|
||||||
@ -138,4 +197,102 @@ public abstract class BasePolicyManagementDAOTest {
|
|||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Object changeFieldValue(Object targetObj, String fieldName, Object valueObj)
|
||||||
|
throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
Field field = targetObj.getClass().getDeclaredField(fieldName);
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object oldVal = field.get(targetObj);
|
||||||
|
field.set(targetObj, valueObj);
|
||||||
|
return oldVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RegistryService getRegistryService() throws RegistryException {
|
||||||
|
RealmService realmService = new InMemoryRealmService();
|
||||||
|
RegistryDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream(
|
||||||
|
"carbon-home/repository/conf/registry.xml");
|
||||||
|
RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
|
||||||
|
context.setSetup(true);
|
||||||
|
return context.getEmbeddedRegistryService();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean enrollDevice(String deviceName, String deviceType) {
|
||||||
|
boolean success = false;
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo(
|
||||||
|
ADMIN_USER, EnrolmentInfo.OwnerShip.BYOD, EnrolmentInfo.Status.ACTIVE);
|
||||||
|
Device device1 = new Device(deviceName, deviceType, deviceName, deviceName, enrolmentInfo, null, null);
|
||||||
|
try {
|
||||||
|
success = deviceMgtService.enrollDevice(device1);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Failed to enroll a device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createDeviceGroup(String groupName) {
|
||||||
|
DeviceGroup deviceGroup = new DeviceGroup(groupName);
|
||||||
|
deviceGroup.setDescription(groupName);
|
||||||
|
deviceGroup.setOwner(ADMIN_USER);
|
||||||
|
try {
|
||||||
|
groupMgtService.createGroup(deviceGroup, null, null);
|
||||||
|
} catch (GroupAlreadyExistException | GroupManagementException e) {
|
||||||
|
String msg = "Failed to create group: " + groupName;
|
||||||
|
log.error(msg, e);
|
||||||
|
Assert.fail(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addDeviceToGroup(DeviceIdentifier deviceIdentifier, String groupName) {
|
||||||
|
List<DeviceIdentifier> groupDevices = new ArrayList<>();
|
||||||
|
groupDevices.add(deviceIdentifier);
|
||||||
|
try {
|
||||||
|
DeviceGroup group = groupMgtService.getGroup(groupName);
|
||||||
|
groupMgtService.addDevices(group.getGroupId(), groupDevices);
|
||||||
|
} catch (DeviceNotFoundException | GroupManagementException e) {
|
||||||
|
String msg = "Failed to add device " + deviceIdentifier.getId() + " to group " + groupName;
|
||||||
|
log.error(msg, e);
|
||||||
|
Assert.fail(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Command {
|
||||||
|
void call(Profile profile) throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void testThrowingException(Profile profile, Command command, String fieldName, Object mockObj,
|
||||||
|
Class<?> exceptionClass) throws Exception {
|
||||||
|
Object oldObj = changeFieldValue(profileManager, fieldName, mockObj);
|
||||||
|
try {
|
||||||
|
command.call(profile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!(e.getCause().getClass().getName().equals(exceptionClass.getName()))) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
changeFieldValue(profileManager, fieldName, oldObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Pair<Connection, Pair<DataSource, DataSource>> mockConnection() throws Exception {
|
||||||
|
//Throwing PolicyManagerDAOException while adding profile
|
||||||
|
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
|
||||||
|
when(databaseMetaData.getDatabaseProductName()).thenReturn("H2");
|
||||||
|
|
||||||
|
Connection conn = mock(Connection.class);
|
||||||
|
when(conn.getMetaData()).thenReturn(databaseMetaData);
|
||||||
|
|
||||||
|
DataSource dataSource = mock(DataSource.class);
|
||||||
|
when(dataSource.getConnection()).thenReturn(conn);
|
||||||
|
|
||||||
|
Field dataSourceField = PolicyManagementDAOFactory.class.getDeclaredField("dataSource");
|
||||||
|
dataSourceField.setAccessible(true);
|
||||||
|
DataSource oldDataSource = (DataSource) dataSourceField.get(null);
|
||||||
|
PolicyManagementDAOFactory.init(dataSource);
|
||||||
|
|
||||||
|
return new Pair<>(conn, new Pair<>(oldDataSource, dataSource));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,12 +52,6 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
|
|||||||
|
|
||||||
private DeviceIdentifier identifier = new DeviceIdentifier();
|
private DeviceIdentifier identifier = new DeviceIdentifier();
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
@Override
|
|
||||||
public void init() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMonitorDao() {
|
public void testMonitorDao() {
|
||||||
|
|
||||||
|
|||||||
@ -52,14 +52,12 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
private static final Log log = LogFactory.getLog(PolicyDAOTestCase.class);
|
private static final Log log = LogFactory.getLog(PolicyDAOTestCase.class);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@Override
|
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
initDatSource();
|
initDatSource();
|
||||||
// System.setProperty("GetTenantIDForTest", "Super");
|
// System.setProperty("GetTenantIDForTest", "Super");
|
||||||
initiatePrivilegedCaronContext();
|
initiatePrivilegedCaronContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addDeviceType() throws DeviceManagementDAOException {
|
public void addDeviceType() throws DeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -45,7 +45,6 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
|
|||||||
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@Override
|
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest();
|
PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest();
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint);
|
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint);
|
||||||
|
|||||||
@ -19,7 +19,6 @@ package org.wso2.carbon.policy.mgt.core;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.mockito.Spy;
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
@ -59,7 +58,7 @@ import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
|||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask;
|
import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mock.TypeADeviceManagementService;
|
import org.wso2.carbon.policy.mgt.core.mock.TypeXDeviceManagementService;
|
||||||
import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
|
import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
|
||||||
import org.wso2.carbon.policy.mgt.core.task.MonitoringTask;
|
import org.wso2.carbon.policy.mgt.core.task.MonitoringTask;
|
||||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
@ -90,8 +89,6 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
|
|||||||
public static final String DEVICE_2 = "device2";
|
public static final String DEVICE_2 = "device2";
|
||||||
public static final String DEVICE_TYPE_B = "deviceTypeB";
|
public static final String DEVICE_TYPE_B = "deviceTypeB";
|
||||||
|
|
||||||
private DeviceManagementProviderService deviceMgtService;
|
|
||||||
private GroupManagementProviderService groupMgtService;
|
|
||||||
private OperationManager operationManager;
|
private OperationManager operationManager;
|
||||||
private PolicyManagerService policyManagerService;
|
private PolicyManagerService policyManagerService;
|
||||||
private Profile profile;
|
private Profile profile;
|
||||||
@ -100,75 +97,8 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
super.initSQLScript();
|
|
||||||
|
|
||||||
DeviceConfigurationManager.getInstance().initConfig();
|
|
||||||
log.info("Initializing policy tests");
|
log.info("Initializing policy tests");
|
||||||
|
super.initializeServices();
|
||||||
deviceMgtService = new DeviceManagementProviderServiceImpl();
|
|
||||||
groupMgtService = new GroupManagementProviderServiceImpl();
|
|
||||||
|
|
||||||
DeviceManagementServiceComponent.notifyStartupListeners();
|
|
||||||
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
|
|
||||||
DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
|
|
||||||
DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
|
|
||||||
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(groupMgtService);
|
|
||||||
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
|
||||||
|
|
||||||
PolicyEvaluationPoint policyEvaluationPoint = new SimplePolicyEvaluationTest();
|
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint("Simple", policyEvaluationPoint);
|
|
||||||
PolicyManagementDataHolder.getInstance().setDeviceManagementService(deviceMgtService);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RegistryService getRegistryService() throws RegistryException {
|
|
||||||
RealmService realmService = new InMemoryRealmService();
|
|
||||||
RegistryDataHolder.getInstance().setRealmService(realmService);
|
|
||||||
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
|
||||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
|
|
||||||
RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
|
|
||||||
context.setSetup(true);
|
|
||||||
return context.getEmbeddedRegistryService();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean enrollDevice(String deviceName, String deviceType) {
|
|
||||||
boolean success = false;
|
|
||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo(
|
|
||||||
ADMIN_USER, EnrolmentInfo.OwnerShip.BYOD, EnrolmentInfo.Status.ACTIVE);
|
|
||||||
Device device1 = new Device(deviceName, deviceType, deviceName, deviceName, enrolmentInfo, null, null);
|
|
||||||
try {
|
|
||||||
success = deviceMgtService.enrollDevice(device1);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String msg = "Failed to enroll a device.";
|
|
||||||
log.error(msg, e);
|
|
||||||
Assert.fail();
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createDeviceGroup(String groupName) {
|
|
||||||
DeviceGroup deviceGroup = new DeviceGroup(groupName);
|
|
||||||
deviceGroup.setDescription(groupName);
|
|
||||||
deviceGroup.setOwner(ADMIN_USER);
|
|
||||||
try {
|
|
||||||
groupMgtService.createGroup(deviceGroup, null, null);
|
|
||||||
} catch (GroupAlreadyExistException | GroupManagementException e) {
|
|
||||||
String msg = "Failed to create group: " + groupName;
|
|
||||||
log.error(msg, e);
|
|
||||||
Assert.fail(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDeviceToGroup(DeviceIdentifier deviceIdentifier, String groupName) {
|
|
||||||
List<DeviceIdentifier> groupDevices = new ArrayList<>();
|
|
||||||
groupDevices.add(deviceIdentifier);
|
|
||||||
try {
|
|
||||||
DeviceGroup group = groupMgtService.getGroup(groupName);
|
|
||||||
groupMgtService.addDevices(group.getGroupId(), groupDevices);
|
|
||||||
} catch (DeviceNotFoundException | GroupManagementException e) {
|
|
||||||
String msg = "Failed to add device " + deviceIdentifier.getId() + " to group " + groupName;
|
|
||||||
log.error(msg, e);
|
|
||||||
Assert.fail(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -176,7 +106,7 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
|
|||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
policyManagerService = new PolicyManagerServiceImpl();
|
policyManagerService = new PolicyManagerServiceImpl();
|
||||||
|
|
||||||
deviceMgtService.registerDeviceType(new TypeADeviceManagementService());
|
deviceMgtService.registerDeviceType(new TypeXDeviceManagementService(DEVICE_TYPE_A));
|
||||||
operationManager = new OperationManagerImpl(DEVICE_TYPE_A);
|
operationManager = new OperationManagerImpl(DEVICE_TYPE_A);
|
||||||
enrollDevice(DEVICE1, DEVICE_TYPE_A);
|
enrollDevice(DEVICE1, DEVICE_TYPE_A);
|
||||||
createDeviceGroup(GROUP1);
|
createDeviceGroup(GROUP1);
|
||||||
|
|||||||
@ -0,0 +1,349 @@
|
|||||||
|
package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.internal.collections.Pair;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.impl.ProfileDAOImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.mock.TypeXDeviceManagementService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.util.FeatureCreator;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.util.ProfileCreator;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Matchers.anyListOf;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
|
||||||
|
private static final Log log = LogFactory.getLog(PolicyManagerServiceImpl.class);
|
||||||
|
|
||||||
|
private static final String DEVICE3 = "device3";
|
||||||
|
private static final String GROUP3 = "group3";
|
||||||
|
private static final String POLICY3 = "policy3";
|
||||||
|
private static final String DEVICE_TYPE_C = "deviceTypeC";
|
||||||
|
|
||||||
|
private Profile profile1;
|
||||||
|
private OperationManager operationManager;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void initialize() throws Exception {
|
||||||
|
log.info("Initializing policy manager tests");
|
||||||
|
super.initializeServices();
|
||||||
|
deviceMgtService.registerDeviceType(new TypeXDeviceManagementService(DEVICE_TYPE_C));
|
||||||
|
operationManager = new OperationManagerImpl(DEVICE_TYPE_C);
|
||||||
|
enrollDevice(DEVICE3, DEVICE_TYPE_C);
|
||||||
|
createDeviceGroup(GROUP3);
|
||||||
|
DeviceGroup group1 = groupMgtService.getGroup(GROUP3);
|
||||||
|
addDeviceToGroup(new DeviceIdentifier(DEVICE3, DEVICE_TYPE_C), GROUP3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests adding new profile")
|
||||||
|
public void testAddProfile() throws Exception {
|
||||||
|
//Creating profile object
|
||||||
|
Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList(), DEVICE_TYPE_C);
|
||||||
|
//Adding profile
|
||||||
|
profile1 = profileManager.addProfile(profile);
|
||||||
|
Assert.assertEquals(profile1.getProfileName(), profile.getProfileName());
|
||||||
|
Assert.assertEquals(profile1.getTenantId(), profile.getTenantId());
|
||||||
|
Assert.assertEquals(profile1.getDeviceType(), profile.getDeviceType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling ProfileManagerDAOException when adding new profile",
|
||||||
|
dependsOnMethods = "testAddProfile")
|
||||||
|
public void testAddProfileThrowingProfileManagerDAOException() throws Exception {
|
||||||
|
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
|
||||||
|
when(profileDAO.addProfile(any(Profile.class))).thenThrow(new ProfileManagerDAOException());
|
||||||
|
//Creating profile object
|
||||||
|
Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList(), DEVICE_TYPE_C);
|
||||||
|
testThrowingException(profile, p -> profileManager.addProfile(p), "profileDAO", profileDAO,
|
||||||
|
ProfileManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling FeatureManagerDAOException when adding new profile",
|
||||||
|
dependsOnMethods = "testAddProfileThrowingProfileManagerDAOException")
|
||||||
|
public void testAddProfileThrowingFeatureManagerDAOException() throws Exception {
|
||||||
|
FeatureDAO featureDAO = mock(FeatureDAO.class);
|
||||||
|
when(featureDAO.addProfileFeatures(anyListOf(ProfileFeature.class), anyInt())).thenThrow(
|
||||||
|
new FeatureManagerDAOException());
|
||||||
|
//Creating profile object
|
||||||
|
Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList(), DEVICE_TYPE_C);
|
||||||
|
testThrowingException(profile, p -> profileManager.addProfile(p), "featureDAO", featureDAO,
|
||||||
|
FeatureManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling SQLException when adding new profile",
|
||||||
|
dependsOnMethods = "testAddProfileThrowingFeatureManagerDAOException",
|
||||||
|
expectedExceptions = IllegalTransactionStateException.class)
|
||||||
|
public void testAddProfileThrowingIllegalTransactionStateException() throws Exception {
|
||||||
|
//Creating profile object
|
||||||
|
Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList(), DEVICE_TYPE_C);
|
||||||
|
Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection();
|
||||||
|
PowerMockito.doThrow(new SQLException()).when(pair.first()).setAutoCommit(anyBoolean());
|
||||||
|
try {
|
||||||
|
profileManager.addProfile(profile);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.init(pair.second().first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests updating profile",
|
||||||
|
dependsOnMethods = "testAddProfile")
|
||||||
|
public void testUpdateProfile() throws Exception {
|
||||||
|
String newProfileName = "Updated Test Profile";
|
||||||
|
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
|
||||||
|
savedProfile.setProfileName(newProfileName);
|
||||||
|
Profile updateProfile = profileManager.updateProfile(savedProfile);
|
||||||
|
Assert.assertEquals(updateProfile.getProfileName(), newProfileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling ProfileManagerDAOException when updating profile",
|
||||||
|
dependsOnMethods = "testUpdateProfile")
|
||||||
|
public void testUpdateProfileThrowingProfileManagerDAOException() throws Exception {
|
||||||
|
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
|
||||||
|
when(profileDAO.updateProfile(any(Profile.class))).thenThrow(new ProfileManagerDAOException());
|
||||||
|
|
||||||
|
String newProfileName = "Updated Test Profile";
|
||||||
|
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
|
||||||
|
savedProfile.setProfileName(newProfileName);
|
||||||
|
testThrowingException(savedProfile, p -> profileManager.updateProfile(p), "profileDAO", profileDAO,
|
||||||
|
ProfileManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling FeatureManagerDAOException when updating profile",
|
||||||
|
dependsOnMethods = "testUpdateProfileThrowingProfileManagerDAOException")
|
||||||
|
public void testUpdateProfileThrowingFeatureManagerDAOException() throws Exception {
|
||||||
|
FeatureDAO featureDAO = mock(FeatureDAO.class);
|
||||||
|
when(featureDAO.updateProfileFeatures(anyListOf(ProfileFeature.class), anyInt())).thenThrow(
|
||||||
|
new FeatureManagerDAOException());
|
||||||
|
|
||||||
|
String newProfileName = "Updated Test Profile";
|
||||||
|
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
|
||||||
|
savedProfile.setProfileName(newProfileName);
|
||||||
|
testThrowingException(savedProfile, p -> profileManager.updateProfile(p), "featureDAO", featureDAO,
|
||||||
|
FeatureManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling SQLException when updating profile",
|
||||||
|
dependsOnMethods = {"testUpdateProfileThrowingFeatureManagerDAOException"},
|
||||||
|
expectedExceptions = IllegalTransactionStateException.class)
|
||||||
|
public void testUpdateProfileThrowingIllegalTransactionStateException() throws Exception {
|
||||||
|
//Retrieving profile object
|
||||||
|
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
|
||||||
|
|
||||||
|
Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection();
|
||||||
|
PowerMockito.doThrow(new SQLException()).when(pair.first()).setAutoCommit(anyBoolean());
|
||||||
|
|
||||||
|
String newProfileName = "Updated Test Profile";
|
||||||
|
savedProfile.setProfileName(newProfileName);
|
||||||
|
try {
|
||||||
|
profileManager.updateProfile(savedProfile);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.init(pair.second().first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests retrieving profile", dependsOnMethods = "testAddProfile")
|
||||||
|
public void testGetProfile() throws Exception {
|
||||||
|
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
|
||||||
|
Assert.assertEquals(profile1.getProfileName(), savedProfile.getProfileName());
|
||||||
|
Assert.assertEquals(profile1.getTenantId(), savedProfile.getTenantId());
|
||||||
|
Assert.assertEquals(profile1.getDeviceType(), savedProfile.getDeviceType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests retrieving non existent profile", dependsOnMethods = "testGetProfile",
|
||||||
|
expectedExceptions = ProfileManagementException.class)
|
||||||
|
public void testGetProfileThrowingProfileManagementException() throws Exception {
|
||||||
|
int nonExistentProfileId = 9999;
|
||||||
|
profileManager.getProfile(nonExistentProfileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling ProfileManagerDAOException when retrieving profile",
|
||||||
|
dependsOnMethods = "testGetProfile")
|
||||||
|
public void testGetProfileThrowingProfileManagerDAOException() throws Exception {
|
||||||
|
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
|
||||||
|
when(profileDAO.getProfile(anyInt())).thenThrow(new ProfileManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.getProfile(p.getProfileId()), "profileDAO", profileDAO,
|
||||||
|
ProfileManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling FeatureManagerDAOException when retrieving profile",
|
||||||
|
dependsOnMethods = "testGetProfileThrowingProfileManagerDAOException")
|
||||||
|
public void testGetProfileThrowingFeatureManagerDAOException() throws Exception {
|
||||||
|
FeatureDAO featureDAO = mock(FeatureDAO.class);
|
||||||
|
when(featureDAO.getFeaturesForProfile(anyInt())).thenThrow(new FeatureManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.getProfile(p.getProfileId()), "featureDAO", featureDAO,
|
||||||
|
FeatureManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling SQLException when retrieving profile",
|
||||||
|
dependsOnMethods = "testGetProfileThrowingFeatureManagerDAOException",
|
||||||
|
expectedExceptions = IllegalTransactionStateException.class)
|
||||||
|
public void testGetProfileThrowingIllegalTransactionStateException() throws Exception {
|
||||||
|
//Creating profile object
|
||||||
|
Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection();
|
||||||
|
PowerMockito.doThrow(new SQLException()).when(pair.second().second()).getConnection();
|
||||||
|
|
||||||
|
try {
|
||||||
|
profileManager.getProfile(profile1.getProfileId());
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.init(pair.second().first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests retrieving all profiles",
|
||||||
|
dependsOnMethods = "testAddProfile")
|
||||||
|
public void testGetAllProfiles() throws Exception {
|
||||||
|
profileManager.getAllProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling ProfileManagerDAOException when retrieving all profiles",
|
||||||
|
dependsOnMethods = "testGetAllProfiles")
|
||||||
|
public void testGetAllProfilesThrowingProfileManagerDAOException() throws Exception {
|
||||||
|
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
|
||||||
|
when(profileDAO.getAllProfiles()).thenThrow(new ProfileManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.getAllProfiles(), "profileDAO", profileDAO,
|
||||||
|
ProfileManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling FeatureManagerDAOException when retrieving all profiles",
|
||||||
|
dependsOnMethods = "testGetAllProfilesThrowingProfileManagerDAOException")
|
||||||
|
public void testGetAllProfilesThrowingFeatureManagerDAOException() throws Exception {
|
||||||
|
FeatureDAO featureDAO = mock(FeatureDAO.class);
|
||||||
|
when(featureDAO.getAllProfileFeatures()).thenThrow(new FeatureManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.getAllProfiles(), "featureDAO", featureDAO,
|
||||||
|
FeatureManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling SQLException when retrieving all profiles",
|
||||||
|
dependsOnMethods = "testGetAllProfilesThrowingFeatureManagerDAOException",
|
||||||
|
expectedExceptions = IllegalTransactionStateException.class)
|
||||||
|
public void testGetAllProfilesThrowingIllegalTransactionStateException() throws Exception {
|
||||||
|
//Creating profile object
|
||||||
|
Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection();
|
||||||
|
PowerMockito.doThrow(new SQLException()).when(pair.second().second()).getConnection();
|
||||||
|
|
||||||
|
try {
|
||||||
|
profileManager.getAllProfiles();
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.init(pair.second().first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests retrieving profiles of a device type",
|
||||||
|
dependsOnMethods = "testAddProfile")
|
||||||
|
public void testGetProfilesOfDeviceType() throws Exception {
|
||||||
|
profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling ProfileManagerDAOException when retrieving all profiles of a " +
|
||||||
|
"device type",
|
||||||
|
dependsOnMethods = "testGetProfilesOfDeviceType")
|
||||||
|
public void testGetProfilesOfDeviceTypeThrowingProfileManagerDAOException() throws Exception {
|
||||||
|
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
|
||||||
|
when(profileDAO.getProfilesOfDeviceType(anyString())).thenThrow(new ProfileManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C), "profileDAO",
|
||||||
|
profileDAO,
|
||||||
|
ProfileManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling FeatureManagerDAOException when retrieving all profiles of a " +
|
||||||
|
"device type",
|
||||||
|
dependsOnMethods = "testGetProfilesOfDeviceTypeThrowingProfileManagerDAOException")
|
||||||
|
public void testGetProfilesOfDeviceTypeThrowingFeatureManagerDAOException() throws Exception {
|
||||||
|
FeatureDAO featureDAO = mock(FeatureDAO.class);
|
||||||
|
when(featureDAO.getAllProfileFeatures()).thenThrow(new FeatureManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C), "featureDAO",
|
||||||
|
featureDAO,
|
||||||
|
FeatureManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling SQLException when retrieving all profiles of a device type",
|
||||||
|
dependsOnMethods = "testGetProfilesOfDeviceTypeThrowingFeatureManagerDAOException",
|
||||||
|
expectedExceptions = IllegalTransactionStateException.class)
|
||||||
|
public void testGetProfilesOfDeviceTypeThrowingIllegalTransactionStateException() throws Exception {
|
||||||
|
//Creating profile object
|
||||||
|
Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection();
|
||||||
|
PowerMockito.doThrow(new SQLException()).when(pair.second().second()).getConnection();
|
||||||
|
|
||||||
|
try {
|
||||||
|
profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.init(pair.second().first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling ProfileManagerDAOException when deleting a profile",
|
||||||
|
dependsOnMethods = "testGetProfilesOfDeviceTypeThrowingIllegalTransactionStateException")
|
||||||
|
public void testDeleteProfileThrowingProfileManagerDAOException() throws Exception {
|
||||||
|
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
|
||||||
|
when(profileDAO.deleteProfile(any(Profile.class))).thenThrow(new ProfileManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.deleteProfile(profile1), "profileDAO", profileDAO,
|
||||||
|
ProfileManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling FeatureManagerDAOException when deleting a profile",
|
||||||
|
dependsOnMethods = "testDeleteProfileThrowingProfileManagerDAOException")
|
||||||
|
public void testDeleteProfileThrowingFeatureManagerDAOException() throws Exception {
|
||||||
|
FeatureDAO featureDAO = mock(FeatureDAO.class);
|
||||||
|
when(featureDAO.deleteFeaturesOfProfile(any(Profile.class))).thenThrow(new FeatureManagerDAOException());
|
||||||
|
testThrowingException(profile1, p -> profileManager.deleteProfile(profile1), "featureDAO", featureDAO,
|
||||||
|
FeatureManagerDAOException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests handling SQLException when deleting a profile",
|
||||||
|
dependsOnMethods = "testDeleteProfileThrowingFeatureManagerDAOException",
|
||||||
|
expectedExceptions = IllegalTransactionStateException.class)
|
||||||
|
public void testDeleteProfileThrowingIllegalTransactionStateException() throws Exception {
|
||||||
|
//Creating profile object
|
||||||
|
Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection();
|
||||||
|
PowerMockito.doThrow(new SQLException()).when(pair.second().second()).getConnection();
|
||||||
|
|
||||||
|
try {
|
||||||
|
profileManager.deleteProfile(profile1);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.init(pair.second().first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests deleting a profile",
|
||||||
|
dependsOnMethods = "testDeleteProfileThrowingIllegalTransactionStateException",
|
||||||
|
expectedExceptions = {ProfileManagementException.class})
|
||||||
|
public void testDeleteProfile() throws Exception {
|
||||||
|
profileManager.deleteProfile(profile1);
|
||||||
|
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -32,12 +32,12 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class TypeADeviceManagementService implements DeviceManagementService {
|
public class TypeXDeviceManagementService implements DeviceManagementService {
|
||||||
|
|
||||||
public static String DEVICE_TYPE = "deviceTypeA";
|
private String deviceType;
|
||||||
|
|
||||||
public TypeADeviceManagementService() {
|
public TypeXDeviceManagementService(String deviceType) {
|
||||||
super();
|
this.deviceType = deviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -47,7 +47,7 @@ public class TypeADeviceManagementService implements DeviceManagementService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return DEVICE_TYPE;
|
return deviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,11 +27,15 @@ import java.util.List;
|
|||||||
public class ProfileCreator {
|
public class ProfileCreator {
|
||||||
|
|
||||||
public static Profile getProfile(List<Feature> features) {
|
public static Profile getProfile(List<Feature> features) {
|
||||||
|
return getProfile(features, "android");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Profile getProfile(List<Feature> features, String deviceType) {
|
||||||
Profile profile = new Profile();
|
Profile profile = new Profile();
|
||||||
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
|
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
|
||||||
profile.setProfileName("Test Profile");
|
profile.setProfileName("Test Profile");
|
||||||
profile.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
profile.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
profile.setDeviceType("android");
|
profile.setDeviceType(deviceType);
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,9 +32,10 @@
|
|||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
|
|
||||||
<test name="Service Unit Tests" preserve-order="true">
|
<test name="Service Unit Tests" preserve-order="true" parallel="false">
|
||||||
<parameter name="dbType" value="H2"/>
|
<parameter name="dbType" value="H2"/>
|
||||||
<classes>
|
<classes>
|
||||||
|
<class name="org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImplTest" />
|
||||||
<class name="org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImplTest"/>
|
<class name="org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImplTest"/>
|
||||||
<class name="org.wso2.carbon.policy.mgt.core.task.TaskSchedulerServiceImplTest" />
|
<class name="org.wso2.carbon.policy.mgt.core.task.TaskSchedulerServiceImplTest" />
|
||||||
</classes>
|
</classes>
|
||||||
|
|||||||
@ -23,13 +23,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>policy-mgt</artifactId>
|
<artifactId>policy-mgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>WSO2 Carbon - Policy Management Component</name>
|
<name>WSO2 Carbon - Policy Management Component</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -195,6 +195,10 @@
|
|||||||
<fileset dir="${device.extensions.deployer}/${target}/${coverge-report}">
|
<fileset dir="${device.extensions.deployer}/${target}/${coverge-report}">
|
||||||
<include name="${individual.test.report.name}" />
|
<include name="${individual.test.report.name}" />
|
||||||
</fileset>
|
</fileset>
|
||||||
|
<fileset dir="${device.mgt.api}/${target}/${coverge-report}">
|
||||||
|
<include name="${individual.test.report.name}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
<!-- Need to list the newly added exec files here -->
|
<!-- Need to list the newly added exec files here -->
|
||||||
</executiondata>
|
</executiondata>
|
||||||
<structure name="Carbon Device Management Component Coverage Report">
|
<structure name="Carbon Device Management Component Coverage Report">
|
||||||
|
|||||||
@ -21,14 +21,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>webapp-authenticator-framework</artifactId>
|
<artifactId>webapp-authenticator-framework</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.webapp.authenticator.framework</artifactId>
|
<artifactId>org.wso2.carbon.webapp.authenticator.framework</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>WSO2 Carbon - Web Application Authenticator Framework Bundle</name>
|
<name>WSO2 Carbon - Web Application Authenticator Framework Bundle</name>
|
||||||
<description>WSO2 Carbon - Web Application Authenticator Framework Bundle</description>
|
<description>WSO2 Carbon - Web Application Authenticator Framework Bundle</description>
|
||||||
@ -167,21 +167,19 @@
|
|||||||
<groupId>org.wso2.tomcat</groupId>
|
<groupId>org.wso2.tomcat</groupId>
|
||||||
<artifactId>tomcat-servlet-api</artifactId>
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.tomcat.ext</artifactId>
|
<artifactId>org.wso2.carbon.tomcat.ext</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--dependency>
|
|
||||||
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
|
|
||||||
<artifactId>axiom</artifactId>
|
|
||||||
</dependency-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.identity.framework</groupId>
|
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||||
<artifactId>org.wso2.carbon.identity.base</artifactId>
|
<artifactId>org.wso2.carbon.identity.base</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.opensaml</groupId>
|
||||||
|
<artifactId>xmltooling</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.identity.framework</groupId>
|
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||||
@ -253,6 +251,21 @@
|
|||||||
<artifactId>powermock-api-mockito</artifactId>
|
<artifactId>powermock-api-mockito</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.identity.jwt.client.extension</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-nop</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.sling</groupId>
|
||||||
|
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.authenticator.framework.authenticator;
|
package org.wso2.carbon.webapp.authenticator.framework.authenticator;
|
||||||
|
|
||||||
import org.apache.catalina.connector.Request;
|
import org.apache.catalina.connector.Request;
|
||||||
@ -39,11 +58,8 @@ public class CertificateAuthenticator implements WebappAuthenticator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(Request request) {
|
public boolean canHandle(Request request) {
|
||||||
if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null || request.getHeader(MUTUAL_AUTH_HEADER) != null
|
return request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null
|
||||||
|| request.getHeader(PROXY_MUTUAL_AUTH_HEADER) != null) {
|
|| request.getHeader(MUTUAL_AUTH_HEADER) != null || request.getHeader(PROXY_MUTUAL_AUTH_HEADER) != null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,8 +80,12 @@ public class CertificateAuthenticator implements WebappAuthenticator {
|
|||||||
authenticationInfo = checkCertificateResponse(certificateResponse);
|
authenticationInfo = checkCertificateResponse(certificateResponse);
|
||||||
}
|
}
|
||||||
else if (request.getHeader(MUTUAL_AUTH_HEADER) != null) {
|
else if (request.getHeader(MUTUAL_AUTH_HEADER) != null) {
|
||||||
X509Certificate[] clientCertificate = (X509Certificate[]) request.
|
Object object = request.getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE);
|
||||||
getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE);
|
X509Certificate[] clientCertificate = null;
|
||||||
|
if (object instanceof X509Certificate[]) {
|
||||||
|
clientCertificate = (X509Certificate[]) request.
|
||||||
|
getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE);
|
||||||
|
}
|
||||||
if (clientCertificate != null && clientCertificate[0] != null) {
|
if (clientCertificate != null && clientCertificate[0] != null) {
|
||||||
CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance().
|
CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance().
|
||||||
getCertificateManagementService().verifyPEMSignature(clientCertificate[0]);
|
getCertificateManagementService().verifyPEMSignature(clientCertificate[0]);
|
||||||
@ -76,7 +96,6 @@ public class CertificateAuthenticator implements WebappAuthenticator {
|
|||||||
authenticationInfo.setMessage("No client certificate is present");
|
authenticationInfo.setMessage("No client certificate is present");
|
||||||
}
|
}
|
||||||
} else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) {
|
} else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) {
|
||||||
|
|
||||||
String certHeader = request.getHeader(CERTIFICATE_VERIFICATION_HEADER);
|
String certHeader = request.getHeader(CERTIFICATE_VERIFICATION_HEADER);
|
||||||
if (certHeader != null &&
|
if (certHeader != null &&
|
||||||
AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService().
|
AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService().
|
||||||
@ -105,7 +124,6 @@ public class CertificateAuthenticator implements WebappAuthenticator {
|
|||||||
EnrolmentInfo enrolmentInfo = tenantedDeviceWrapper.getDevice().getEnrolmentInfo();
|
EnrolmentInfo enrolmentInfo = tenantedDeviceWrapper.getDevice().getEnrolmentInfo();
|
||||||
authenticationInfo.setUsername(enrolmentInfo.getOwner());
|
authenticationInfo.setUsername(enrolmentInfo.getOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticationInfo.setStatus(Status.CONTINUE);
|
authenticationInfo.setStatus(Status.CONTINUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,6 +86,12 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
@Override
|
@Override
|
||||||
public AuthenticationInfo authenticate(Request request, Response response) {
|
public AuthenticationInfo authenticate(Request request, Response response) {
|
||||||
String requestUri = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
|
SignedJWT jwsObject;
|
||||||
|
String username;
|
||||||
|
String tenantDomain;
|
||||||
|
int tenantId;
|
||||||
|
String issuer;
|
||||||
|
|
||||||
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
|
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
|
||||||
if (requestUri == null || "".equals(requestUri)) {
|
if (requestUri == null || "".equals(requestUri)) {
|
||||||
authenticationInfo.setStatus(Status.CONTINUE);
|
authenticationInfo.setStatus(Status.CONTINUE);
|
||||||
@ -94,19 +100,25 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
requestUri = "";
|
requestUri = "";
|
||||||
}
|
}
|
||||||
StringTokenizer tokenizer = new StringTokenizer(requestUri, "/");
|
StringTokenizer tokenizer = new StringTokenizer(requestUri, "/");
|
||||||
String context = tokenizer.nextToken();
|
String context = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
|
||||||
if (context == null || "".equals(context)) {
|
if (context == null || "".equals(context)) {
|
||||||
authenticationInfo.setStatus(Status.CONTINUE);
|
authenticationInfo.setStatus(Status.CONTINUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String authorizationHeader = request.getHeader(JWT_ASSERTION_HEADER);
|
String authorizationHeader = request.getHeader(JWT_ASSERTION_HEADER);
|
||||||
|
jwsObject = SignedJWT.parse(authorizationHeader);
|
||||||
|
username = jwsObject.getJWTClaimsSet().getStringClaim(SIGNED_JWT_AUTH_USERNAME);
|
||||||
|
tenantDomain = MultitenantUtils.getTenantDomain(username);
|
||||||
|
tenantId = Integer.parseInt(jwsObject.getJWTClaimsSet().getStringClaim(SIGNED_JWT_AUTH_TENANT_ID));
|
||||||
|
issuer = jwsObject.getJWTClaimsSet().getIssuer();
|
||||||
|
} catch (ParseException e) {
|
||||||
|
log.error("Error occurred while parsing JWT header.", e);
|
||||||
|
authenticationInfo.setMessage("Error occurred while parsing JWT header");
|
||||||
|
return authenticationInfo;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
|
||||||
SignedJWT jwsObject = SignedJWT.parse(authorizationHeader);
|
|
||||||
String username = jwsObject.getJWTClaimsSet().getStringClaim(SIGNED_JWT_AUTH_USERNAME);
|
|
||||||
String tenantDomain = MultitenantUtils.getTenantDomain(username);
|
|
||||||
int tenantId = Integer.parseInt(jwsObject.getJWTClaimsSet().getStringClaim(SIGNED_JWT_AUTH_TENANT_ID));
|
|
||||||
String issuer = jwsObject.getJWTClaimsSet().getIssuer();
|
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
|
||||||
@ -116,7 +128,7 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
loadTenantRegistry(tenantId);
|
loadTenantRegistry(tenantId);
|
||||||
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenantId);
|
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenantId);
|
||||||
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
String alias = properties.getProperty(issuer);
|
String alias = properties == null ? null : properties.getProperty(issuer);
|
||||||
if (alias != null && !alias.isEmpty()) {
|
if (alias != null && !alias.isEmpty()) {
|
||||||
ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
|
ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
|
||||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
@ -124,7 +136,8 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
String trustStorePassword = serverConfig.getFirstProperty(
|
String trustStorePassword = serverConfig.getFirstProperty(
|
||||||
DEFAULT_TRUST_STORE_PASSWORD);
|
DEFAULT_TRUST_STORE_PASSWORD);
|
||||||
keyStore.load(new FileInputStream(trustStorePath), trustStorePassword.toCharArray());
|
keyStore.load(new FileInputStream(trustStorePath), trustStorePassword.toCharArray());
|
||||||
publicKey = keyStore.getCertificate(alias).getPublicKey();
|
java.security.cert.Certificate certificate = keyStore.getCertificate(alias);
|
||||||
|
publicKey = certificate == null ? null : certificate.getPublicKey();
|
||||||
} else {
|
} else {
|
||||||
authenticationInfo.setStatus(Status.FAILURE);
|
authenticationInfo.setStatus(Status.FAILURE);
|
||||||
return authenticationInfo;
|
return authenticationInfo;
|
||||||
@ -139,33 +152,32 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
publicKeyHolder.put(issuerAlias, publicKey);
|
publicKeyHolder.put(issuerAlias, publicKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the filesystem keystore default primary certificate
|
//Get the filesystem keystore default primary certificate
|
||||||
JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) publicKey);
|
JWSVerifier verifier = null;
|
||||||
if (jwsObject.verify(verifier)) {
|
if (publicKey != null) {
|
||||||
|
verifier = new RSASSAVerifier((RSAPublicKey) publicKey);
|
||||||
|
}
|
||||||
|
if (verifier != null && jwsObject.verify(verifier)) {
|
||||||
username = MultitenantUtils.getTenantAwareUsername(username);
|
username = MultitenantUtils.getTenantAwareUsername(username);
|
||||||
if (tenantId == -1) {
|
UserStoreManager userStore = AuthenticatorFrameworkDataHolder.getInstance().getRealmService().
|
||||||
log.error("tenantDomain is not valid. username : " + username + ", tenantDomain " +
|
getTenantUserRealm(tenantId).getUserStoreManager();
|
||||||
": " + tenantDomain);
|
if (userStore.isExistingUser(username)) {
|
||||||
|
authenticationInfo.setTenantId(tenantId);
|
||||||
|
authenticationInfo.setUsername(username);
|
||||||
|
authenticationInfo.setTenantDomain(tenantDomain);
|
||||||
|
authenticationInfo.setStatus(Status.CONTINUE);
|
||||||
} else {
|
} else {
|
||||||
UserStoreManager userStore = AuthenticatorFrameworkDataHolder.getInstance().getRealmService().
|
authenticationInfo.setStatus(Status.FAILURE);
|
||||||
getTenantUserRealm(tenantId).getUserStoreManager();
|
|
||||||
if (userStore.isExistingUser(username)) {
|
|
||||||
authenticationInfo.setTenantId(tenantId);
|
|
||||||
authenticationInfo.setUsername(username);
|
|
||||||
authenticationInfo.setTenantDomain(tenantDomain);
|
|
||||||
authenticationInfo.setStatus(Status.CONTINUE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
authenticationInfo.setStatus(Status.FAILURE);
|
authenticationInfo.setStatus(Status.FAILURE);
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
log.error("Error occurred while obtaining the user.", e);
|
log.error("Error occurred while obtaining the user.", e);
|
||||||
} catch (ParseException e) {
|
authenticationInfo.setStatus(Status.FAILURE);
|
||||||
log.error("Error occurred while parsing the JWT header.", e);
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error occurred while verifying the JWT header.", e);
|
log.error("Error occurred while verifying the JWT header.", e);
|
||||||
|
authenticationInfo.setStatus(Status.FAILURE);
|
||||||
} finally {
|
} finally {
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,18 +21,25 @@ package org.wso2.carbon.webapp.authenticator.framework;
|
|||||||
import org.testng.annotations.BeforeSuite;
|
import org.testng.annotations.BeforeSuite;
|
||||||
import org.wso2.carbon.CarbonConstants;
|
import org.wso2.carbon.CarbonConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.core.internal.CarbonCoreDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils;
|
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils;
|
||||||
|
import org.wso2.carbon.registry.core.config.RegistryContext;
|
||||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
|
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
|
||||||
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
||||||
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.user.api.Permission;
|
import org.wso2.carbon.user.api.Permission;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
import org.wso2.carbon.webapp.authenticator.framework.internal.AuthenticatorFrameworkDataHolder;
|
import org.wso2.carbon.webapp.authenticator.framework.internal.AuthenticatorFrameworkDataHolder;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.util.TestTenantIndexingLoader;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.util.TestTenantRegistryLoader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import static org.wso2.carbon.security.SecurityConstants.ADMIN_USER;
|
import static org.wso2.carbon.security.SecurityConstants.ADMIN_USER;
|
||||||
@ -56,6 +63,17 @@ public class BaseWebAppAuthenticatorFrameworkTest {
|
|||||||
.setTenantDomain(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
.setTenantDomain(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||||
.setTenantId(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID);
|
.setTenantId(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
CarbonCoreDataHolder.getInstance().setRegistryService(getRegistryService());
|
||||||
|
AuthenticatorFrameworkDataHolder.getInstance().setTenantRegistryLoader(new TestTenantRegistryLoader());
|
||||||
|
AuthenticatorFrameworkDataHolder.getInstance().setTenantIndexingLoader(new TestTenantIndexingLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the registry service.
|
||||||
|
* @return RegistryService
|
||||||
|
* @throws RegistryException Registry Exception
|
||||||
|
*/
|
||||||
|
private RegistryService getRegistryService() throws RegistryException, UserStoreException {
|
||||||
RealmService realmService = new InMemoryRealmService();
|
RealmService realmService = new InMemoryRealmService();
|
||||||
AuthenticatorFrameworkDataHolder.getInstance().setRealmService(realmService);
|
AuthenticatorFrameworkDataHolder.getInstance().setRealmService(realmService);
|
||||||
UserStoreManager userStoreManager = AuthenticatorFrameworkDataHolder.getInstance().getRealmService()
|
UserStoreManager userStoreManager = AuthenticatorFrameworkDataHolder.getInstance().getRealmService()
|
||||||
@ -63,5 +81,12 @@ public class BaseWebAppAuthenticatorFrameworkTest {
|
|||||||
Permission adminPermission = new Permission(PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH,
|
Permission adminPermission = new Permission(PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH,
|
||||||
CarbonConstants.UI_PERMISSION_ACTION);
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
userStoreManager.addRole(ADMIN_ROLE + "t", new String[] { ADMIN_USER }, new Permission[] { adminPermission });
|
userStoreManager.addRole(ADMIN_ROLE + "t", new String[] { ADMIN_USER }, new Permission[] { adminPermission });
|
||||||
|
RegistryDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
InputStream is = BaseWebAppAuthenticatorFrameworkTest.class.getClassLoader()
|
||||||
|
.getResourceAsStream("carbon-home/repository/conf/registry.xml");
|
||||||
|
RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
|
||||||
|
context.setSetup(true);
|
||||||
|
return context.getEmbeddedRegistryService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,284 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.authenticator.framework.authenticator;
|
||||||
|
|
||||||
|
import org.apache.catalina.Context;
|
||||||
|
import org.apache.catalina.connector.Request;
|
||||||
|
import org.apache.catalina.core.StandardContext;
|
||||||
|
import org.apache.tomcat.util.buf.MessageBytes;
|
||||||
|
import org.apache.tomcat.util.http.MimeHeaders;
|
||||||
|
import org.bouncycastle.cert.jcajce.JcaCertStore;
|
||||||
|
import org.bouncycastle.cms.CMSAbsentContent;
|
||||||
|
import org.bouncycastle.cms.CMSException;
|
||||||
|
import org.bouncycastle.cms.CMSSignedData;
|
||||||
|
import org.bouncycastle.cms.CMSSignedDataGenerator;
|
||||||
|
import org.h2.jdbcx.JdbcDataSource;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.impl.KeyStoreReader;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.scep.SCEPException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.scep.SCEPManager;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.scep.SCEPManagerImpl;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.scep.TenantedDeviceWrapper;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.AuthenticationInfo;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.internal.AuthenticatorFrameworkDataHolder;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.util.TestCertificateGenerator;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.cert.CertificateEncodingException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a test case for {@link CertificateAuthenticator}.
|
||||||
|
*/
|
||||||
|
public class CertificateAuthenticatorTest {
|
||||||
|
private CertificateAuthenticator certificateAuthenticator;
|
||||||
|
private Request certificationVerificationRequest;
|
||||||
|
private Request mutalAuthHeaderRequest;
|
||||||
|
private Request proxyMutalAuthHeaderRequest;
|
||||||
|
private Field headersField;
|
||||||
|
private static final String MUTUAL_AUTH_HEADER = "mutual-auth-header";
|
||||||
|
private static final String PROXY_MUTUAL_AUTH_HEADER = "proxy-mutual-auth-header";
|
||||||
|
private static final String CERTIFICATE_VERIFICATION_HEADER = "Mdm-Signature";
|
||||||
|
private static final String CLIENT_CERTIFICATE_ATTRIBUTE = "javax.servlet.request.X509Certificate";
|
||||||
|
private X509Certificate X509certificate;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void setup() throws KeystoreException, NoSuchFieldException, IllegalAccessException, SQLException,
|
||||||
|
DeviceManagementException, CertificateEncodingException, CMSException, IOException, SCEPException {
|
||||||
|
certificateAuthenticator = new CertificateAuthenticator();
|
||||||
|
CertificateManagementService certificateManagementService = Mockito
|
||||||
|
.mock(CertificateManagementServiceImpl.class, Mockito.CALLS_REAL_METHODS);
|
||||||
|
headersField = org.apache.coyote.Request.class.getDeclaredField("headers");
|
||||||
|
headersField.setAccessible(true);
|
||||||
|
|
||||||
|
Field certificateManagementServiceImpl = CertificateManagementServiceImpl.class.getDeclaredField
|
||||||
|
("certificateManagementServiceImpl");
|
||||||
|
certificateManagementServiceImpl.setAccessible(true);
|
||||||
|
Field keyStoreReaderField = CertificateManagementServiceImpl.class.getDeclaredField("keyStoreReader");
|
||||||
|
keyStoreReaderField.setAccessible(true);
|
||||||
|
Field certificateGeneratorField = CertificateManagementServiceImpl.class.getDeclaredField
|
||||||
|
("certificateGenerator");
|
||||||
|
certificateGeneratorField.setAccessible(true);
|
||||||
|
certificateManagementServiceImpl.set(null, certificateManagementService);
|
||||||
|
|
||||||
|
// Create KeyStore Reader
|
||||||
|
Field dataSource = CertificateManagementDAOFactory.class.getDeclaredField("dataSource");
|
||||||
|
dataSource.setAccessible(true);
|
||||||
|
dataSource.set(null, createDatabase());
|
||||||
|
Field databaseEngine = CertificateManagementDAOFactory.class.getDeclaredField("databaseEngine");
|
||||||
|
databaseEngine.setAccessible(true);
|
||||||
|
databaseEngine.set(null, "H2");
|
||||||
|
KeyStoreReader keyStoreReader = new KeyStoreReader();
|
||||||
|
keyStoreReaderField.set(null, keyStoreReader);
|
||||||
|
|
||||||
|
CertificateGenerator certificateGenerator = new TestCertificateGenerator();
|
||||||
|
certificateGeneratorField.set(null, certificateGenerator);
|
||||||
|
|
||||||
|
AuthenticatorFrameworkDataHolder.getInstance().
|
||||||
|
setCertificateManagementService(certificateManagementService);
|
||||||
|
X509certificate = certificateManagementService.generateX509Certificate();
|
||||||
|
|
||||||
|
proxyMutalAuthHeaderRequest = createRequest(PROXY_MUTUAL_AUTH_HEADER, String.valueOf(X509certificate));
|
||||||
|
System.setProperty("carbon.config.dir.path",
|
||||||
|
System.getProperty("carbon.home") + File.separator + "repository" + File.separator + "conf");
|
||||||
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
|
certificationVerificationRequest = createRequest(CERTIFICATE_VERIFICATION_HEADER,
|
||||||
|
createEncodedSignature(X509certificate));
|
||||||
|
|
||||||
|
mutalAuthHeaderRequest = createRequest(MUTUAL_AUTH_HEADER, "test");
|
||||||
|
|
||||||
|
SCEPManager scepManager = Mockito.mock(SCEPManagerImpl.class, Mockito.CALLS_REAL_METHODS);
|
||||||
|
TenantedDeviceWrapper tenantedDeviceWrapper = new TenantedDeviceWrapper();
|
||||||
|
tenantedDeviceWrapper.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||||
|
tenantedDeviceWrapper.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
Device device = new Device();
|
||||||
|
device.setEnrolmentInfo(new EnrolmentInfo("admin", null, null));
|
||||||
|
tenantedDeviceWrapper.setDevice(device);
|
||||||
|
Mockito.doReturn(tenantedDeviceWrapper).when(scepManager).getValidatedDevice(Mockito.any());
|
||||||
|
AuthenticatorFrameworkDataHolder.getInstance().setScepManager(scepManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests the behaviour of the CertificateAuthenticator for Proxy mutal Auth "
|
||||||
|
+ "Header requests")
|
||||||
|
public void testRequestsWithProxyMutalAuthHeader()
|
||||||
|
throws KeystoreException, NoSuchFieldException, IllegalAccessException {
|
||||||
|
Assert.assertTrue(certificateAuthenticator.canHandle(proxyMutalAuthHeaderRequest), "canHandle method "
|
||||||
|
+ "returned false for a request with all the required header");
|
||||||
|
AuthenticationInfo authenticationInfo = certificateAuthenticator
|
||||||
|
.authenticate(proxyMutalAuthHeaderRequest, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
|
||||||
|
Assert.assertNull(authenticationInfo.getTenantDomain(),
|
||||||
|
"Authentication got succeeded without proper certificate");
|
||||||
|
|
||||||
|
proxyMutalAuthHeaderRequest = createRequest(PROXY_MUTUAL_AUTH_HEADER,
|
||||||
|
String.valueOf(X509certificate.getIssuerDN()));
|
||||||
|
authenticationInfo = certificateAuthenticator.authenticate(proxyMutalAuthHeaderRequest, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
|
||||||
|
Assert.assertNotNull(authenticationInfo.getTenantDomain(),
|
||||||
|
"Authentication got failed for a proper certificate");
|
||||||
|
|
||||||
|
CertificateGenerator tempCertificateGenerator = new CertificateGenerator();
|
||||||
|
X509Certificate certificateWithOutCN = tempCertificateGenerator.generateX509Certificate();
|
||||||
|
proxyMutalAuthHeaderRequest = createRequest(PROXY_MUTUAL_AUTH_HEADER,
|
||||||
|
String.valueOf(certificateWithOutCN.getIssuerDN()));
|
||||||
|
authenticationInfo = certificateAuthenticator.authenticate(proxyMutalAuthHeaderRequest, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
|
||||||
|
Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.FAILURE,
|
||||||
|
"Authentication got passed with a certificate without CN");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests the behaviour of the CertificateAuthenticator for Certification "
|
||||||
|
+ "Verification Header requests")
|
||||||
|
public void testRequestCertificateVerificationHeader()
|
||||||
|
throws CertificateEncodingException, IOException, CMSException, NoSuchFieldException,
|
||||||
|
IllegalAccessException {
|
||||||
|
Assert.assertTrue(certificateAuthenticator.canHandle(certificationVerificationRequest),
|
||||||
|
"canHandle method returned false for a request with all the required header");
|
||||||
|
AuthenticationInfo authenticationInfo = certificateAuthenticator
|
||||||
|
.authenticate(certificationVerificationRequest, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
|
||||||
|
Assert.assertNull(authenticationInfo.getTenantDomain(), "Authentication got passed without proper certificate");
|
||||||
|
authenticationInfo = certificateAuthenticator.authenticate(certificationVerificationRequest, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
|
||||||
|
Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
|
||||||
|
"Authentication failed for a valid request with " + CERTIFICATE_VERIFICATION_HEADER + " header");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests the behaviour of the Certificate Authenticator for the requests with "
|
||||||
|
+ "Mutal Auth Header")
|
||||||
|
public void testMutalAuthHeaderRequest() {
|
||||||
|
Assert.assertTrue(certificateAuthenticator.canHandle(mutalAuthHeaderRequest),
|
||||||
|
"canHandle method returned false for a request with all the required header");
|
||||||
|
|
||||||
|
AuthenticationInfo authenticationInfo = certificateAuthenticator.authenticate(mutalAuthHeaderRequest, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
|
||||||
|
Assert.assertEquals(authenticationInfo.getMessage(), "No client certificate is present",
|
||||||
|
"Authentication got passed without proper certificate");
|
||||||
|
|
||||||
|
X509Certificate[] x509Certificates = new X509Certificate[1];
|
||||||
|
x509Certificates[0] = X509certificate;
|
||||||
|
mutalAuthHeaderRequest.setAttribute(CLIENT_CERTIFICATE_ATTRIBUTE, x509Certificates);
|
||||||
|
authenticationInfo = certificateAuthenticator.authenticate(mutalAuthHeaderRequest, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
|
||||||
|
Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
|
||||||
|
"Authentication failed even with proper certificate");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* To create a request that can be understandable by Certificate Authenticator.
|
||||||
|
*
|
||||||
|
* @param headerName Name of the header
|
||||||
|
* @param value Value for the header
|
||||||
|
* @return Request that is created.
|
||||||
|
* @throws IllegalAccessException Illegal Access Exception.
|
||||||
|
* @throws NoSuchFieldException No Such Field Exception.
|
||||||
|
*/
|
||||||
|
private Request createRequest(String headerName, String value) throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
Request request = new Request();
|
||||||
|
Context context = new StandardContext();
|
||||||
|
request.setContext(context);
|
||||||
|
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
|
||||||
|
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||||
|
MessageBytes bytes = mimeHeaders.addValue(headerName);
|
||||||
|
bytes.setString(value);
|
||||||
|
headersField.set(coyoteRequest, mimeHeaders);
|
||||||
|
|
||||||
|
request.setCoyoteRequest(coyoteRequest);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To create certificate management database.
|
||||||
|
*
|
||||||
|
* @return Datasource.
|
||||||
|
* @throws SQLException SQL Exception.
|
||||||
|
*/
|
||||||
|
private DataSource createDatabase() throws SQLException {
|
||||||
|
URL resourceURL = ClassLoader.getSystemResource("sql-scripts" + File.separator + "h2.sql");
|
||||||
|
JdbcDataSource dataSource = new JdbcDataSource();
|
||||||
|
dataSource.setURL("jdbc:h2:mem:cert;DB_CLOSE_DELAY=-1");
|
||||||
|
dataSource.setUser("sa");
|
||||||
|
dataSource.setPassword("sa");
|
||||||
|
final String LOAD_DATA_QUERY = "RUNSCRIPT FROM '" + resourceURL.getPath() + "'";
|
||||||
|
Connection conn = null;
|
||||||
|
Statement statement = null;
|
||||||
|
try {
|
||||||
|
conn = dataSource.getConnection();
|
||||||
|
statement = conn.createStatement();
|
||||||
|
statement.execute(LOAD_DATA_QUERY);
|
||||||
|
} finally {
|
||||||
|
if (conn != null) {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {}
|
||||||
|
}
|
||||||
|
if (statement != null) {
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To create a encoded signature from certificate.
|
||||||
|
*
|
||||||
|
* @param x509Certificate Certificate that need to be encoded.
|
||||||
|
* @return Encoded signature.
|
||||||
|
* @throws CertificateEncodingException Certificate Encoding Exception.
|
||||||
|
* @throws CMSException CMS Exception.
|
||||||
|
* @throws IOException IO Exception.
|
||||||
|
*/
|
||||||
|
private String createEncodedSignature(X509Certificate x509Certificate) throws CertificateEncodingException,
|
||||||
|
CMSException, IOException {
|
||||||
|
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
|
||||||
|
List<X509Certificate> list = new ArrayList<>();
|
||||||
|
list.add(x509Certificate);
|
||||||
|
JcaCertStore store = new JcaCertStore(list);
|
||||||
|
generator.addCertificates(store);
|
||||||
|
AtomicReference<CMSSignedData> degenerateSd = new AtomicReference<>(generator.generate(new CMSAbsentContent()));
|
||||||
|
byte[] signature = degenerateSd.get().getEncoded();
|
||||||
|
return Base64.getEncoder().encodeToString(signature);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.authenticator.framework.authenticator;
|
||||||
|
|
||||||
|
import org.apache.catalina.connector.Request;
|
||||||
|
import org.apache.tomcat.util.buf.MessageBytes;
|
||||||
|
import org.apache.tomcat.util.http.MimeHeaders;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.dto.JWTConfig;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.util.JWTClientUtil;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.AuthenticationInfo;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a test class for {@link JWTAuthenticator}.
|
||||||
|
*/
|
||||||
|
public class JWTAuthenticatorTest {
|
||||||
|
private JWTAuthenticator jwtAuthenticator;
|
||||||
|
private Field headersField;
|
||||||
|
private final String JWT_HEADER = "X-JWT-Assertion";
|
||||||
|
private String jwtToken;
|
||||||
|
private String wrongJwtToken;
|
||||||
|
private String jwtTokenWithWrongUser;
|
||||||
|
private static final String SIGNED_JWT_AUTH_USERNAME = "http://wso2.org/claims/enduser";
|
||||||
|
private static final String SIGNED_JWT_AUTH_TENANT_ID = "http://wso2.org/claims/enduserTenantId";
|
||||||
|
private Properties properties;
|
||||||
|
private final String ISSUER = "wso2.org/products/iot";
|
||||||
|
private final String ALIAS = "wso2carbon";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void setup() throws NoSuchFieldException, IOException, JWTClientException {
|
||||||
|
jwtAuthenticator = new JWTAuthenticator();
|
||||||
|
headersField = org.apache.coyote.Request.class.getDeclaredField("headers");
|
||||||
|
headersField.setAccessible(true);
|
||||||
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
|
URL resourceUrl = classLoader.getResource("jwt.properties");
|
||||||
|
File jwtPropertyFile;
|
||||||
|
JWTConfig jwtConfig = null;
|
||||||
|
if (resourceUrl != null) {
|
||||||
|
jwtPropertyFile = new File(resourceUrl.getFile());
|
||||||
|
Properties jwtConfigProperties = new Properties();
|
||||||
|
jwtConfigProperties.load(new FileInputStream(jwtPropertyFile));
|
||||||
|
jwtConfig = new JWTConfig(jwtConfigProperties);
|
||||||
|
}
|
||||||
|
Map<String, String> customClaims = new HashMap<>();
|
||||||
|
customClaims.put(SIGNED_JWT_AUTH_USERNAME, "admin");
|
||||||
|
customClaims.put(SIGNED_JWT_AUTH_TENANT_ID, String.valueOf(MultitenantConstants.SUPER_TENANT_ID));
|
||||||
|
jwtToken = JWTClientUtil.generateSignedJWTAssertion("admin", jwtConfig, false, customClaims);
|
||||||
|
customClaims = new HashMap<>();
|
||||||
|
customClaims.put(SIGNED_JWT_AUTH_USERNAME, "admin");
|
||||||
|
customClaims.put(SIGNED_JWT_AUTH_TENANT_ID, "-1");
|
||||||
|
wrongJwtToken = JWTClientUtil.generateSignedJWTAssertion("admin", jwtConfig, false, customClaims);
|
||||||
|
customClaims = new HashMap<>();
|
||||||
|
customClaims.put(SIGNED_JWT_AUTH_USERNAME, "notexisting");
|
||||||
|
customClaims.put(SIGNED_JWT_AUTH_TENANT_ID, String.valueOf(MultitenantConstants.SUPER_TENANT_ID));
|
||||||
|
jwtTokenWithWrongUser = JWTClientUtil.generateSignedJWTAssertion("notexisting", jwtConfig, false, customClaims);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the get methods in the JWTAuthenticator",
|
||||||
|
dependsOnMethods = "testAuthenticate")
|
||||||
|
public void testGetMethods() {
|
||||||
|
Assert.assertEquals(jwtAuthenticator.getName(), "JWT", "GetName method returns wrong value");
|
||||||
|
Assert.assertNotNull(jwtAuthenticator.getProperties(), "Properties are not properly added to JWT "
|
||||||
|
+ "Authenticator");
|
||||||
|
Assert.assertEquals(jwtAuthenticator.getProperties().size(), properties.size(),
|
||||||
|
"Added properties do not match with retrieved properties");
|
||||||
|
Assert.assertNull(jwtAuthenticator.getProperty("test"), "Retrieved a propety that was never added");
|
||||||
|
Assert.assertNotNull(jwtAuthenticator.getProperty(ISSUER), ALIAS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the canHandle method under different conditions of request")
|
||||||
|
public void testHandle() throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
Request request = new Request();
|
||||||
|
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
|
||||||
|
request.setCoyoteRequest(coyoteRequest);
|
||||||
|
Assert.assertFalse(jwtAuthenticator.canHandle(request));
|
||||||
|
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||||
|
MessageBytes bytes = mimeHeaders.addValue(JWT_HEADER);
|
||||||
|
bytes.setString("test");
|
||||||
|
headersField.set(coyoteRequest, mimeHeaders);
|
||||||
|
request.setCoyoteRequest(coyoteRequest);
|
||||||
|
Assert.assertTrue(jwtAuthenticator.canHandle(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests authenticate method under the successful condition", dependsOnMethods =
|
||||||
|
{ "testAuthenticateFailureScenarios" })
|
||||||
|
public void testAuthenticate() throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
Request request = createJWTRequest(jwtToken, "test");
|
||||||
|
AuthenticationInfo authenticationInfo = jwtAuthenticator.authenticate(request, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo.getUsername(), "Proper authentication request is not properly "
|
||||||
|
+ "authenticated by the JWTAuthenticator");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the authenticate method under failure conditions")
|
||||||
|
public void testAuthenticateFailureScenarios() throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Request request = createJWTRequest("test", "");
|
||||||
|
AuthenticationInfo authenticationInfo = jwtAuthenticator.authenticate(request, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Returned authentication info was null");
|
||||||
|
Assert.assertNull(authenticationInfo.getUsername(), "Un-authenticated request contain username");
|
||||||
|
request = createJWTRequest(jwtToken, "");
|
||||||
|
authenticationInfo = jwtAuthenticator.authenticate(request, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Returned authentication info was null");
|
||||||
|
Assert.assertNull(authenticationInfo.getUsername(), "Un-authenticated request contain username");
|
||||||
|
properties = new Properties();
|
||||||
|
properties.setProperty(ISSUER, "test");
|
||||||
|
jwtAuthenticator.setProperties(properties);
|
||||||
|
request = createJWTRequest(jwtToken, "");
|
||||||
|
authenticationInfo = jwtAuthenticator.authenticate(request, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Returned authentication info was null");
|
||||||
|
Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.FAILURE,
|
||||||
|
"Un authenticated request does not contain status as failure");
|
||||||
|
properties = new Properties();
|
||||||
|
properties.setProperty(ISSUER, ALIAS);
|
||||||
|
jwtAuthenticator.setProperties(properties);
|
||||||
|
request = createJWTRequest(wrongJwtToken, "");
|
||||||
|
authenticationInfo = jwtAuthenticator.authenticate(request, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Returned authentication info was null");
|
||||||
|
Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.FAILURE,
|
||||||
|
"Un authenticated request does not contain status as failure");
|
||||||
|
request = createJWTRequest(jwtTokenWithWrongUser, "");
|
||||||
|
authenticationInfo = jwtAuthenticator.authenticate(request, null);
|
||||||
|
Assert.assertNotNull(authenticationInfo, "Returned authentication info was null");
|
||||||
|
Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.FAILURE,
|
||||||
|
"Un authenticated request does not contain status as failure");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To create a JWT request with the given jwt header.
|
||||||
|
* @param jwtToken JWT token to be added to the header
|
||||||
|
* @param requestUri Request URI to be added to the request.
|
||||||
|
*/
|
||||||
|
private Request createJWTRequest(String jwtToken, String requestUri)
|
||||||
|
throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
Request request = new Request();
|
||||||
|
org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
|
||||||
|
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||||
|
MessageBytes bytes = mimeHeaders.addValue(JWT_HEADER);
|
||||||
|
bytes.setString(jwtToken);
|
||||||
|
headersField.set(coyoteRequest, mimeHeaders);
|
||||||
|
Field uriMB = org.apache.coyote.Request.class.getDeclaredField("uriMB");
|
||||||
|
uriMB.setAccessible(true);
|
||||||
|
bytes = MessageBytes.newInstance();
|
||||||
|
bytes.setString(requestUri);
|
||||||
|
uriMB.set(coyoteRequest, bytes);
|
||||||
|
request.setCoyoteRequest(coyoteRequest);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.authenticator.framework.internal;
|
||||||
|
|
||||||
|
import org.apache.sling.testing.mock.osgi.MockOsgi;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a test class for {@link WebappAuthenticatorFrameworkServiceComponent}
|
||||||
|
*/
|
||||||
|
public class WebappAuthenticatorFrameworkServiceComponentTest {
|
||||||
|
|
||||||
|
@Test(description = "This method tests whether the bundle activator does not throw any exceptions, even under "
|
||||||
|
+ "possible exception scenarios")
|
||||||
|
public void testActivateWithException() {
|
||||||
|
WebappAuthenticatorFrameworkServiceComponent webappAuthenticatorFrameworkServiceComponent = new
|
||||||
|
WebappAuthenticatorFrameworkServiceComponent();
|
||||||
|
webappAuthenticatorFrameworkServiceComponent.activate(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests whether bundle activation succeed with the proper confitions.")
|
||||||
|
public void testActivateWithoutExceptions() {
|
||||||
|
WebappAuthenticatorFrameworkServiceComponent webappAuthenticatorFrameworkServiceComponent = new
|
||||||
|
WebappAuthenticatorFrameworkServiceComponent();
|
||||||
|
webappAuthenticatorFrameworkServiceComponent.activate(MockOsgi.newComponentContext());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.authenticator.framework.util;
|
||||||
|
|
||||||
|
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
||||||
|
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
|
||||||
|
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
|
||||||
|
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
|
import org.bouncycastle.operator.ContentSigner;
|
||||||
|
import org.bouncycastle.operator.OperatorCreationException;
|
||||||
|
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.bean.Certificate;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.util.CertificateManagementConstants;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.util.CommonUtil;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
|
import javax.security.auth.x500.X500Principal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.KeyPairGenerator;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.NoSuchProviderException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.Security;
|
||||||
|
import java.security.SignatureException;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.CertificateExpiredException;
|
||||||
|
import java.security.cert.CertificateNotYetValidException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a mock implementation of {@link CertificateGenerator}.
|
||||||
|
*/
|
||||||
|
public class TestCertificateGenerator extends CertificateGenerator {
|
||||||
|
private int count = 0;
|
||||||
|
|
||||||
|
public X509Certificate generateX509Certificate() throws KeystoreException {
|
||||||
|
BigInteger serialNumber = CommonUtil.generateSerialNumber();
|
||||||
|
String defaultPrinciple = "CN=" + serialNumber + ",O=WSO2,OU=Mobile,C=LK";
|
||||||
|
CommonUtil commonUtil = new CommonUtil();
|
||||||
|
Date validityBeginDate = commonUtil.getValidityStartDate();
|
||||||
|
Date validityEndDate = commonUtil.getValidityEndDate();
|
||||||
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
|
||||||
|
try {
|
||||||
|
KeyPairGenerator keyPairGenerator = KeyPairGenerator
|
||||||
|
.getInstance(CertificateManagementConstants.RSA, CertificateManagementConstants.PROVIDER);
|
||||||
|
keyPairGenerator.initialize(CertificateManagementConstants.RSA_KEY_LENGTH, new SecureRandom());
|
||||||
|
KeyPair pair = keyPairGenerator.generateKeyPair();
|
||||||
|
X500Principal principal = new X500Principal(defaultPrinciple);
|
||||||
|
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(principal, serialNumber,
|
||||||
|
validityBeginDate, validityEndDate, principal, pair.getPublic());
|
||||||
|
ContentSigner contentSigner = new JcaContentSignerBuilder(CertificateManagementConstants.SHA256_RSA)
|
||||||
|
.setProvider(CertificateManagementConstants.PROVIDER).build(pair.getPrivate());
|
||||||
|
X509Certificate certificate = new JcaX509CertificateConverter()
|
||||||
|
.setProvider(CertificateManagementConstants.PROVIDER)
|
||||||
|
.getCertificate(certificateBuilder.build(contentSigner));
|
||||||
|
certificate.verify(certificate.getPublicKey());
|
||||||
|
List<Certificate> certificates = new ArrayList<>();
|
||||||
|
org.wso2.carbon.certificate.mgt.core.bean.Certificate certificateToStore =
|
||||||
|
new org.wso2.carbon.certificate.mgt.core.bean.Certificate();
|
||||||
|
certificateToStore.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
certificateToStore.setCertificate(certificate);
|
||||||
|
certificates.add(certificateToStore);
|
||||||
|
saveCertInKeyStore(certificates);
|
||||||
|
return certificate;
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
String errorMsg = "No such algorithm found when generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (NoSuchProviderException e) {
|
||||||
|
String errorMsg = "No such provider found when generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (OperatorCreationException e) {
|
||||||
|
String errorMsg = "Issue in operator creation when generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateExpiredException e) {
|
||||||
|
String errorMsg = "Certificate expired after generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateNotYetValidException e) {
|
||||||
|
String errorMsg = "Certificate not yet valid when generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
String errorMsg = "Certificate issue occurred when generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
String errorMsg = "Invalid key used when generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (SignatureException e) {
|
||||||
|
String errorMsg = "Signature related issue occurred when generating certificate";
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String extractChallengeToken(X509Certificate certificate) {
|
||||||
|
if (count != 0) {
|
||||||
|
return "WSO2 (Challenge)";
|
||||||
|
} else {
|
||||||
|
count++;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.authenticator.framework.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a mock implementation of {@link TenantIndexingLoader}
|
||||||
|
*/
|
||||||
|
public class TestTenantIndexingLoader implements TenantIndexingLoader {
|
||||||
|
@Override
|
||||||
|
public void loadTenantIndex(int i) { }
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.webapp.authenticator.framework.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
|
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a mock implementation of {@link TenantRegistryLoader} for the test cases.
|
||||||
|
*/
|
||||||
|
public class TestTenantRegistryLoader implements TenantRegistryLoader {
|
||||||
|
@Override
|
||||||
|
public void loadTenantRegistry(int i) throws RegistryException { }
|
||||||
|
}
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<DeviceMgtConfiguration>
|
||||||
|
<ManagementRepository>
|
||||||
|
<DataSourceConfiguration>
|
||||||
|
<JndiLookupDefinition>
|
||||||
|
<Name>jdbc/DM_DS</Name>
|
||||||
|
</JndiLookupDefinition>
|
||||||
|
</DataSourceConfiguration>
|
||||||
|
</ManagementRepository>
|
||||||
|
<PushNotificationConfiguration>
|
||||||
|
<SchedulerBatchSize>1000</SchedulerBatchSize>
|
||||||
|
<SchedulerBatchDelayMills>60000</SchedulerBatchDelayMills>
|
||||||
|
<SchedulerTaskInitialDelay>60000</SchedulerTaskInitialDelay>
|
||||||
|
<SchedulerTaskEnabled>true</SchedulerTaskEnabled>
|
||||||
|
<PushNotificationProviders>
|
||||||
|
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider</Provider>
|
||||||
|
<!--<Provider>org.wso2.carbon.device.mgt.mobile.impl.ios.apns.APNSBasedPushNotificationProvider</Provider>-->
|
||||||
|
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider</Provider>
|
||||||
|
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider</Provider>
|
||||||
|
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider</Provider>
|
||||||
|
</PushNotificationProviders>
|
||||||
|
</PushNotificationConfiguration>
|
||||||
|
<PullNotificationConfiguration>
|
||||||
|
<Enabled>false</Enabled>
|
||||||
|
</PullNotificationConfiguration>
|
||||||
|
<IdentityConfiguration>
|
||||||
|
<ServerUrl>https://localhost:9443</ServerUrl>
|
||||||
|
<AdminUsername>admin</AdminUsername>
|
||||||
|
<AdminPassword>admin</AdminPassword>
|
||||||
|
</IdentityConfiguration>
|
||||||
|
<PolicyConfiguration>
|
||||||
|
<MonitoringClass>org.wso2.carbon.policy.mgt</MonitoringClass>
|
||||||
|
<MonitoringEnable>true</MonitoringEnable>
|
||||||
|
<MonitoringFrequency>60000</MonitoringFrequency>
|
||||||
|
<MaxRetries>5</MaxRetries>
|
||||||
|
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
|
||||||
|
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
|
||||||
|
<!--Set the policy evaluation point name-->
|
||||||
|
<!--Simple -> Simple policy evaluation point-->
|
||||||
|
<!--Merged -> Merged policy evaluation point -->
|
||||||
|
<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>
|
||||||
|
</PolicyConfiguration>
|
||||||
|
<!-- Default Page size configuration for paginated DM APIs-->
|
||||||
|
<PaginationConfiguration>
|
||||||
|
<DeviceListPageSize>20</DeviceListPageSize>
|
||||||
|
<GroupListPageSize>20</GroupListPageSize>
|
||||||
|
<NotificationListPageSize>20</NotificationListPageSize>
|
||||||
|
<ActivityListPageSize>20</ActivityListPageSize>
|
||||||
|
<OperationListPageSize>20</OperationListPageSize>
|
||||||
|
<TopicListPageSize>20</TopicListPageSize>
|
||||||
|
</PaginationConfiguration>
|
||||||
|
<!--This specifies whether to enable the DeviceStatus Task in this node. In clustered setup only master node
|
||||||
|
should have to run this task.-->
|
||||||
|
<DeviceStatusTaskConfig>
|
||||||
|
<Enable>true</Enable>
|
||||||
|
</DeviceStatusTaskConfig>
|
||||||
|
<!--This controls the in-memory device cache which is local to this node. Setting it enable will activate the
|
||||||
|
device caching for upto configured expiry-time in seconds. In clustered setup all worker nodes can enable the
|
||||||
|
device-cache to improve performance. -->
|
||||||
|
<DeviceCacheConfiguration>
|
||||||
|
<Enable>true</Enable>
|
||||||
|
<ExpiryTime>600</ExpiryTime>
|
||||||
|
<!--This configuration specifies the number of cache entries in device cache. default capacity is 10000 entries.
|
||||||
|
This can be configured to higher number if cache eviction happens due to large number of devices in the
|
||||||
|
server environment-->
|
||||||
|
<Capacity>10000</Capacity>
|
||||||
|
</DeviceCacheConfiguration>
|
||||||
|
<CertificateCacheConfiguration>
|
||||||
|
<Enable>false</Enable>
|
||||||
|
<ExpiryTime>86400</ExpiryTime>
|
||||||
|
</CertificateCacheConfiguration>
|
||||||
|
<GeoLocationConfiguration>
|
||||||
|
<isEnabled>false</isEnabled>
|
||||||
|
<PublishLocationOperationResponse>false</PublishLocationOperationResponse>
|
||||||
|
</GeoLocationConfiguration>
|
||||||
|
<DefaultGroupsConfiguration>BYOD,COPE</DefaultGroupsConfiguration>
|
||||||
|
</DeviceMgtConfiguration>
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,57 @@
|
|||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
#issuer of the JWT
|
||||||
|
iss=wso2.org/products/iot
|
||||||
|
|
||||||
|
TokenEndpoint=https://${iot.gateway.host}:${iot.gateway.https.port}/token?tenantDomain=carbon.super
|
||||||
|
|
||||||
|
#audience of JWT claim
|
||||||
|
#comma seperated values
|
||||||
|
aud=devicemgt
|
||||||
|
|
||||||
|
#expiration time of JWT (number of minutes from the current time)
|
||||||
|
exp=1000
|
||||||
|
|
||||||
|
#issued at time of JWT (number of minutes from the current time)
|
||||||
|
iat=0
|
||||||
|
|
||||||
|
#nbf time of JWT (number of minutes from current time)
|
||||||
|
nbf=0
|
||||||
|
|
||||||
|
#skew between IDP and issuer(seconds)
|
||||||
|
skew=0
|
||||||
|
|
||||||
|
# JWT Id
|
||||||
|
#jti=token123
|
||||||
|
|
||||||
|
#KeyStore to cryptographic credentials
|
||||||
|
KeyStore=target/test-classes/carbon-home/repository/resources/security/wso2carbon.jks
|
||||||
|
|
||||||
|
#Password of the KeyStore
|
||||||
|
KeyStorePassword=wso2carbon
|
||||||
|
|
||||||
|
#Alias of the SP's private key
|
||||||
|
PrivateKeyAlias=wso2carbon
|
||||||
|
|
||||||
|
#Private key password to retrieve the private key used to sign
|
||||||
|
#AuthnRequest and LogoutRequest messages
|
||||||
|
PrivateKeyPassword=wso2carbon
|
||||||
|
|
||||||
|
#this will be used as the default IDP config if there isn't any config available for tenants.
|
||||||
|
default-jwt-client=false
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
--
|
||||||
|
-- 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.
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
|
||||||
|
ID INTEGER auto_increment NOT NULL,
|
||||||
|
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
|
||||||
|
CERTIFICATE BLOB DEFAULT NULL,
|
||||||
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
|
USERNAME VARCHAR(500) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
);
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<suite name="WebappAuthenticatorFramework">
|
<suite name="WebappAuthenticatorFramework">
|
||||||
<parameter name="useDefaultListeners" value="false"/>
|
<parameter name="useDefaultListeners" value="false"/>
|
||||||
|
|
||||||
<test name="WebappAuthenticatorTests" preserve-order="true">
|
<test name="WebappAuthenticatorTests" parallel="false">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="org.wso2.carbon.webapp.authenticator.framework.BaseWebAppAuthenticatorFrameworkTest"/>
|
<class name="org.wso2.carbon.webapp.authenticator.framework.BaseWebAppAuthenticatorFrameworkTest"/>
|
||||||
<class name="org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorConfigTest"/>
|
<class name="org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorConfigTest"/>
|
||||||
@ -31,6 +31,9 @@
|
|||||||
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.BasicAuthAuthenticatorTest" />
|
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.BasicAuthAuthenticatorTest" />
|
||||||
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.BSTAuthenticatorTest" />
|
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.BSTAuthenticatorTest" />
|
||||||
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.OauthAuthenticatorTest" />
|
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.OauthAuthenticatorTest" />
|
||||||
|
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.JWTAuthenticatorTest" />
|
||||||
|
<class name="org.wso2.carbon.webapp.authenticator.framework.authenticator.CertificateAuthenticatorTest" />
|
||||||
|
<class name="org.wso2.carbon.webapp.authenticator.framework.internal.WebappAuthenticatorFrameworkServiceComponentTest"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
|
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>webapp-authenticator-framework</artifactId>
|
<artifactId>webapp-authenticator-framework</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>WSO2 Carbon - Webapp Authenticator Framework</name>
|
<name>WSO2 Carbon - Webapp Authenticator Framework</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
|
|||||||
@ -21,14 +21,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>apimgt-extensions-feature</artifactId>
|
<artifactId>apimgt-extensions-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.application.extension.feature</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.application.extension.feature</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<name>WSO2 Carbon - API Management Application Extension Feature</name>
|
<name>WSO2 Carbon - API Management Application Extension Feature</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
<description>This feature contains an implementation of a api application registration, which takes care of subscription
|
<description>This feature contains an implementation of a api application registration, which takes care of subscription
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>apimgt-extensions-feature</artifactId>
|
<artifactId>apimgt-extensions-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.handler.server.feature</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.handler.server.feature</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<name>WSO2 Carbon - Device Management - APIM handler Server Feature</name>
|
<name>WSO2 Carbon - Device Management - APIM handler Server Feature</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
<description>This feature contains the handler for the api authentications
|
<description>This feature contains the handler for the api authentications
|
||||||
|
|||||||
@ -21,13 +21,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>apimgt-extensions-feature</artifactId>
|
<artifactId>apimgt-extensions-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.integration.client.feature</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.integration.client.feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>WSO2 Carbon - APIM Integration Client Feature</name>
|
<name>WSO2 Carbon - APIM Integration Client Feature</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
|
|||||||
@ -21,14 +21,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>apimgt-extensions-feature</artifactId>
|
<artifactId>apimgt-extensions-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.apimgt.webapp.publisher.feature</artifactId>
|
<artifactId>org.wso2.carbon.apimgt.webapp.publisher.feature</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<name>WSO2 Carbon - API Management Webapp Publisher Feature</name>
|
<name>WSO2 Carbon - API Management Webapp Publisher Feature</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
<description>This feature contains an implementation of a Tomcat lifecycle listener, which takes care of publishing
|
<description>This feature contains an implementation of a Tomcat lifecycle listener, which takes care of publishing
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>apimgt-extensions-feature</artifactId>
|
<artifactId>apimgt-extensions-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>WSO2 Carbon - API Management Extensions Feature</name>
|
<name>WSO2 Carbon - API Management Extensions Feature</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>certificate-mgt-feature</artifactId>
|
<artifactId>certificate-mgt-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>certificate-mgt-feature</artifactId>
|
<artifactId>certificate-mgt-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,14 +22,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>certificate-mgt-feature</artifactId>
|
<artifactId>certificate-mgt-feature</artifactId>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>org.wso2.carbon.certificate.mgt.server.feature</artifactId>
|
<artifactId>org.wso2.carbon.certificate.mgt.server.feature</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>3.0.148-SNAPSHOT</version>
|
<version>3.0.152-SNAPSHOT</version>
|
||||||
<name>WSO2 Carbon - Certificate Management Server Feature</name>
|
<name>WSO2 Carbon - Certificate Management Server Feature</name>
|
||||||
<url>http://wso2.org</url>
|
<url>http://wso2.org</url>
|
||||||
<description>This feature contains the core bundles required for back-end Certificate Management functionality
|
<description>This feature contains the core bundles required for back-end Certificate Management functionality
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user