forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt into remote-control
commit
719dd24d57
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.certificate.mgt.core.cache;
|
||||
|
||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||
|
||||
/**
|
||||
* This interface for caching the certificates.
|
||||
*/
|
||||
|
||||
public interface CertificateCacheManager {
|
||||
|
||||
void addCertificateBySerial(String serialNumber, CertificateResponse certificate) ;
|
||||
|
||||
void addCertificateByCN(String commonName, CertificateResponse certificate) ;
|
||||
|
||||
CertificateResponse getCertificateBySerial(String serialNumber) ;
|
||||
|
||||
CertificateResponse getCertificateByCN(String commonName) ;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.certificate.mgt.core.cache.impl;
|
||||
|
||||
import org.wso2.carbon.certificate.mgt.core.cache.CertificateCacheManager;
|
||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheConfiguration;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CertificateCacheManagerImpl implements CertificateCacheManager {
|
||||
|
||||
public static final String CERTIFICATE_CACHE_MANAGER = "CERTIFICATE_CACHE_MANAGER";
|
||||
public static final String CERTIFICATE_CACHE = "CERTIFICATE_CACHE";
|
||||
private static boolean isCertificateCacheInitialized = false;
|
||||
private static String SERIAL_PRE = "S_";
|
||||
private static String COMMON_NAME_PRE = "C_";
|
||||
|
||||
private static CertificateCacheManager certificateCacheManager;
|
||||
|
||||
|
||||
private CertificateCacheManagerImpl() {
|
||||
}
|
||||
|
||||
public static CertificateCacheManager getInstance() {
|
||||
if (certificateCacheManager == null) {
|
||||
synchronized (CertificateCacheManagerImpl.class) {
|
||||
if (certificateCacheManager == null) {
|
||||
certificateCacheManager = new CertificateCacheManagerImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
return certificateCacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCertificateBySerial(String serialNumber, CertificateResponse certificate) {
|
||||
CertificateCacheManagerImpl.getCertificateCache().put(SERIAL_PRE + serialNumber, certificate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCertificateByCN(String commonName, CertificateResponse certificate) {
|
||||
CertificateCacheManagerImpl.getCertificateCache().put(COMMON_NAME_PRE + commonName, certificate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CertificateResponse getCertificateBySerial(String serialNumber) {
|
||||
return CertificateCacheManagerImpl.getCertificateCache().get(SERIAL_PRE + serialNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CertificateResponse getCertificateByCN(String commonName) {
|
||||
return CertificateCacheManagerImpl.getCertificateCache().get(COMMON_NAME_PRE + commonName);
|
||||
}
|
||||
|
||||
|
||||
private static CacheManager getCacheManager() {
|
||||
return Caching.getCacheManagerFactory().getCacheManager(CertificateCacheManagerImpl.CERTIFICATE_CACHE_MANAGER);
|
||||
}
|
||||
|
||||
public static Cache<String, CertificateResponse> getCertificateCache() {
|
||||
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||
CacheManager manager = getCacheManager();
|
||||
Cache<String, CertificateResponse> certificateCache = null;
|
||||
if (config.getDeviceCacheConfiguration().isEnabled()) {
|
||||
if (!isCertificateCacheInitialized) {
|
||||
initializeCertificateCache();
|
||||
}
|
||||
if (manager != null) {
|
||||
certificateCache = manager.<String, CertificateResponse>getCache(CertificateCacheManagerImpl.CERTIFICATE_CACHE);
|
||||
} else {
|
||||
certificateCache = Caching.getCacheManager(CertificateCacheManagerImpl.CERTIFICATE_CACHE_MANAGER).
|
||||
<String, CertificateResponse>getCache(CertificateCacheManagerImpl.CERTIFICATE_CACHE);
|
||||
}
|
||||
}
|
||||
return certificateCache;
|
||||
}
|
||||
|
||||
public static void initializeCertificateCache() {
|
||||
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||
int certificateCacheExpiry = config.getCertificateCacheConfiguration().getExpiryTime();
|
||||
CacheManager manager = getCacheManager();
|
||||
if (config.getCertificateCacheConfiguration().isEnabled()) {
|
||||
if (!isCertificateCacheInitialized) {
|
||||
isCertificateCacheInitialized = true;
|
||||
if (manager != null) {
|
||||
if (certificateCacheExpiry > 0) {
|
||||
manager.<String, CertificateResponse>createCacheBuilder(CertificateCacheManagerImpl.CERTIFICATE_CACHE).
|
||||
setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS,
|
||||
certificateCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration.
|
||||
Duration(TimeUnit.SECONDS, certificateCacheExpiry)).setStoreByValue(true).build();
|
||||
} else {
|
||||
manager.<String, CertificateResponse>getCache(CertificateCacheManagerImpl.CERTIFICATE_CACHE);
|
||||
}
|
||||
} else {
|
||||
if (certificateCacheExpiry > 0) {
|
||||
Caching.getCacheManager().
|
||||
<String, CertificateResponse>createCacheBuilder(CertificateCacheManagerImpl.CERTIFICATE_CACHE).
|
||||
setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS,
|
||||
certificateCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration.
|
||||
Duration(TimeUnit.SECONDS, certificateCacheExpiry)).setStoreByValue(true).build();
|
||||
} else {
|
||||
Caching.getCacheManager().<String, CertificateResponse>getCache(CertificateCacheManagerImpl.CERTIFICATE_CACHE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ApiModel(value = "BasicUserInfoWrapper", description = "This contains basic details of a set of users that matches " +
|
||||
"a given criteria as a collection and a message if there's any.")
|
||||
public class BasicUserInfoWrapper {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "basicUserInfo",
|
||||
value = "Details of the User.",
|
||||
required = true)
|
||||
private BasicUserInfo basicUserInfo;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "message",
|
||||
value = "Response message if there's any.")
|
||||
private String message;
|
||||
|
||||
public BasicUserInfo getBasicUserInfo() {
|
||||
return basicUserInfo;
|
||||
}
|
||||
|
||||
public void setBasicUserInfo(BasicUserInfo basicUserInfo) {
|
||||
this.basicUserInfo = basicUserInfo;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.common.group.mgt;
|
||||
|
||||
public class GroupNotExistException extends Exception{
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public GroupNotExistException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public GroupNotExistException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public GroupNotExistException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public GroupNotExistException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GroupNotExistException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.core.config.cache;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "CertificateCacheConfiguration")
|
||||
public class CertificateCacheConfiguration {
|
||||
|
||||
private boolean isEnabled;
|
||||
private int expiryTime;
|
||||
|
||||
@XmlElement(name = "Enable", required = true)
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ExpiryTime", required = true)
|
||||
public int getExpiryTime() {
|
||||
return expiryTime;
|
||||
}
|
||||
|
||||
public void setExpiryTime(int expiryTime) {
|
||||
this.expiryTime = expiryTime;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.core.operation.mgt;
|
||||
|
||||
public interface OperationManagementServiceProvider {
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.push.notification.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PushNotificationBasedOperationManager implements OperationManager {
|
||||
|
||||
private OperationManager operationManager;
|
||||
private NotificationStrategy notificationProvider;
|
||||
|
||||
public PushNotificationBasedOperationManager(
|
||||
OperationManager operationManager, NotificationStrategy notificationProvider) {
|
||||
this.operationManager = operationManager;
|
||||
this.notificationProvider = notificationProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity addOperation(Operation operation,
|
||||
List<DeviceIdentifier> devices) throws OperationManagementException, InvalidDeviceException {
|
||||
Activity activity = this.operationManager.addOperation(operation, devices);
|
||||
for (DeviceIdentifier deviceId : devices) {
|
||||
try {
|
||||
this.notificationProvider.execute(new NotificationContext(deviceId, operation));
|
||||
} catch (PushNotificationExecutionFailedException e) {
|
||||
throw new OperationManagementException("Error occurred while sending push notification to device", e);
|
||||
}
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperations(
|
||||
DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult getOperations(DeviceIdentifier deviceId,
|
||||
PaginationRequest request) throws OperationManagementException {
|
||||
return this.operationManager.getOperations(deviceId, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getPendingOperations(
|
||||
DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getPendingOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getNextPendingOperation(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOperation(DeviceIdentifier deviceId,
|
||||
Operation operation) throws OperationManagementException {
|
||||
this.operationManager.updateOperation(deviceId, operation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteOperation(int operationId) throws OperationManagementException {
|
||||
this.operationManager.deleteOperation(operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperationByDeviceAndOperationId(
|
||||
DeviceIdentifier deviceId, int operationId) throws OperationManagementException {
|
||||
return this.operationManager.getOperationByDeviceAndOperationId(deviceId, operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(
|
||||
DeviceIdentifier deviceId,
|
||||
Operation.Status status) throws OperationManagementException {
|
||||
try {
|
||||
return this.operationManager.getOperationsByDeviceAndStatus(deviceId, status);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while retrieving the list of operations by " +
|
||||
"device and status", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int operationId) throws OperationManagementException {
|
||||
return this.operationManager.getOperation(operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getOperationByActivityId(String activity) throws OperationManagementException {
|
||||
return this.operationManager.getOperationByActivityId(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getOperationByActivityIdAndDevice(String activity, DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return this.operationManager.getOperationByActivityIdAndDevice(activity, deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperationUpdatedAfter(long timestamp) throws OperationManagementException {
|
||||
return this.operationManager.getOperationUpdatedAfter(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException {
|
||||
return this.operationManager.getActivitiesUpdatedAfter(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException {
|
||||
return this.operationManager.getActivitiesUpdatedAfter(timestamp, limit, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException {
|
||||
return this.operationManager.getActivityCountUpdatedAfter(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotificationStrategy(NotificationStrategy notificationStrategy) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotificationStrategy getNotificationStrategy() {
|
||||
return notificationProvider;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.task.TestTaskManagerImpl;
|
||||
import org.wso2.carbon.ntask.common.TaskException;
|
||||
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||
import org.wso2.carbon.ntask.core.TaskManager;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestTaskServiceImpl implements TaskService {
|
||||
private Set<String> registeredTaskTypes;
|
||||
private TaskManager taskManager;
|
||||
|
||||
public TestTaskServiceImpl() {
|
||||
|
||||
this.registeredTaskTypes = new HashSet<>();
|
||||
this.taskManager = new TestTaskManagerImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager(String s) throws TaskException {
|
||||
return this.taskManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskManager> getAllTenantTaskManagersForType(String s) throws TaskException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTaskType(String s) throws TaskException {
|
||||
this.registeredTaskTypes.add(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRegisteredTaskTypes() {
|
||||
return this.registeredTaskTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverInitialized() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isServerInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskServiceConfiguration getServerConfiguration() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAfterRegistrationActions() throws TaskException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,356 @@
|
||||
/*
|
||||
* 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.core.authorization;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mockito.Mockito;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.CarbonConstants;
|
||||
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.authorization.DeviceAccessAuthorizationException;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAuthorizationResult;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
||||
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
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.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.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.api.UserStoreException;
|
||||
import org.wso2.carbon.user.api.UserStoreManager;
|
||||
import org.wso2.carbon.user.api.Permission;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.user.core.tenant.JDBCTenantManager;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Unit tests for DeviceAccessAuthorizationServiceTest
|
||||
*/
|
||||
public class DeviceAccessAuthorizationServiceTest {
|
||||
private static final Log log = LogFactory.getLog(DeviceAccessAuthorizationServiceTest.class);
|
||||
private static final String DEVICE_TYPE = "AUTH_SERVICE_TEST_TYPE";
|
||||
private static final int NO_OF_DEVICES = 5;
|
||||
private static final String ADMIN_USER = "admin";
|
||||
private static final String NON_ADMIN_ALLOWED_USER = "nonAdmin";
|
||||
private static final String NORMAL_USER = "normal";
|
||||
private static final String ADMIN_ROLE = "adminRole";
|
||||
private static final String NON_ADMIN_ROLE = "nonAdminRole";
|
||||
private static final String DEFAULT_GROUP = "defaultGroup";
|
||||
private static final String DEVICE_ID_PREFIX = "AUTH-SERVICE-TEST-DEVICE-ID-";
|
||||
private static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress";
|
||||
private static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
|
||||
private static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
|
||||
private static final String ADMIN_PERMISSION = "/permission/admin";
|
||||
private static final String NON_ADMIN_PERMISSION = "/permission/admin/manage/device-mgt/devices/owning-device/view";
|
||||
private static final String FIRST_NAME = "firstName";
|
||||
private static final String LAST_NAME = "lastName";
|
||||
private static final String EMAIL = "email";
|
||||
private static final String PASSWORD = "password";
|
||||
private DeviceAccessAuthorizationServiceImpl deviceAccessAuthorizationService;
|
||||
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||
private List<DeviceIdentifier> groupDeviceIds = new ArrayList<>();
|
||||
private Map<String, String> defaultUserClaims;
|
||||
|
||||
@BeforeClass
|
||||
public void init() throws Exception {
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
log.info("Initializing test environment to test DeviceAccessAuthorization Class");
|
||||
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
||||
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||
}
|
||||
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
||||
DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl();
|
||||
DeviceManagementServiceComponent.notifyStartupListeners();
|
||||
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
|
||||
DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
|
||||
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new
|
||||
GroupManagementProviderServiceImpl());
|
||||
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
||||
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||
for (Device device : devices) {
|
||||
deviceMgtService.enrollDevice(device);
|
||||
}
|
||||
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
|
||||
for (Device device : returnedDevices) {
|
||||
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||
}
|
||||
}
|
||||
deviceAccessAuthorizationService = Mockito.mock(DeviceAccessAuthorizationServiceImpl.class,
|
||||
Mockito.CALLS_REAL_METHODS);
|
||||
defaultUserClaims = buildDefaultUserClaims(FIRST_NAME, LAST_NAME, EMAIL);
|
||||
initializeTestEnvironment();
|
||||
//Starting tenant flow
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
|
||||
}
|
||||
|
||||
private RegistryService getRegistryService() throws RegistryException, UserStoreException {
|
||||
RealmService realmService = new InMemoryRealmService();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
BasicDataSource dataSource = new BasicDataSource();
|
||||
String connectionUrl = "jdbc:h2:./target/databasetest/CARBON_TEST";
|
||||
dataSource.setUrl(connectionUrl);
|
||||
dataSource.setDriverClassName("org.h2.Driver");
|
||||
JDBCTenantManager jdbcTenantManager = new JDBCTenantManager(dataSource,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
realmService.setTenantManager(jdbcTenantManager);
|
||||
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 void initializeTestEnvironment() throws UserStoreException, GroupManagementException,
|
||||
RoleDoesNotExistException, DeviceNotFoundException {
|
||||
//creating UI permission
|
||||
Permission adminPermission = new Permission(ADMIN_PERMISSION, CarbonConstants.UI_PERMISSION_ACTION);
|
||||
Permission deviceViewPermission = new Permission(NON_ADMIN_PERMISSION, CarbonConstants.UI_PERMISSION_ACTION);
|
||||
UserStoreManager userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService()
|
||||
.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getUserStoreManager();
|
||||
//Adding a non Admin User
|
||||
userStoreManager.addUser(NON_ADMIN_ALLOWED_USER, PASSWORD, null, defaultUserClaims, null);
|
||||
//Adding a normal user
|
||||
userStoreManager.addUser(NORMAL_USER, PASSWORD, null, defaultUserClaims, null);
|
||||
//Adding role with permission to Admin user
|
||||
userStoreManager.addRole(ADMIN_ROLE, new String[]{ADMIN_USER}, new Permission[]{adminPermission});
|
||||
//Adding role with permission to non Admin user
|
||||
userStoreManager.addRole(NON_ADMIN_ROLE, new String[]{NON_ADMIN_ALLOWED_USER},
|
||||
new Permission[]{deviceViewPermission});
|
||||
//Creating default group
|
||||
GroupManagementProviderService groupManagementProviderService = DeviceManagementDataHolder.getInstance()
|
||||
.getGroupManagementProviderService();
|
||||
groupManagementProviderService.createDefaultGroup(DEFAULT_GROUP);
|
||||
int groupId = groupManagementProviderService.getGroup(DEFAULT_GROUP).getGroupId();
|
||||
//Sharing group with admin and non admin roles
|
||||
groupManagementProviderService.manageGroupSharing(groupId, new ArrayList<>(Arrays.asList(ADMIN_ROLE,
|
||||
NON_ADMIN_ROLE)));
|
||||
//Adding first 2 devices to the group
|
||||
groupDeviceIds.add(deviceIds.get(0));
|
||||
groupDeviceIds.add(deviceIds.get(1));
|
||||
groupManagementProviderService.addDevices(groupId, groupDeviceIds);
|
||||
}
|
||||
|
||||
private Map<String, String> buildDefaultUserClaims(String firstName, String lastName, String emailAddress) {
|
||||
Map<String, String> defaultUserClaims = new HashMap<>();
|
||||
defaultUserClaims.put(USER_CLAIM_FIRST_NAME, firstName);
|
||||
defaultUserClaims.put(USER_CLAIM_LAST_NAME, lastName);
|
||||
defaultUserClaims.put(USER_CLAIM_EMAIL_ADDRESS, emailAddress);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Default claim map is created for new user: " + defaultUserClaims.toString());
|
||||
}
|
||||
return defaultUserClaims;
|
||||
}
|
||||
|
||||
//Admin User test cases
|
||||
@Test(description = "Check authorization giving a device identifier and username")
|
||||
public void userAuthDevIdUserName() throws Exception {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
for (DeviceIdentifier deviceId : deviceIds) {
|
||||
Assert.assertTrue(deviceAccessAuthorizationService.isUserAuthorized(deviceId, ADMIN_USER),
|
||||
"Device access authorization for admin user failed");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(description = "Authorization for multiple device identifiers and username")
|
||||
public void userAuthDevIdUserNameResult() throws DeviceAccessAuthorizationException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
DeviceAuthorizationResult deviceAuthorizationResult = deviceAccessAuthorizationService.
|
||||
isUserAuthorized(deviceIds, ADMIN_USER);
|
||||
Assert.assertEquals(deviceAuthorizationResult.getAuthorizedDevices().size(), 5,
|
||||
"Expected 5 authorized devices for admin user");
|
||||
Assert.assertEquals(deviceAuthorizationResult.getUnauthorizedDevices().size(), 0,
|
||||
"Expected 0 un-authorized devices for admin user");
|
||||
}
|
||||
|
||||
@Test(description = "Authorization by device identifier")
|
||||
public void userAuthDevId() throws Exception {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
for (DeviceIdentifier deviceId : deviceIds) {
|
||||
Assert.assertTrue(deviceAccessAuthorizationService.isUserAuthorized(deviceId),
|
||||
"Authorize user from device identifier failed");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(description = "Authorization by multiple device identifiers")
|
||||
public void userAuthDevIdResult() throws Exception {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
DeviceAuthorizationResult deviceAuthorizationResult = deviceAccessAuthorizationService.
|
||||
isUserAuthorized(deviceIds);
|
||||
Assert.assertEquals(deviceAuthorizationResult.getAuthorizedDevices().size(), 5,
|
||||
"Expected 5 authorized devices for admin user");
|
||||
Assert.assertEquals(deviceAuthorizationResult.getUnauthorizedDevices().size(), 0,
|
||||
"Expected 0 un-authorized devices for admin user");
|
||||
}
|
||||
|
||||
@Test(description = "Check current user is a device administrator")
|
||||
public void isDevAdminAdminUser() throws DeviceAccessAuthorizationException, UserStoreException,
|
||||
PermissionManagementException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
Assert.assertTrue(deviceAccessAuthorizationService.isDeviceAdminUser(),
|
||||
"Admin user failed to authorize as admin");
|
||||
}
|
||||
|
||||
//Non admin user tests
|
||||
@Test(description = "Check authorization by device identifier and permission Allowed test case")
|
||||
public void userAuthDevIdPermission() throws DeviceAccessAuthorizationException, UserStoreException,
|
||||
PermissionManagementException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
Assert.assertTrue(deviceAccessAuthorizationService.isUserAuthorized(deviceIds.get(0),
|
||||
new String[]{NON_ADMIN_PERMISSION}), "Non admin user with permissions attempt to access failed");
|
||||
}
|
||||
|
||||
@Test(description = "Check authorization by device identifier and permission Not-allowed test case")
|
||||
public void userAuthFalseDevIdPermission() throws DeviceAccessAuthorizationException, UserStoreException,
|
||||
PermissionManagementException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
Assert.assertFalse(deviceAccessAuthorizationService.isUserAuthorized(deviceIds.get(3),
|
||||
new String[]{NON_ADMIN_PERMISSION}), "Non admin user accessing not allowed device authorized");
|
||||
}
|
||||
|
||||
@Test(description = "Authorization by giving a device identifier, username and permission Allowed test case")
|
||||
public void userAuthDevIdUserNamePermission() throws DeviceAccessAuthorizationException, UserStoreException,
|
||||
PermissionManagementException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
Assert.assertTrue(deviceAccessAuthorizationService.isUserAuthorized(deviceIds.get(0), NON_ADMIN_ALLOWED_USER,
|
||||
new String[]{NON_ADMIN_PERMISSION}), "Non admin user with permissions attempt to access failed");
|
||||
}
|
||||
|
||||
@Test(description = "Authorization by giving a device identifier, username and permission Not-allowed test case")
|
||||
public void userAuthFalseDevIdUserNamePermission() throws DeviceAccessAuthorizationException, UserStoreException,
|
||||
PermissionManagementException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
Assert.assertFalse(deviceAccessAuthorizationService.isUserAuthorized(deviceIds.get(3), NON_ADMIN_ALLOWED_USER,
|
||||
new String[]{NON_ADMIN_PERMISSION}), "Non admin user accessing not allowed device authorized");
|
||||
}
|
||||
|
||||
@Test(description = "Authorization by giving device identifiers and permission")
|
||||
public void userAuthDevIdPermissionResult() throws DeviceAccessAuthorizationException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
DeviceAuthorizationResult deviceAuthorizationResult = deviceAccessAuthorizationService.
|
||||
isUserAuthorized(deviceIds, new String[]{NON_ADMIN_PERMISSION});
|
||||
Assert.assertEquals(deviceAuthorizationResult.getAuthorizedDevices().size(), 2,
|
||||
"Non admin user authentication to 2 devices in a shared group failed");
|
||||
Assert.assertEquals(deviceAuthorizationResult.getUnauthorizedDevices().size(), 3,
|
||||
"Non admin user authentication to 3 devices in a non-shared group failed");
|
||||
}
|
||||
|
||||
@Test(description = "Authorization by giving device identifiers, username and permission")
|
||||
public void userAuthDevIdUserNamePermissionResult() throws DeviceAccessAuthorizationException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
DeviceAuthorizationResult deviceAuthorizationResult = deviceAccessAuthorizationService.
|
||||
isUserAuthorized(deviceIds, NON_ADMIN_ALLOWED_USER, new String[]{NON_ADMIN_PERMISSION});
|
||||
Assert.assertEquals(deviceAuthorizationResult.getAuthorizedDevices().size(), 2,
|
||||
"Non admin user authentication to 2 devices in a shared group failed");
|
||||
Assert.assertEquals(deviceAuthorizationResult.getUnauthorizedDevices().size(), 3,
|
||||
"Non admin user authentication to 3 devices in a non-shared group failed");
|
||||
}
|
||||
|
||||
@Test(description = "Authorization for device admin called by normal user")
|
||||
public void isDevAdminNormalUser() throws DeviceAccessAuthorizationException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NORMAL_USER);
|
||||
Assert.assertFalse(deviceAccessAuthorizationService.isDeviceAdminUser(), "Normal user allowed as admin user");
|
||||
}
|
||||
|
||||
//Check branches of isUserAuthorized
|
||||
@Test(description = "Checking branch - user is device owner")
|
||||
public void nonAdminDeviceOwner() throws DeviceAccessAuthorizationException, DeviceManagementException {
|
||||
|
||||
//Creating a temporary device
|
||||
Device device = new Device();
|
||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo(NON_ADMIN_ALLOWED_USER, EnrolmentInfo.OwnerShip.BYOD, null);
|
||||
device.setEnrolmentInfo(enrolmentInfo);
|
||||
device.setName("temp");
|
||||
device.setType(DEVICE_TYPE);
|
||||
device.setDeviceIdentifier("1234");
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().enrollDevice(device);
|
||||
|
||||
//temporary device identifier
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setType(DEVICE_TYPE);
|
||||
deviceIdentifier.setId("1234");
|
||||
|
||||
List<DeviceIdentifier> tempList = new ArrayList<>();
|
||||
tempList.add(deviceIdentifier);
|
||||
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
DeviceAuthorizationResult deviceAuthorizationResult = deviceAccessAuthorizationService.
|
||||
isUserAuthorized(tempList, NON_ADMIN_ALLOWED_USER, new String[]{NON_ADMIN_PERMISSION});
|
||||
Assert.assertEquals(deviceAuthorizationResult.getAuthorizedDevices().size(), 1,
|
||||
"Non admin device owner failed to access device");
|
||||
Assert.assertEquals(deviceAuthorizationResult.getUnauthorizedDevices().size(), 0,
|
||||
"Non admin device owner failed to access device");
|
||||
}
|
||||
|
||||
@Test(description = "Check authorization without giving permissions")
|
||||
public void userAuthWithoutPermissions() throws DeviceAccessAuthorizationException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
DeviceAuthorizationResult deviceAuthorizationResult = deviceAccessAuthorizationService.
|
||||
isUserAuthorized(deviceIds, NON_ADMIN_ALLOWED_USER, null);
|
||||
Assert.assertEquals(deviceAuthorizationResult.getAuthorizedDevices().size(), 0,
|
||||
"Non admin user try authentication without permission failed");
|
||||
Assert.assertEquals(deviceAuthorizationResult.getUnauthorizedDevices().size(), 5,
|
||||
"Non admin user try authentication without permission failed");
|
||||
}
|
||||
|
||||
//check Exception cases
|
||||
@Test(description = "check a null username in isUserAuthorized method")
|
||||
public void callUserAuthWithoutUsername() throws DeviceAccessAuthorizationException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_ALLOWED_USER);
|
||||
DeviceAuthorizationResult deviceAuthorizationResult = deviceAccessAuthorizationService.
|
||||
isUserAuthorized(deviceIds, "", new String[]{NON_ADMIN_PERMISSION});
|
||||
Assert.assertEquals(deviceAuthorizationResult, null,
|
||||
"Not null result for empty username in isUserAuthorized method");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void clearAll() {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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.core.notification.mgt;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.EntityDoesNotExistException;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
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.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
||||
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 org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the test class for {@link NotificationManagementServiceImpl}
|
||||
*/
|
||||
public class NotificationManagementServiceImplTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(NotificationManagementServiceImplTests.class);
|
||||
private static final String DEVICE_TYPE = "NOTIFICATION_TEST_DEVICE";
|
||||
private static final String DEVICE_ID_PREFIX = "NOTIFICATION-TEST-DEVICE-ID-";
|
||||
private static final int NO_OF_DEVICES = 10;
|
||||
private static final int NO_OF_NOTIFICATIONS = 10;
|
||||
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||
private NotificationManagementServiceImpl notificationManagementService;
|
||||
private static final String TEST_NOTIFICATION_DESCRIPTION = "test notification";
|
||||
private static final int NOTIFICATION_OPERATION_ID = 1;
|
||||
|
||||
@BeforeClass
|
||||
public void init() throws Exception {
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
log.info("Initializing");
|
||||
for (int i = 1; i <= NO_OF_DEVICES; i++) {
|
||||
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||
}
|
||||
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
||||
DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl();
|
||||
DeviceManagementServiceComponent.notifyStartupListeners();
|
||||
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
|
||||
DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
|
||||
DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
|
||||
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
|
||||
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
||||
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||
for (Device device : devices) {
|
||||
Assert.assertTrue(deviceMgtService.enrollDevice(device), "Device with Identifier - " +
|
||||
device.getDeviceIdentifier() + " is not enrolled.");
|
||||
}
|
||||
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
|
||||
|
||||
for (Device device : returnedDevices) {
|
||||
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||
}
|
||||
}
|
||||
notificationManagementService = new NotificationManagementServiceImpl();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@Test(description = "Add notifications using addNotification method and check whether it returns true.")
|
||||
public void addNotification() throws NotificationManagementException {
|
||||
for (int i = 1; i <= NO_OF_DEVICES; i++) {
|
||||
DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE);
|
||||
Notification notification = TestDataHolder.getNotification(i, Notification.Status.NEW.toString(),
|
||||
testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i,
|
||||
NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
|
||||
Assert.assertTrue(notificationManagementService.addNotification(testDeviceIdentifier, notification),
|
||||
"Adding notification failed for [" + notification.toString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = EntityDoesNotExistException.class, description = "AddNotification method is checked" +
|
||||
" whether it returns EntityDoesNotExistException when the device not registered is added notification")
|
||||
public void addNotificationExceptions() throws NotificationManagementException {
|
||||
DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + 123, DEVICE_TYPE);
|
||||
Notification notification = TestDataHolder.getNotification(1, Notification.Status.NEW.toString(),
|
||||
testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + 123,
|
||||
NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
|
||||
notificationManagementService.addNotification(new DeviceIdentifier(DEVICE_ID_PREFIX + 123,
|
||||
DEVICE_TYPE), notification);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NotificationManagementException.class, description = "This tests the method getDevice which" +
|
||||
" is called internally in addNotification for DeviceManagementException exception passing null device Id.")
|
||||
public void getDevice() throws NotificationManagementException {
|
||||
DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + 123, DEVICE_TYPE);
|
||||
Notification notification = TestDataHolder.getNotification(1, Notification.Status.NEW.toString(),
|
||||
testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + 123,
|
||||
NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
|
||||
notificationManagementService.addNotification(null, notification);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addNotification", description = "This tests the updateNotification Method" +
|
||||
" and check whether it returns true ( got updated )")
|
||||
public void updateNotification() throws NotificationManagementException {
|
||||
for (int i = 1; i <= NO_OF_DEVICES; i++) {
|
||||
DeviceIdentifier testDeviceIdentifier = new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE);
|
||||
Notification notification = TestDataHolder.getNotification(i, Notification.Status.CHECKED.toString(),
|
||||
testDeviceIdentifier.toString(), TEST_NOTIFICATION_DESCRIPTION, DEVICE_ID_PREFIX + i,
|
||||
NOTIFICATION_OPERATION_ID, DEVICE_TYPE);
|
||||
Assert.assertTrue(notificationManagementService.updateNotification(notification), "Notification " +
|
||||
"update failed for [" + notification.toString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateNotification", description = "This method update notification status " +
|
||||
"and check whether it got updated")
|
||||
public void updateNotificationStatus() throws NotificationManagementException {
|
||||
for (int i = 1; i <= NO_OF_DEVICES; i++) {
|
||||
Assert.assertTrue(notificationManagementService.updateNotificationStatus(i, Notification.Status.CHECKED),
|
||||
"Notification update status failed for notification id:- " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addNotification", description = "this tests getAllNotifications" +
|
||||
" method by listing down all the notifications.")
|
||||
public void getAllNotifications() throws NotificationManagementException {
|
||||
List<Notification> returnedNotifications = notificationManagementService.getAllNotifications();
|
||||
Assert.assertEquals(returnedNotifications.size(), NO_OF_DEVICES, "No. of notifications added is not " +
|
||||
"equal to no. of notifications retrieved.");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateNotificationStatus", description = "this method retries notification by id" +
|
||||
" and checks it")
|
||||
public void getNotification() throws NotificationManagementException {
|
||||
for (int i = 1; i <= NO_OF_DEVICES; i++) {
|
||||
Notification returnedNotification = notificationManagementService.getNotification(i);
|
||||
Assert.assertEquals(returnedNotification.getNotificationId(), i, "Returned notification ID is not " +
|
||||
"same as added notification Id.");
|
||||
Assert.assertEquals(returnedNotification.getStatus(), Notification.Status.CHECKED, "Returned " +
|
||||
"notification status is not same as added notification status.");
|
||||
Assert.assertEquals(returnedNotification.getDescription(), TEST_NOTIFICATION_DESCRIPTION, "Returned" +
|
||||
" notification description is not same as added notification description.");
|
||||
Assert.assertEquals(returnedNotification.getOperationId(), NOTIFICATION_OPERATION_ID, "Returned " +
|
||||
"notification operation ID is not same as added notification operation Id.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateNotificationStatus", description = "this method gets all notification by status checked")
|
||||
public void getNotificationsByStatus() throws NotificationManagementException {
|
||||
List<Notification> returnedNotifications = notificationManagementService.getNotificationsByStatus(Notification.
|
||||
Status.CHECKED);
|
||||
Assert.assertEquals(returnedNotifications.size(), NO_OF_NOTIFICATIONS, "Returned no. of notification is " +
|
||||
"not same as added no. of notifications.");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addNotification", description = "this tests for getAllNotification method by passing " +
|
||||
"pagination request and validates the no. of total records and filtered records. ")
|
||||
public void getAllNotificationsWithPaginationRequest() throws NotificationManagementException {
|
||||
PaginationRequest request = new PaginationRequest(1, 2);
|
||||
PaginationResult result = notificationManagementService.getAllNotifications(request);
|
||||
Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS, "Returned filtered records is " +
|
||||
"not same as added filtered records.");
|
||||
Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS, "Returned no. of records is not " +
|
||||
"same as added no. of records.");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateNotificationStatus", description = "this tests for getAllNotification method by" +
|
||||
" passing pagination request & status and validates the no. of total records and filtered records. ")
|
||||
public void getAllNotificationsWithPaginationRequestAndStatus() throws NotificationManagementException {
|
||||
PaginationRequest request = new PaginationRequest(1, 2);
|
||||
PaginationResult result = notificationManagementService.getNotificationsByStatus(Notification.Status.CHECKED,
|
||||
request);
|
||||
Assert.assertEquals(result.getRecordsFiltered(), NO_OF_NOTIFICATIONS, "Returned filtered records is not " +
|
||||
"same as added filtered records.");
|
||||
Assert.assertEquals(result.getRecordsTotal(), NO_OF_NOTIFICATIONS, "Returned no. of records is not same" +
|
||||
" as added no. of records.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,656 @@
|
||||
/*
|
||||
* 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.core.operation;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
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.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the testcase which covers the methods from {@link OperationManager}
|
||||
*/
|
||||
public class OperationManagementTests extends BaseDeviceManagementTest {
|
||||
|
||||
private static final String DEVICE_TYPE = "OP_TEST_TYPE";
|
||||
private static final String DEVICE_ID_PREFIX = "OP-TEST-DEVICE-ID-";
|
||||
private static final String COMMAND_OPERATON_CODE = "COMMAND-TEST";
|
||||
private static final String POLICY_OPERATION_CODE = "POLICY-TEST";
|
||||
private static final String CONFIG_OPERATION_CODE = "CONFIG-TEST";
|
||||
private static final String PROFILE_OPERATION_CODE = "PROFILE-TEST";
|
||||
private static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
|
||||
private static final int NO_OF_DEVICES = 5;
|
||||
private static final String ADMIN_USER = "admin";
|
||||
private static final String NON_ADMIN_USER = "test";
|
||||
private static final String INVALID_DEVICE = "ThisIsInvalid";
|
||||
|
||||
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||
private OperationManager operationMgtService;
|
||||
private DeviceManagementProviderService deviceMgmtProvider;
|
||||
private Activity commandActivity;
|
||||
private long commandActivityBeforeUpdatedTimestamp;
|
||||
|
||||
@BeforeClass
|
||||
public void init() throws Exception {
|
||||
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
||||
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||
}
|
||||
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
||||
DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance().
|
||||
getDeviceManagementProvider();
|
||||
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||
for (Device device : devices) {
|
||||
deviceMgtService.enrollDevice(device);
|
||||
}
|
||||
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
|
||||
for (Device device : returnedDevices) {
|
||||
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||
}
|
||||
}
|
||||
this.deviceMgmtProvider = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
|
||||
NotificationStrategy notificationStrategy = new TestNotificationStrategy();
|
||||
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
this.commandActivity = this.operationMgtService.addOperation(
|
||||
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
|
||||
this.deviceIds);
|
||||
validateOperationResponse(this.commandActivity, ActivityStatus.Status.PENDING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCommandOperationInvalidDeviceIds() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
startTenantFlowAsNonAdmin();
|
||||
try {
|
||||
ArrayList<DeviceIdentifier> invalidDevices = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
invalidDevices.add(new DeviceIdentifier(INVALID_DEVICE + i, DEVICE_TYPE));
|
||||
}
|
||||
invalidDevices.addAll(this.deviceIds);
|
||||
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
|
||||
Operation.Type.COMMAND, COMMAND_OPERATON_CODE), invalidDevices);
|
||||
Assert.assertEquals(activity.getActivityStatus().size(), invalidDevices.size(),
|
||||
"The operation response for add operation only have - " + activity.getActivityStatus().size());
|
||||
for (int i = 0; i < activity.getActivityStatus().size(); i++) {
|
||||
ActivityStatus status = activity.getActivityStatus().get(i);
|
||||
if (i < 3) {
|
||||
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.INVALID);
|
||||
} else {
|
||||
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = InvalidDeviceException.class)
|
||||
public void addEmptyDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND,
|
||||
COMMAND_OPERATON_CODE),
|
||||
new ArrayList<>());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = InvalidDeviceException.class)
|
||||
public void addNonInitializedDevicesCommandOperation() throws DeviceManagementException,
|
||||
OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||
deviceIdentifiers.add(deviceIdentifier);
|
||||
this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND,
|
||||
COMMAND_OPERATON_CODE),
|
||||
deviceIdentifiers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNonAdminUserDevicesCommandOperation() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
startTenantFlowAsNonAdmin();
|
||||
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
|
||||
Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
|
||||
deviceIds);
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
validateOperationResponse(activity, ActivityStatus.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
private void startTenantFlowAsNonAdmin() {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(NON_ADMIN_USER);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addCommandOperation")
|
||||
public void addPolicyOperation() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
Activity activity = this.operationMgtService.addOperation(getOperation(new PolicyOperation(),
|
||||
Operation.Type.POLICY, POLICY_OPERATION_CODE),
|
||||
this.deviceIds);
|
||||
validateOperationResponse(activity, ActivityStatus.Status.PENDING);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addPolicyOperation")
|
||||
public void addConfigOperation() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
Activity activity = this.operationMgtService.addOperation(getOperation(new ConfigOperation(),
|
||||
Operation.Type.CONFIG, CONFIG_OPERATION_CODE),
|
||||
this.deviceIds);
|
||||
validateOperationResponse(activity, ActivityStatus.Status.PENDING);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addConfigOperation")
|
||||
public void addProfileOperation() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
Activity activity = this.operationMgtService.addOperation(getOperation(new ProfileOperation(),
|
||||
Operation.Type.PROFILE, PROFILE_OPERATION_CODE),
|
||||
this.deviceIds);
|
||||
validateOperationResponse(activity, ActivityStatus.Status.PENDING);
|
||||
}
|
||||
|
||||
static Operation getOperation(Operation operation, Operation.Type type, String code) {
|
||||
String date = new SimpleDateFormat(DATE_FORMAT_NOW).format(new Date());
|
||||
operation.setCreatedTimeStamp(date);
|
||||
operation.setType(type);
|
||||
operation.setCode(code);
|
||||
return operation;
|
||||
}
|
||||
|
||||
private void validateOperationResponse(Activity activity, ActivityStatus.Status expectedStatus) {
|
||||
Assert.assertEquals(activity.getActivityStatus().size(), NO_OF_DEVICES, "The operation response for add " +
|
||||
"operation only have - " + activity.getActivityStatus().size());
|
||||
for (ActivityStatus status : activity.getActivityStatus()) {
|
||||
Assert.assertEquals(status.getStatus(), expectedStatus);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addProfileOperation")
|
||||
public void getOperations() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
List operations = this.operationMgtService.getOperations(deviceIdentifier);
|
||||
Assert.assertEquals(operations.size(), 4, "The operations should be 4, but found only " + operations.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addProfileOperation", expectedExceptions = OperationManagementException.class)
|
||||
public void getOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
try {
|
||||
startTenantFlowAsNonAdmin();
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
this.operationMgtService.getOperations(deviceIdentifier);
|
||||
}
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperations")
|
||||
public void getPendingOperations() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
List operations = this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||
Assert.assertEquals(operations.size(), 4, "The pending operations should be 4, but found only "
|
||||
+ operations.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperations", expectedExceptions = OperationManagementException.class)
|
||||
public void getPendingOperationsAsNonAdmin() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException {
|
||||
try {
|
||||
startTenantFlowAsNonAdmin();
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||
}
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getPendingOperations")
|
||||
public void getPaginatedRequestAsAdmin() throws OperationManagementException {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
PaginationRequest request = new PaginationRequest(1, 2);
|
||||
request.setDeviceType(DEVICE_TYPE);
|
||||
request.setOwner(ADMIN_USER);
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
PaginationResult result = this.operationMgtService.getOperations(deviceIdentifier, request);
|
||||
Assert.assertEquals(result.getRecordsFiltered(), 4);
|
||||
Assert.assertEquals(result.getData().size(), 2);
|
||||
Assert.assertEquals(result.getRecordsTotal(), 4);
|
||||
}
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getPendingOperations", expectedExceptions = OperationManagementException.class)
|
||||
public void getPaginatedRequestAsNonAdmin() throws OperationManagementException {
|
||||
try {
|
||||
startTenantFlowAsNonAdmin();
|
||||
PaginationRequest request = new PaginationRequest(1, 2);
|
||||
request.setDeviceType(DEVICE_TYPE);
|
||||
request.setOwner(ADMIN_USER);
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
try {
|
||||
this.operationMgtService.getOperations(deviceIdentifier, request);
|
||||
} catch (OperationManagementException ex) {
|
||||
if (ex.getMessage() == null) {
|
||||
Assert.assertTrue(ex.getMessage().contains("User '" + NON_ADMIN_USER + "' is not authorized"));
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getPaginatedRequestAsAdmin")
|
||||
public void updateOperation() throws OperationManagementException {
|
||||
//This is required to introduce a delay for the update operation of the device.
|
||||
this.commandActivityBeforeUpdatedTimestamp = System.currentTimeMillis();
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
List operations = this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||
Assert.assertTrue(operations != null && operations.size() == 4);
|
||||
Operation operation = (Operation) operations.get(0);
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
operation.setOperationResponse("The operation is successfully completed");
|
||||
this.operationMgtService.updateOperation(deviceIdentifier, operation);
|
||||
List pendingOperations = this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||
Assert.assertEquals(pendingOperations.size(), 3);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateOperation", expectedExceptions = OperationManagementException.class)
|
||||
public void updateOperationAsNonAdmin() throws OperationManagementException {
|
||||
//This is required to introduce a delay for the update operation of the device.
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
List operations = this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||
Assert.assertTrue(operations != null && operations.size() == 3);
|
||||
startTenantFlowAsNonAdmin();
|
||||
Operation operation = (Operation) operations.get(0);
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
operation.setOperationResponse("The operation is successfully completed, and updated by non admin!");
|
||||
this.operationMgtService.updateOperation(deviceIdentifier, operation);
|
||||
List pendingOperations = this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||
Assert.assertEquals(pendingOperations.size(), 3);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateOperation")
|
||||
public void getNextPendingOperation() throws OperationManagementException {
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
Operation operation = this.operationMgtService.getNextPendingOperation(deviceIdentifier);
|
||||
Assert.assertTrue(operation.getType().equals(Operation.Type.POLICY));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateOperation", expectedExceptions = OperationManagementException.class)
|
||||
public void getNextPendingOperationAsNonAdmin() throws OperationManagementException {
|
||||
startTenantFlowAsNonAdmin();
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
this.operationMgtService.getNextPendingOperation(deviceIdentifier);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getNextPendingOperation")
|
||||
public void getOperationByDeviceAndOperationId() throws OperationManagementException {
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
Operation operation = this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier,
|
||||
getOperationId(this.commandActivity.getActivityId()));
|
||||
Assert.assertTrue(operation.getStatus().equals(Operation.Status.COMPLETED));
|
||||
Assert.assertTrue(operation.getType().equals(Operation.Type.COMMAND));
|
||||
}
|
||||
|
||||
private int getOperationId(String activityId) {
|
||||
return Integer.parseInt(activityId.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getNextPendingOperation", expectedExceptions = OperationManagementException.class)
|
||||
public void getOperationByDeviceAndOperationIdNonAdmin() throws OperationManagementException {
|
||||
startTenantFlowAsNonAdmin();
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
String operationId = this.commandActivity.getActivityId().
|
||||
replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "");
|
||||
this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier,
|
||||
Integer.parseInt(operationId));
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationByDeviceAndOperationId")
|
||||
public void getOperationsByDeviceAndStatus() throws OperationManagementException, DeviceManagementException {
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
List operation = this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier,
|
||||
Operation.Status.PENDING);
|
||||
Assert.assertEquals(operation.size(), 3);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationByDeviceAndOperationId", expectedExceptions = OperationManagementException.class)
|
||||
public void getOperationsByDeviceAndStatusByNonAdmin() throws OperationManagementException,
|
||||
DeviceManagementException {
|
||||
startTenantFlowAsNonAdmin();
|
||||
try {
|
||||
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||
this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationsByDeviceAndStatus")
|
||||
public void getOperation() throws OperationManagementException, DeviceManagementException {
|
||||
String operationId = this.commandActivity.getActivityId().
|
||||
replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "");
|
||||
Operation operation = this.operationMgtService.getOperation(Integer.parseInt(operationId));
|
||||
Assert.assertEquals(operation.getType(), Operation.Type.COMMAND);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperation")
|
||||
public void getOperationActivity() throws OperationManagementException {
|
||||
Activity activity = this.operationMgtService.getOperationByActivityId(commandActivity.getActivityId());
|
||||
Assert.assertEquals(activity.getType(), Activity.Type.COMMAND);
|
||||
Assert.assertEquals(activity.getActivityStatus().size(), this.deviceIds.size());
|
||||
Assert.assertEquals(activity.getActivityStatus().get(0).getStatus(), ActivityStatus.Status.COMPLETED);
|
||||
for (int i = 1; i < this.deviceIds.size(); i++) {
|
||||
Assert.assertEquals(activity.getActivityStatus().get(i).getStatus(), ActivityStatus.Status.PENDING);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationActivity")
|
||||
public void getOperationByActivityIdAndDevice() throws OperationManagementException {
|
||||
Activity activity = this.operationMgtService.
|
||||
getOperationByActivityIdAndDevice(this.commandActivity.getActivityId(), this.deviceIds.get(0));
|
||||
Assert.assertEquals(activity.getType(), Activity.Type.COMMAND);
|
||||
Assert.assertEquals(activity.getActivityStatus().size(), 1);
|
||||
Assert.assertEquals(activity.getActivityStatus().get(0).getStatus(), ActivityStatus.Status.COMPLETED);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationActivity", expectedExceptions = OperationManagementException.class)
|
||||
public void getOperationByActivityIdAndDeviceAsNonAdmin() throws OperationManagementException {
|
||||
startTenantFlowAsNonAdmin();
|
||||
try {
|
||||
this.operationMgtService.
|
||||
getOperationByActivityIdAndDevice(this.commandActivity.getActivityId(), this.deviceIds.get(0));
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateOperation")
|
||||
public void getOperationUpdatedAfterWithLimitAndOffset() throws OperationManagementException, ParseException {
|
||||
List<Activity> operations = this.operationMgtService.getActivitiesUpdatedAfter
|
||||
(this.commandActivityBeforeUpdatedTimestamp / 1000, 10, 0);
|
||||
Assert.assertTrue(operations != null && operations.size() == 1,
|
||||
"The operations updated after the created should be 1");
|
||||
Activity operation = operations.get(0);
|
||||
Assert.assertTrue(operation.getActivityStatus() != null && operation.getActivityStatus().size() == 1,
|
||||
"The operation should be having the activity status of atleast one device");
|
||||
Assert.assertEquals(operation.getActivityStatus().get(0).getDeviceIdentifier().getId(),
|
||||
deviceIds.get(0).getId());
|
||||
Assert.assertEquals(operation.getActivityStatus().get(0).getDeviceIdentifier().getType(),
|
||||
deviceIds.get(0).getType());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationUpdatedAfterWithLimitAndOffset")
|
||||
public void getActivityCountUpdatedAfter() throws OperationManagementException, ParseException {
|
||||
int activityCount = this.operationMgtService.getActivityCountUpdatedAfter
|
||||
(this.commandActivityBeforeUpdatedTimestamp / 1000);
|
||||
Assert.assertTrue(activityCount == 1,
|
||||
"The activities updated after the created should be 1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNotificationStrategy() {
|
||||
Assert.assertTrue(this.operationMgtService.getNotificationStrategy() != null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"getOperationByActivityIdAndDevice", "getOperationByActivityIdAndDeviceAsNonAdmin"})
|
||||
public void getOperationForInactiveDevice() throws DeviceManagementException, OperationManagementException {
|
||||
boolean disEnrolled = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
|
||||
disenrollDevice(deviceIds.get(0));
|
||||
Assert.assertTrue(disEnrolled);
|
||||
List operations = this.operationMgtService.getOperations(deviceIds.get(0));
|
||||
Assert.assertTrue(operations == null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class)
|
||||
public void getPaginatedOperationDeviceForInvalidDevice() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||
try {
|
||||
PaginationRequest request = new PaginationRequest(1, 2);
|
||||
request.setDeviceType(DEVICE_TYPE);
|
||||
request.setOwner(ADMIN_USER);
|
||||
PaginationResult result = this.operationMgtService.getOperations
|
||||
(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), request);
|
||||
Assert.assertEquals(result.getRecordsFiltered(), 4);
|
||||
Assert.assertEquals(result.getData().size(), 2);
|
||||
Assert.assertEquals(result.getRecordsTotal(), 4);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class)
|
||||
public void getPendingOperationDeviceForInvalidDevice() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
this.operationMgtService.getPendingOperations(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getPendingOperationDeviceForInvalidDevice",
|
||||
expectedExceptions = OperationManagementException.class)
|
||||
public void getNextPendingOperationDeviceForInvalidDevice() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
this.operationMgtService.getNextPendingOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getNextPendingOperationDeviceForInvalidDevice",
|
||||
expectedExceptions = OperationManagementException.class)
|
||||
public void getUpdateOperationForInvalidDevice() throws DeviceManagementException, OperationManagementException {
|
||||
this.operationMgtService.updateOperation(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
|
||||
getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getUpdateOperationForInvalidDevice",
|
||||
expectedExceptions = OperationManagementException.class)
|
||||
public void getOperationByDeviceAndOperationIdInvalidDevice() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
this.operationMgtService.getOperationByDeviceAndOperationId(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
|
||||
getOperationId(this.commandActivity.getActivityId()));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationByDeviceAndOperationIdInvalidDevice",
|
||||
expectedExceptions = OperationManagementException.class)
|
||||
public void getOperationsByDeviceAndStatusInvalidDevice() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
this.operationMgtService.getOperationsByDeviceAndStatus(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE),
|
||||
Operation.Status.PENDING);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationsByDeviceAndStatusInvalidDevice",
|
||||
expectedExceptions = OperationManagementException.class)
|
||||
public void getOperationsInvalidOperationId() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
this.operationMgtService.getOperation(123445);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationsInvalidOperationId", expectedExceptions = IllegalArgumentException.class)
|
||||
public void getOperationsByActivityIdInvalidActivityId() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
this.operationMgtService.getOperationByActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + 0);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationsByActivityIdInvalidActivityId",
|
||||
expectedExceptions = IllegalArgumentException.class)
|
||||
public void getOperationByActivityIdAndDeviceInvalidActivityId() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
this.operationMgtService.getOperationByActivityIdAndDevice(
|
||||
DeviceManagementConstants.OperationAttributes.ACTIVITY + 0,
|
||||
new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationByActivityIdAndDeviceInvalidActivityId")
|
||||
public void getPendingOperationsInactiveEnrollment() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
changeStatus(EnrolmentInfo.Status.INACTIVE);
|
||||
List operations = this.operationMgtService.getPendingOperations(this.deviceIds.get(1));
|
||||
Assert.assertTrue(operations != null);
|
||||
Assert.assertEquals(operations.size(), 4);
|
||||
changeStatus(EnrolmentInfo.Status.ACTIVE);
|
||||
}
|
||||
|
||||
private void changeStatus(EnrolmentInfo.Status status) throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
Device device = this.deviceMgmtProvider.getDevice(this.deviceIds.get(1));
|
||||
Assert.assertTrue(device != null);
|
||||
Assert.assertEquals(device.getType(), DEVICE_TYPE);
|
||||
Assert.assertTrue(device.getEnrolmentInfo() != null);
|
||||
device.getEnrolmentInfo().setStatus(status);
|
||||
boolean modified = this.deviceMgmtProvider.changeDeviceStatus(this.deviceIds.get(1), status);
|
||||
Assert.assertTrue(modified);
|
||||
device = this.deviceMgmtProvider.getDevice(this.deviceIds.get(1));
|
||||
Assert.assertEquals(device.getEnrolmentInfo().getStatus(), status);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getPendingOperationsInactiveEnrollment")
|
||||
public void getNextPendingOperationInactiveEnrollment() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
changeStatus(EnrolmentInfo.Status.INACTIVE);
|
||||
Operation operation = this.operationMgtService.getNextPendingOperation(this.deviceIds.get(1));
|
||||
Assert.assertTrue(operation != null);
|
||||
changeStatus(EnrolmentInfo.Status.ACTIVE);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getNextPendingOperationInactiveEnrollment")
|
||||
public void getNextPendingOperationForAllOperations() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Operation operation = this.operationMgtService.getNextPendingOperation(this.deviceIds.get(1));
|
||||
operation.setStatus(Operation.Status.COMPLETED);
|
||||
this.operationMgtService.updateOperation(deviceIds.get(1), operation);
|
||||
}
|
||||
Assert.assertTrue(this.operationMgtService.getNextPendingOperation(this.deviceIds.get(1)) == null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getNextPendingOperationForAllOperations")
|
||||
public void getOperationByDeviceAndOperationIdForAllOperations() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
Operation operation = this.operationMgtService.getOperationByDeviceAndOperationId(this.deviceIds.get(1), i);
|
||||
Assert.assertEquals(operation.getStatus(), Operation.Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationByDeviceAndOperationIdForAllOperations")
|
||||
public void getOperationForAllOperations() throws DeviceManagementException,
|
||||
OperationManagementException {
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
Operation operation = this.operationMgtService.getOperation(i);
|
||||
Assert.assertTrue(operation != null);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationForAllOperations")
|
||||
public void addCustomPolicyOperation() throws OperationManagementException, InvalidDeviceException {
|
||||
this.addCustomOperation(Operation.Type.POLICY, DeviceManagementConstants.AuthorizationSkippedOperationCodes.
|
||||
POLICY_OPERATION_CODE);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationForAllOperations")
|
||||
public void addCustomMonitorOperation() throws OperationManagementException, InvalidDeviceException {
|
||||
this.addCustomOperation(Operation.Type.COMMAND, DeviceManagementConstants.AuthorizationSkippedOperationCodes.
|
||||
MONITOR_OPERATION_CODE);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getOperationForAllOperations")
|
||||
public void addCustomPolicyRevokeOperation() throws OperationManagementException, InvalidDeviceException {
|
||||
this.addCustomOperation(Operation.Type.POLICY, DeviceManagementConstants.AuthorizationSkippedOperationCodes.
|
||||
POLICY_REVOKE_OPERATION_CODE);
|
||||
}
|
||||
|
||||
private void addCustomOperation(Operation.Type type, String operationCode) throws OperationManagementException, InvalidDeviceException {
|
||||
Operation operation = new Operation();
|
||||
operation.setCode(operationCode);
|
||||
operation.setType(type);
|
||||
Activity activity = this.operationMgtService.addOperation(operation, Collections.singletonList(this.deviceIds.get(2)));
|
||||
Assert.assertEquals(activity.getActivityStatus().size(), 1);
|
||||
for (ActivityStatus status : activity.getActivityStatus()) {
|
||||
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.PENDING);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.core.operation;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
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.InvalidDeviceException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.TestTaskServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
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.operation.mgt.CommandOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl;
|
||||
import org.wso2.carbon.ntask.core.internal.TasksDSComponent;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.wso2.carbon.device.mgt.core.operation.OperationManagementTests.getOperation;
|
||||
|
||||
/**
|
||||
* This class tests the tasks based operations of {@link OperationManager}
|
||||
*/
|
||||
public class ScheduledTaskOperationTests extends BaseDeviceManagementTest {
|
||||
private static final String DEVICE_TYPE = "OP_SCHEDULE_TEST_TYPE";
|
||||
private static final String DEVICE_ID_PREFIX = "OP-SCHEDULED_TEST-DEVICE-ID-";
|
||||
private static final String COMMAND_OPERATON_CODE = "COMMAND-TEST";
|
||||
private static final int NO_OF_DEVICES = 5;
|
||||
private static final String DS_TASK_COMPONENT_FIELD = "taskService";
|
||||
private static final String CDM_CONFIG_LOCATION = "src" + File.separator + "test" + File.separator + "resources" +
|
||||
File.separator + "config" + File.separator + "operation" + File.separator + "cdm-config.xml";
|
||||
|
||||
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||
private OperationManager operationMgtService;
|
||||
|
||||
@BeforeClass
|
||||
public void init() throws Exception {
|
||||
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
||||
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||
}
|
||||
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
||||
DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
|
||||
initTaskService();
|
||||
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, COMMAND_OPERATON_CODE));
|
||||
for (Device device : devices) {
|
||||
deviceMgtService.enrollDevice(device);
|
||||
}
|
||||
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
|
||||
for (Device device : returnedDevices) {
|
||||
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||
}
|
||||
}
|
||||
DeviceConfigurationManager.getInstance().initConfig(CDM_CONFIG_LOCATION);
|
||||
TestNotificationStrategy notificationStrategy = new TestNotificationStrategy();
|
||||
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
|
||||
}
|
||||
|
||||
|
||||
private void initTaskService() throws NoSuchFieldException, IllegalAccessException {
|
||||
TaskService taskService = new TestTaskServiceImpl();
|
||||
DeviceManagementDataHolder.getInstance().setTaskService(taskService);
|
||||
DeviceTaskManagerService deviceTaskManager = new DeviceTaskManagerServiceImpl();
|
||||
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(deviceTaskManager);
|
||||
Field taskServiceField = TasksDSComponent.class.getDeclaredField(DS_TASK_COMPONENT_FIELD);
|
||||
taskServiceField.setAccessible(true);
|
||||
taskServiceField.set(null, Mockito.mock(TaskServiceImpl.class, Mockito.RETURNS_MOCKS));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
|
||||
InvalidDeviceException, NoSuchFieldException {
|
||||
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
|
||||
this.deviceIds);
|
||||
Assert.assertEquals(activity.getActivityStatus(), null);
|
||||
Assert.assertEquals(activity.getType(), Activity.Type.COMMAND);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.core.operation;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TestNotificationStrategy implements NotificationStrategy {
|
||||
private PushNotificationConfig pushNotificationConfig;
|
||||
|
||||
public TestNotificationStrategy(){
|
||||
this.pushNotificationConfig = new PushNotificationConfig("TEST", true, new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotificationContext buildContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeploy() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushNotificationConfig getConfig() {
|
||||
return pushNotificationConfig;
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.core.permission.mgt;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
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.permission.mgt.Permission;
|
||||
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
|
||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
@PrepareForTest(PermissionUtils.class)
|
||||
public class PermissionManagerServiceTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PermissionManagerServiceTest.class);;
|
||||
private static final String PERMISSION_URL = "permission/admin/device-mgt/test/testPermission";
|
||||
private static final String PERMISSION_PATH = "permission/admin/device-mgt/test/testPermission";
|
||||
private static final String PERMISSION_METHOD = "ui.execute";
|
||||
private static final String PERMISSION_NAME = "Test Permission";
|
||||
|
||||
//For create properties to retrieve permission.
|
||||
private static final String HTTP_METHOD = "HTTP_METHOD";
|
||||
private static final String URL = "URL";
|
||||
|
||||
private Permission permission;
|
||||
private PermissionManagerService permissionManagerService;
|
||||
|
||||
@ObjectFactory
|
||||
public IObjectFactory getObjectFactory() {
|
||||
return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public void init() throws RegistryException {
|
||||
initMocks(this);
|
||||
permissionManagerService = PermissionManagerServiceImpl.getInstance();
|
||||
this.permission = new Permission();
|
||||
permission.setName(PERMISSION_NAME);
|
||||
permission.setPath(PERMISSION_PATH);
|
||||
permission.setMethod(PERMISSION_METHOD);
|
||||
permission.setUrl(PERMISSION_URL);
|
||||
}
|
||||
|
||||
@Test (description = "Create a new permission in the permission tree.")
|
||||
public void testCreatePermission() {
|
||||
try {
|
||||
PowerMockito.mockStatic(PermissionUtils.class);
|
||||
PowerMockito.when(PermissionUtils.putPermission(permission)).thenReturn(true);
|
||||
|
||||
Assert.assertTrue(permissionManagerService.addPermission(permission));
|
||||
} catch (PermissionManagementException e) {
|
||||
log.error("Error creating permission " + e.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test (dependsOnMethods = {"testCreatePermission"}, description = "Test for retrieving the created permission " +
|
||||
"from the permission tree.")
|
||||
public void testGetPermission() throws PermissionManagementException {
|
||||
Permission permission = permissionManagerService.getPermission(createProperties());
|
||||
|
||||
Assert.assertEquals(permission.getMethod(), PERMISSION_METHOD);
|
||||
Assert.assertEquals(permission.getName(), PERMISSION_NAME);
|
||||
Assert.assertEquals(permission.getPath(), PERMISSION_PATH);
|
||||
Assert.assertEquals(permission.getUrl(), PERMISSION_URL);
|
||||
}
|
||||
|
||||
@Test (dependsOnMethods = {"testCreatePermission"},
|
||||
expectedExceptions = {PermissionManagementException.class},
|
||||
expectedExceptionsMessageRegExp = "Resource URI/HTTP method is empty")
|
||||
public void testGetPermissionError() throws PermissionManagementException {
|
||||
Permission permission = permissionManagerService.getPermission(createErrorProperty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Property object which will be passed to getPermission method to retrieve a permission.
|
||||
* @return : Property object which contains permission url and method.
|
||||
* */
|
||||
private Properties createProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(URL, PERMISSION_URL);
|
||||
properties.setProperty(HTTP_METHOD, PERMISSION_METHOD);
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates property object with empty properties.
|
||||
* @return : Properties object with empty set of properties.
|
||||
* */
|
||||
private Properties createErrorProperty() {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(URL, "");
|
||||
properties.setProperty(HTTP_METHOD, "");
|
||||
return properties;
|
||||
}
|
||||
}
|
@ -0,0 +1,285 @@
|
||||
/*
|
||||
* 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.core.service;
|
||||
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.*;
|
||||
import org.wso2.carbon.device.mgt.core.TestUtils;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
||||
import org.wso2.carbon.user.api.Permission;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.api.UserStoreManager;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest {
|
||||
|
||||
private GroupManagementProviderService groupManagementProviderService;
|
||||
private static final String DEFAULT_ADMIN_ROLE = "admin";
|
||||
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
|
||||
"/permission/device-mgt/user/groups"};
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
groupManagementProviderService = new GroupManagementProviderServiceImpl();
|
||||
RealmService realmService = new InMemoryRealmService();
|
||||
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
||||
realmService.getTenantManager().getSuperTenantDomain();
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {GroupManagementException.class, GroupAlreadyExistException.class})
|
||||
public void createGroupNull() throws GroupManagementException, GroupAlreadyExistException {
|
||||
groupManagementProviderService.createGroup(null, null, null);
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = {GroupManagementException.class, GroupAlreadyExistException.class, TransactionManagementException.class})
|
||||
public void createGroupError() throws GroupManagementException, GroupAlreadyExistException, TransactionManagementException {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void createGroup() throws GroupManagementException, GroupAlreadyExistException {
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup1(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup2(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup3(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void updateGroup() throws GroupManagementException, GroupNotExistException {
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName());
|
||||
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
||||
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
||||
public void getGroupNull() throws GroupManagementException, GroupNotExistException {
|
||||
groupManagementProviderService.getGroup(null);
|
||||
}
|
||||
|
||||
// Rename again to use in different place.
|
||||
@Test(dependsOnMethods = ("updateGroup"))
|
||||
public void updateGroupSecondTime() throws GroupManagementException, GroupNotExistException {
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName() + "_UPDATED");
|
||||
deviceGroup.setName(TestUtils.createDeviceGroup1().getName());
|
||||
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
||||
public void updateGroupError() throws GroupManagementException, GroupNotExistException {
|
||||
groupManagementProviderService.updateGroup(null, 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
||||
public void updateGroupErrorNotExist() throws GroupManagementException, GroupNotExistException {
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup2().getName());
|
||||
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
||||
groupManagementProviderService.updateGroup(deviceGroup, 6);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void deleteGroup() throws GroupManagementException {
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup4().getName());
|
||||
Assert.assertTrue(groupManagementProviderService.deleteGroup(deviceGroup.getGroupId()));
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void deleteGroupNotExists() throws GroupManagementException {
|
||||
groupManagementProviderService.deleteGroup(8);
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroup() throws GroupManagementException {
|
||||
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName());
|
||||
Assert.assertNotNull(groupManagementProviderService.getGroup(deviceGroup.getGroupId()));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupByName() throws GroupManagementException {
|
||||
Assert.assertNotNull(groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName()));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroups() throws GroupManagementException {
|
||||
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups();
|
||||
Assert.assertNotNull(deviceGroups);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByUsername() throws GroupManagementException {
|
||||
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups("admin");
|
||||
Assert.assertNotNull(deviceGroups);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
||||
public void getGroupsByUsernameError() throws GroupManagementException {
|
||||
groupManagementProviderService.getGroups((String) null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByPagination() throws GroupManagementException {
|
||||
PaginationResult result = groupManagementProviderService.getGroups(TestUtils.createPaginationRequest());
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
||||
public void getGroupsByPaginationError() throws GroupManagementException {
|
||||
GroupPaginationRequest request = null;
|
||||
groupManagementProviderService.getGroups(request);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByUsernameAndPagination()
|
||||
throws GroupManagementException {
|
||||
PaginationResult result = groupManagementProviderService.getGroups("admin", TestUtils.createPaginationRequest());
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
||||
public void getGroupsByUsernameAndPaginationError()
|
||||
throws GroupManagementException {
|
||||
groupManagementProviderService.getGroups(null, TestUtils.createPaginationRequest());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupCount() throws GroupManagementException {
|
||||
int x = groupManagementProviderService.getGroupCount();
|
||||
Assert.assertNotNull(x);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupCountByUsername(String username) throws GroupManagementException {
|
||||
int x = groupManagementProviderService.getGroupCount(username);
|
||||
Assert.assertNotNull(x);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("updateGroupSecondTime"))
|
||||
public void manageGroupSharing() throws GroupManagementException, RoleDoesNotExistException, UserStoreException {
|
||||
groupManagementProviderService.manageGroupSharing(0, null);
|
||||
List<String> newRoles = new ArrayList<>();
|
||||
newRoles.add("TEST_ROLE_1");
|
||||
newRoles.add("TEST_ROLE_2");
|
||||
newRoles.add("TEST_ROLE_3");
|
||||
|
||||
UserStoreManager userStoreManager =
|
||||
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
|
||||
-1234).getUserStoreManager();
|
||||
Permission[] permissions = new Permission[1];
|
||||
Permission perm = new Permission("/admin/test/perm", "add");
|
||||
permissions[0] = perm;
|
||||
|
||||
userStoreManager.addRole("TEST_ROLE_1", null, permissions);
|
||||
userStoreManager.addRole("TEST_ROLE_2", null, permissions);
|
||||
userStoreManager.addRole("TEST_ROLE_3", null, permissions);
|
||||
|
||||
groupManagementProviderService.manageGroupSharing(groupManagementProviderService.getGroup(
|
||||
TestUtils.createDeviceGroup1().getName()).getGroupId(), newRoles);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getRoles() throws GroupManagementException {
|
||||
List<String> roles = groupManagementProviderService.getRoles(1);
|
||||
Assert.assertNotNull(roles);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getDevices() throws GroupManagementException {
|
||||
List<Device> devices = groupManagementProviderService.getDevices(1, 1, 50);
|
||||
Assert.assertNotNull(devices);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getDeviceCount() throws GroupManagementException {
|
||||
int x = groupManagementProviderService.getDeviceCount(1);
|
||||
Assert.assertEquals(0, x);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void addDevices() throws GroupManagementException, DeviceNotFoundException {
|
||||
|
||||
DeviceCacheConfiguration configuration = new DeviceCacheConfiguration();
|
||||
configuration.setEnabled(false);
|
||||
|
||||
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().setDeviceCacheConfiguration(configuration);
|
||||
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
|
||||
groupManagementProviderService.addDevices(groupManagementProviderService.getGroup(
|
||||
TestUtils.createDeviceGroup1().getName()).getGroupId(), list);
|
||||
groupManagementProviderService.addDevices(groupManagementProviderService.getGroup(
|
||||
TestUtils.createDeviceGroup2().getName()).getGroupId(), list);
|
||||
groupManagementProviderService.addDevices(groupManagementProviderService.getGroup(
|
||||
TestUtils.createDeviceGroup3().getName()).getGroupId(), list);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("addDevices"))
|
||||
public void removeDevice() throws GroupManagementException, DeviceNotFoundException {
|
||||
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
|
||||
groupManagementProviderService.removeDevice(groupManagementProviderService.getGroup(
|
||||
TestUtils.createDeviceGroup2().getName()).getGroupId(), list);
|
||||
groupManagementProviderService.removeDevice(groupManagementProviderService.getGroup(
|
||||
TestUtils.createDeviceGroup3().getName()).getGroupId(), list);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByUsernameAndPermissions() throws GroupManagementException {
|
||||
List<DeviceGroup> groups = groupManagementProviderService.getGroups("admin", "/permission/device-mgt/admin/groups");
|
||||
Assert.assertNotNull(groups);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("addDevices"))
|
||||
public void getGroupsByDeviceIdentifier() throws GroupManagementException {
|
||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||
identifier.setId("12345");
|
||||
identifier.setType("Test");
|
||||
List<DeviceGroup> groups = groupManagementProviderService.getGroups(identifier);
|
||||
Assert.assertNotNull(groups);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDefaultGroup() throws GroupManagementException {
|
||||
groupManagementProviderService.createDefaultGroup("BYOD");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createDefaultGroup"))
|
||||
public void createDefaultGroupTwice() throws GroupManagementException {
|
||||
groupManagementProviderService.createDefaultGroup("BYOD");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,124 @@
|
||||
package org.wso2.carbon.device.mgt.core.task;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.opensaml.xml.signature.P;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.quartz.impl.StdSchedulerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||
import org.wso2.carbon.device.mgt.core.TestTaskServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.TestUtils;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
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.permission.mgt.PermissionUtils;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl;
|
||||
import org.wso2.carbon.ntask.common.TaskException;
|
||||
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||
import org.wso2.carbon.ntask.core.TaskManager;
|
||||
import org.wso2.carbon.ntask.core.TaskUtils;
|
||||
import org.wso2.carbon.ntask.core.impl.QuartzCachedThreadPool;
|
||||
import org.wso2.carbon.ntask.core.internal.TasksDSComponent;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
|
||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DeviceTaskManagerServiceTest {
|
||||
private static final Log log = LogFactory.getLog(DeviceTaskManagerService.class);
|
||||
private static final String TASK_TYPE = "DEVICE_MONITORING";
|
||||
private DeviceTaskManagerService deviceTaskManagerService;
|
||||
@Mock private TaskService taskService;
|
||||
|
||||
@BeforeClass public void init() throws Exception {
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
log.info("Initializing Device Task Manager Service Test Suite");
|
||||
this.taskService = new TestTaskServiceImpl();
|
||||
DeviceManagementDataHolder.getInstance().setTaskService(this.taskService);
|
||||
this.deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
|
||||
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(this.deviceTaskManagerService);
|
||||
Field taskServiceField = TasksDSComponent.class.getDeclaredField("taskService");
|
||||
taskServiceField.setAccessible(true);
|
||||
taskServiceField.set(null, Mockito.mock(TaskServiceImpl.class, Mockito.RETURNS_MOCKS));
|
||||
}
|
||||
|
||||
@Test(groups = "Device Task Manager")
|
||||
public void testStartTask() {
|
||||
try {
|
||||
log.debug("Attempting to start task from testStartTask");
|
||||
this.deviceTaskManagerService
|
||||
.startTask(TestDataHolder.TEST_DEVICE_TYPE, generateValidMonitoringTaskConfig("DEVICE_INFO"));
|
||||
TaskManager taskManager = this.taskService.getTaskManager(TASK_TYPE);
|
||||
Assert.assertEquals(this.taskService.getRegisteredTaskTypes().size(), 1);
|
||||
Assert.assertNotNull(taskManager
|
||||
.getTask(TestDataHolder.TEST_DEVICE_TYPE + String.valueOf(TestDataHolder.SUPER_TENANT_ID)));
|
||||
log.debug("Task Successfully started");
|
||||
} catch (DeviceMgtTaskException | TaskException e) {
|
||||
Assert.fail("Exception occurred when starting the task", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "Device Task Manager", dependsOnMethods = "testStartTask")
|
||||
public void testUpdateTask() {
|
||||
try {
|
||||
log.debug("Attempting to update task from testStartTask");
|
||||
this.deviceTaskManagerService
|
||||
.updateTask(TestDataHolder.TEST_DEVICE_TYPE, generateValidMonitoringTaskConfig("DEVICE_LOCATION"));
|
||||
Assert.assertEquals(this.taskService.getRegisteredTaskTypes().size(), 1);
|
||||
TaskManager taskManager = this.taskService.getTaskManager(TASK_TYPE);
|
||||
Assert.assertEquals(taskManager.getAllTasks().size(), 1);
|
||||
log.debug("Task Successfully updated");
|
||||
} catch (DeviceMgtTaskException | TaskException e) {
|
||||
Assert.fail("Exception occurred when updating the task", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "Device Task Manager", dependsOnMethods = "testUpdateTask")
|
||||
public void testStopTask() {
|
||||
log.debug("Attempting to stop task from testStopTask");
|
||||
try {
|
||||
this.deviceTaskManagerService
|
||||
.stopTask(TestDataHolder.TEST_DEVICE_TYPE, generateValidMonitoringTaskConfig("DEVICE_LOCATION"));
|
||||
TaskManager taskManager = this.taskService.getTaskManager(TASK_TYPE);
|
||||
Assert.assertEquals(taskManager.getAllTasks().size(), 0);
|
||||
} catch (DeviceMgtTaskException | TaskException e) {
|
||||
Assert.fail("Exception occurred when stopping the task", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private OperationMonitoringTaskConfig generateValidMonitoringTaskConfig(String operationConfig) {
|
||||
OperationMonitoringTaskConfig validTaskConfig = new OperationMonitoringTaskConfig();
|
||||
List<MonitoringOperation> operationList = new ArrayList<>();
|
||||
MonitoringOperation operation = new MonitoringOperation();
|
||||
operation.setTaskName(operationConfig);
|
||||
operation.setRecurrentTimes(1);
|
||||
operationList.add(operation);
|
||||
|
||||
validTaskConfig.setEnabled(true);
|
||||
validTaskConfig.setFrequency(60000);
|
||||
validTaskConfig.setMonitoringOperation(operationList);
|
||||
|
||||
return validTaskConfig;
|
||||
}
|
||||
|
||||
private Properties getStandardQuartzProps() {
|
||||
Properties result = new Properties();
|
||||
result.put("org.quartz.scheduler.skipUpdateCheck", "true");
|
||||
result.put("org.quartz.threadPool.class", QuartzCachedThreadPool.class.getName());
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package org.wso2.carbon.device.mgt.core.task;
|
||||
|
||||
import org.wso2.carbon.ntask.common.TaskException;
|
||||
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||
import org.wso2.carbon.ntask.core.TaskManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestTaskManagerImpl implements TaskManager {
|
||||
private List<TaskInfo> registeredTasks;
|
||||
|
||||
public TestTaskManagerImpl() {
|
||||
this.registeredTasks = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initStartupTasks() throws TaskException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleTask(String taskName) throws TaskException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rescheduleTask(String taskName) throws TaskException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteTask(String taskName) throws TaskException {
|
||||
for (TaskInfo task : this.registeredTasks) {
|
||||
if (task.getName().contains(taskName)) {
|
||||
this.registeredTasks.remove(task);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseTask(String taskName) throws TaskException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeTask(String taskName) throws TaskException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTask(TaskInfo taskInfo) throws TaskException {
|
||||
this.registeredTasks.add(taskInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskState getTaskState(String taskName) throws TaskException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskInfo getTask(String taskName) throws TaskException {
|
||||
for (TaskInfo task : this.registeredTasks) {
|
||||
if (task.getName().contains(taskName)) {
|
||||
return task;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskInfo> getAllTasks() throws TaskException {
|
||||
return this.registeredTasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskScheduled(String taskName) throws TaskException {
|
||||
return this.registeredTasks.size() > 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,429 @@
|
||||
CREATE TABLE IF NOT EXISTS REG_CLUSTER_LOCK (
|
||||
REG_LOCK_NAME VARCHAR (20),
|
||||
REG_LOCK_STATUS VARCHAR (20),
|
||||
REG_LOCKED_TIME TIMESTAMP,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (REG_LOCK_NAME)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_LOG (
|
||||
REG_LOG_ID INTEGER AUTO_INCREMENT,
|
||||
REG_PATH VARCHAR (2000),
|
||||
REG_USER_ID VARCHAR (31) NOT NULL,
|
||||
REG_LOGGED_TIME TIMESTAMP NOT NULL,
|
||||
REG_ACTION INTEGER NOT NULL,
|
||||
REG_ACTION_DATA VARCHAR (500),
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (REG_LOG_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS REG_LOG_IND_BY_REG_LOGTIME ON REG_LOG(REG_LOGGED_TIME, REG_TENANT_ID);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_PATH(
|
||||
REG_PATH_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_PATH_VALUE VARCHAR(2000) NOT NULL,
|
||||
REG_PATH_PARENT_ID INT,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_PATH PRIMARY KEY(REG_PATH_ID, REG_TENANT_ID)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_NAME ON REG_PATH(REG_PATH_VALUE, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_PARENT_ID ON REG_PATH(REG_PATH_PARENT_ID, REG_TENANT_ID);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_CONTENT (
|
||||
REG_CONTENT_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_CONTENT_DATA LONGBLOB,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_CONTENT PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_CONTENT_HISTORY (
|
||||
REG_CONTENT_ID INTEGER NOT NULL,
|
||||
REG_CONTENT_DATA LONGBLOB,
|
||||
REG_DELETED SMALLINT,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_CONTENT_HISTORY PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_RESOURCE (
|
||||
REG_PATH_ID INTEGER NOT NULL,
|
||||
REG_NAME VARCHAR(256),
|
||||
REG_VERSION INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_MEDIA_TYPE VARCHAR(500),
|
||||
REG_CREATOR VARCHAR(31) NOT NULL,
|
||||
REG_CREATED_TIME TIMESTAMP NOT NULL,
|
||||
REG_LAST_UPDATOR VARCHAR(31),
|
||||
REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL,
|
||||
REG_DESCRIPTION VARCHAR(1000),
|
||||
REG_CONTENT_ID INTEGER,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
REG_UUID VARCHAR(100) NOT NULL,
|
||||
CONSTRAINT PK_REG_RESOURCE PRIMARY KEY(REG_VERSION, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
|
||||
ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT (REG_CONTENT_ID, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_NAME ON REG_RESOURCE(REG_NAME, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_UUID ON REG_RESOURCE(REG_UUID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TENANT ON REG_RESOURCE(REG_TENANT_ID, REG_UUID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TYPE ON REG_RESOURCE(REG_TENANT_ID, REG_MEDIA_TYPE);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_RESOURCE_HISTORY (
|
||||
REG_PATH_ID INTEGER NOT NULL,
|
||||
REG_NAME VARCHAR(256),
|
||||
REG_VERSION INTEGER NOT NULL,
|
||||
REG_MEDIA_TYPE VARCHAR(500),
|
||||
REG_CREATOR VARCHAR(31) NOT NULL,
|
||||
REG_CREATED_TIME TIMESTAMP NOT NULL,
|
||||
REG_LAST_UPDATOR VARCHAR(31),
|
||||
REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL,
|
||||
REG_DESCRIPTION VARCHAR(1000),
|
||||
REG_CONTENT_ID INTEGER,
|
||||
REG_DELETED SMALLINT,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
REG_UUID VARCHAR(100) NOT NULL,
|
||||
CONSTRAINT PK_REG_RESOURCE_HISTORY PRIMARY KEY(REG_VERSION, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_PATHID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
|
||||
ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT_HISTORY (REG_CONTENT_ID, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_NAME ON REG_RESOURCE_HISTORY(REG_NAME, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_COMMENT (
|
||||
REG_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_COMMENT_TEXT VARCHAR(500) NOT NULL,
|
||||
REG_USER_ID VARCHAR(31) NOT NULL,
|
||||
REG_COMMENTED_TIME TIMESTAMP NOT NULL,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_COMMENT PRIMARY KEY(REG_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_RESOURCE_COMMENT (
|
||||
REG_COMMENT_ID INTEGER NOT NULL,
|
||||
REG_VERSION INTEGER,
|
||||
REG_PATH_ID INTEGER,
|
||||
REG_RESOURCE_NAME VARCHAR(256),
|
||||
REG_TENANT_ID INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
|
||||
ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_COMMENT_ID FOREIGN KEY (REG_COMMENT_ID, REG_TENANT_ID) REFERENCES REG_COMMENT (REG_ID, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_COMMENT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_VERSION ON REG_RESOURCE_COMMENT(REG_VERSION, REG_TENANT_ID);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_RATING (
|
||||
REG_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_RATING INTEGER NOT NULL,
|
||||
REG_USER_ID VARCHAR(31) NOT NULL,
|
||||
REG_RATED_TIME TIMESTAMP NOT NULL,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_RATING PRIMARY KEY(REG_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_RESOURCE_RATING (
|
||||
REG_RATING_ID INTEGER NOT NULL,
|
||||
REG_VERSION INTEGER,
|
||||
REG_PATH_ID INTEGER,
|
||||
REG_RESOURCE_NAME VARCHAR(256),
|
||||
REG_TENANT_ID INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
|
||||
ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_RATING_ID FOREIGN KEY (REG_RATING_ID, REG_TENANT_ID) REFERENCES REG_RATING (REG_ID, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_RATING(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_VERSION ON REG_RESOURCE_RATING(REG_VERSION, REG_TENANT_ID);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_TAG (
|
||||
REG_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_TAG_NAME VARCHAR(500) NOT NULL,
|
||||
REG_USER_ID VARCHAR(31) NOT NULL,
|
||||
REG_TAGGED_TIME TIMESTAMP NOT NULL,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_TAG PRIMARY KEY(REG_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_RESOURCE_TAG (
|
||||
REG_TAG_ID INTEGER NOT NULL,
|
||||
REG_VERSION INTEGER,
|
||||
REG_PATH_ID INTEGER,
|
||||
REG_RESOURCE_NAME VARCHAR(256),
|
||||
REG_TENANT_ID INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
|
||||
ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_TAG_ID FOREIGN KEY (REG_TAG_ID, REG_TENANT_ID) REFERENCES REG_TAG (REG_ID, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_TAG(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_VERSION ON REG_RESOURCE_TAG(REG_VERSION, REG_TENANT_ID);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_PROPERTY (
|
||||
REG_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_NAME VARCHAR(100) NOT NULL,
|
||||
REG_VALUE VARCHAR(1000),
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_PROPERTY PRIMARY KEY(REG_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_RESOURCE_PROPERTY (
|
||||
REG_PROPERTY_ID INTEGER NOT NULL,
|
||||
REG_VERSION INTEGER,
|
||||
REG_PATH_ID INTEGER,
|
||||
REG_RESOURCE_NAME VARCHAR(256),
|
||||
REG_TENANT_ID INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
|
||||
ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_TAG_ID FOREIGN KEY (REG_PROPERTY_ID, REG_TENANT_ID) REFERENCES REG_PROPERTY (REG_ID, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_PROPERTY(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_VERSION ON REG_RESOURCE_PROPERTY(REG_VERSION, REG_TENANT_ID);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_ASSOCIATION (
|
||||
REG_ASSOCIATION_ID INTEGER AUTO_INCREMENT,
|
||||
REG_SOURCEPATH VARCHAR (2000) NOT NULL,
|
||||
REG_TARGETPATH VARCHAR (2000) NOT NULL,
|
||||
REG_ASSOCIATION_TYPE VARCHAR (2000) NOT NULL,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (REG_ASSOCIATION_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS REG_SNAPSHOT (
|
||||
REG_SNAPSHOT_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
REG_PATH_ID INTEGER NOT NULL,
|
||||
REG_RESOURCE_NAME VARCHAR (256),
|
||||
REG_RESOURCE_VIDS LONGBLOB NOT NULL,
|
||||
REG_TENANT_ID INTEGER DEFAULT 0,
|
||||
CONSTRAINT PK_REG_SNAPSHOT PRIMARY KEY(REG_SNAPSHOT_ID, REG_TENANT_ID)
|
||||
);
|
||||
|
||||
ALTER TABLE REG_SNAPSHOT ADD CONSTRAINT IF NOT EXISTS REG_SNAPSHOT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
|
||||
CREATE INDEX IF NOT EXISTS REG_SNAPSHOT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_SNAPSHOT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
|
||||
|
||||
-- ################################
|
||||
-- USER MANAGER TABLES
|
||||
-- ################################
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_TENANT (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_DOMAIN_NAME VARCHAR(255) NOT NULL,
|
||||
UM_EMAIL VARCHAR(255),
|
||||
UM_ACTIVE BOOLEAN DEFAULT FALSE,
|
||||
UM_CREATED_DATE TIMESTAMP NOT NULL,
|
||||
UM_USER_CONFIG LONGBLOB NOT NULL,
|
||||
PRIMARY KEY (UM_ID),
|
||||
UNIQUE(UM_DOMAIN_NAME));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_DOMAIN(
|
||||
UM_DOMAIN_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_DOMAIN_NAME VARCHAR(255),
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (UM_DOMAIN_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS INDEX_UM_TENANT_UM_DOMAIN_NAME ON UM_TENANT (UM_DOMAIN_NAME);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_USER (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_USER_NAME VARCHAR(255) NOT NULL,
|
||||
UM_USER_PASSWORD VARCHAR(255) NOT NULL,
|
||||
UM_SALT_VALUE VARCHAR(31),
|
||||
UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE,
|
||||
UM_CHANGED_TIME TIMESTAMP NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID),
|
||||
UNIQUE(UM_USER_NAME, UM_TENANT_ID));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_USER_NAME VARCHAR(255) NOT NULL,
|
||||
UM_USER_PASSWORD VARCHAR(255) NOT NULL,
|
||||
UM_SALT_VALUE VARCHAR(31),
|
||||
UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE,
|
||||
UM_CHANGED_TIME TIMESTAMP NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID),
|
||||
UNIQUE(UM_USER_NAME, UM_TENANT_ID));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_USER_ATTRIBUTE (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_ATTR_NAME VARCHAR(255) NOT NULL,
|
||||
UM_ATTR_VALUE VARCHAR(1024),
|
||||
UM_PROFILE_ID VARCHAR(255),
|
||||
UM_USER_ID INTEGER,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID),
|
||||
FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID));
|
||||
|
||||
CREATE INDEX IF NOT EXISTS UM_USER_ID_INDEX ON UM_USER_ATTRIBUTE(UM_USER_ID);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_ROLE (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_ROLE_NAME VARCHAR(255) NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UM_SHARED_ROLE BOOLEAN DEFAULT FALSE,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID),
|
||||
UNIQUE(UM_ROLE_NAME, UM_TENANT_ID));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_MODULE(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_MODULE_NAME VARCHAR(100),
|
||||
UNIQUE(UM_MODULE_NAME),
|
||||
PRIMARY KEY(UM_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_MODULE_ACTIONS(
|
||||
UM_ACTION VARCHAR(255) NOT NULL,
|
||||
UM_MODULE_ID INTEGER NOT NULL,
|
||||
PRIMARY KEY(UM_ACTION, UM_MODULE_ID),
|
||||
FOREIGN KEY (UM_MODULE_ID) REFERENCES UM_MODULE(UM_ID) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_PERMISSION (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_RESOURCE_ID VARCHAR(255) NOT NULL,
|
||||
UM_ACTION VARCHAR(255) NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UM_MODULE_ID INTEGER DEFAULT 0,
|
||||
UNIQUE(UM_RESOURCE_ID,UM_ACTION, UM_TENANT_ID),
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID));
|
||||
|
||||
CREATE INDEX IF NOT EXISTS INDEX_UM_PERMISSION_UM_RESOURCE_ID_UM_ACTION ON UM_PERMISSION (UM_RESOURCE_ID, UM_ACTION, UM_TENANT_ID);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_ROLE_PERMISSION (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_PERMISSION_ID INTEGER NOT NULL,
|
||||
UM_ROLE_NAME VARCHAR(255) NOT NULL,
|
||||
UM_IS_ALLOWED SMALLINT NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UM_DOMAIN_ID INTEGER,
|
||||
FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
|
||||
FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_USER_PERMISSION (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_PERMISSION_ID INTEGER NOT NULL,
|
||||
UM_USER_NAME VARCHAR(255) NOT NULL,
|
||||
UM_IS_ALLOWED SMALLINT NOT NULL,
|
||||
UNIQUE (UM_PERMISSION_ID, UM_USER_NAME, UM_TENANT_ID),
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_USER_ROLE (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_ROLE_ID INTEGER NOT NULL,
|
||||
UM_USER_ID INTEGER NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UNIQUE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID),
|
||||
FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_ROLE(UM_ID, UM_TENANT_ID),
|
||||
FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID),
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID));
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_SHARED_USER_ROLE(
|
||||
UM_ROLE_ID INTEGER NOT NULL,
|
||||
UM_USER_ID INTEGER NOT NULL,
|
||||
UM_USER_TENANT_ID INTEGER NOT NULL,
|
||||
UM_ROLE_TENANT_ID INTEGER NOT NULL,
|
||||
UNIQUE(UM_USER_ID,UM_ROLE_ID,UM_USER_TENANT_ID, UM_ROLE_TENANT_ID),
|
||||
FOREIGN KEY(UM_ROLE_ID,UM_ROLE_TENANT_ID) REFERENCES UM_ROLE(UM_ID,UM_TENANT_ID) ON DELETE CASCADE ,
|
||||
FOREIGN KEY(UM_USER_ID,UM_USER_TENANT_ID) REFERENCES UM_USER(UM_ID,UM_TENANT_ID) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_ACCOUNT_MAPPING(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_USER_NAME VARCHAR(255) NOT NULL,
|
||||
UM_TENANT_ID INTEGER NOT NULL,
|
||||
UM_USER_STORE_DOMAIN VARCHAR(100),
|
||||
UM_ACC_LINK_ID INTEGER NOT NULL,
|
||||
UNIQUE(UM_USER_NAME, UM_TENANT_ID, UM_USER_STORE_DOMAIN, UM_ACC_LINK_ID),
|
||||
FOREIGN KEY (UM_TENANT_ID) REFERENCES UM_TENANT(UM_ID) ON DELETE CASCADE,
|
||||
PRIMARY KEY (UM_ID)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_DIALECT(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_DIALECT_URI VARCHAR(255) NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UNIQUE(UM_DIALECT_URI, UM_TENANT_ID),
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_CLAIM(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_DIALECT_ID INTEGER NOT NULL,
|
||||
UM_CLAIM_URI VARCHAR(255) NOT NULL,
|
||||
UM_DISPLAY_TAG VARCHAR(255),
|
||||
UM_DESCRIPTION VARCHAR(255),
|
||||
UM_MAPPED_ATTRIBUTE_DOMAIN VARCHAR(255),
|
||||
UM_MAPPED_ATTRIBUTE VARCHAR(255),
|
||||
UM_REG_EX VARCHAR(255),
|
||||
UM_SUPPORTED SMALLINT,
|
||||
UM_REQUIRED SMALLINT,
|
||||
UM_DISPLAY_ORDER INTEGER,
|
||||
UM_CHECKED_ATTRIBUTE SMALLINT,
|
||||
UM_READ_ONLY SMALLINT,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UNIQUE(UM_DIALECT_ID, UM_CLAIM_URI,UM_MAPPED_ATTRIBUTE_DOMAIN, UM_TENANT_ID),
|
||||
FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID),
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_PROFILE_CONFIG(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_DIALECT_ID INTEGER,
|
||||
UM_PROFILE_NAME VARCHAR(255),
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID),
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_HYBRID_ROLE(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_ROLE_NAME VARCHAR(255),
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_HYBRID_USER_ROLE(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_USER_NAME VARCHAR(255),
|
||||
UM_ROLE_ID INTEGER NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UM_DOMAIN_ID INTEGER,
|
||||
UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID,UM_DOMAIN_ID),
|
||||
FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_HYBRID_ROLE(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
|
||||
FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_HYBRID_REMEMBER_ME (
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_USER_NAME VARCHAR(255) NOT NULL,
|
||||
UM_COOKIE_VALUE VARCHAR(1024),
|
||||
UM_CREATED_TIME TIMESTAMP,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_SYSTEM_ROLE(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_ROLE_NAME VARCHAR(255),
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER_ROLE(
|
||||
UM_ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
UM_USER_NAME VARCHAR(255),
|
||||
UM_ROLE_ID INTEGER NOT NULL,
|
||||
UM_TENANT_ID INTEGER DEFAULT 0,
|
||||
UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID),
|
||||
FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_SYSTEM_ROLE(UM_ID, UM_TENANT_ID),
|
||||
PRIMARY KEY (UM_ID, UM_TENANT_ID)
|
||||
);
|
@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2015, 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>false</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>
|
||||
|
@ -0,0 +1,51 @@
|
||||
<tasks-configuration xmlns:svns="http://org.wso2.securevault/configuration">
|
||||
|
||||
<!--
|
||||
The currently running server mode; possible values are:-
|
||||
STANDALONE, CLUSTERED, REMOTE, AUTO.
|
||||
In AUTO mode, the server startup checks whether clustering is enabled in the system,
|
||||
if so, CLUSTERED mode will be used, or else, the the server mode will be STANDALONE.
|
||||
-->
|
||||
<taskServerMode>STANDALONE</taskServerMode>
|
||||
|
||||
<!--
|
||||
To be used in CLUSTERED mode to notify how many servers are there in
|
||||
the task server cluster, the servers wait till this amount of servers
|
||||
are activated before the tasks are scheduled -->
|
||||
<taskServerCount>2</taskServerCount>
|
||||
|
||||
<!-- The default location resolver configuration -->
|
||||
<defaultLocationResolver>
|
||||
<locationResolverClass>org.wso2.carbon.ntask.core.impl.RoundRobinTaskLocationResolver</locationResolverClass>
|
||||
</defaultLocationResolver>
|
||||
|
||||
<!--
|
||||
if task-type-pattern matches and task-name-pattern matches, check existing addresses of address-pattern,
|
||||
and if addresses exist, select address in round-robin fashion, if not move onto next rule in sequence.
|
||||
<property name="rule-[order]">[task-type-pattern],[task-name-pattern],[address-pattern]</property>
|
||||
-->
|
||||
<!--defaultLocationResolver>
|
||||
<locationResolverClass>org.wso2.carbon.ntask.core.impl.RuleBasedLocationResolver</locationResolverClass>
|
||||
<properties>
|
||||
<property name="rule-1">HIVE_TASK,.*,192.168.2.*</property>
|
||||
<property name="rule-5">.*,.*,.*</property>
|
||||
</properties>
|
||||
</defaultLocationResolver-->
|
||||
|
||||
<!-- The address to which the remote task server should dispatch the trigger messages to,
|
||||
usually this would be an endpoint to a load balancer -->
|
||||
<taskClientDispatchAddress>https://localhost:9448</taskClientDispatchAddress>
|
||||
|
||||
<!-- The address of the remote task server -->
|
||||
<remoteServerAddress>https://localhost:9443</remoteServerAddress>
|
||||
|
||||
<!-- The username to authenticate to the remote task server -->
|
||||
<remoteServerUsername>admin</remoteServerUsername>
|
||||
|
||||
<!-- The password to authenticate to the remote task server -->
|
||||
<remoteServerPassword>admin</remoteServerPassword>
|
||||
|
||||
<!-- Below contain a sample to be used when using with secure vault -->
|
||||
<!--remoteServerPassword svns:secretAlias="remote.task.server.password"></remoteServerPassword-->
|
||||
|
||||
</tasks-configuration>
|
@ -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>2</SchedulerBatchSize>
|
||||
<SchedulerBatchDelayMills>2000</SchedulerBatchDelayMills>
|
||||
<SchedulerTaskInitialDelay>2000</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>false</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>
|
||||
|
@ -0,0 +1,101 @@
|
||||
<!--
|
||||
~ Copyright (c) 2005-2011, 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.
|
||||
-->
|
||||
<UserManager>
|
||||
<Realm>
|
||||
<Configuration>
|
||||
<AddAdmin>true</AddAdmin>
|
||||
<AdminRole>admin</AdminRole>
|
||||
<AdminUser>
|
||||
<UserName>admin</UserName>
|
||||
<Password>admin</Password>
|
||||
</AdminUser>
|
||||
<EveryOneRoleName>everyone</EveryOneRoleName>
|
||||
<ReadOnly>false</ReadOnly>
|
||||
<MaxUserNameListLength>500</MaxUserNameListLength>
|
||||
<Property name="url">jdbc:h2:target/databasetest/CARBON_TEST</Property>
|
||||
<Property name="driverName">org.h2.Driver</Property>
|
||||
<Property name="maxActive">50</Property>
|
||||
<Property name="maxWait">60000</Property>
|
||||
<Property name="minIdle">5</Property>
|
||||
</Configuration>
|
||||
<UserStoreManager
|
||||
class="org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager">
|
||||
<Property name="PasswordJavaRegEx">[\S]{5,30}$</Property>
|
||||
<Property name="PasswordJavaScriptRegEx">[\\S]{5,30}</Property>
|
||||
<Property name="SelectUserSQL">SELECT * FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>
|
||||
<!--<Property name="GetRoleListSQL">SELECT UM_ROLE_NAME FROM UM_ROLE WHERE UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="UserFilterSQL">SELECT UM_USER_NAME FROM UM_USER WHERE UM_USER_NAME LIKE ? AND UM_TENANT_ID=? ORDER BY UM_USER_NAME</Property>-->
|
||||
<!--<Property name="UserRoleSQL">SELECT UM_ROLE_NAME FROM UM_USER_ROLE, UM_ROLE, UM_USER WHERE UM_USER.UM_USER_NAME=? AND UM_USER.UM_ID=UM_USER_ROLE.UM_USER_ID AND UM_ROLE.UM_ID=UM_USER_ROLE.UM_ROLE_ID AND UM_USER_ROLE.UM_TENANT_ID=? AND UM_ROLE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="IsRoleExistingSQL">SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="IsUserExistingSQL">SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserListOfRoleSQL">SELECT UM_USER_NAME FROM UM_USER_ROLE, UM_ROLE, UM_USER WHERE UM_ROLE.UM_ROLE_NAME=? AND UM_USER.UM_ID=UM_USER_ROLE.UM_USER_ID AND UM_ROLE.UM_ID=UM_USER_ROLE.UM_ROLE_ID AND UM_USER_ROLE.UM_TENANT_ID=? AND UM_ROLE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserPropertyForProfileSQL">SELECT UM_ATTR_VALUE FROM UM_USER_ATTRIBUTE, UM_USER WHERE UM_USER.UM_ID = UM_USER_ATTRIBUTE.UM_USER_ID AND UM_USER.UM_USER_NAME=? AND UM_ATTR_NAME=? AND UM_PROFILE_ID=? AND UM_USER_ATTRIBUTE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserPropertiesForProfileSQL">SELECT UM_ATTR_NAME, UM_ATTR_VALUE FROM UM_USER_ATTRIBUTE, UM_USER WHERE UM_USER.UM_ID = UM_USER_ATTRIBUTE.UM_USER_ID AND UM_USER.UM_USER_NAME=? AND UM_PROFILE_ID=? AND UM_USER_ATTRIBUTE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetProfileNamesSQL">SELECT DISTINCT UM_PROFILE_ID FROM UM_USER_ATTRIBUTE WHERE UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserProfileNamesSQL">SELECT DISTINCT UM_PROFILE_ID FROM UM_USER_ATTRIBUTE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUsersWithDefaultPasswordsSQL">SELECT UM_USER_NAME FROM UM_USER WHERE WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="UserNameUniqueAcrossTenantsSQL">SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=?</Property>-->
|
||||
<!--<Property name="GetUserIDFromUserNameSQL">SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserNameFromTenantIDSQL">SELECT UM_USER_NAME FROM UM_USER WHERE UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetTenantIDFromUserNameSQL">SELECT UM_TENANT_ID FROM UM_USER WHERE UM_USER_NAME=?</Property>-->
|
||||
<Property name="PasswordDigest">SHA-256</Property>
|
||||
<Property name="StoreSaltedPassword">true</Property>
|
||||
<Property name="UserNameUniqueAcrossTenants">false</Property>
|
||||
<Property name="IsEmailUserName">false</Property>
|
||||
<Property name="SuperDomain">wso2.com</Property>
|
||||
<Property name="IsUsersOfRoleListing">true</Property>
|
||||
<Property name="MaxUserNameListLength">100</Property>
|
||||
<!-- writing sqls follow-->
|
||||
<!--<Property name="AddUserSQL">INSERT INTO UM_USER (UM_USER_NAME, UM_USER_PASSWORD, UM_SALT_VALUE, UM_REQUIRE_CHANGE, UM_CHANGED_TIME, UM_TENANT_ID) VALUES (?, ?, ?, ?, ?, ?)</Property>-->
|
||||
<Property name="AddRoleSQL">INSERT INTO UM_ROLE (UM_ROLE_NAME, UM_TENANT_ID) VALUES (?, ?)</Property>
|
||||
<!--<Property name="AddUserToRoleSQL">INSERT INTO UM_USER_ROLE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID) VALUES ((SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?), ?)</Property>-->
|
||||
<!--<Property name="AddUserToRoleSQL-mssql">INSERT INTO UM_USER_ROLE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID) SELECT (SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?),(?)</Property>-->
|
||||
<!--<Property name="RemoveUserFromRoleSQL">DELETE FROM UM_USER_ROLE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_ROLE_ID=(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="AddRoleToUserSQL">INSERT INTO UM_USER_ROLE (UM_ROLE_ID, UM_USER_ID, UM_TENANT_ID) VALUES ((SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), ?)</Property>-->
|
||||
<!--<Property name="AddRoleToUserSQL-mssql">INSERT INTO UM_USER_ROLE (UM_ROLE_ID, UM_USER_ID, UM_TENANT_ID) SELECT (SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), (?)</Property>-->
|
||||
<!--<Property name="RemoveRoleFromUserSQL">DELETE FROM UM_USER_ROLE WHERE UM_ROLE_ID=(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="DeleteRoleSQL">DELETE FROM UM_ROLE WHERE UM_ROLE_NAME = ? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="OnDeleteRoleRemoveUserRoleMappingSQL">DELETE FROM UM_USER_ROLE WHERE UM_ROLE_ID=(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="OnDeleteUserRemoveUserRoleMappingSQL">DELETE FROM UM_USER_ROLE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="OnDeleteUserRemoveUserAttributeSQL">DELETE FROM UM_USER_ATTRIBUTE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="DeleteUserSQL">DELETE FROM UM_USER WHERE UM_USER_NAME = ? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="UpdateUserPasswordSQL">UPDATE UM_USER SET UM_USER_PASSWORD= ?, UM_SALT_VALUE=?, UM_REQUIRE_CHANGE=?, UM_CHANGED_TIME=? WHERE UM_USER_NAME= ? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="AddUserPropertySQL">INSERT INTO UM_USER_ATTRIBUTE (UM_USER_ID, UM_ATTR_NAME, UM_ATTR_VALUE, UM_PROFILE_ID, UM_TENANT_ID) VALUES ((SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), ?, ?, ?, ?)</Property>-->
|
||||
<!--<Property name="AddUserPropertySQL-mssql">INSERT INTO UM_USER_ATTRIBUTE (UM_USER_ID, UM_ATTR_NAME, UM_ATTR_VALUE, UM_PROFILE_ID, UM_TENANT_ID) SELECT (SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), (?), (?), (?), (?)</Property>-->
|
||||
<!--<Property name="UpdateUserPropertySQL">UPDATE UM_USER_ATTRIBUTE SET UM_ATTR_VALUE=? WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_ATTR_NAME=? AND UM_PROFILE_ID=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="DeleteUserPropertySQL">DELETE FROM UM_USER_ATTRIBUTE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_ATTR_NAME=? AND UM_PROFILE_ID=? AND UM_TENANT_ID=?</Property>-->
|
||||
<Property name="TenantManager">org.wso2.carbon.user.core.tenant.JDBCTenantManager</Property>
|
||||
</UserStoreManager>
|
||||
<AuthorizationManager
|
||||
class="org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager">
|
||||
<Property name="AuthorizationCacheEnabled">true</Property>
|
||||
</AuthorizationManager>
|
||||
</Realm>
|
||||
<SystemPermission>
|
||||
<Permission>login</Permission>
|
||||
<Permission>manage-configuration</Permission>
|
||||
<Permission>manage-security</Permission>
|
||||
<Permission>upload-services</Permission>
|
||||
<Permission>manage-services</Permission>
|
||||
<Permission>manage-lc-configuration</Permission>
|
||||
<Permission>manage-mediation</Permission>
|
||||
<Permission>monitor-system</Permission>
|
||||
<Permission>delegate-identity</Permission>
|
||||
</SystemPermission>
|
||||
</UserManager>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue