diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java index 8b8e22b75e..596d1202a0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java @@ -45,12 +45,6 @@ public class DeviceManagementRepository { public void removeDeviceManagementProvider(DeviceMgtService provider) throws DeviceManagementException { String deviceType = provider.getProviderType(); - try { - DeviceManagerUtil.unregisterDeviceType(deviceType); - } catch (DeviceManagementException e) { - throw new DeviceManagementException("Error occurred while removing device management provider '" + - deviceType + "'", e); - } providers.remove(deviceType); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index caac62456f..f2f0ac8937 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -120,6 +120,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; + DeviceType deviceType = null; try { conn = this.getConnection(); String sql = "SELECT ID From DM_DEVICE_TYPE WHERE NAME = ?"; @@ -127,14 +128,11 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { stmt.setString(1, type); rs = stmt.executeQuery(); - int id = -1; if (rs.next()) { - id = rs.getInt("ID"); + deviceType = new DeviceType(); + deviceType.setId(rs.getInt("ID")); + deviceType.setName(type); } - DeviceType deviceType = new DeviceType(); - deviceType.setId(id); - deviceType.setName(type); - return deviceType; } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while fetch device type id for device type " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index ab985dcda2..54b279bc45 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -55,10 +55,9 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; +import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.registry.core.service.RegistryService; -import org.wso2.carbon.user.core.service.RealmService; - import java.util.ArrayList; import java.util.List; @@ -267,7 +266,7 @@ public class DeviceManagementServiceComponent { */ protected void unsetDeviceManager(DeviceMgtService deviceManager) { if (log.isDebugEnabled()) { - log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); + log.debug("Un setting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); } try { this.getPluginRepository().removeDeviceManagementProvider(deviceManager); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 5000bd56a6..6e66527c58 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +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.operation.mgt.Operation; @@ -195,20 +196,33 @@ public class OperationManagerImpl implements OperationManager { } @Override - public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { + public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException { if (log.isDebugEnabled()) { - log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]"); + log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType() + "]"); } Operation operation = null; + Device device; try { + device = deviceManagementService.getCoreDevice(deviceIdentifier); + + if (device == null) { + throw new OperationManagementException("Device not found for given device " + + "Identifier:" + deviceIdentifier.getId() + " and given type" + deviceIdentifier.getType()); + } org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO - .getNextOperation(deviceId); + .getNextOperation(device.getId()); if (dtoOperation != null) { operation = OperationDAOUtil.convertOperation(dtoOperation); } return operation; - } catch (OperationManagementDAOException e) { + } catch (DeviceManagementException deviceMgtException) { + String errorMsg = "Error occurred while retrieving the device " + + "for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '" + + deviceIdentifier.getId(); + log.error(errorMsg, deviceMgtException); + throw new OperationManagementException(errorMsg, deviceMgtException); + } catch (OperationManagementDAOException e) { throw new OperationManagementException("Error occurred while retrieving next pending operation", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index bd7699e670..07572f98c7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -42,6 +42,6 @@ public interface OperationDAO { List getOperationsForStatus(Operation.Status status) throws OperationManagementDAOException; - Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException; + Operation getNextOperation(int deviceId) throws OperationManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java index 9b996e1069..35f0f0cd10 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java @@ -66,7 +66,6 @@ public class OperationDAOImpl implements OperationDAO { throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); } finally { OperationManagementDAOUtil.cleanupResources(stmt, rs); - OperationManagementDAOFactory.closeConnection(); } } @@ -462,7 +461,7 @@ public class OperationDAOImpl implements OperationDAO { } @Override - public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { + public Operation getNextOperation(int deviceId) throws OperationManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; @@ -483,9 +482,9 @@ public class OperationDAOImpl implements OperationDAO { "o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " + "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); - stmt.setString(1, deviceId.getType()); - stmt.setString(2, deviceId.getId()); - stmt.setString(3, Operation.Status.PENDING.toString()); + stmt.setString(1, Operation.Status.PENDING.toString()); + stmt.setInt(2, deviceId); + rs = stmt.executeQuery(); Operation operation = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index f59fe6452d..f23e77eafa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -59,7 +59,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { return operationId; } - @Override public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { PreparedStatement stmt = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 80e2b5b371..308ed6813f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -111,23 +111,23 @@ public final class DeviceManagerUtil { /** * Adds a new device type to the database if it does not exists. * - * @param deviceType device type + * @param typeName device type * @return status of the operation */ - public static boolean registerDeviceType(String deviceType) throws DeviceManagementException { + public static boolean registerDeviceType(String typeName) throws DeviceManagementException { boolean status; try { DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType); - if (deviceTypeId == null) { + DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName); + if (deviceType == null) { DeviceType dt = new DeviceType(); - dt.setName(deviceType); + dt.setName(typeName); deviceTypeDAO.addDeviceType(dt); } status = true; } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while registering the device type '" + - deviceType + "'", e); + typeName + "'", e); } return status; } @@ -135,22 +135,22 @@ public final class DeviceManagerUtil { /** * Un-registers an existing device type from the device management metadata repository. * - * @param deviceType device type + * @param typeName device type * @return status of the operation */ - public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException { + public static boolean unregisterDeviceType(String typeName) throws DeviceManagementException { try { DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType); - if (deviceTypeId == null) { + DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName); + if (deviceType != null) { DeviceType dt = new DeviceType(); - dt.setName(deviceType); - deviceTypeDAO.removeDeviceType(deviceType); + dt.setName(typeName); + deviceTypeDAO.removeDeviceType(typeName); } return true; } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while registering the device type '" + - deviceType + "'", e); + typeName + "'", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index d15a958212..83a5410439 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATED_TIMESTAMP TIMESTAMP NOT NULL, RECEIVED_TIMESTAMP TIMESTAMP NULL, STATUS VARCHAR(50) NULL, - OPERATION_CODE VARCHAR(25) NOT NULL, + OPERATION_CODE VARCHAR(1000) NOT NULL, PRIMARY KEY (ID) ); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index 7d1e7244ab..53f8411bbc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java @@ -62,6 +62,8 @@ public interface PolicyAdministratorPoint { List getPolicies() throws PolicyManagementException; + Policy getPolicy(int policyId) throws PolicyManagementException; + /** * This method gives the device specific policy. * diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index e00e6c1c43..a5778e2c32 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -592,11 +592,11 @@ public class PolicyDAOImpl implements PolicyDAO { resultSet = stmt.executeQuery(); while (resultSet.next()) { - policy.setId(policyId); policy.setPolicyName(resultSet.getString("NAME")); policy.setTenantId(resultSet.getInt("TENANT_ID")); policy.setPriorityId(resultSet.getInt("PRIORITY")); + policy.setProfileId(resultSet.getInt("PROFILE_ID")); } return policy; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 0029b26983..c1c8f73d92 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -83,6 +83,10 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { return policyManager.getPolicies(); } + @Override public Policy getPolicy(int policyId) throws PolicyManagementException { + return policyManager.getPolicy(policyId); + } + @Override public List getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { return policyManager.getPoliciesOfDevice(deviceIdentifier); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 72bc9c5943..e5b41d7a3c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -399,7 +399,7 @@ public class PolicyManagerImpl implements PolicyManager { policyDAO.getTimesOfPolicy(policy); policyDAO.getLocationsOfPolicy(policy); - Profile profile = profileDAO.getProfiles(policy.getProfile().getProfileId()); + Profile profile = profileDAO.getProfiles(policy.getProfileId()); policy.setProfile(profile); policy.setRoles(roleNames); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index a5c29692d9..ae97ac9a6e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -140,7 +140,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ID INT(11) NOT NULL AUTO_INCREMENT, PROFILE_ID INT(11) NOT NULL, - FEATURE_CODE VARCHAR(10) NOT NULL, + FEATURE_CODE VARCHAR(30) NOT NULL, DEVICE_TYPE_ID INT NOT NULL, CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java index e14480d822..66982112bd 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java @@ -44,9 +44,11 @@ public class WebappAuthenticatorFrameworkValve extends CarbonTomcatValve { case SUCCESS: case CONTINUE: this.getNext().invoke(request, response, compositeValve); + break; case FAILURE: AuthenticationFrameworkUtil.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, "Failed to authorize the incoming request"); + break; } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 14f3265dd3..57845c0d5e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATED_TIMESTAMP TIMESTAMP NOT NULL, RECEIVED_TIMESTAMP TIMESTAMP NULL, STATUS VARCHAR(50) NULL, - OPERATION_CODE VARCHAR(25) NOT NULL, + OPERATION_CODE VARCHAR(1000) NOT NULL, PRIMARY KEY (ID) );