hasuniea 9 years ago
commit 30acecda8c

@ -17,6 +17,8 @@
*/ */
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
public final class DeviceManagementConstants { public final class DeviceManagementConstants {
public static final class Common { public static final class Common {
@ -47,4 +49,13 @@ public final class DeviceManagementConstants {
public static final String ENROL_NOTIFICATION_TYPE = "enrol"; public static final String ENROL_NOTIFICATION_TYPE = "enrol";
public static final String USER_REGISTRATION_NOTIFICATION_TYPE = "userRegistration"; public static final String USER_REGISTRATION_NOTIFICATION_TYPE = "userRegistration";
} }
public static final class AuthorizationSkippedOperationCodes {
private AuthorizationSkippedOperationCodes() {
throw new AssertionError();
}
public static final String MONITOR_OPERATION_CODE = "MONITOR";
public static final String POLICY_OPERATION_CODE = PolicyOperation.POLICY_OPERATION_CODE;
}
} }

@ -71,6 +71,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int status = -1; int status = -1;
int rows;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " + String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " +
@ -85,12 +86,12 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
stmt.setString(6, enrolmentInfo.getOwner()); stmt.setString(6, enrolmentInfo.getOwner());
stmt.setInt(7, tenantId); stmt.setInt(7, tenantId);
stmt.setInt(8, enrolmentInfo.getId()); stmt.setInt(8, enrolmentInfo.getId());
stmt.executeUpdate(); rows = stmt.executeUpdate();
rs = stmt.getGeneratedKeys(); if (rows > 0) {
if (rs.next()) {
status = 1; status = 1;
} }
return status; return status;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e); throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);

@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 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.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -83,7 +84,7 @@ public class OperationManagerImpl implements OperationManager {
} }
try { try {
List<DeviceIdentifier> authorizedDeviceList; List<DeviceIdentifier> authorizedDeviceList;
if (operation != null && PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) { if (operation != null && isAuthenticationSkippedOperation(operation)) {
authorizedDeviceList = deviceIds; authorizedDeviceList = deviceIds;
} else { } else {
authorizedDeviceList = DeviceManagementDataHolder.getInstance(). authorizedDeviceList = DeviceManagementDataHolder.getInstance().
@ -618,4 +619,20 @@ public class OperationManagerImpl implements OperationManager {
return CarbonContext.getThreadLocalCarbonContext().getUsername(); return CarbonContext.getThreadLocalCarbonContext().getUsername();
} }
private boolean isAuthenticationSkippedOperation(Operation operation) {
boolean status;
switch (operation.getCode()) {
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE :
status = true;
break;
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE :
status = true;
break;
default:
status = false;
}
return status;
}
} }

@ -59,7 +59,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement( stmt = connection.prepareStatement(
"UPDATE DM_COMMAND_OPERATION O SET O.ENABLED = ? WHERE O.OPERATION_ID = ?"); "UPDATE DM_COMMAND_OPERATION SET ENABLED = ? WHERE OPERATION_ID = ?");
stmt.setBoolean(1, operation.isEnabled()); stmt.setBoolean(1, operation.isEnabled());
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();

@ -82,8 +82,8 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
try { try {
super.updateOperation(operation); super.updateOperation(operation);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION O SET O.OPERATION_CONFIG = ? " + stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION SET OPERATION_CONFIG = ? " +
"WHERE O.OPERATION_ID = ?"); "WHERE OPERATION_ID = ?");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);
oos.writeObject(operation); oos.writeObject(operation);

@ -70,8 +70,8 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=? " + stmt = connection.prepareStatement("UPDATE DM_OPERATION SET RECEIVED_TIMESTAMP=? " +
"WHERE O.ID=?"); "WHERE ID=?");
stmt.setTimestamp(1, new Timestamp(new Date().getTime())); stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
@ -87,8 +87,8 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING O SET O.STATUS=? " + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS=? " +
"WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?"); "WHERE ENROLMENT_ID=? and OPERATION_ID=?");
stmt.setString(1, status.toString()); stmt.setString(1, status.toString());
stmt.setInt(2, enrolmentId); stmt.setInt(2, enrolmentId);
stmt.setInt(3, operationId); stmt.setInt(3, operationId);

@ -90,8 +90,8 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
try { try {
super.updateOperation(operation); super.updateOperation(operation);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_POLICY_OPERATION O SET O.OPERATION_DETAILS=? " + stmt = connection.prepareStatement("UPDATE DM_POLICY_OPERATION SET OPERATION_DETAILS=? " +
"WHERE O.OPERATION_ID=?"); "WHERE OPERATION_ID=?");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);
oos.writeObject(operation); oos.writeObject(operation);

@ -90,8 +90,8 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
try { try {
super.updateOperation(operation); super.updateOperation(operation);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_PROFILE_OPERATION O SET O.OPERATION_DETAILS=? " + stmt = connection.prepareStatement("UPDATE DM_PROFILE_OPERATION SET OPERATION_DETAILS=? " +
"WHERE O.OPERATION_ID=?"); "WHERE OPERATION_ID=?");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);

Loading…
Cancel
Save