diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 261e2e43107..0e56262c14e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -22,7 +22,6 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; import java.util.List; @@ -42,16 +41,8 @@ public interface DeviceDAO { */ int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; - /** - * This method is used to update a given device. - * - * @param typeId device type id. - * @param device device object. - * @param tenantId tenant id. - * @return returns the id of updated device. - * @throws DeviceManagementDAOException - */ - int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; + + boolean updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; /** * This method is used to remove a device. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index ae9a67f25a7..9f4ca53f4c6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -66,11 +66,11 @@ public class DeviceDAOImpl implements DeviceDAO { } @Override - public int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException { + public boolean updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; - ResultSet rs = null; - int deviceId = -1; + boolean status = false; + int rows; try { conn = this.getConnection(); String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " + @@ -81,18 +81,16 @@ public class DeviceDAOImpl implements DeviceDAO { stmt.setString(3, device.getDeviceIdentifier()); stmt.setInt(4, typeId); stmt.setInt(5, tenantId); - stmt.executeUpdate(); - - rs = stmt.getGeneratedKeys(); - if (rs.next()) { - deviceId = rs.getInt(1); + rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; } - return deviceId; + return status; } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while enrolling device '" + device.getName() + "'", e); } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); + DeviceManagementDAOUtil.cleanupResources(stmt, null); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index d5000da8891..234666a8232 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -139,6 +139,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv EnrolmentInfo newEnrolmentInfo = device.getEnrolmentInfo(); if (existingEnrolmentInfo != null && newEnrolmentInfo != null) { if (existingEnrolmentInfo.equals(newEnrolmentInfo)) { + device.setId(existingDevice.getId()); device.getEnrolmentInfo().setDateOfEnrolment(existingEnrolmentInfo.getDateOfEnrolment()); this.modifyEnrollment(device); status = true; @@ -214,8 +215,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.beginTransaction(); DeviceType type = deviceTypeDAO.getDeviceType(device.getType()); - int deviceId = deviceDAO.updateDevice(type.getId(), device, tenantId); - enrolmentDAO.updateEnrollment(deviceId, device.getEnrolmentInfo(), tenantId); + deviceDAO.updateDevice(type.getId(), device, tenantId); + enrolmentDAO.updateEnrollment(device.getId(), device.getEnrolmentInfo(), tenantId); DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java index 97683448320..c700fb304f3 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java @@ -35,7 +35,7 @@ public class WebappAuthenticationHandler extends CarbonTomcatValve { @Override public void invoke(Request request, Response response, CompositeValve compositeValve) { - if (this.isContextSkipped(request) || (this.isNonAdminService(request) && this.skipAuthentication(request))) { + if (this.isContextSkipped(request) || (!this.isAdminService(request) && this.skipAuthentication(request))) { this.getNext().invoke(request, response, compositeValve); return; } @@ -49,9 +49,9 @@ public class WebappAuthenticationHandler extends CarbonTomcatValve { this.processResponse(request, response, compositeValve, status); } - private boolean isNonAdminService(Request request) { + private boolean isAdminService(Request request) { String param = request.getContext().findParameter("isAdminService"); - return !(param != null && Boolean.parseBoolean(param)); + return (param != null && Boolean.parseBoolean(param)); } private boolean skipAuthentication(Request request) {