revert-70aa11f8
Kamidu Sachith 9 years ago
commit cdfc224dde

@ -71,11 +71,12 @@
org.bouncycastle.operator.jcajce, org.bouncycastle.operator.jcajce,
org.bouncycastle.pkcs, org.bouncycastle.pkcs,
org.bouncycastle.util, org.bouncycastle.util,
org.bouncycastle.asn1.util,
org.jscep.message, org.jscep.message,
org.jscep.transaction, org.jscep.transaction,
org.w3c.dom, org.w3c.dom,
org.xml.sax org.xml.sax,
javax.xml.bind,
org.bouncycastle.pkcs.jcajce
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
!org.wso2.carbon.certificate.mgt.core.internal.*, !org.wso2.carbon.certificate.mgt.core.internal.*,

@ -44,14 +44,7 @@ import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.pkcs.PKCS10CertificationRequest;
import org.bouncycastle.util.Store; import org.bouncycastle.util.Store;
import org.jscep.message.CertRep; import org.jscep.message.*;
import org.jscep.message.MessageDecodingException;
import org.jscep.message.MessageEncodingException;
import org.jscep.message.PkcsPkiEnvelopeDecoder;
import org.jscep.message.PkcsPkiEnvelopeEncoder;
import org.jscep.message.PkiMessage;
import org.jscep.message.PkiMessageDecoder;
import org.jscep.message.PkiMessageEncoder;
import org.jscep.transaction.FailInfo; import org.jscep.transaction.FailInfo;
import org.jscep.transaction.Nonce; import org.jscep.transaction.Nonce;
import org.jscep.transaction.TransactionId; import org.jscep.transaction.TransactionId;
@ -62,32 +55,11 @@ import org.wso2.carbon.certificate.mgt.core.util.CommonUtil;
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil; import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import java.io.ByteArrayInputStream; import javax.xml.bind.DatatypeConverter;
import java.io.DataInputStream; import java.io.*;
import java.io.File; import java.security.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException; import java.security.cert.*;
import java.security.cert.CertificateException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateFactory;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.util.ArrayList; import java.util.ArrayList;
@ -348,18 +320,20 @@ public class CertificateGenerator {
Date validityBeginDate = commonUtil.getValidityStartDate(); Date validityBeginDate = commonUtil.getValidityStartDate();
Date validityEndDate = commonUtil.getValidityEndDate(); Date validityEndDate = commonUtil.getValidityEndDate();
X500Name certSubject = request.getSubject(); X500Name certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
Attribute attributes[] = request.getAttributes(); //X500Name certSubject = request.getSubject();
if (certSubject == null) { Attribute attributes[] = request.getAttributes();
certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
} else {
org.bouncycastle.asn1.x500.RDN[] rdn = certSubject.getRDNs();
if (rdn == null || rdn.length == 0) { // if (certSubject == null) {
certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL); // certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
} // } else {
} // org.bouncycastle.asn1.x500.RDN[] rdn = certSubject.getRDNs();
//
// if (rdn == null || rdn.length == 0) {
// certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
// }
// }
X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder( X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
new X500Name(issueSubject), CommonUtil.generateSerialNumber(), new X500Name(issueSubject), CommonUtil.generateSerialNumber(),
@ -596,4 +570,31 @@ public class CertificateGenerator {
return null; return null;
} }
/**
* Get Signed certificate by parsing certificate.
* @param binarySecurityToken CSR that comes from the client as a String value.It is base 64 encoded request
* security token.
* @return Return signed certificate in X508Certificate type object.
* @throws KeystoreException
*/
public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken)
throws KeystoreException {
byte[] byteArrayBst = DatatypeConverter.parseBase64Binary(binarySecurityToken);
PKCS10CertificationRequest certificationRequest;
KeyStoreReader keyStoreReader = new KeyStoreReader();
PrivateKey privateKeyCA = keyStoreReader.getCAPrivateKey();
X509Certificate certCA = (X509Certificate) keyStoreReader.getCACertificate();
try {
certificationRequest = new PKCS10CertificationRequest(byteArrayBst);
} catch (IOException e) {
String msg = "CSR cannot be recovered.";
log.error(msg, e);
throw new KeystoreException(msg, e);
}
X509Certificate signedCertificate = generateCertificateFromCSR(privateKeyCA, certificationRequest,
certCA.getIssuerX500Principal().getName());
return signedCertificate;
}
} }

@ -53,4 +53,6 @@ public interface CertificateManagementService {
public X509Certificate extractCertificateFromSignature(String headerSignature) throws KeystoreException; public X509Certificate extractCertificateFromSignature(String headerSignature) throws KeystoreException;
String extractChallengeToken(X509Certificate certificate); String extractChallengeToken(X509Certificate certificate);
X509Certificate getSignedCertificateFromCSR(String binarySecurityToken) throws KeystoreException;
} }

@ -100,4 +100,9 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
public String extractChallengeToken(X509Certificate certificate) { public String extractChallengeToken(X509Certificate certificate) {
return certificateGenerator.extractChallengeToken(certificate); return certificateGenerator.extractChallengeToken(certificate);
} }
public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken) throws KeystoreException {
return certificateGenerator.getSignedCertificateFromCSR(binarySecurityToken);
}
} }

@ -37,7 +37,7 @@ public class ConfigurationUtil {
public static final String KEYSTORE_RA_CERT_PRIV_PASSWORD = "RAPrivateKeyPassword"; public static final String KEYSTORE_RA_CERT_PRIV_PASSWORD = "RAPrivateKeyPassword";
public static final String CA_CERT_ALIAS = "CACertAlias"; public static final String CA_CERT_ALIAS = "CACertAlias";
public static final String RA_CERT_ALIAS = "RACertAlias"; public static final String RA_CERT_ALIAS = "RACertAlias";
public static final String SIGNATUREALGO = "SHA1withRSA"; public static final String SIGNATURE_ALGORITHM = "SHA1withRSA";
public static final String PROVIDER = "BC"; public static final String PROVIDER = "BC";
public static final String KEYSTORE = "Type"; public static final String KEYSTORE = "Type";
public static final String CERTIFICATE_KEYSTORE = "CertificateKeystoreType"; public static final String CERTIFICATE_KEYSTORE = "CertificateKeystoreType";
@ -56,6 +56,7 @@ public class ConfigurationUtil {
public static final String RSA_PRIVATE_KEY_END_TEXT = "-----END RSA PRIVATE KEY-----"; public static final String RSA_PRIVATE_KEY_END_TEXT = "-----END RSA PRIVATE KEY-----";
public static final String EMPTY_TEXT = ""; public static final String EMPTY_TEXT = "";
public static final int RSA_KEY_LENGTH = 1024; public static final int RSA_KEY_LENGTH = 1024;
public static final long MILLI_SECONDS = 1000L * 60 * 60 * 24;
private static ConfigurationUtil configurationUtil; private static ConfigurationUtil configurationUtil;

@ -24,10 +24,14 @@ public interface FeatureManager {
boolean addFeature(Feature feature) throws DeviceManagementException; boolean addFeature(Feature feature) throws DeviceManagementException;
boolean addFeatures(List<Feature> features) throws DeviceManagementException;
Feature getFeature(String name) throws DeviceManagementException; Feature getFeature(String name) throws DeviceManagementException;
List<Feature> getFeatures() throws DeviceManagementException; List<Feature> getFeatures() throws DeviceManagementException;
boolean removeFeature(String name) throws DeviceManagementException; boolean removeFeature(String name) throws DeviceManagementException;
boolean addSupportedFeaturesToDB() throws DeviceManagementException;
} }

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -163,6 +164,14 @@ public interface DeviceDAO {
*/ */
int getDeviceCount(int tenantId) throws DeviceManagementDAOException; int getDeviceCount(int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the available device types of a given tenant.
*
* @return returns list of device types.
* @throws DeviceManagementDAOException
*/
List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException;
/** /**
* This method is used to retrieve devices of a given device name. * This method is used to retrieve devices of a given device name.
* *

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -120,7 +121,33 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result; return result;
} }
private Connection getConnection() throws SQLException { @Override
public List<DeviceType> getDeviceTypes()
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection(); return DeviceManagementDAOFactory.getConnection();
} }
} }

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -116,7 +117,31 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result; return result;
} }
private Connection getConnection() throws SQLException { @Override public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection(); return DeviceManagementDAOFactory.getConnection();
} }
} }

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -116,7 +117,31 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result; return result;
} }
private Connection getConnection() throws SQLException { @Override public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection(); return DeviceManagementDAOFactory.getConnection();
} }
} }

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -116,7 +117,32 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result; return result;
} }
private Connection getConnection() throws SQLException { @Override
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection(); return DeviceManagementDAOFactory.getConnection();
} }
} }

@ -23,6 +23,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
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.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.tenant.TenantManager; import org.wso2.carbon.user.core.tenant.TenantManager;
@ -153,4 +154,11 @@ public final class DeviceManagementDAOUtil {
device.setEnrolmentInfo(loadEnrolment(rs)); device.setEnrolmentInfo(loadEnrolment(rs));
return device; return device;
} }
public static DeviceType loadDeviceType(ResultSet rs) throws SQLException {
DeviceType deviceType = new DeviceType();
deviceType.setId(rs.getInt("ID"));
deviceType.setName(rs.getString("NAME"));
return deviceType;
}
} }

@ -123,7 +123,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED, dm.STATUS " + "o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED, dm.STATUS " +
"FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS " + "FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS " +
"FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? AND STATUS = ?) dm " + "FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? AND STATUS = ?) dm " +
"ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID"; "ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -164,7 +164,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT co.OPERATION_ID, co.OPERATION_CONFIG FROM DM_CONFIG_OPERATION co " + String sql = "SELECT co.OPERATION_ID, co.OPERATION_CONFIG FROM DM_CONFIG_OPERATION co " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? " +
"AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID"; "AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -87,7 +87,7 @@ 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_OPERATION_MAPPING O SET O.STATUS=? " + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING O SET O.STATUS=? " +
"WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?"); "WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?");
stmt.setString(1, status.toString()); stmt.setString(1, status.toString());
stmt.setInt(2, enrolmentId); stmt.setInt(2, enrolmentId);
@ -203,7 +203,7 @@ public class OperationDAOImpl implements OperationDAO {
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " +
" FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + " FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," +
"OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + "OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"DM_ENROLMENT_OPERATION_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"ON o.ID = om.OPERATION_ID "; "ON o.ID = om.OPERATION_ID ";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
@ -243,7 +243,7 @@ public class OperationDAOImpl implements OperationDAO {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"FROM DM_OPERATION o " + "FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
@ -283,7 +283,7 @@ public class OperationDAOImpl implements OperationDAO {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + "OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
@ -320,7 +320,7 @@ public class OperationDAOImpl implements OperationDAO {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE FROM DM_OPERATION o " + "OPERATION_CODE FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " +
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
@ -361,7 +361,7 @@ public class OperationDAOImpl implements OperationDAO {
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"FROM DM_OPERATION o WHERE o.TYPE = ?) o " + "FROM DM_OPERATION o WHERE o.TYPE = ?) o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -35,7 +35,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_ENROLMENT_OPERATION_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS) VALUES (?, ?,?)"; String sql = "INSERT INTO DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS) VALUES (?, ?,?)";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
stmt.setInt(2, operationId); stmt.setInt(2, operationId);
@ -54,7 +54,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "DELETE FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?"; String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, 0); stmt.setInt(1, 0);
stmt.setInt(2, operationId); stmt.setInt(2, operationId);

@ -164,7 +164,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT po.OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_POLICY_OPERATION po " + String sql = "SELECT po.OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_POLICY_OPERATION po " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? " +
"AND STATUS = ?) dm ON dm.OPERATION_ID = po.OPERATION_ID"; "AND STATUS = ?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -167,7 +167,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " + String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " +
"INNER JOIN " + "INNER JOIN " +
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " + "(Select * From DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID=? " +
"AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID"; "AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -24,6 +24,8 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
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.dto.DeviceType;
import java.util.List; import java.util.List;
/** /**
@ -127,6 +129,8 @@ public interface DeviceManagementProviderService extends OperationManager {
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
List<DeviceType> getAvailableDeviceTypes() throws DeviceManagementException;
boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException; boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException;
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;

@ -617,7 +617,23 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return device; return device;
} }
@Override @Override
public List<DeviceType> getAvailableDeviceTypes() throws DeviceManagementException {
List<DeviceType> deviceTypes;
try {
DeviceManagementDAOFactory.openConnection();
deviceTypes = deviceDAO.getDeviceTypes();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device types.", e);
} catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
return deviceTypes;
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); DeviceManager deviceManager = this.getDeviceManager(deviceId.getType());
if (deviceManager == null) { if (deviceManager == null) {

@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,

@ -123,7 +123,7 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
boolean isSaaSApp = profile.isSaasApp(); boolean isSaaSApp = profile.isSaasApp();
String audience = profile.getAudience(); String audience = profile.getAudience();
String assertionConsumerURL = profile.getAssertionConsumerURL(); String assertionConsumerURL = profile.getAssertionConsumerURL();
String recepientValidationURL = profile.getRecepientValidationURL(); String recipientValidationURL = profile.getRecepientValidationURL();
if (userId == null || userId.isEmpty()) { if (userId == null || userId.isEmpty()) {
return null; return null;
@ -223,7 +223,7 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
samlssoServiceProviderDTO.setDoSignResponse(true); samlssoServiceProviderDTO.setDoSignResponse(true);
samlssoServiceProviderDTO.setRequestedAudiences(new String[] { audience }); samlssoServiceProviderDTO.setRequestedAudiences(new String[] { audience });
samlssoServiceProviderDTO.setDefaultAssertionConsumerUrl(assertionConsumerURL); samlssoServiceProviderDTO.setDefaultAssertionConsumerUrl(assertionConsumerURL);
samlssoServiceProviderDTO.setRequestedRecipients(new String[] {recepientValidationURL}); samlssoServiceProviderDTO.setRequestedRecipients(new String[] {recipientValidationURL});
samlssoServiceProviderDTO.setDoSignAssertions(true); samlssoServiceProviderDTO.setDoSignAssertions(true);

@ -117,7 +117,7 @@ public class DynamicClientWebAppRegistrationManager {
} }
public void initiateDynamicClientRegistration() { public void initiateDynamicClientRegistration() {
String requiredDynamicClientRegistration, webAppName; String requiredDynamicClientRegistration, webAppName, serviceProviderName;
ServletContext servletContext; ServletContext servletContext;
RegistrationProfile registrationProfile; RegistrationProfile registrationProfile;
OAuthAppDetails oAuthAppDetails; OAuthAppDetails oAuthAppDetails;
@ -131,15 +131,15 @@ public class DynamicClientWebAppRegistrationManager {
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
oAuthAppDetails = new OAuthAppDetails(); oAuthAppDetails = new OAuthAppDetails();
webAppName = (String) enumeration.nextElement(); webAppName = (String) enumeration.nextElement();
serviceProviderName = DynamicClientWebAppRegistrationUtil.getUserName() + "_" + webAppName;
servletContext = DynamicClientWebAppRegistrationManager.webAppContexts.get(webAppName); servletContext = DynamicClientWebAppRegistrationManager.webAppContexts.get(webAppName);
requiredDynamicClientRegistration = servletContext.getInitParameter( requiredDynamicClientRegistration = servletContext.getInitParameter(
DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG); DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG);
//Java web-app section //Java web-app section
if ((requiredDynamicClientRegistration != null) && (Boolean. if ((requiredDynamicClientRegistration != null) && (Boolean.parseBoolean(
parseBoolean( requiredDynamicClientRegistration))) {
requiredDynamicClientRegistration))) {
//Check whether this is an already registered application //Check whether this is an already registered application
if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) {
//Construct the RegistrationProfile //Construct the RegistrationProfile
registrationProfile = DynamicClientWebAppRegistrationUtil. registrationProfile = DynamicClientWebAppRegistrationUtil.
constructRegistrationProfile(servletContext, webAppName); constructRegistrationProfile(servletContext, webAppName);
@ -155,7 +155,7 @@ public class DynamicClientWebAppRegistrationManager {
JaggeryOAuthConfigurationSettings jaggeryOAuthConfigurationSettings = JaggeryOAuthConfigurationSettings jaggeryOAuthConfigurationSettings =
DynamicClientWebAppRegistrationUtil.getJaggeryAppOAuthSettings(servletContext); DynamicClientWebAppRegistrationUtil.getJaggeryAppOAuthSettings(servletContext);
if (jaggeryOAuthConfigurationSettings.isRequireDynamicClientRegistration()) { if (jaggeryOAuthConfigurationSettings.isRequireDynamicClientRegistration()) {
if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) {
registrationProfile = DynamicClientWebAppRegistrationUtil. registrationProfile = DynamicClientWebAppRegistrationUtil.
constructRegistrationProfile(jaggeryOAuthConfigurationSettings, constructRegistrationProfile(jaggeryOAuthConfigurationSettings,
webAppName); webAppName);

@ -116,7 +116,7 @@ public class DynamicClientWebAppRegistrationUtil {
resource.setContent(writer.toString()); resource.setContent(writer.toString());
resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML);
String resourcePath = DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + String resourcePath = DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" +
oAuthAppDetails.getWebAppName(); oAuthAppDetails.getClientName();
status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new DynamicClientRegistrationException( throw new DynamicClientRegistrationException(

@ -41,6 +41,8 @@ public interface PolicyDAO {
*/ */
Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagerDAOException; Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagerDAOException;
Policy updateRolesOfPolicy(List<String> rolesToAdd, Policy policy) throws PolicyManagerDAOException;
/** /**
* This method is used to add/update the users associated with the policy. * This method is used to add/update the users associated with the policy.
* @param usernameList - List of the users that needs to be applied * @param usernameList - List of the users that needs to be applied
@ -50,6 +52,8 @@ public interface PolicyDAO {
*/ */
Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagerDAOException; Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagerDAOException;
Policy updateUserOfPolicy(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException;
Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException; Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException;
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException; boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException;
@ -114,6 +118,8 @@ public interface PolicyDAO {
boolean deleteAllPolicyRelatedConfigs(int policyId) throws PolicyManagerDAOException; boolean deleteAllPolicyRelatedConfigs(int policyId) throws PolicyManagerDAOException;
boolean deleteCriteriaAndDeviceRelatedConfigs(int policyId) throws PolicyManagerDAOException;
List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException; List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException;
List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException; List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException;

@ -71,8 +71,52 @@ public class PolicyDAOImpl implements PolicyDAO {
public Policy addPolicyToRole(List<String> rolesToAdd, Policy policy) throws PolicyManagerDAOException { public Policy addPolicyToRole(List<String> rolesToAdd, Policy policy) throws PolicyManagerDAOException {
Connection conn; Connection conn;
PreparedStatement insertStmt = null; PreparedStatement insertStmt = null;
// PreparedStatement deleteStmt = null;
// final List<String> currentRoles = this.getPolicy(policy.getId()).getRoles();
//
// SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
//
// transformer.transform(currentRoles, rolesToAdd);
// rolesToAdd = transformer.getObjectsToAdd();
// List<String> rolesToDelete = transformer.getObjectsToRemove();
try {
conn = this.getConnection();
if (rolesToAdd.size() > 0) {
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query);
for (String role : rolesToAdd) {
insertStmt.setString(1, role);
insertStmt.setInt(2, policy.getId());
insertStmt.addBatch();
}
insertStmt.executeBatch();
}
// if (rolesToDelete.size() > 0){
// String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?";
// deleteStmt = conn.prepareStatement(deleteQuery);
// for (String role : rolesToDelete) {
// deleteStmt.setString(1, role);
// deleteStmt.setInt(2, policy.getId());
// deleteStmt.addBatch();
// }
// deleteStmt.executeBatch();
// }
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while adding the role name with policy to database", e);
} finally {
PolicyManagementDAOUtil.cleanupResources(insertStmt, null);
}
return policy;
}
@Override
public Policy updateRolesOfPolicy(List<String> rolesToAdd, Policy previousPolicy) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement insertStmt = null;
PreparedStatement deleteStmt = null; PreparedStatement deleteStmt = null;
final List<String> currentRoles = policy.getRoles();
final List<String> currentRoles = previousPolicy.getRoles();
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>(); SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
@ -81,22 +125,22 @@ public class PolicyDAOImpl implements PolicyDAO {
List<String> rolesToDelete = transformer.getObjectsToRemove(); List<String> rolesToDelete = transformer.getObjectsToRemove();
try { try {
conn = this.getConnection(); conn = this.getConnection();
if (rolesToAdd.size() > 0){ if (rolesToAdd.size() > 0) {
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)"; String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query); insertStmt = conn.prepareStatement(query);
for (String role : rolesToAdd) { for (String role : rolesToAdd) {
insertStmt.setString(1, role); insertStmt.setString(1, role);
insertStmt.setInt(2, policy.getId()); insertStmt.setInt(2, previousPolicy.getId());
insertStmt.addBatch(); insertStmt.addBatch();
} }
insertStmt.executeBatch(); insertStmt.executeBatch();
} }
if (rolesToAdd.size() > 0){ if (rolesToDelete.size() > 0) {
String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?"; String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?";
deleteStmt = conn.prepareStatement(deleteQuery); deleteStmt = conn.prepareStatement(deleteQuery);
for (String role : rolesToDelete) { for (String role : rolesToDelete) {
deleteStmt.setString(1, role); deleteStmt.setString(1, role);
deleteStmt.setInt(2, policy.getId()); deleteStmt.setInt(2, previousPolicy.getId());
deleteStmt.addBatch(); deleteStmt.addBatch();
} }
deleteStmt.executeBatch(); deleteStmt.executeBatch();
@ -105,14 +149,60 @@ public class PolicyDAOImpl implements PolicyDAO {
throw new PolicyManagerDAOException("Error occurred while adding the role name with policy to database", e); throw new PolicyManagerDAOException("Error occurred while adding the role name with policy to database", e);
} finally { } finally {
PolicyManagementDAOUtil.cleanupResources(insertStmt, null); PolicyManagementDAOUtil.cleanupResources(insertStmt, null);
PolicyManagementDAOUtil.cleanupResources(deleteStmt, null);
} }
return policy; return previousPolicy;
} }
@Override @Override
public Policy addPolicyToUser(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException { public Policy addPolicyToUser(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException {
Connection conn; Connection conn;
PreparedStatement insertStmt = null; PreparedStatement insertStmt = null;
// PreparedStatement deleteStmt = null;
// final List<String> currentUsers = this.getPolicy(policy.getId()).getUsers();
//
// SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
//
// transformer.transform(currentUsers, usersToAdd);
// usersToAdd = transformer.getObjectsToAdd();
// List<String> usersToDelete = transformer.getObjectsToRemove();
try {
conn = this.getConnection();
if (usersToAdd.size() > 0) {
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query);
for (String username : usersToAdd) {
insertStmt.setInt(1, policy.getId());
insertStmt.setString(2, username);
insertStmt.addBatch();
}
insertStmt.executeBatch();
}
// if (usersToDelete.size() > 0){
// String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?";
// deleteStmt = conn.prepareStatement(deleteQuery);
// for (String username : usersToDelete) {
// deleteStmt.setString(1, username);
// deleteStmt.setInt(2, policy.getId());
// deleteStmt.addBatch();
// }
// deleteStmt.executeBatch();
// }
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while adding the user name with policy to database", e);
} finally {
PolicyManagementDAOUtil.cleanupResources(insertStmt, null);
// PolicyManagementDAOUtil.cleanupResources(deleteStmt, null);
}
return policy;
}
@Override
public Policy updateUserOfPolicy(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement insertStmt = null;
PreparedStatement deleteStmt = null; PreparedStatement deleteStmt = null;
final List<String> currentUsers = policy.getUsers(); final List<String> currentUsers = policy.getUsers();
@ -123,7 +213,7 @@ public class PolicyDAOImpl implements PolicyDAO {
List<String> usersToDelete = transformer.getObjectsToRemove(); List<String> usersToDelete = transformer.getObjectsToRemove();
try { try {
conn = this.getConnection(); conn = this.getConnection();
if (usersToAdd.size() > 0){ if (usersToAdd.size() > 0) {
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)"; String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
insertStmt = conn.prepareStatement(query); insertStmt = conn.prepareStatement(query);
for (String username : usersToAdd) { for (String username : usersToAdd) {
@ -133,7 +223,7 @@ public class PolicyDAOImpl implements PolicyDAO {
} }
insertStmt.executeBatch(); insertStmt.executeBatch();
} }
if (usersToDelete.size() > 0){ if (usersToDelete.size() > 0) {
String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?"; String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?";
deleteStmt = conn.prepareStatement(deleteQuery); deleteStmt = conn.prepareStatement(deleteQuery);
for (String username : usersToDelete) { for (String username : usersToDelete) {
@ -153,6 +243,7 @@ public class PolicyDAOImpl implements PolicyDAO {
return policy; return policy;
} }
@Override @Override
public Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException { public Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException {
Connection conn; Connection conn;
@ -1202,6 +1293,46 @@ public class PolicyDAOImpl implements PolicyDAO {
} }
} }
@Override
public boolean deleteCriteriaAndDeviceRelatedConfigs(int policyId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
// String userPolicy = "DELETE FROM DM_USER_POLICY WHERE POLICY_ID = ?";
// stmt = conn.prepareStatement(userPolicy);
// stmt.setInt(1, policyId);
// stmt.executeUpdate();
//
// String rolePolicy = "DELETE FROM DM_ROLE_POLICY WHERE POLICY_ID = ?";
// stmt = conn.prepareStatement(rolePolicy);
// stmt.setInt(1, policyId);
// stmt.executeUpdate();
String devicePolicy = "DELETE FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?";
stmt = conn.prepareStatement(devicePolicy);
stmt.setInt(1, policyId);
stmt.executeUpdate();
String deleteCriteria = "DELETE FROM DM_POLICY_CRITERIA WHERE POLICY_ID = ?";
stmt = conn.prepareStatement(deleteCriteria);
stmt.setInt(1, policyId);
stmt.executeUpdate();
if (log.isDebugEnabled()) {
log.debug("Policy (" + policyId + ") related configs deleted from database.");
}
return true;
} catch (SQLException e) {
throw new PolicyManagerDAOException("Unable to delete the policy (" + policyId +
") related configs from database", e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
}
private Connection getConnection() throws PolicyManagerDAOException { private Connection getConnection() throws PolicyManagerDAOException {
return PolicyManagementDAOFactory.getConnection(); return PolicyManagementDAOFactory.getConnection();
} }
@ -1345,7 +1476,8 @@ public class PolicyDAOImpl implements PolicyDAO {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ? AND ENROLMENT_ID = ?"; String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ? AND " +
"ENROLMENT_ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);

@ -62,6 +62,8 @@ public class MonitoringManagerImpl implements MonitoringManager {
private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class); private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class);
private static final String OPERATION_MONITOR = "MONITOR"; private static final String OPERATION_MONITOR = "MONITOR";
private static final String OPERATION_INFO = "DEVICE_INFO";
private static final String OPERATION_APP_LIST = "APPLICATION_LIST";
public MonitoringManagerImpl() { public MonitoringManagerImpl() {
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO(); this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
@ -378,9 +380,19 @@ public class MonitoringManagerImpl implements MonitoringManager {
monitoringOperation.setEnabled(true); monitoringOperation.setEnabled(true);
monitoringOperation.setType(Operation.Type.COMMAND); monitoringOperation.setType(Operation.Type.COMMAND);
monitoringOperation.setCode(OPERATION_MONITOR); monitoringOperation.setCode(OPERATION_MONITOR);
CommandOperation infoOperation = new CommandOperation();
infoOperation.setEnabled(true);
infoOperation.setType(Operation.Type.COMMAND);
infoOperation.setCode(OPERATION_INFO);
CommandOperation appListOperation = new CommandOperation();
appListOperation.setEnabled(true);
appListOperation.setType(Operation.Type.COMMAND);
appListOperation.setCode(OPERATION_APP_LIST);
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
service.addOperation(monitoringOperation, deviceIdentifiers); service.addOperation(monitoringOperation, deviceIdentifiers);
service.addOperation(infoOperation, deviceIdentifiers);
service.addOperation(appListOperation, deviceIdentifiers);
} }
private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) { private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) {

@ -180,15 +180,15 @@ public class PolicyManagerImpl implements PolicyManager {
if (!newFeaturesList.isEmpty()) { if (!newFeaturesList.isEmpty()) {
featureDAO.addProfileFeatures(newFeaturesList, profileId); featureDAO.addProfileFeatures(newFeaturesList, profileId);
} }
policyDAO.deleteAllPolicyRelatedConfigs(policy.getId()); policyDAO.deleteCriteriaAndDeviceRelatedConfigs(policy.getId());
if (policy.getUsers() != null) { if (policy.getUsers() != null) {
policyDAO.addPolicyToUser(policy.getUsers(), previousPolicy); policyDAO.updateUserOfPolicy(policy.getUsers(), previousPolicy);
} }
if (policy.getRoles() != null) { if (policy.getRoles() != null) {
policyDAO.addPolicyToRole(policy.getRoles(), previousPolicy); policyDAO.updateRolesOfPolicy(policy.getRoles(), previousPolicy);
} }
if (policy.getDevices() != null) { if (policy.getDevices() != null) {
@ -539,7 +539,7 @@ public class PolicyManagerImpl implements PolicyManager {
policy.setDevices(deviceList); policy.setDevices(deviceList);
try { try {
// PolicyManagementDAOFactory.openConnection(); // PolicyManagementDAOFactory.openConnection();
Profile profile = profileManager.getProfile(policy.getProfileId()); Profile profile = profileManager.getProfile(policy.getProfileId());
policy.setProfile(profile); policy.setProfile(profile);
} catch (ProfileManagementException e) { } catch (ProfileManagementException e) {

@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,

@ -90,6 +90,7 @@
org.wso2.carbon.utils, org.wso2.carbon.utils,
org.wso2.carbon.utils.multitenancy, org.wso2.carbon.utils.multitenancy,
org.xml.sax, org.xml.sax,
javax.servlet,
javax.servlet.http, javax.servlet.http,
javax.xml, javax.xml,
org.apache.axis2.transport.http, org.apache.axis2.transport.http,

@ -26,6 +26,7 @@ import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthen
public class AuthenticationInfo { public class AuthenticationInfo {
private WebappAuthenticator.Status status = WebappAuthenticator.Status.FAILURE; private WebappAuthenticator.Status status = WebappAuthenticator.Status.FAILURE;
private String message;
private String username; private String username;
private String tenantDomain; private String tenantDomain;
private int tenantId = -1; private int tenantId = -1;
@ -43,6 +44,14 @@ public class AuthenticationInfo {
return username; return username;
} }
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }

@ -74,12 +74,12 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId()); privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId());
privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain()); privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain());
privilegedCarbonContext.setUsername(authenticationInfo.getUsername()); privilegedCarbonContext.setUsername(authenticationInfo.getUsername());
this.processRequest(request, response, compositeValve, authenticationInfo.getStatus()); this.processRequest(request, response, compositeValve, authenticationInfo);
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }
} else { } else {
this.processRequest(request, response, compositeValve, authenticationInfo.getStatus()); this.processRequest(request, response, compositeValve, authenticationInfo);
} }
} }
@ -113,14 +113,18 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
} }
private void processRequest(Request request, Response response, CompositeValve compositeValve, private void processRequest(Request request, Response response, CompositeValve compositeValve,
WebappAuthenticator.Status status) { AuthenticationInfo authenticationInfo) {
switch (status) { switch (authenticationInfo.getStatus()) {
case SUCCESS: case SUCCESS:
case CONTINUE: case CONTINUE:
this.getNext().invoke(request, response, compositeValve); this.getNext().invoke(request, response, compositeValve);
break; break;
case FAILURE: case FAILURE:
String msg = "Failed to authorize incoming request"; String msg = "Failed to authorize incoming request";
if(authenticationInfo.getMessage() != null && !authenticationInfo.getMessage().isEmpty()) {
msg = authenticationInfo.getMessage();
response.setHeader("WWW-Authenticate", msg);
}
log.error(msg); log.error(msg);
AuthenticationFrameworkUtil AuthenticationFrameworkUtil
.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, .handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED,

@ -51,7 +51,8 @@ public class CertificateAuthenticator implements WebappAuthenticator {
if (certHeader != null && if (certHeader != null &&
AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService(). AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService().
verifySignature(certHeader)) { verifySignature(certHeader)) {
AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService().
extractCertificateFromSignature(certHeader);
X509Certificate certificate = X509Certificate certificate =
AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService(). AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService().
extractCertificateFromSignature(certHeader); extractCertificateFromSignature(certHeader);

@ -102,7 +102,8 @@ public class OAuthAuthenticator implements WebappAuthenticator {
resourceContextParam.setValue(requestUri + ":" + requestMethod); resourceContextParam.setValue(requestUri + ":" + requestMethod);
OAuth2TokenValidationRequestDTO.TokenValidationContextParam[] OAuth2TokenValidationRequestDTO.TokenValidationContextParam[]
tokenValidationContextParams = new OAuth2TokenValidationRequestDTO.TokenValidationContextParam[1]; tokenValidationContextParams =
new OAuth2TokenValidationRequestDTO.TokenValidationContextParam[1];
tokenValidationContextParams[0] = resourceContextParam; tokenValidationContextParams[0] = resourceContextParam;
dto.setContext(tokenValidationContextParams); dto.setContext(tokenValidationContextParams);
@ -110,17 +111,14 @@ public class OAuthAuthenticator implements WebappAuthenticator {
AuthenticatorFrameworkDataHolder.getInstance().getoAuth2TokenValidationService().validate(dto); AuthenticatorFrameworkDataHolder.getInstance().getoAuth2TokenValidationService().validate(dto);
if (oAuth2TokenValidationResponseDTO.isValid()) { if (oAuth2TokenValidationResponseDTO.isValid()) {
String username = oAuth2TokenValidationResponseDTO.getAuthorizedUser(); String username = oAuth2TokenValidationResponseDTO.getAuthorizedUser();
// try { authenticationInfo.setUsername(username);
authenticationInfo.setUsername(username); authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username));
authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username)); authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username));
authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username));
// } catch (AuthenticationException e) {
// throw new AuthenticationException(
// "Error occurred while retrieving the tenant ID of user '" + username + "'", e);
// }
if (oAuth2TokenValidationResponseDTO.isValid()) { if (oAuth2TokenValidationResponseDTO.isValid()) {
authenticationInfo.setStatus(Status.CONTINUE); authenticationInfo.setStatus(Status.CONTINUE);
} }
} else {
authenticationInfo.setMessage(oAuth2TokenValidationResponseDTO.getErrorMsg());
} }
} }
} catch (AuthenticationException e) { } catch (AuthenticationException e) {
@ -148,7 +146,7 @@ public class OAuthAuthenticator implements WebappAuthenticator {
tokenValue = tokenValue.substring(matcher.end()); tokenValue = tokenValue.substring(matcher.end());
} }
} }
if(log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Oauth Token : " + tokenValue); log.debug("Oauth Token : " + tokenValue);
} }
return tokenValue; return tokenValue;

@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
@ -97,10 +97,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
--- POLICY RELATED TABLES ---- -- POLICY RELATED TABLES --
CREATE TABLE IF NOT EXISTS DM_PROFILE ( CREATE TABLE IF NOT EXISTS DM_PROFILE (
ID INT NOT NULL AUTO_INCREMENT , ID INT NOT NULL AUTO_INCREMENT ,
@ -358,8 +355,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
CREATE TABLE IF NOT EXISTS DM_APPLICATION ( CREATE TABLE IF NOT EXISTS DM_APPLICATION (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
NAME VARCHAR(50) NOT NULL, NAME VARCHAR(150) NOT NULL,
APP_IDENTIFIER VARCHAR(50) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL,
PLATFORM VARCHAR(50) DEFAULT NULL, PLATFORM VARCHAR(50) DEFAULT NULL,
CATEGORY VARCHAR(50) NULL, CATEGORY VARCHAR(50) NULL,
VERSION VARCHAR(50) NULL, VERSION VARCHAR(50) NULL,
@ -401,6 +398,3 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
); );
-- NOTIFICATION TABLE END -- -- NOTIFICATION TABLE END --
-- TO:DO - Remove this INSERT sql statement.
--Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android');
--Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (2, 'ios');

@ -1,8 +1,5 @@
/* SQLINES EVALUATION VERSION TRUNCATES VARIABLE NAMES AND COMMENTS. */
/* OBTAIN A LICENSE AT WWW.SQLINES.COM FOR FULL CONVERSION. THANK YOU. */
CREATE TABLE DM_DEVICE_TYPE ( CREATE TABLE DM_DEVICE_TYPE (
ID INT identity NOT NULL, ID INT IDENTITY NOT NULL,
NAME VARCHAR(300) DEFAULT NULL, NAME VARCHAR(300) DEFAULT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
@ -76,7 +73,7 @@ CREATE TABLE DM_ENROLMENT (
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE DM_ENROLMENT_OPERATION_MAPPING ( CREATE TABLE DM_ENROLMENT_OP_MAPPING (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
@ -100,7 +97,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
--- POLICY RELA... *** SQLINES FOR EVALUATION USE ONLY *** -- POLICY RELATED TABLES --
@ -361,8 +358,8 @@ CREATE TABLE DM_ENROLMENT (
CREATE TABLE DM_APPLICATION ( CREATE TABLE DM_APPLICATION (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
NAME VARCHAR(50) NOT NULL, NAME VARCHAR(150) NOT NULL,
APP_IDENTIFIER VARCHAR(50) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL,
PLATFORM VARCHAR(50) DEFAULT NULL, PLATFORM VARCHAR(50) DEFAULT NULL,
CATEGORY VARCHAR(50) NULL, CATEGORY VARCHAR(50) NULL,
VERSION VARCHAR(50) NULL, VERSION VARCHAR(50) NULL,
@ -386,9 +383,9 @@ CREATE TABLE DM_DEVICE_APPLICATION_MAPPING (
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
-- POLICY RELAT... *** SQLINES FOR EVALUATION USE ONLY *** -- POLICY RELATED TABLES FINISHED --
-- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY *** -- NOTIFICATION TABLE --
CREATE TABLE DM_NOTIFICATION ( CREATE TABLE DM_NOTIFICATION (
NOTIFICATION_ID INTEGER IDENTITY NOT NULL, NOTIFICATION_ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL,
@ -402,8 +399,4 @@ CREATE TABLE DM_NOTIFICATION (
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
-- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY *** -- NOTIFICATION TABLE END --
-- TO:DO - Remo... *** SQLINES FOR EVALUATION USE ONLY ***
--Insert into D... *** SQLINES FOR EVALUATION USE ONLY ***
--Insert into D... *** SQLINES FOR EVALUATION USE ONLY ***

@ -1,30 +1,399 @@
-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
-- Table `DM_DEVICE_TYPE` ID INTEGER AUTO_INCREMENT NOT NULL,
-- ----------------------------------------------------- NAME VARCHAR(300) DEFAULT NULL,
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` ( PRIMARY KEY (ID)
`ID` INT(11) NOT NULL , )ENGINE = InnoDB;
`NAME` VARCHAR(300) DEFAULT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB CREATE TABLE IF NOT EXISTS DM_DEVICE (
DEFAULT CHARACTER SET = latin1; ID INTEGER AUTO_INCREMENT NOT NULL,
DESCRIPTION TEXT DEFAULT NULL,
NAME VARCHAR(100) DEFAULT NULL,
-- ----------------------------------------------------- DEVICE_TYPE_ID INT(11) DEFAULT NULL,
-- Table `DM_DEVICE` DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
-- ----------------------------------------------------- TENANT_ID INTEGER DEFAULT 0,
CREATE TABLE IF NOT EXISTS `DM_DEVICE` ( PRIMARY KEY (ID),
`ID` VARCHAR(20) NOT NULL , CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID)
`DESCRIPTION` TEXT DEFAULT NULL , REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
`NAME` VARCHAR(100) DEFAULT NULL , )ENGINE = InnoDB;
`DEVICE_TYPE_ID` INT(11) DEFAULT NULL ,
`DEVICE_IDENTIFICATION` VARCHAR(300) DEFAULT NULL ,
`TENANT_ID` INTEGER DEFAULT 0, CREATE TABLE IF NOT EXISTS DM_OPERATION (
PRIMARY KEY (`ID`) , ID INTEGER AUTO_INCREMENT NOT NULL,
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) , TYPE VARCHAR(50) NOT NULL,
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2` CREATED_TIMESTAMP TIMESTAMP NOT NULL,
FOREIGN KEY (`DEVICE_TYPE_ID` ) RECEIVED_TIMESTAMP TIMESTAMP NULL,
REFERENCES `DM_DEVICE_TYPE` (`ID` ) OPERATION_CODE VARCHAR(1000) NOT NULL,
ON DELETE NO ACTION PRIMARY KEY (ID)
ON UPDATE NO ACTION) )ENGINE = InnoDB;
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL,
OPERATION_CONFIG BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT FK_DM_OPERATION_COMMAND FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT FK_DM_OPERATION_POLICY FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT FK_DM_OPERATION_PROFILE FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_ENROLMENT FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE BLOB DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_response_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
-- POLICY RELATED TABLES ---
CREATE TABLE IF NOT EXISTS DM_PROFILE (
ID INT NOT NULL AUTO_INCREMENT ,
PROFILE_NAME VARCHAR(45) NOT NULL ,
TENANT_ID INT NOT NULL ,
DEVICE_TYPE_ID INT NOT NULL ,
CREATED_TIME DATETIME NOT NULL ,
UPDATED_TIME DATETIME NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT DM_PROFILE_DEVICE_TYPE
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_POLICY (
ID INT(11) NOT NULL AUTO_INCREMENT ,
NAME VARCHAR(45) DEFAULT NULL ,
DESCRIPTION VARCHAR(1000) NULL,
TENANT_ID INT(11) NOT NULL ,
PROFILE_ID INT(11) NOT NULL ,
OWNERSHIP_TYPE VARCHAR(45) NULL,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL,
ACTIVE INT(2) NOT NULL,
UPDATED INT(1) NULL,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_PROFILE_DM_POLICY
FOREIGN KEY (PROFILE_ID )
REFERENCES DM_PROFILE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
ID INT(11) NOT NULL AUTO_INCREMENT ,
DEVICE_ID INT(11) NOT NULL ,
ENROLMENT_ID INT(11) NOT NULL,
DEVICE BLOB NOT NULL,
POLICY_ID INT(11) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_POLICY_DEVICE_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DEVICE_DEVICE_POLICY
FOREIGN KEY (DEVICE_ID )
REFERENCES DM_DEVICE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
ID INT(11) NOT NULL ,
DEVICE_TYPE_ID INT(11) NOT NULL ,
POLICY_ID INT(11) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DEVICE_TYPE_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
ID INT(11) NOT NULL AUTO_INCREMENT,
PROFILE_ID INT(11) NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT(11) NOT NULL ,
CONTENT BLOB NULL DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
FOREIGN KEY (PROFILE_ID)
REFERENCES DM_PROFILE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
ID INT(11) NOT NULL AUTO_INCREMENT ,
ROLE_NAME VARCHAR(45) NOT NULL ,
POLICY_ID INT(11) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_ROLE_POLICY_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
ID INT NOT NULL AUTO_INCREMENT ,
POLICY_ID INT NOT NULL ,
USERNAME VARCHAR(45) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT DM_POLICY_USER_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
ID INT NOT NULL AUTO_INCREMENT ,
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT(11) NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT(1) NULL ,
CREATED_TIME TIMESTAMP NULL ,
UPDATED_TIME TIMESTAMP NULL ,
APPLIED_TIME TIMESTAMP NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_POLICY_DEVCIE_APPLIED
FOREIGN KEY (DEVICE_ID )
REFERENCES DM_DEVICE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DEVICE_APPLIED_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
ID INT NOT NULL AUTO_INCREMENT,
TENANT_ID INT NOT NULL,
NAME VARCHAR(50) NULL,
PRIMARY KEY (ID)
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ID INT NOT NULL AUTO_INCREMENT,
CRITERIA_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
FOREIGN KEY (CRITERIA_ID)
REFERENCES DM_CRITERIA (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_POLICY_POLICY_CRITERIA
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ID INT NOT NULL AUTO_INCREMENT,
POLICY_CRITERION_ID INT NOT NULL,
PROP_KEY VARCHAR(45) NULL,
PROP_VALUE VARCHAR(100) NULL,
CONTENT BLOB NULL COMMENT 'This is used to ',
PRIMARY KEY (ID),
CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES
FOREIGN KEY (POLICY_CRITERION_ID)
REFERENCES DM_POLICY_CRITERIA (ID)
ON DELETE CASCADE
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT(11) NOT NULL,
POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
STATUS INT NULL,
LAST_SUCCESS_TIME TIMESTAMP NULL,
LAST_REQUESTED_TIME TIMESTAMP NULL,
LAST_FAILED_TIME TIMESTAMP NULL,
ATTEMPTS INT NULL,
PRIMARY KEY (ID),
UNIQUE INDEX DEVICE_ID_UNIQUE (DEVICE_ID ASC),
CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
ID INT NOT NULL AUTO_INCREMENT,
POLICY_ID INT NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT(11) NOT NULL,
PRIMARY KEY (ID)
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ID INT NOT NULL AUTO_INCREMENT,
COMPLIANCE_STATUS_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
FEATURE_CODE VARCHAR(15) NOT NULL,
STATUS INT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
FOREIGN KEY (COMPLIANCE_STATUS_ID)
REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
NAME VARCHAR(150) NOT NULL,
APP_IDENTIFIER VARCHAR(150) NOT NULL,
PLATFORM VARCHAR(50) DEFAULT NULL,
CATEGORY VARCHAR(50) NULL,
VERSION VARCHAR(50) NULL,
TYPE VARCHAR(50) NULL,
LOCATION_URL VARCHAR(100) DEFAULT NULL,
IMAGE_URL VARCHAR(100) DEFAULT NULL,
APP_PROPERTIES BLOB NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
)ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
-- END OF POLICY RELATED TABLES --
-- NOTIFICATION TABLES --
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
STATUS VARCHAR(10) NULL,
DESCRIPTION VARCHAR(100) NULL,
PRIMARY KEY (NOTIFICATION_ID),
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
-- END NOTIFICATION TABLES --

@ -1,8 +1,5 @@
/* SQLINES EVALUATION VERSION TRUNCATES VARIABLE NAMES AND COMMENTS. */
/* OBTAIN A LICENSE AT WWW.SQLINES.COM FOR FULL CONVERSION. THANK YOU. */
CREATE TABLE DM_DEVICE_TYPE ( CREATE TABLE DM_DEVICE_TYPE (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
NAME VARCHAR2(300) DEFAULT NULL, NAME VARCHAR2(300) DEFAULT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
@ -120,7 +117,7 @@ BEGIN
END; END;
/ /
CREATE TABLE DM_ENROLMENT_OPERATION_MAPPING ( CREATE TABLE DM_ENROLMENT_OP_MAPPING (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
ENROLMENT_ID NUMBER(10) NOT NULL, ENROLMENT_ID NUMBER(10) NOT NULL,
OPERATION_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL,
@ -133,13 +130,13 @@ CREATE TABLE DM_ENROLMENT_OPERATION_MAPPING (
); );
-- Generate ID using sequence and trigger -- Generate ID using sequence and trigger
CREATE SEQUENCE DM_ENROLMENT_OPERATION_MAPPING_seq START WITH 1 INCREMENT BY 1; CREATE SEQUENCE DM_ENROLMENT_OP_MAPPING_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_ENROLMENT_OPERATION_MAPPING_seq_tr CREATE OR REPLACE TRIGGER DM_ENROLMENT_OP_MAPPING_seq_tr
BEFORE INSERT ON DM_ENROLMENT_OPERATION_MAPPING FOR EACH ROW BEFORE INSERT ON DM_ENROLMENT_OP_MAPPING FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_ENROLMENT_OPERATION_MAPPING_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_ENROLMENT_OP_MAPPING_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
@ -166,7 +163,7 @@ BEGIN
END; END;
/ /
--- POLICY RELA... *** SQLINES FOR EVALUATION USE ONLY *** -- POLICY RELATED TABLES ---
@ -554,8 +551,8 @@ END;
CREATE TABLE DM_APPLICATION ( CREATE TABLE DM_APPLICATION (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
NAME VARCHAR2(50) NOT NULL, NAME VARCHAR2(150) NOT NULL,
APP_IDENTIFIER VARCHAR2(50) NOT NULL, APP_IDENTIFIER VARCHAR2(150) NOT NULL,
PLATFORM VARCHAR2(50) DEFAULT NULL, PLATFORM VARCHAR2(50) DEFAULT NULL,
CATEGORY VARCHAR2(50) NULL, CATEGORY VARCHAR2(50) NULL,
VERSION VARCHAR2(50) NULL, VERSION VARCHAR2(50) NULL,
@ -601,9 +598,9 @@ BEGIN
END; END;
/ /
-- POLICY RELAT... *** SQLINES FOR EVALUATION USE ONLY *** -- POLICY RELATED TABLES FINISHED --
-- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY *** -- NOTIFICATION TABLE --
CREATE TABLE DM_NOTIFICATION ( CREATE TABLE DM_NOTIFICATION (
NOTIFICATION_ID NUMBER(10) NOT NULL, NOTIFICATION_ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NOT NULL, DEVICE_ID NUMBER(10) NOT NULL,
@ -628,8 +625,6 @@ BEGIN
SELECT DM_NOTIFICATION_seq.NEXTVAL INTO :NEW.NOTIFICATION_ID FROM DUAL; SELECT DM_NOTIFICATION_seq.NEXTVAL INTO :NEW.NOTIFICATION_ID FROM DUAL;
END; END;
/ /
-- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY *** -- NOTIFICATION TABLE END --
-- TO:DO - Remo... *** SQLINES FOR EVALUATION USE ONLY ***
--Insert into D... *** SQLINES FOR EVALUATION USE ONLY ***
--Insert into D... *** SQLINES FOR EVALUATION USE ONLY ***

@ -1,455 +0,0 @@
/* SQLINES EVALUATION VERSION TRUNCATES VARIABLE NAMES AND COMMENTS. */
/* OBTAIN A LICENSE AT WWW.SQLINES.COM FOR FULL CONVERSION. THANK YOU. */
CREATE SEQUENCE CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID INT default nextval ('DM_DEVICE_TYPE_seq') NOT NULL,
NAME VARCHAR(300) DEFAULT NULL,
PRIMARY KEY (ID)
);
CREATE SEQUENCE CREATE SEQUEN;
CREATE TABLE IF NOT EXISTS DM_DEVICE (
ID INTEGER default nextval ('DM_DEVICE_seq') NOT NULL,
DESCRIPTION TEXT DEFAULT NULL,
NAME VARCHAR(100) DEFAULT NULL,
DEVICE_TYPE_ID INT DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_OPERATION (
ID INTEGER DEFAULT NEXTVAL ('DM_OPERATION_seq') NOT NULL,
TYPE VARCHAR(50) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
OPERATION_CODE VARCHAR(1000) NOT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL,
OPERATION_CONFIG BYTEA DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BYTEA DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BYTEA DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID INTEGER DEFAULT NEXTVAL ('DM_ENROLMENT_seq') NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT TIMESTAMP(0) DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING (
ID INTEGER DEFAULT NEXTVAL ('DM_ENROLMENT_OPERATION_MAPPING_seq') NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_OPERATION_RESPONSE_seq') NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE BYTEA DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_response_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
--- POLICY RELA... *** SQLINES FOR EVALUATION USE ONLY ***
CREATE SEQUENCE CREATE SEQUENC;
CREATE TABLE IF NOT EXISTS DM_PROFILE (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_PROFILE_seq') ,
PROFILE_NAME VARCHAR(45) NOT NULL ,
TENANT_ID INT NOT NULL ,
DEVICE_TYPE_ID INT NOT NULL ,
CREATED_TIME TIMESTAMP(0) NOT NULL ,
UPDATED_TIME TIMESTAMP(0) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT DM_PROFILE_DEVICE_TYPE
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUEN;
CREATE TABLE IF NOT EXISTS DM_POLICY (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_POLICY_seq') ,
NAME VARCHAR(45) DEFAULT NULL ,
DESCRIPTION VARCHAR(1000) NULL,
TENANT_ID INT NOT NULL ,
PROFILE_ID INT NOT NULL ,
OWNERSHIP_TYPE VARCHAR(45) NULL,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL,
ACTIVE INT NOT NULL,
UPDATED INT NULL,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_PROFILE_DM_POLICY
FOREIGN KEY (PROFILE_ID )
REFERENCES DM_PROFILE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE DEFAULT ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_POLICY_seq') ,
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
DEVICE BYTEA NOT NULL,
POLICY_ID INT NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_POLICY_DEVICE_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DEVICE_DEVICE_POLICY
FOREIGN KEY (DEVICE_ID )
REFERENCES DM_DEVICE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
ID INT NOT NULL ,
DEVICE_TYPE_ID INT NOT NULL ,
POLICY_ID INT NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DEVICE_TYPE_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE DEFAULT ;
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_PROFILE_FEATURES_seq'),
PROFILE_ID INT NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT NOT NULL ,
CONTENT BYTEA NULL DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
FOREIGN KEY (PROFILE_ID)
REFERENCES DM_PROFILE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_ROLE_POLICY_seq') ,
ROLE_NAME VARCHAR(45) NOT NULL ,
POLICY_ID INT NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_ROLE_POLICY_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_USER_POLICY_seq') ,
POLICY_ID INT NOT NULL ,
USERNAME VARCHAR(45) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT DM_POLICY_USER_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_POLICY_APPLIED_seq') ,
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BYTEA NULL ,
TENANT_ID INT NOT NULL,
APPLIED SMALLINT NULL ,
CREATED_TIME TIMESTAMP(0) NULL ,
UPDATED_TIME TIMESTAMP(0) NULL ,
APPLIED_TIME TIMESTAMP(0) NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_POLICY_DEVCIE_APPLIED
FOREIGN KEY (DEVICE_ID )
REFERENCES DM_DEVICE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DEVICE_APPLIED_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUENCE;
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_CRITERIA_seq'),
TENANT_ID INT NOT NULL,
NAME VARCHAR(50) NULL,
PRIMARY KEY (ID)
);
CREATE SEQUENCE DEFAULT ;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_POLICY_CRITERIA_seq'),
CRITERIA_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
FOREIGN KEY (CRITERIA_ID)
REFERENCES DM_CRITERIA (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_POLICY_POLICY_CRITERIA
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_POLICY_CRITERIA_PROPERTIES_seq'),
POLICY_CRITERION_ID INT NOT NULL,
PROP_KEY VARCHAR(45) NULL,
PROP_VALUE VARCHAR(100) NULL,
CONTENT BYTEA NULL ,
PRIMARY KEY (ID),
CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES
FOREIGN KEY (POLICY_CRITERION_ID)
REFERENCES DM_POLICY_CRITERIA (ID)
ON DELETE CASCADE
ON UPDATE NO ACTION
);
CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_POLICY_COMPLIANCE_STATUS_seq'),
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
STATUS INT NULL,
LAST_SUCCESS_TIME TIMESTAMP(0) NULL,
LAST_REQUESTED_TIME TIMESTAMP(0) NULL,
LAST_FAILED_TIME TIMESTAMP(0) NULL,
ATTEMPTS INT NULL,
PRIMARY KEY (ID),
CONSTRAINT DEVICE_ID_UNIQUE UNIQUE (DEVICE_ID ASC),
CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE DEFAULT ;
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_POLICY_CHANGE_MGT_seq'),
POLICY_ID INT NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID)
);
CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_POLICY_COMPLIANCE_FEATURES_seq'),
COMPLIANCE_STATUS_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
FEATURE_CODE VARCHAR(15) NOT NULL,
STATUS INT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
FOREIGN KEY (COMPLIANCE_STATUS_ID)
REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID INTEGER DEFAULT NEXTVAL ('DM_ENROLMENT_seq') NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT TIMESTAMP(0) DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE SEQUENCE CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
ID INTEGER DEFAULT NEXTVAL ('DM_APPLICATION_seq') NOT NULL,
NAME VARCHAR(50) NOT NULL,
APP_IDENTIFIER VARCHAR(50) NOT NULL,
PLATFORM VARCHAR(50) DEFAULT NULL,
CATEGORY VARCHAR(50) NULL,
VERSION VARCHAR(50) NULL,
TYPE VARCHAR(50) NULL,
LOCATION_URL VARCHAR(100) DEFAULT NULL,
IMAGE_URL VARCHAR(100) DEFAULT NULL,
APP_PROPERTIES BYTEA NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
);
CREATE SEQUENCE ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_APPLICATION_MAPPING_seq') NOT NULL,
DEVICE_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- POLICY RELAT... *** SQLINES FOR EVALUATION USE ONLY ***
-- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY ***
CREATE SEQUENCE P<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DM_O;
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
NOTIFICATION_ID INTEGER DEFAULT NEXTVAL ('DM_NOTIFICATION_seq') NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
STATUS VARCHAR(10) NULL,
DESCRIPTION VARCHAR(100) NULL,
PRIMARY KEY (NOTIFICATION_ID),
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY ***
-- TO:DO - Remo... *** SQLINES FOR EVALUATION USE ONLY ***
--Insert into D... *** SQLINES FOR EVALUATION USE ONLY ***
--Insert into D... *** SQLINES FOR EVALUATION USE ONLY ***

@ -0,0 +1,340 @@
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID BIGSERIAL PRIMARY KEY,
NAME VARCHAR(300) DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS DM_DEVICE (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DESCRIPTION TEXT DEFAULT NULL,
NAME VARCHAR(100) DEFAULT NULL,
DEVICE_TYPE_ID INTEGER DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_OPERATION (
ID BIGSERIAL NOT NULL PRIMARY KEY,
TYPE VARCHAR(50) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
OPERATION_CODE VARCHAR(1000) NOT NULL
);
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL,
OPERATION_CONFIG BYTEA DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BYTEA DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BYTEA DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
TENANT_ID INTEGER NOT NULL,
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
ID BIGSERIAL NOT NULL PRIMARY KEY,
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL,
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE BYTEA DEFAULT NULL,
CONSTRAINT fk_dm_device_operation_response_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- POLICY RELATED TABLES ---
CREATE TABLE DM_PROFILE (
ID BIGSERIAL NOT NULL PRIMARY KEY,
PROFILE_NAME VARCHAR(45) NOT NULL ,
TENANT_ID INTEGER NOT NULL ,
DEVICE_TYPE_ID INTEGER NOT NULL ,
CREATED_TIME TIMESTAMP NOT NULL ,
UPDATED_TIME TIMESTAMP NOT NULL ,
CONSTRAINT DM_PROFILE_DEVICE_TYPE
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE DM_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
NAME VARCHAR(45) DEFAULT NULL ,
DESCRIPTION VARCHAR(1000) NULL,
TENANT_ID INTEGER NOT NULL ,
PROFILE_ID INTEGER NOT NULL ,
OWNERSHIP_TYPE VARCHAR(45) NULL,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INTEGER NOT NULL,
ACTIVE INTEGER NOT NULL,
UPDATED INTEGER NULL,
CONSTRAINT FK_DM_PROFILE_DM_POLICY
FOREIGN KEY (PROFILE_ID )
REFERENCES DM_PROFILE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE DM_DEVICE_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INTEGER NOT NULL,
DEVICE BYTEA NOT NULL,
POLICY_ID INTEGER NOT NULL ,
CONSTRAINT FK_POLICY_DEVICE_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DEVICE_DEVICE_POLICY
FOREIGN KEY (DEVICE_ID )
REFERENCES DM_DEVICE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE DM_DEVICE_TYPE_POLICY (
ID INTEGER NOT NULL,
DEVICE_TYPE_ID INTEGER NOT NULL ,
POLICY_ID INTEGER NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DEVICE_TYPE_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE DM_PROFILE_FEATURES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
PROFILE_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(30) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INTEGER NOT NULL ,
CONTENT BYTEA NULL DEFAULT NULL,
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
FOREIGN KEY (PROFILE_ID)
REFERENCES DM_PROFILE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE DM_ROLE_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
ROLE_NAME VARCHAR(45) NOT NULL ,
POLICY_ID INTEGER NOT NULL,
CONSTRAINT FK_ROLE_POLICY_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE DM_USER_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
POLICY_ID INT NOT NULL ,
USERNAME VARCHAR(45) NOT NULL,
CONSTRAINT DM_POLICY_USER_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE DM_DEVICE_POLICY_APPLIED (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL ,
POLICY_CONTENT BYTEA NULL ,
TENANT_ID INTEGER NOT NULL,
APPLIED INTEGER[1] NULL ,
CREATED_TIME TIMESTAMP NULL ,
UPDATED_TIME TIMESTAMP NULL ,
APPLIED_TIME TIMESTAMP NULL ,
CONSTRAINT FK_DM_POLICY_DEVCIE_APPLIED
FOREIGN KEY (DEVICE_ID )
REFERENCES DM_DEVICE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DEVICE_APPLIED_POLICY
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
ID BIGSERIAL NOT NULL PRIMARY KEY,
TENANT_ID INT NOT NULL,
NAME VARCHAR(50) NULL
);
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ID BIGSERIAL NOT NULL PRIMARY KEY,
CRITERIA_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
FOREIGN KEY (CRITERIA_ID)
REFERENCES DM_CRITERIA (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_POLICY_POLICY_CRITERIA
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
POLICY_CRITERION_ID INT NOT NULL,
PROP_KEY VARCHAR(45) NULL,
PROP_VALUE VARCHAR(100) NULL,
CONTENT BYTEA NULL,
CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES
FOREIGN KEY (POLICY_CRITERION_ID)
REFERENCES DM_POLICY_CRITERIA (ID)
ON DELETE CASCADE
ON UPDATE NO ACTION
);
COMMENT ON COLUMN DM_POLICY_CRITERIA_PROPERTIES.CONTENT IS 'This is used to ';
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
STATUS INTEGER NULL,
LAST_SUCCESS_TIME TIMESTAMP NULL,
LAST_REQUESTED_TIME TIMESTAMP NULL,
LAST_FAILED_TIME TIMESTAMP NULL,
ATTEMPTS INTEGER NULL,
CONSTRAINT FK_POLICY_COMPLIANCE_STATUS_POLICY
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE UNIQUE INDEX DEVICE_ID_UNIQUE ON DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID ASC);
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
ID BIGSERIAL NOT NULL PRIMARY KEY,
POLICY_ID INTEGER NOT NULL,
DEVICE_TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
COMPLIANCE_STATUS_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(15) NOT NULL,
STATUS INTEGER NULL,
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
FOREIGN KEY (COMPLIANCE_STATUS_ID)
REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
TENANT_ID INT NOT NULL,
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
ID BIGSERIAL NOT NULL PRIMARY KEY,
NAME VARCHAR(150) NOT NULL,
APP_IDENTIFIER VARCHAR(150) NOT NULL,
PLATFORM VARCHAR(50) DEFAULT NULL,
CATEGORY VARCHAR(50) NULL,
VERSION VARCHAR(50) NULL,
TYPE VARCHAR(50) NULL,
LOCATION_URL VARCHAR(100) DEFAULT NULL,
IMAGE_URL VARCHAR(100) DEFAULT NULL,
APP_PROPERTIES BYTEA NULL,
TENANT_ID INTEGER NOT NULL
);
-- POLICY RELATED TABLES FINISHED --
-- NOTIFICATION TABLE --
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
STATUS VARCHAR(10) NULL,
DESCRIPTION VARCHAR(100) NULL,
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- NOTIFICATION TABLE END --
Loading…
Cancel
Save