From 7a110a8eb5b23cbc181b155ffe4788aa21206225 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Mon, 19 Oct 2015 20:49:26 +0530 Subject: [PATCH 01/27] implemented certificateGenerater --- .../pom.xml | 5 +- .../mgt/core/impl/CertificateGenerator.java | 96 ++++++++++++++++++- .../service/CertificateManagementService.java | 3 + .../CertificateManagementServiceImpl.java | 7 ++ .../mgt/core/util/ConfigurationUtil.java | 3 +- .../pom.xml | 1 + .../CertificateAuthenticator.java | 3 +- 7 files changed, 112 insertions(+), 6 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index a253cc9a7f..a38c8ca3db 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -71,11 +71,12 @@ org.bouncycastle.operator.jcajce, org.bouncycastle.pkcs, org.bouncycastle.util, - org.bouncycastle.asn1.util, org.jscep.message, org.jscep.transaction, org.w3c.dom, - org.xml.sax + org.xml.sax, + javax.xml.bind, + org.bouncycastle.pkcs.jcajce !org.wso2.carbon.certificate.mgt.core.internal.*, diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index c97d84472d..853741206d 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -26,8 +26,7 @@ import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.pkcs.Attribute; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x509.KeyUsage; -import org.bouncycastle.asn1.x509.X509Extension; +import org.bouncycastle.asn1.x509.*; import org.bouncycastle.cert.CertIOException; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; @@ -43,6 +42,7 @@ import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.pkcs.PKCS10CertificationRequest; +import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest; import org.bouncycastle.util.Store; import org.jscep.message.CertRep; import org.jscep.message.MessageDecodingException; @@ -62,6 +62,7 @@ import org.wso2.carbon.certificate.mgt.core.util.CommonUtil; import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil; import javax.security.auth.x500.X500Principal; +import javax.xml.bind.DatatypeConverter; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.File; @@ -69,6 +70,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.KeyFactory; import java.security.KeyPair; @@ -97,6 +99,20 @@ import java.util.List; public class CertificateGenerator { + private enum PropertyIndex { + COMMON_NAME_INDEX(0), + NOT_BEFORE_DAYS_INDEX(1), + NOT_AFTER_DAYS_INDEX(2); + + private final int itemPosition; + private PropertyIndex(final int itemPosition) { + this.itemPosition = itemPosition; + } + public int getValue() { + return this.itemPosition; + } + } + private static final Log log = LogFactory.getLog(CertificateGenerator.class); public List getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException { @@ -596,4 +612,80 @@ public class CertificateGenerator { return null; } + + public X509Certificate getSignCertificateFromCSR(String binarySecurityToken, + X509Certificate caCert, List certPropertyList) + throws KeystoreException { + byte[] byteArrayBst = DatatypeConverter.parseBase64Binary(binarySecurityToken); + PKCS10CertificationRequest certificationRequest = null; + KeyStoreReader keyStoreReader = new KeyStoreReader(); + PrivateKey privateKeyCA = keyStoreReader.getCAPrivateKey(); + + try { + certificationRequest = new PKCS10CertificationRequest(byteArrayBst); + } catch (IOException e) { + String msg = "CSR cannot be recovered."; + log.error(msg, e); + } + JcaPKCS10CertificationRequest csr = new JcaPKCS10CertificationRequest(certificationRequest); + X509Certificate signedCertificate = signCSR(csr, privateKeyCA, caCert, certPropertyList); + saveCertInKeyStore(signedCertificate); + return signedCertificate; + } + + private static X509Certificate signCSR(JcaPKCS10CertificationRequest jcaRequest, + PrivateKey privateKey, X509Certificate caCert, + List certParameterList) { + + String commonName = + (String) certParameterList.get(PropertyIndex.COMMON_NAME_INDEX.getValue()); + int notBeforeDays = + (Integer) certParameterList.get(PropertyIndex.NOT_BEFORE_DAYS_INDEX.getValue()); + int notAfterDays = + (Integer) certParameterList.get(PropertyIndex.NOT_AFTER_DAYS_INDEX.getValue()); + X509v3CertificateBuilder certificateBuilder; + X509Certificate signedCertificate = null; + + try { + ContentSigner signer; + BigInteger serialNumber = BigInteger.valueOf(new SecureRandom(). + nextInt(Integer.MAX_VALUE)); + Date notBeforeDate = new Date(System.currentTimeMillis() - + (ConfigurationUtil.MILLI_SECONDS * notBeforeDays)); + Date notAfterDate = new Date(System.currentTimeMillis() + + (ConfigurationUtil.MILLI_SECONDS * notAfterDays)); + certificateBuilder = + new JcaX509v3CertificateBuilder(caCert, serialNumber, notBeforeDate, notAfterDate, + new X500Principal(commonName), + jcaRequest.getPublicKey()); + + //Adding extensions to the signed certificate. + certificateBuilder.addExtension(Extension.keyUsage, true, + new KeyUsage(KeyUsage.digitalSignature)); + certificateBuilder.addExtension(Extension.extendedKeyUsage, false, + new ExtendedKeyUsage(KeyPurposeId.id_kp_clientAuth)); + certificateBuilder.addExtension(Extension.basicConstraints, true, + new BasicConstraints(false)); + + signer = new JcaContentSignerBuilder(ConfigurationUtil.SIGNATURE_ALGORITHM). + setProvider(ConfigurationUtil.PROVIDER).build(privateKey); + + signedCertificate = new JcaX509CertificateConverter().setProvider( + ConfigurationUtil.PROVIDER).getCertificate( + certificateBuilder.build(signer)); + } catch (InvalidKeyException e) { + //throw new CertificateGenerationException("CSR's public key is invalid", e); + } catch (NoSuchAlgorithmException e) { + //throw new CertificateGenerationException("Certificate cannot be generated", e); + } catch (CertIOException e) { + // throw new CertificateGenerationException( + // "Cannot add extension(s) to signed certificate", e); + } catch (OperatorCreationException e) { + // throw new CertificateGenerationException("Content signer cannot be created", e); + } catch (CertificateException e) { + //throw new CertificateGenerationException("Signed certificate cannot be generated", e); + } + return signedCertificate; + } + } \ No newline at end of file diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java index 00a8a68e74..2a969bfa1a 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java @@ -53,4 +53,7 @@ public interface CertificateManagementService { public X509Certificate extractCertificateFromSignature(String headerSignature) throws KeystoreException; String extractChallengeToken(X509Certificate certificate); + + X509Certificate getSignCertificateFromCSR(String binarySecurityToken, X509Certificate caCert, + List certParameterList) throws KeystoreException; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java index cc3fb3efeb..71b1d32db7 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java @@ -100,4 +100,11 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe public String extractChallengeToken(X509Certificate certificate) { return certificateGenerator.extractChallengeToken(certificate); } + + public X509Certificate getSignCertificateFromCSR(String binarySecurityToken, + X509Certificate caCert, List certParameterList) + throws KeystoreException { + return certificateGenerator.getSignCertificateFromCSR(binarySecurityToken, caCert, + certParameterList); + } } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/util/ConfigurationUtil.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/util/ConfigurationUtil.java index 3767d82824..36d9182c10 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/util/ConfigurationUtil.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/util/ConfigurationUtil.java @@ -37,7 +37,7 @@ public class ConfigurationUtil { public static final String KEYSTORE_RA_CERT_PRIV_PASSWORD = "RAPrivateKeyPassword"; public static final String CA_CERT_ALIAS = "CACertAlias"; 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 KEYSTORE = "Type"; 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 EMPTY_TEXT = ""; public static final int RSA_KEY_LENGTH = 1024; + public static final long MILLI_SECONDS = 1000L * 60 * 60 * 24; private static ConfigurationUtil configurationUtil; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index 2053ed89ad..4c28efc1f5 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -90,6 +90,7 @@ org.wso2.carbon.utils, org.wso2.carbon.utils.multitenancy, org.xml.sax, + javax.servlet, javax.servlet.http, javax.xml, org.apache.axis2.transport.http, diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java index 83631d49fd..88d695cf16 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java @@ -51,7 +51,8 @@ public class CertificateAuthenticator implements WebappAuthenticator { if (certHeader != null && AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService(). verifySignature(certHeader)) { - + AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService(). + extractCertificateFromSignature(certHeader); X509Certificate certificate = AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService(). extractCertificateFromSignature(certHeader); From 8d52735e6ad21ecfc15da2ee98052b5e732fba5b Mon Sep 17 00:00:00 2001 From: Kasun Delgolla Date: Tue, 20 Oct 2015 09:51:43 +0530 Subject: [PATCH 02/27] Adding app list + info to monitoring operation --- .../mgt/core/mgt/impl/MonitoringManagerImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 75350b3fdc..f6d14166a4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -62,6 +62,8 @@ public class MonitoringManagerImpl implements MonitoringManager { private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class); 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() { this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO(); @@ -378,9 +380,19 @@ public class MonitoringManagerImpl implements MonitoringManager { monitoringOperation.setEnabled(true); monitoringOperation.setType(Operation.Type.COMMAND); 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(); service.addOperation(monitoringOperation, deviceIdentifiers); + service.addOperation(infoOperation, deviceIdentifiers); + service.addOperation(appListOperation, deviceIdentifiers); } private List getDeviceIdentifiersFromDevices(List devices) { From 2c2216e48d5d73161f684db0853a86dc623bae0b Mon Sep 17 00:00:00 2001 From: hasuniea Date: Wed, 21 Oct 2015 10:38:09 +0530 Subject: [PATCH 03/27] implement certificateManagement service --- .../mgt/core/impl/CertificateGenerator.java | 22 +++++++++++-------- .../service/CertificateManagementService.java | 2 +- .../CertificateManagementServiceImpl.java | 5 ++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index 853741206d..fb09454df0 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -613,7 +613,7 @@ public class CertificateGenerator { return null; } - public X509Certificate getSignCertificateFromCSR(String binarySecurityToken, + public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken, X509Certificate caCert, List certPropertyList) throws KeystoreException { byte[] byteArrayBst = DatatypeConverter.parseBase64Binary(binarySecurityToken); @@ -635,7 +635,7 @@ public class CertificateGenerator { private static X509Certificate signCSR(JcaPKCS10CertificationRequest jcaRequest, PrivateKey privateKey, X509Certificate caCert, - List certParameterList) { + List certParameterList) throws KeystoreException { String commonName = (String) certParameterList.get(PropertyIndex.COMMON_NAME_INDEX.getValue()); @@ -644,7 +644,7 @@ public class CertificateGenerator { int notAfterDays = (Integer) certParameterList.get(PropertyIndex.NOT_AFTER_DAYS_INDEX.getValue()); X509v3CertificateBuilder certificateBuilder; - X509Certificate signedCertificate = null; + X509Certificate signedCertificate; try { ContentSigner signer; @@ -674,16 +674,20 @@ public class CertificateGenerator { ConfigurationUtil.PROVIDER).getCertificate( certificateBuilder.build(signer)); } catch (InvalidKeyException e) { - //throw new CertificateGenerationException("CSR's public key is invalid", e); + String errorMsg = "CSR's public key is invalid"; + throw new KeystoreException(errorMsg, e); } catch (NoSuchAlgorithmException e) { - //throw new CertificateGenerationException("Certificate cannot be generated", e); + String errorMsg = "Certificate cannot be generated"; + throw new KeystoreException(errorMsg, e); } catch (CertIOException e) { - // throw new CertificateGenerationException( - // "Cannot add extension(s) to signed certificate", e); + String errorMsg = "Cannot add extension(s) to signed certificate"; + throw new KeystoreException(errorMsg, e); } catch (OperatorCreationException e) { - // throw new CertificateGenerationException("Content signer cannot be created", e); + String errorMsg = "Content signer cannot be created"; + throw new KeystoreException(errorMsg, e); } catch (CertificateException e) { - //throw new CertificateGenerationException("Signed certificate cannot be generated", e); + String errorMsg = "Signed certificate cannot be generated"; + throw new KeystoreException(errorMsg, e); } return signedCertificate; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java index 2a969bfa1a..7810878bcf 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java @@ -54,6 +54,6 @@ public interface CertificateManagementService { String extractChallengeToken(X509Certificate certificate); - X509Certificate getSignCertificateFromCSR(String binarySecurityToken, X509Certificate caCert, + X509Certificate getSignedCertificateFromCSR(String binarySecurityToken, X509Certificate caCert, List certParameterList) throws KeystoreException; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java index 71b1d32db7..dc8487219e 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java @@ -101,10 +101,9 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe return certificateGenerator.extractChallengeToken(certificate); } - public X509Certificate getSignCertificateFromCSR(String binarySecurityToken, + public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken, X509Certificate caCert, List certParameterList) throws KeystoreException { - return certificateGenerator.getSignCertificateFromCSR(binarySecurityToken, caCert, - certParameterList); + return certificateGenerator.getSignedCertificateFromCSR(binarySecurityToken, caCert, certParameterList); } } From 323357d6138326f0d958907c6e5028f421e04684 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Thu, 22 Oct 2015 15:24:35 +0530 Subject: [PATCH 04/27] Refactored mysql DB Script --- .../main/resources/dbscripts/cdm/mysql.sql | 428 ++++++++++++++++-- 1 file changed, 398 insertions(+), 30 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index eb887f68c6..a7b6ecf00f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -1,30 +1,398 @@ --- ----------------------------------------------------- --- Table `DM_DEVICE_TYPE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` ( - `ID` INT(11) NOT NULL , - `NAME` VARCHAR(300) DEFAULT NULL , - PRIMARY KEY (`ID`) ) -ENGINE = InnoDB -DEFAULT CHARACTER SET = latin1; - - --- ----------------------------------------------------- --- Table `DM_DEVICE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `DM_DEVICE` ( - `ID` VARCHAR(20) NOT NULL , - `DESCRIPTION` TEXT DEFAULT NULL , - `NAME` VARCHAR(100) DEFAULT NULL , - `DEVICE_TYPE_ID` INT(11) DEFAULT NULL , - `DEVICE_IDENTIFICATION` VARCHAR(300) DEFAULT NULL , - `TENANT_ID` INTEGER DEFAULT 0, - PRIMARY KEY (`ID`) , - INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) , - 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) -ENGINE = InnoDB -DEFAULT CHARACTER SET = latin1; +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( + ID INT auto_increment NOT NULL, + NAME VARCHAR(300) DEFAULT NULL, + PRIMARY KEY (ID) +); + + +CREATE TABLE IF NOT EXISTS DM_DEVICE ( + ID INTEGER auto_increment NOT NULL, + DESCRIPTION TEXT DEFAULT NULL, + NAME VARCHAR(100) DEFAULT NULL, + DEVICE_TYPE_ID INT(11) 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 TABLE IF NOT EXISTS DM_OPERATION ( + ID INTEGER AUTO_INCREMENT NOT NULL, + TYPE VARCHAR(50) NOT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP 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 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 +); + + +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 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 +); + + +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 +); + + +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 +); + + +CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_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 +); + + +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 +); + +-- 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 +); + + +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 +); + + +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 +); + + +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 +); + + +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 +); + + +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 +); + + +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 +); + + + 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 +); + + +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) +); + + +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 +); + + +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 +); + + +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 +); + + +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) +); + + +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 +); + + +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 +); + + +CREATE TABLE IF NOT EXISTS DM_APPLICATION ( + ID INTEGER AUTO_INCREMENT 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 BLOB NULL, + TENANT_ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + + +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 +); + +-- POLICY RELATED TABLES FINISHED -- + +-- NOTIFICATION TABLE -- +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 +); +-- NOTIFICATION TABLE END -- + From e1a24abfa3e8336c4e8608211050ae6cdbdbb042 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 23 Oct 2015 14:46:56 +0530 Subject: [PATCH 05/27] refactored certificate service --- .../mgt/core/impl/CertificateGenerator.java | 112 ++---------------- .../service/CertificateManagementService.java | 3 +- .../CertificateManagementServiceImpl.java | 8 +- pom.xml | 2 +- 4 files changed, 18 insertions(+), 107 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index fb09454df0..1bb973e76d 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -26,7 +26,8 @@ import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.pkcs.Attribute; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x509.*; +import org.bouncycastle.asn1.x509.KeyUsage; +import org.bouncycastle.asn1.x509.X509Extension; import org.bouncycastle.cert.CertIOException; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; @@ -44,14 +45,7 @@ import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest; import org.bouncycastle.util.Store; -import org.jscep.message.CertRep; -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.message.*; import org.jscep.transaction.FailInfo; import org.jscep.transaction.Nonce; import org.jscep.transaction.TransactionId; @@ -63,33 +57,10 @@ import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil; import javax.security.auth.x500.X500Principal; import javax.xml.bind.DatatypeConverter; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -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.io.*; +import java.security.*; import java.security.cert.Certificate; -import java.security.cert.CertificateEncodingException; -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.cert.*; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.util.ArrayList; @@ -613,83 +584,24 @@ public class CertificateGenerator { return null; } - public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken, - X509Certificate caCert, List certPropertyList) + public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken) throws KeystoreException { byte[] byteArrayBst = DatatypeConverter.parseBase64Binary(binarySecurityToken); - PKCS10CertificationRequest certificationRequest = null; + 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); } JcaPKCS10CertificationRequest csr = new JcaPKCS10CertificationRequest(certificationRequest); - X509Certificate signedCertificate = signCSR(csr, privateKeyCA, caCert, certPropertyList); - saveCertInKeyStore(signedCertificate); + X509Certificate signedCertificate = generateCertificateFromCSR(privateKeyCA, certificationRequest, + certCA.getIssuerX500Principal().getName()); return signedCertificate; } - - private static X509Certificate signCSR(JcaPKCS10CertificationRequest jcaRequest, - PrivateKey privateKey, X509Certificate caCert, - List certParameterList) throws KeystoreException { - - String commonName = - (String) certParameterList.get(PropertyIndex.COMMON_NAME_INDEX.getValue()); - int notBeforeDays = - (Integer) certParameterList.get(PropertyIndex.NOT_BEFORE_DAYS_INDEX.getValue()); - int notAfterDays = - (Integer) certParameterList.get(PropertyIndex.NOT_AFTER_DAYS_INDEX.getValue()); - X509v3CertificateBuilder certificateBuilder; - X509Certificate signedCertificate; - - try { - ContentSigner signer; - BigInteger serialNumber = BigInteger.valueOf(new SecureRandom(). - nextInt(Integer.MAX_VALUE)); - Date notBeforeDate = new Date(System.currentTimeMillis() - - (ConfigurationUtil.MILLI_SECONDS * notBeforeDays)); - Date notAfterDate = new Date(System.currentTimeMillis() + - (ConfigurationUtil.MILLI_SECONDS * notAfterDays)); - certificateBuilder = - new JcaX509v3CertificateBuilder(caCert, serialNumber, notBeforeDate, notAfterDate, - new X500Principal(commonName), - jcaRequest.getPublicKey()); - - //Adding extensions to the signed certificate. - certificateBuilder.addExtension(Extension.keyUsage, true, - new KeyUsage(KeyUsage.digitalSignature)); - certificateBuilder.addExtension(Extension.extendedKeyUsage, false, - new ExtendedKeyUsage(KeyPurposeId.id_kp_clientAuth)); - certificateBuilder.addExtension(Extension.basicConstraints, true, - new BasicConstraints(false)); - - signer = new JcaContentSignerBuilder(ConfigurationUtil.SIGNATURE_ALGORITHM). - setProvider(ConfigurationUtil.PROVIDER).build(privateKey); - - signedCertificate = new JcaX509CertificateConverter().setProvider( - ConfigurationUtil.PROVIDER).getCertificate( - certificateBuilder.build(signer)); - } catch (InvalidKeyException e) { - String errorMsg = "CSR's public key is invalid"; - throw new KeystoreException(errorMsg, e); - } catch (NoSuchAlgorithmException e) { - String errorMsg = "Certificate cannot be generated"; - throw new KeystoreException(errorMsg, e); - } catch (CertIOException e) { - String errorMsg = "Cannot add extension(s) to signed certificate"; - throw new KeystoreException(errorMsg, e); - } catch (OperatorCreationException e) { - String errorMsg = "Content signer cannot be created"; - throw new KeystoreException(errorMsg, e); - } catch (CertificateException e) { - String errorMsg = "Signed certificate cannot be generated"; - throw new KeystoreException(errorMsg, e); - } - return signedCertificate; - } - } \ No newline at end of file diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java index 7810878bcf..f89ab4f986 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java @@ -54,6 +54,5 @@ public interface CertificateManagementService { String extractChallengeToken(X509Certificate certificate); - X509Certificate getSignedCertificateFromCSR(String binarySecurityToken, X509Certificate caCert, - List certParameterList) throws KeystoreException; + X509Certificate getSignedCertificateFromCSR(String binarySecurityToken) throws KeystoreException; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java index dc8487219e..6ac4ee9192 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java @@ -101,9 +101,9 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe return certificateGenerator.extractChallengeToken(certificate); } - public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken, - X509Certificate caCert, List certParameterList) - throws KeystoreException { - return certificateGenerator.getSignedCertificateFromCSR(binarySecurityToken, caCert, certParameterList); + @Override + public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken) throws KeystoreException { + return certificateGenerator.getSignedCertificateFromCSR(binarySecurityToken); } + } diff --git a/pom.xml b/pom.xml index ca47a56a5c..ccf063dbdb 100644 --- a/pom.xml +++ b/pom.xml @@ -1427,7 +1427,7 @@ 6.1.1 - 4.4.1 + 4.4.2 1.5.4 1.3 From b55c5bc79304069a779d6db8dd375ee6a2497bd3 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Mon, 26 Oct 2015 17:52:19 +0530 Subject: [PATCH 06/27] Refactored mysql DB Script --- .../main/resources/dbscripts/cdm/mysql.sql | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index a7b6ecf00f..61180cf19f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT auto_increment NOT NULL, NAME VARCHAR(300) DEFAULT NULL, PRIMARY KEY (ID) -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_DEVICE ( @@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( 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 -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_OPERATION ( @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( RECEIVED_TIMESTAMP TIMESTAMP NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, PRIMARY KEY (ID) -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( @@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( 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 ( @@ -43,7 +43,7 @@ CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( 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 ( @@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( 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 ( @@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( 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 ( @@ -78,7 +78,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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_OPERATION_MAPPING ( @@ -91,7 +91,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( 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 ( @@ -104,7 +104,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( 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 --- @@ -121,7 +121,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_POLICY ( @@ -141,7 +141,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( REFERENCES DM_PROFILE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( @@ -161,7 +161,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( REFERENCES DM_DEVICE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( @@ -179,7 +179,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( @@ -195,7 +195,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( REFERENCES DM_PROFILE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( @@ -208,7 +208,7 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( REFERENCES DM_POLICY (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( @@ -221,7 +221,7 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( REFERENCES DM_POLICY (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( @@ -246,7 +246,7 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( REFERENCES DM_POLICY (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_CRITERIA ( @@ -254,7 +254,7 @@ CREATE TABLE IF NOT EXISTS DM_CRITERIA ( TENANT_ID INT NOT NULL, NAME VARCHAR(50) NULL, PRIMARY KEY (ID) -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( @@ -272,7 +272,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( REFERENCES DM_POLICY (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( @@ -287,7 +287,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( REFERENCES DM_POLICY_CRITERIA (ID) ON DELETE CASCADE ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( @@ -308,7 +308,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( REFERENCES DM_POLICY (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( @@ -317,7 +317,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( 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 ( @@ -332,7 +332,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( @@ -347,7 +347,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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 ( @@ -363,7 +363,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( APP_PROPERTIES BLOB NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) -); +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( @@ -376,7 +376,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( 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; -- POLICY RELATED TABLES FINISHED -- @@ -393,6 +393,6 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( 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; -- NOTIFICATION TABLE END -- From ac731551474cda9ea5fe835a7018ddf2acf47bb0 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Wed, 28 Oct 2015 14:27:00 +0530 Subject: [PATCH 07/27] Refactored DB Scripts --- .../src/main/resources/dbscripts/cdm/mssql.sql | 2 +- .../src/main/resources/dbscripts/cdm/mysql.sql | 2 +- .../src/main/resources/dbscripts/cdm/oracle.sql | 2 +- .../src/main/resources/dbscripts/cdm/postgres.sql | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index 5ddcee39fd..f8b05280f3 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -362,7 +362,7 @@ CREATE TABLE DM_ENROLMENT ( CREATE TABLE DM_APPLICATION ( ID INTEGER IDENTITY NOT NULL, NAME VARCHAR(50) NOT NULL, - APP_IDENTIFIER VARCHAR(50) NOT NULL, + APP_IDENTIFIER VARCHAR(150) NOT NULL, PLATFORM VARCHAR(50) DEFAULT NULL, CATEGORY VARCHAR(50) NULL, VERSION VARCHAR(50) NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 61180cf19f..10c1e83114 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -353,7 +353,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( CREATE TABLE IF NOT EXISTS DM_APPLICATION ( ID INTEGER AUTO_INCREMENT NOT NULL, NAME VARCHAR(50) NOT NULL, - APP_IDENTIFIER VARCHAR(50) NOT NULL, + APP_IDENTIFIER VARCHAR(150) NOT NULL, PLATFORM VARCHAR(50) DEFAULT NULL, CATEGORY VARCHAR(50) NULL, VERSION VARCHAR(50) NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 2982217eec..be78bc1ded 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -555,7 +555,7 @@ END; CREATE TABLE DM_APPLICATION ( ID NUMBER(10) NOT NULL, NAME VARCHAR2(50) NOT NULL, - APP_IDENTIFIER VARCHAR2(50) NOT NULL, + APP_IDENTIFIER VARCHAR2(150) NOT NULL, PLATFORM VARCHAR2(50) DEFAULT NULL, CATEGORY VARCHAR2(50) NULL, VERSION VARCHAR2(50) NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql index 2b3436ec5d..94a24f6177 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql @@ -404,7 +404,7 @@ 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, + APP_IDENTIFIER VARCHAR(150) NOT NULL, PLATFORM VARCHAR(50) DEFAULT NULL, CATEGORY VARCHAR(50) NULL, VERSION VARCHAR(50) NULL, From d7dc46d3a7924c5a380bb38d8794f05f11ab666e Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Wed, 28 Oct 2015 15:44:49 +0530 Subject: [PATCH 08/27] Refactored DB Scripts --- .../src/main/resources/dbscripts/cdm/h2.sql | 9 +++------ .../src/main/resources/dbscripts/cdm/mssql.sql | 17 +++++++---------- .../src/main/resources/dbscripts/cdm/mysql.sql | 3 +++ .../src/main/resources/dbscripts/cdm/oracle.sql | 17 +++++++---------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 95a32302b1..42ee0a0df1 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -97,10 +97,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); ---- POLICY RELATED TABLES ---- - - - +-- POLICY RELATED TABLES -- CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID INT NOT NULL AUTO_INCREMENT , @@ -402,5 +399,5 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( -- 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'); +Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android'); +Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (2, 'ios'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index f8b05280f3..8bf49804b0 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -1,6 +1,3 @@ -/* 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 ( ID INT identity NOT NULL, NAME VARCHAR(300) DEFAULT NULL, @@ -100,7 +97,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); ---- POLICY RELA... *** SQLINES FOR EVALUATION USE ONLY *** +-- POLICY RELATED TABLES -- @@ -386,9 +383,9 @@ CREATE TABLE DM_DEVICE_APPLICATION_MAPPING ( 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 ( NOTIFICATION_ID INTEGER IDENTITY NOT NULL, DEVICE_ID INTEGER NOT NULL, @@ -402,8 +399,8 @@ CREATE TABLE DM_NOTIFICATION ( 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 *** +-- 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 *** \ No newline at end of file +-- 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'); \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 10c1e83114..d7ca858e09 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -396,3 +396,6 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( )ENGINE = InnoDB; -- 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'); \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index be78bc1ded..2e8333d537 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -1,6 +1,3 @@ -/* 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 ( ID NUMBER(10) NOT NULL, NAME VARCHAR2(300) DEFAULT NULL, @@ -166,7 +163,7 @@ BEGIN END; / ---- POLICY RELA... *** SQLINES FOR EVALUATION USE ONLY *** +-- POLICY RELATED TABLES --- @@ -601,9 +598,9 @@ BEGIN END; / --- POLICY RELAT... *** SQLINES FOR EVALUATION USE ONLY *** +-- POLICY RELATED TABLES FINISHED -- --- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY *** +-- NOTIFICATION TABLE -- CREATE TABLE DM_NOTIFICATION ( NOTIFICATION_ID NUMBER(10) NOT NULL, DEVICE_ID NUMBER(10) NOT NULL, @@ -628,8 +625,8 @@ BEGIN SELECT DM_NOTIFICATION_seq.NEXTVAL INTO :NEW.NOTIFICATION_ID FROM DUAL; 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 *** \ No newline at end of file +-- 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'); \ No newline at end of file From ab969c7369184bac43c0b4b72101a6f0872f5b78 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Wed, 28 Oct 2015 18:31:02 +0530 Subject: [PATCH 09/27] Refactored postgresql DB Script --- .../main/resources/dbscripts/cdm/postgres.sql | 532 +++++++----------- 1 file changed, 213 insertions(+), 319 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql index 94a24f6177..2eeef9d8d8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql @@ -1,455 +1,349 @@ -/* 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) + ID BIGSERIAL PRIMARY KEY, + NAME VARCHAR(300) DEFAULT NULL ); -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 + 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 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) + 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 + 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 + 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 + 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 + 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 + 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 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 + 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 + 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 + 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 + 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; +-- POLICY RELATED TABLES --- CREATE TABLE IF NOT EXISTS DM_PROFILE ( - ID INT NOT NULL DEFAULT NEXTVAL ('DM_PROFILE_seq') , + ID BIGSERIAL NOT NULL PRIMARY KEY, 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) , + 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 + 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') , + ID BIGSERIAL NOT NULL PRIMARY KEY, NAME VARCHAR(45) DEFAULT NULL , DESCRIPTION VARCHAR(1000) NULL, - TENANT_ID INT NOT NULL , - PROFILE_ID INT NOT NULL , + TENANT_ID INTEGER NOT NULL , + PROFILE_ID INTEGER 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) , + 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 + 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, + ID BIGSERIAL NOT NULL PRIMARY KEY, + DEVICE_ID INTEGER NOT NULL , + ENROLMENT_ID INTEGER NOT NULL, DEVICE BYTEA NOT NULL, - POLICY_ID INT NOT NULL , - PRIMARY KEY (ID) , + 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, + 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 + 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 , + 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, + 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 + 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, + 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 INT NOT NULL , + TENANT_ID INTEGER 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 + 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') , + ID BIGSERIAL NOT NULL PRIMARY KEY, ROLE_NAME VARCHAR(45) NOT NULL , - POLICY_ID INT NOT NULL , - PRIMARY KEY (ID) , + 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 + 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') , + ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_ID INT NOT NULL , - USERNAME VARCHAR(45) NOT NULL , - PRIMARY KEY (ID) , + 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 + 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 , +CREATE TABLE IF NOT EXISTS 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 INT NOT NULL, - APPLIED SMALLINT NULL , - CREATED_TIME TIMESTAMP(0) NULL , - UPDATED_TIME TIMESTAMP(0) NULL , - APPLIED_TIME TIMESTAMP(0) NULL , - PRIMARY KEY (ID) , + 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, + 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 + 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'), + ID BIGSERIAL NOT NULL PRIMARY KEY, TENANT_ID INT NOT NULL, - NAME VARCHAR(50) NULL, - PRIMARY KEY (ID) + NAME VARCHAR(50) NULL ); - - -CREATE SEQUENCE DEFAULT ; - CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( - ID INT NOT NULL DEFAULT NEXTVAL ('DM_POLICY_CRITERIA_seq'), + ID BIGSERIAL NOT NULL PRIMARY KEY, 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, + 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 + 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'), + 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 , - PRIMARY KEY (ID), + 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 + 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 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), + 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 + 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 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) + ID BIGSERIAL NOT NULL PRIMARY KEY, + POLICY_ID INTEGER NOT NULL, + DEVICE_TYPE_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL ); -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, + ID BIGSERIAL NOT NULL PRIMARY KEY, + COMPLIANCE_STATUS_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, FEATURE_CODE VARCHAR(15) NOT NULL, - STATUS INT NULL, - PRIMARY KEY (ID), + 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 + 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 + 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 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(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, - 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 + ID BIGSERIAL NOT NULL PRIMARY KEY, + NAME VARCHAR(50) 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 RELAT... *** SQLINES FOR EVALUATION USE ONLY *** - --- NOTIFICATION... *** SQLINES FOR EVALUATION USE ONLY *** -CREATE SEQUENCE P���������DM_O; +-- POLICY RELATED TABLES FINISHED -- +-- NOTIFICATION TABLE -- 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 + 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 + 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 *** +-- 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 *** \ No newline at end of file +-- 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'); \ No newline at end of file From 0b800b86153d55a28ed9b7afa24f3eca2df4396b Mon Sep 17 00:00:00 2001 From: Dilshan Edirisuriya Date: Wed, 28 Oct 2015 18:49:47 +0530 Subject: [PATCH 10/27] Bug fixes --- .../pom.xml | 2 +- .../mgt/core/impl/CertificateGenerator.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index a253cc9a7f..b4c1513c04 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -58,7 +58,7 @@ org.apache.commons.logging, javax.security.auth.x500, javax.xml.parsers, - org.apache.commons.codec.binary, + org.apache.commons.codec.binary;version="${version.commons.codec}", org.bouncycastle.asn1, org.bouncycastle.asn1.x500, org.bouncycastle.asn1.x509, diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index c97d84472d..a9c79553db 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -348,19 +348,19 @@ public class CertificateGenerator { Date validityBeginDate = commonUtil.getValidityStartDate(); Date validityEndDate = commonUtil.getValidityEndDate(); - X500Name certSubject = request.getSubject(); + X500Name certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL); Attribute attributes[] = request.getAttributes(); - if (certSubject == null) { - 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); - } - } - +// if (certSubject == null) { +// 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( new X500Name(issueSubject), CommonUtil.generateSerialNumber(), validityBeginDate, validityEndDate, certSubject, request.getSubjectPublicKeyInfo()); From bbc11321001283325dc82e99c29c666d41cf0cb6 Mon Sep 17 00:00:00 2001 From: Dilshan Edirisuriya Date: Wed, 28 Oct 2015 19:24:05 +0530 Subject: [PATCH 11/27] Commenting previous lines --- .../certificate/mgt/core/impl/CertificateGenerator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index a9c79553db..7735922f51 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -349,6 +349,8 @@ public class CertificateGenerator { Date validityEndDate = commonUtil.getValidityEndDate(); X500Name certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL); + //X500Name certSubject = request.getSubject(); + Attribute attributes[] = request.getAttributes(); // if (certSubject == null) { @@ -360,7 +362,7 @@ public class CertificateGenerator { // certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL); // } // } - + X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder( new X500Name(issueSubject), CommonUtil.generateSerialNumber(), validityBeginDate, validityEndDate, certSubject, request.getSubjectPublicKeyInfo()); From 5c2b7c9624e6a0c72f3f3edf4b72e460eaa5b310 Mon Sep 17 00:00:00 2001 From: Dilshan Edirisuriya Date: Wed, 28 Oct 2015 20:06:10 +0530 Subject: [PATCH 12/27] Removing commons codec version --- .../org.wso2.carbon.certificate.mgt.core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index b4c1513c04..a253cc9a7f 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -58,7 +58,7 @@ org.apache.commons.logging, javax.security.auth.x500, javax.xml.parsers, - org.apache.commons.codec.binary;version="${version.commons.codec}", + org.apache.commons.codec.binary, org.bouncycastle.asn1, org.bouncycastle.asn1.x500, org.bouncycastle.asn1.x509, From 79cc441c7166f1053c21440e1b864475d6d46d9f Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 28 Oct 2015 20:42:43 +0530 Subject: [PATCH 13/27] Renaming postgres.sql to postgresql.sql --- .../main/resources/dbscripts/cdm/{postgres.sql => postgresql.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/{postgres.sql => postgresql.sql} (100%) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgres.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql From 8a1dba166aad361435dcd56c5da2716042266b4b Mon Sep 17 00:00:00 2001 From: harshanl Date: Wed, 28 Oct 2015 22:09:01 +0530 Subject: [PATCH 14/27] Updated FeatureMgr spec --- .../org/wso2/carbon/device/mgt/common/FeatureManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java index 16d2f4063f..884311e935 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java @@ -24,10 +24,14 @@ public interface FeatureManager { boolean addFeature(Feature feature) throws DeviceManagementException; + boolean addFeatures(List features) throws DeviceManagementException; + Feature getFeature(String name) throws DeviceManagementException; List getFeatures() throws DeviceManagementException; boolean removeFeature(String name) throws DeviceManagementException; + boolean addSupportedFeaturesToDB() throws DeviceManagementException; + } From 0282cff5b36746ee16c3d88d01c73b6d7d5d333c Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 28 Oct 2015 22:39:47 +0530 Subject: [PATCH 15/27] Adding missing auto_increment declaration in DEVICE_TYPE table config and script clean up --- .../src/main/resources/dbscripts/cdm/mssql.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/mysql.sql | 14 +++++++------- .../src/main/resources/dbscripts/cdm/oracle.sql | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index 5ddcee39fd..3e528bbbaa 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -2,7 +2,7 @@ /* OBTAIN A LICENSE AT WWW.SQLINES.COM FOR FULL CONVERSION. THANK YOU. */ CREATE TABLE DM_DEVICE_TYPE ( - ID INT identity NOT NULL, + ID INT IDENTITY NOT NULL, NAME VARCHAR(300) DEFAULT NULL, PRIMARY KEY (ID) ); @@ -406,4 +406,4 @@ CREATE TABLE DM_NOTIFICATION ( -- TO:DO - Remo... *** SQLINES FOR EVALUATION USE ONLY *** --Insert into D... *** SQLINES FOR EVALUATION USE ONLY *** ---Insert into D... *** SQLINES FOR EVALUATION USE ONLY *** \ No newline at end of file +--Insert into D... *** SQLINES FOR EVALUATION USE ONLY *** diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index eb887f68c6..56bf241c20 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -2,8 +2,8 @@ -- Table `DM_DEVICE_TYPE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` ( - `ID` INT(11) NOT NULL , - `NAME` VARCHAR(300) DEFAULT NULL , + `ID` INT(11) NOT NULL AUTO_INCREMENT, + `NAME` VARCHAR(300) NOT NULL , PRIMARY KEY (`ID`) ) ENGINE = InnoDB DEFAULT CHARACTER SET = latin1; @@ -13,12 +13,12 @@ DEFAULT CHARACTER SET = latin1; -- Table `DM_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `DM_DEVICE` ( - `ID` VARCHAR(20) NOT NULL , + `ID` VARCHAR(20) NOT NULL AUTO_INCREMENT , `DESCRIPTION` TEXT DEFAULT NULL , - `NAME` VARCHAR(100) DEFAULT NULL , - `DEVICE_TYPE_ID` INT(11) DEFAULT NULL , - `DEVICE_IDENTIFICATION` VARCHAR(300) DEFAULT NULL , - `TENANT_ID` INTEGER DEFAULT 0, + `NAME` VARCHAR(100) NOT NULL , + `DEVICE_TYPE_ID` INT(11) NOT NULL , + `DEVICE_IDENTIFICATION` VARCHAR(300) NOT NULL , + `TENANT_ID` INTEGER NOT NULL, PRIMARY KEY (`ID`) , INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) , CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2` diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 2982217eec..ef8909f917 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -2,7 +2,7 @@ /* OBTAIN A LICENSE AT WWW.SQLINES.COM FOR FULL CONVERSION. THANK YOU. */ CREATE TABLE DM_DEVICE_TYPE ( - ID NUMBER(10) NOT NULL, + ID NUMBER(10) NOT NULL, NAME VARCHAR2(300) DEFAULT NULL, PRIMARY KEY (ID) ); @@ -632,4 +632,4 @@ 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 *** \ No newline at end of file +--Insert into D... *** SQLINES FOR EVALUATION USE ONLY *** From 3de4718ab517d37d3c3e1640fe46d1e12ad13771 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 29 Oct 2015 10:04:13 +0530 Subject: [PATCH 16/27] refactored certificate generator --- .../mgt/core/impl/CertificateGenerator.java | 23 ++++++------------- .../CertificateManagementServiceImpl.java | 1 - pom.xml | 2 +- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index 1bb973e76d..cda449e1ab 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -43,7 +43,6 @@ import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.pkcs.PKCS10CertificationRequest; -import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest; import org.bouncycastle.util.Store; import org.jscep.message.*; import org.jscep.transaction.FailInfo; @@ -70,20 +69,6 @@ import java.util.List; public class CertificateGenerator { - private enum PropertyIndex { - COMMON_NAME_INDEX(0), - NOT_BEFORE_DAYS_INDEX(1), - NOT_AFTER_DAYS_INDEX(2); - - private final int itemPosition; - private PropertyIndex(final int itemPosition) { - this.itemPosition = itemPosition; - } - public int getValue() { - return this.itemPosition; - } - } - private static final Log log = LogFactory.getLog(CertificateGenerator.class); public List getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException { @@ -584,6 +569,13 @@ public class CertificateGenerator { 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); @@ -599,7 +591,6 @@ public class CertificateGenerator { log.error(msg, e); throw new KeystoreException(msg, e); } - JcaPKCS10CertificationRequest csr = new JcaPKCS10CertificationRequest(certificationRequest); X509Certificate signedCertificate = generateCertificateFromCSR(privateKeyCA, certificationRequest, certCA.getIssuerX500Principal().getName()); return signedCertificate; diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java index 6ac4ee9192..77dfe1686c 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java @@ -101,7 +101,6 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe return certificateGenerator.extractChallengeToken(certificate); } - @Override public X509Certificate getSignedCertificateFromCSR(String binarySecurityToken) throws KeystoreException { return certificateGenerator.getSignedCertificateFromCSR(binarySecurityToken); } diff --git a/pom.xml b/pom.xml index 316508d24c..40d1b95b4b 100644 --- a/pom.xml +++ b/pom.xml @@ -1427,7 +1427,7 @@ 6.1.1 - 4.4.2 + 4.4.1 1.5.4 1.3 From 1b62efebc5908c9734240222d779b0695bd733ea Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Thu, 29 Oct 2015 10:36:55 +0530 Subject: [PATCH 17/27] Renamed SQL Table 'DM_ENROLMENT_OPERATION_MAPPING' to 'DM_ENROLMENT_OP_MAPPING' --- .../mgt/dao/impl/CommandOperationDAOImpl.java | 2 +- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 2 +- .../mgt/dao/impl/OperationDAOImpl.java | 12 +-- .../mgt/dao/impl/OperationMappingDAOImpl.java | 4 +- .../mgt/dao/impl/PolicyOperationDAOImpl.java | 2 +- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 2 +- .../src/test/resources/sql/h2.sql | 2 +- .../src/test/resources/sql/CreateH2TestDB.sql | 2 +- .../src/main/resources/dbscripts/cdm/h2.sql | 2 +- .../main/resources/dbscripts/cdm/mssql.sql | 2 +- .../main/resources/dbscripts/cdm/mysql.sql | 2 +- .../main/resources/dbscripts/cdm/oracle.sql | 10 +-- .../resources/dbscripts/cdm/postgresql.sql | 87 ++++++++++++------- 13 files changed, 76 insertions(+), 55 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index f485408d67..d65835a760 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -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, " + "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_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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 7d62fa8d79..be3b1ab788 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -164,7 +164,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl { try { Connection conn = OperationManagementDAOFactory.getConnection(); 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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java index 3608d11be7..7908dc63a8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java @@ -87,7 +87,7 @@ public class OperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; try { 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=?"); stmt.setString(1, status.toString()); 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 " + " FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + "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 "; stmt = conn.prepareStatement(sql); stmt.setInt(1, operationId); @@ -243,7 +243,7 @@ public class OperationDAOImpl implements OperationDAO { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, 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 ORDER BY o.CREATED_TIMESTAMP ASC"; stmt = conn.prepareStatement(sql); stmt.setInt(1, enrolmentId); @@ -283,7 +283,7 @@ public class OperationDAOImpl implements OperationDAO { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + "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"; stmt = conn.prepareStatement(sql); stmt.setInt(1, enrolmentId); @@ -320,7 +320,7 @@ public class OperationDAOImpl implements OperationDAO { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + "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 " + "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); 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 " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java index 9f69b1a6f5..71de8548be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java @@ -35,7 +35,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { PreparedStatement stmt = null; try { 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.setInt(1, deviceId); stmt.setInt(2, operationId); @@ -54,7 +54,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { PreparedStatement stmt = null; try { 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.setInt(1, 0); stmt.setInt(2, operationId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java index 4f501bb8a6..07c6112bd6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java @@ -164,7 +164,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl { try { Connection conn = OperationManagementDAOFactory.getConnection(); 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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index 56da664251..664ac370da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -167,7 +167,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " + "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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 8919ac5441..0eaa54a00f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 6af5c86031..9f488a8694 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 42ee0a0df1..f8c2fc8e80 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index b0962b5085..cc5d0b13c1 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -73,7 +73,7 @@ CREATE TABLE DM_ENROLMENT ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 02cfd0d31e..d4419bc3ff 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -81,7 +81,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( )ENGINE = InnoDB; -CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( +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, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index c369bf0149..7917fdaf87 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -117,7 +117,7 @@ BEGIN END; / -CREATE TABLE DM_ENROLMENT_OPERATION_MAPPING ( +CREATE TABLE DM_ENROLMENT_OP_MAPPING ( ID NUMBER(10) NOT NULL, ENROLMENT_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL, @@ -130,13 +130,13 @@ CREATE TABLE DM_ENROLMENT_OPERATION_MAPPING ( ); -- 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 - BEFORE INSERT ON DM_ENROLMENT_OPERATION_MAPPING FOR EACH ROW +CREATE OR REPLACE TRIGGER DM_ENROLMENT_OP_MAPPING_seq_tr + BEFORE INSERT ON DM_ENROLMENT_OP_MAPPING FOR EACH ROW WHEN (NEW.ID IS NULL) 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; / diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 2eeef9d8d8..91ac1c8d8e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -1,9 +1,11 @@ -CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( +DROP TABLE IF EXISTS DM_DEVICE_TYPE; +CREATE TABLE DM_DEVICE_TYPE ( ID BIGSERIAL PRIMARY KEY, NAME VARCHAR(300) DEFAULT NULL ); -CREATE TABLE IF NOT EXISTS DM_DEVICE ( +DROP TABLE IF EXISTS DM_DEVICE; +CREATE TABLE DM_DEVICE ( ID BIGSERIAL NOT NULL PRIMARY KEY, DESCRIPTION TEXT DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL, @@ -14,7 +16,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_OPERATION ( +DROP TABLE IF EXISTS DM_OPERATION; +CREATE TABLE DM_OPERATION ( ID BIGSERIAL NOT NULL PRIMARY KEY, TYPE VARCHAR(50) NOT NULL, CREATED_TIMESTAMP TIMESTAMP NOT NULL, @@ -22,7 +25,8 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( OPERATION_CODE VARCHAR(1000) NOT NULL ); -CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( +DROP TABLE IF EXISTS DM_CONFIG_OPERATION; +CREATE TABLE DM_CONFIG_OPERATION ( OPERATION_ID INTEGER NOT NULL, OPERATION_CONFIG BYTEA DEFAULT NULL, PRIMARY KEY (OPERATION_ID), @@ -30,7 +34,8 @@ CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( +DROP TABLE IF EXISTS DM_COMMAND_OPERATION; +CREATE TABLE DM_COMMAND_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (OPERATION_ID), @@ -38,7 +43,8 @@ CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( +DROP TABLE IF EXISTS DM_POLICY_OPERATION; +CREATE TABLE DM_POLICY_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED INTEGER NOT NULL DEFAULT 0, OPERATION_DETAILS BYTEA DEFAULT NULL, @@ -47,7 +53,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( +DROP TABLE IF EXISTS DM_PROFILE_OPERATION; +CREATE TABLE DM_PROFILE_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED INTEGER NOT NULL DEFAULT 0, OPERATION_DETAILS BYTEA DEFAULT NULL, @@ -56,7 +63,8 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( +DROP TABLE IF EXISTS DM_ENROLMENT; +CREATE TABLE DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OWNER VARCHAR(50) NOT NULL, @@ -69,7 +77,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( +DROP TABLE IF EXISTS DM_ENROLMENT_OP_MAPPING; +CREATE TABLE DM_ENROLMENT_OP_MAPPING ( ID BIGSERIAL NOT NULL PRIMARY KEY, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, @@ -80,7 +89,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( +DROP TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE; +CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, @@ -93,7 +103,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( -- POLICY RELATED TABLES --- -CREATE TABLE IF NOT EXISTS DM_PROFILE ( +DROP TABLE IF EXISTS DM_PROFILE; +CREATE TABLE DM_PROFILE ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INTEGER NOT NULL , @@ -107,8 +118,8 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ON UPDATE NO ACTION ); - -CREATE TABLE IF NOT EXISTS DM_POLICY ( +DROP TABLE IF EXISTS DM_POLICY; +CREATE TABLE DM_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, NAME VARCHAR(45) DEFAULT NULL , DESCRIPTION VARCHAR(1000) NULL, @@ -126,7 +137,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( +DROP TABLE IF EXISTS DM_DEVICE_POLICY; +CREATE TABLE DM_DEVICE_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL , ENROLMENT_ID INTEGER NOT NULL, @@ -144,7 +156,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( +DROP TABLE IF EXISTS DM_DEVICE_TYPE_POLICY; +CREATE TABLE DM_DEVICE_TYPE_POLICY ( ID INTEGER NOT NULL, DEVICE_TYPE_ID INTEGER NOT NULL , POLICY_ID INTEGER NOT NULL , @@ -161,7 +174,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( +DROP TABLE IF EXISTS DM_PROFILE_FEATURES; +CREATE TABLE DM_PROFILE_FEATURES ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_ID INTEGER NOT NULL, FEATURE_CODE VARCHAR(30) NOT NULL, @@ -175,7 +189,8 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( +DROP TABLE IF EXISTS DM_ROLE_POLICY; +CREATE TABLE DM_ROLE_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, ROLE_NAME VARCHAR(45) NOT NULL , POLICY_ID INTEGER NOT NULL, @@ -186,7 +201,8 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( +DROP TABLE IF EXISTS DM_USER_POLICY; +CREATE TABLE DM_USER_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_ID INT NOT NULL , USERNAME VARCHAR(45) NOT NULL, @@ -197,7 +213,8 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( +DROP TABLE IF EXISTS DM_DEVICE_POLICY_APPLIED; +CREATE TABLE DM_DEVICE_POLICY_APPLIED ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL , ENROLMENT_ID INTEGER NOT NULL, @@ -220,13 +237,15 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_CRITERIA ( +DROP TABLE IF EXISTS DM_CRITERIA; +CREATE TABLE 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 ( +DROP TABLE IF EXISTS DM_POLICY_CRITERIA; +CREATE TABLE DM_POLICY_CRITERIA ( ID BIGSERIAL NOT NULL PRIMARY KEY, CRITERIA_ID INT NOT NULL, POLICY_ID INT NOT NULL, @@ -242,7 +261,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( +DROP TABLE IF EXISTS DM_POLICY_CRITERIA_PROPERTIES; +CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES ( ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_CRITERION_ID INT NOT NULL, PROP_KEY VARCHAR(45) NULL, @@ -256,8 +276,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( ); COMMENT ON COLUMN DM_POLICY_CRITERIA_PROPERTIES.CONTENT IS 'This is used to '; - -CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( +DROP TABLE IF EXISTS DM_POLICY_COMPLIANCE_STATUS; +CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -276,16 +296,16 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( ); CREATE UNIQUE INDEX DEVICE_ID_UNIQUE ON DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID ASC); - -CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( +DROP TABLE IF EXISTS DM_POLICY_CHANGE_MGT; +CREATE TABLE 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 ( +DROP TABLE IF EXISTS DM_POLICY_COMPLIANCE_FEATURES; +CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES ( ID BIGSERIAL NOT NULL PRIMARY KEY, COMPLIANCE_STATUS_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL, @@ -298,8 +318,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); - -CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( +DROP TABLE IF EXISTS DM_ENROLMENT; +CREATE TABLE DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OWNER VARCHAR(50) NOT NULL, @@ -312,8 +332,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); - -CREATE TABLE IF NOT EXISTS DM_APPLICATION ( +DROP TABLE IF EXISTS DM_APPLICATION; +CREATE TABLE DM_APPLICATION ( ID BIGSERIAL NOT NULL PRIMARY KEY, NAME VARCHAR(50) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL, @@ -330,7 +350,8 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( -- POLICY RELATED TABLES FINISHED -- -- NOTIFICATION TABLE -- -CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( +DROP TABLE IF EXISTS DM_NOTIFICATION; +CREATE TABLE DM_NOTIFICATION ( NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, From fb3e7f4c33994c79cad71f3f5506500a875abae8 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 29 Oct 2015 10:49:19 +0530 Subject: [PATCH 18/27] Fixing issues encountered in CDM-F core database schema --- .../main/resources/dbscripts/cdm/mysql.sql | 26 +++++++++---------- .../main/resources/dbscripts/cdm/oracle.sql | 3 --- .../resources/dbscripts/cdm/postgresql.sql | 3 --- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 02cfd0d31e..e0b9135f24 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -1,19 +1,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( - ID INT auto_increment NOT NULL, + ID INTEGER AUTO_INCREMENT NOT NULL, NAME VARCHAR(300) DEFAULT NULL, PRIMARY KEY (ID) )ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_DEVICE ( - ID INTEGER auto_increment NOT NULL, + ID INTEGER AUTO_INCREMENT NOT NULL, DESCRIPTION TEXT DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL, DEVICE_TYPE_ID INT(11) 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 ) + 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 )ENGINE = InnoDB; @@ -32,7 +32,7 @@ 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 + CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -41,7 +41,7 @@ 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 + CONSTRAINT FK_DM_OPERATION_COMMAND FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( 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 + CONSTRAINT FK_DM_OPERATION_POLICY FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -61,7 +61,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( 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 + CONSTRAINT FK_DM_OPERATION_PROFILE FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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 + CONSTRAINT FK_DM_DEVICE_ENROLMENT FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -378,9 +378,10 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; --- POLICY RELATED TABLES FINISHED -- +-- END OF POLICY RELATED TABLES -- + +-- NOTIFICATION TABLES -- --- NOTIFICATION TABLE -- CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, @@ -394,9 +395,6 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; --- 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'); +-- END NOTIFICATION TABLES -- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index c369bf0149..0b82e2e525 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -627,7 +627,4 @@ 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'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 2eeef9d8d8..ac0eef4f66 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -344,6 +344,3 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( ); -- 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'); \ No newline at end of file From 935455f7005f259dbf625fa74b8aa70465a1d7d2 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Thu, 29 Oct 2015 11:46:49 +0530 Subject: [PATCH 19/27] Refactored postgresql.sql DB script --- .../resources/dbscripts/cdm/postgresql.sql | 65 ++++++------------- 1 file changed, 19 insertions(+), 46 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 91ac1c8d8e..421a4b9cbd 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -1,11 +1,9 @@ -DROP TABLE IF EXISTS DM_DEVICE_TYPE; -CREATE TABLE DM_DEVICE_TYPE ( +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID BIGSERIAL PRIMARY KEY, NAME VARCHAR(300) DEFAULT NULL ); -DROP TABLE IF EXISTS DM_DEVICE; -CREATE TABLE DM_DEVICE ( +CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID BIGSERIAL NOT NULL PRIMARY KEY, DESCRIPTION TEXT DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL, @@ -16,8 +14,7 @@ CREATE TABLE DM_DEVICE ( REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_OPERATION; -CREATE TABLE DM_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID BIGSERIAL NOT NULL PRIMARY KEY, TYPE VARCHAR(50) NOT NULL, CREATED_TIMESTAMP TIMESTAMP NOT NULL, @@ -25,8 +22,7 @@ CREATE TABLE DM_OPERATION ( OPERATION_CODE VARCHAR(1000) NOT NULL ); -DROP TABLE IF EXISTS DM_CONFIG_OPERATION; -CREATE TABLE DM_CONFIG_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( OPERATION_ID INTEGER NOT NULL, OPERATION_CONFIG BYTEA DEFAULT NULL, PRIMARY KEY (OPERATION_ID), @@ -34,8 +30,7 @@ CREATE TABLE DM_CONFIG_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_COMMAND_OPERATION; -CREATE TABLE DM_COMMAND_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (OPERATION_ID), @@ -43,8 +38,7 @@ CREATE TABLE DM_COMMAND_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_POLICY_OPERATION; -CREATE TABLE DM_POLICY_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED INTEGER NOT NULL DEFAULT 0, OPERATION_DETAILS BYTEA DEFAULT NULL, @@ -53,8 +47,7 @@ CREATE TABLE DM_POLICY_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_PROFILE_OPERATION; -CREATE TABLE DM_PROFILE_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED INTEGER NOT NULL DEFAULT 0, OPERATION_DETAILS BYTEA DEFAULT NULL, @@ -63,8 +56,7 @@ CREATE TABLE DM_PROFILE_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_ENROLMENT; -CREATE TABLE DM_ENROLMENT ( +CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OWNER VARCHAR(50) NOT NULL, @@ -77,8 +69,7 @@ CREATE TABLE DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_ENROLMENT_OP_MAPPING; -CREATE TABLE DM_ENROLMENT_OP_MAPPING ( +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, @@ -89,8 +80,7 @@ CREATE TABLE DM_ENROLMENT_OP_MAPPING ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE; -CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( +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, @@ -103,7 +93,6 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( -- POLICY RELATED TABLES --- -DROP TABLE IF EXISTS DM_PROFILE; CREATE TABLE DM_PROFILE ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_NAME VARCHAR(45) NOT NULL , @@ -118,7 +107,6 @@ CREATE TABLE DM_PROFILE ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_POLICY; CREATE TABLE DM_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, NAME VARCHAR(45) DEFAULT NULL , @@ -137,7 +125,6 @@ CREATE TABLE DM_POLICY ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_DEVICE_POLICY; CREATE TABLE DM_DEVICE_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL , @@ -156,7 +143,6 @@ CREATE TABLE DM_DEVICE_POLICY ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_DEVICE_TYPE_POLICY; CREATE TABLE DM_DEVICE_TYPE_POLICY ( ID INTEGER NOT NULL, DEVICE_TYPE_ID INTEGER NOT NULL , @@ -174,7 +160,6 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_PROFILE_FEATURES; CREATE TABLE DM_PROFILE_FEATURES ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_ID INTEGER NOT NULL, @@ -189,7 +174,6 @@ CREATE TABLE DM_PROFILE_FEATURES ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_ROLE_POLICY; CREATE TABLE DM_ROLE_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, ROLE_NAME VARCHAR(45) NOT NULL , @@ -201,7 +185,6 @@ CREATE TABLE DM_ROLE_POLICY ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_USER_POLICY; CREATE TABLE DM_USER_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_ID INT NOT NULL , @@ -213,7 +196,6 @@ CREATE TABLE DM_USER_POLICY ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_DEVICE_POLICY_APPLIED; CREATE TABLE DM_DEVICE_POLICY_APPLIED ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL , @@ -237,15 +219,13 @@ CREATE TABLE DM_DEVICE_POLICY_APPLIED ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_CRITERIA; -CREATE TABLE DM_CRITERIA ( +CREATE TABLE IF NOT EXISTS DM_CRITERIA ( ID BIGSERIAL NOT NULL PRIMARY KEY, TENANT_ID INT NOT NULL, NAME VARCHAR(50) NULL ); -DROP TABLE IF EXISTS DM_POLICY_CRITERIA; -CREATE TABLE DM_POLICY_CRITERIA ( +CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( ID BIGSERIAL NOT NULL PRIMARY KEY, CRITERIA_ID INT NOT NULL, POLICY_ID INT NOT NULL, @@ -261,8 +241,7 @@ CREATE TABLE DM_POLICY_CRITERIA ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_POLICY_CRITERIA_PROPERTIES; -CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES ( +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, @@ -276,8 +255,7 @@ CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES ( ); COMMENT ON COLUMN DM_POLICY_CRITERIA_PROPERTIES.CONTENT IS 'This is used to '; -DROP TABLE IF EXISTS DM_POLICY_COMPLIANCE_STATUS; -CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( +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, @@ -296,16 +274,14 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( ); CREATE UNIQUE INDEX DEVICE_ID_UNIQUE ON DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID ASC); -DROP TABLE IF EXISTS DM_POLICY_CHANGE_MGT; -CREATE TABLE DM_POLICY_CHANGE_MGT ( +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 ); -DROP TABLE IF EXISTS DM_POLICY_COMPLIANCE_FEATURES; -CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES ( +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, @@ -318,8 +294,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_ENROLMENT; -CREATE TABLE DM_ENROLMENT ( +CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OWNER VARCHAR(50) NOT NULL, @@ -332,8 +307,7 @@ CREATE TABLE DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -DROP TABLE IF EXISTS DM_APPLICATION; -CREATE TABLE DM_APPLICATION ( +CREATE TABLE IF NOT EXISTS DM_APPLICATION ( ID BIGSERIAL NOT NULL PRIMARY KEY, NAME VARCHAR(50) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL, @@ -350,8 +324,7 @@ CREATE TABLE DM_APPLICATION ( -- POLICY RELATED TABLES FINISHED -- -- NOTIFICATION TABLE -- -DROP TABLE IF EXISTS DM_NOTIFICATION; -CREATE TABLE DM_NOTIFICATION ( +CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, From abe49b57d01e5a44f589655bb0ceb920060aa67e Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Thu, 29 Oct 2015 12:33:38 +0530 Subject: [PATCH 20/27] Refactored CDM sql scripts --- .../src/main/resources/dbscripts/cdm/h2.sql | 3 --- .../src/main/resources/dbscripts/cdm/mssql.sql | 3 --- .../src/main/resources/dbscripts/cdm/mysql.sql | 5 ----- .../src/main/resources/dbscripts/cdm/oracle.sql | 3 --- .../src/main/resources/dbscripts/cdm/postgresql.sql | 6 +----- 5 files changed, 1 insertion(+), 19 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index f8c2fc8e80..1959c2f241 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -398,6 +398,3 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( ); -- 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'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index cc5d0b13c1..118895e81c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -401,7 +401,4 @@ CREATE TABLE DM_NOTIFICATION ( ); -- 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'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index d4419bc3ff..0e3f18db85 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -395,8 +395,3 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; -- 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'); - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 7917fdaf87..fa522c3dc7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -627,7 +627,4 @@ 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'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 421a4b9cbd..8e60325b70 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -336,8 +336,4 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); --- 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'); \ No newline at end of file +-- NOTIFICATION TABLE END -- \ No newline at end of file From 5ec27d989fd2bddadfa3f474b2e814d7c39edba5 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 29 Oct 2015 14:02:21 +0530 Subject: [PATCH 21/27] Removing unnecessary INSERT statements found in device management schema --- .../src/main/resources/dbscripts/cdm/h2.sql | 3 --- .../src/main/resources/dbscripts/cdm/mssql.sql | 4 ---- 2 files changed, 7 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 42ee0a0df1..f0c0e17f1a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -398,6 +398,3 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( ); -- 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'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index b0962b5085..de4c58d2df 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -401,7 +401,3 @@ CREATE TABLE DM_NOTIFICATION ( ); -- 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'); - From 90240e7d3fccf1f96a52ce4fc0c6c9142ef9b637 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 29 Oct 2015 14:11:24 +0530 Subject: [PATCH 22/27] Merging https://github.com/wso2/carbon-device-mgt/pull/40 and resolving conflicts --- .../mgt/dao/impl/CommandOperationDAOImpl.java | 2 +- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 2 +- .../mgt/dao/impl/OperationDAOImpl.java | 12 ++-- .../mgt/dao/impl/OperationMappingDAOImpl.java | 4 +- .../mgt/dao/impl/PolicyOperationDAOImpl.java | 2 +- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 2 +- .../src/test/resources/sql/h2.sql | 2 +- .../src/test/resources/sql/CreateH2TestDB.sql | 2 +- .../src/main/resources/dbscripts/cdm/h2.sql | 2 +- .../main/resources/dbscripts/cdm/mssql.sql | 2 +- .../main/resources/dbscripts/cdm/mysql.sql | 3 +- .../main/resources/dbscripts/cdm/oracle.sql | 10 +-- .../resources/dbscripts/cdm/postgresql.sql | 62 +++++++++---------- 13 files changed, 50 insertions(+), 57 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index f485408d67..d65835a760 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -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, " + "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_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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 7d62fa8d79..be3b1ab788 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -164,7 +164,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl { try { Connection conn = OperationManagementDAOFactory.getConnection(); 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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java index 3608d11be7..7908dc63a8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java @@ -87,7 +87,7 @@ public class OperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; try { 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=?"); stmt.setString(1, status.toString()); 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 " + " FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + "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 "; stmt = conn.prepareStatement(sql); stmt.setInt(1, operationId); @@ -243,7 +243,7 @@ public class OperationDAOImpl implements OperationDAO { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, 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 ORDER BY o.CREATED_TIMESTAMP ASC"; stmt = conn.prepareStatement(sql); stmt.setInt(1, enrolmentId); @@ -283,7 +283,7 @@ public class OperationDAOImpl implements OperationDAO { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + "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"; stmt = conn.prepareStatement(sql); stmt.setInt(1, enrolmentId); @@ -320,7 +320,7 @@ public class OperationDAOImpl implements OperationDAO { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + "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 " + "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); 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 " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java index 9f69b1a6f5..71de8548be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java @@ -35,7 +35,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { PreparedStatement stmt = null; try { 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.setInt(1, deviceId); stmt.setInt(2, operationId); @@ -54,7 +54,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { PreparedStatement stmt = null; try { 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.setInt(1, 0); stmt.setInt(2, operationId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java index 4f501bb8a6..07c6112bd6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java @@ -164,7 +164,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl { try { Connection conn = OperationManagementDAOFactory.getConnection(); 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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index 56da664251..664ac370da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -167,7 +167,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " + "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"; stmt = conn.prepareStatement(sql); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 8919ac5441..0eaa54a00f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 6af5c86031..9f488a8694 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index f0c0e17f1a..1959c2f241 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index de4c58d2df..7e824bfd95 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -73,7 +73,7 @@ CREATE TABLE DM_ENROLMENT ( 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, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index e0b9135f24..a8a64597d6 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -81,7 +81,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( )ENGINE = InnoDB; -CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( +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, @@ -397,4 +397,3 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( )ENGINE = InnoDB; -- END NOTIFICATION TABLES -- - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 0b82e2e525..fa522c3dc7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -117,7 +117,7 @@ BEGIN END; / -CREATE TABLE DM_ENROLMENT_OPERATION_MAPPING ( +CREATE TABLE DM_ENROLMENT_OP_MAPPING ( ID NUMBER(10) NOT NULL, ENROLMENT_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL, @@ -130,13 +130,13 @@ CREATE TABLE DM_ENROLMENT_OPERATION_MAPPING ( ); -- 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 - BEFORE INSERT ON DM_ENROLMENT_OPERATION_MAPPING FOR EACH ROW +CREATE OR REPLACE TRIGGER DM_ENROLMENT_OP_MAPPING_seq_tr + BEFORE INSERT ON DM_ENROLMENT_OP_MAPPING FOR EACH ROW WHEN (NEW.ID IS NULL) 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; / diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index ac0eef4f66..9e6ecafa39 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -1,9 +1,9 @@ -CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID BIGSERIAL PRIMARY KEY, NAME VARCHAR(300) DEFAULT NULL ); -CREATE TABLE IF NOT EXISTS DM_DEVICE ( +CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID BIGSERIAL NOT NULL PRIMARY KEY, DESCRIPTION TEXT DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL, @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID BIGSERIAL NOT NULL PRIMARY KEY, TYPE VARCHAR(50) NOT NULL, CREATED_TIMESTAMP TIMESTAMP NOT NULL, @@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( OPERATION_CODE VARCHAR(1000) NOT NULL ); -CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( OPERATION_ID INTEGER NOT NULL, OPERATION_CONFIG BYTEA DEFAULT NULL, PRIMARY KEY (OPERATION_ID), @@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (OPERATION_ID), @@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED INTEGER NOT NULL DEFAULT 0, OPERATION_DETAILS BYTEA DEFAULT NULL, @@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( +CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( OPERATION_ID INTEGER NOT NULL, ENABLED INTEGER NOT NULL DEFAULT 0, OPERATION_DETAILS BYTEA DEFAULT NULL, @@ -56,7 +56,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( +CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OWNER VARCHAR(50) NOT NULL, @@ -69,7 +69,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( 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 BIGSERIAL NOT NULL PRIMARY KEY, ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, @@ -80,7 +80,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( +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, @@ -93,7 +93,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( -- POLICY RELATED TABLES --- -CREATE TABLE IF NOT EXISTS DM_PROFILE ( +CREATE TABLE DM_PROFILE ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INTEGER NOT NULL , @@ -107,8 +107,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ON UPDATE NO ACTION ); - -CREATE TABLE IF NOT EXISTS DM_POLICY ( +CREATE TABLE DM_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, NAME VARCHAR(45) DEFAULT NULL , DESCRIPTION VARCHAR(1000) NULL, @@ -126,7 +125,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( +CREATE TABLE DM_DEVICE_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL , ENROLMENT_ID INTEGER NOT NULL, @@ -144,7 +143,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( +CREATE TABLE DM_DEVICE_TYPE_POLICY ( ID INTEGER NOT NULL, DEVICE_TYPE_ID INTEGER NOT NULL , POLICY_ID INTEGER NOT NULL , @@ -161,7 +160,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( +CREATE TABLE DM_PROFILE_FEATURES ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_ID INTEGER NOT NULL, FEATURE_CODE VARCHAR(30) NOT NULL, @@ -175,7 +174,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( +CREATE TABLE DM_ROLE_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, ROLE_NAME VARCHAR(45) NOT NULL , POLICY_ID INTEGER NOT NULL, @@ -186,7 +185,7 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( +CREATE TABLE DM_USER_POLICY ( ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_ID INT NOT NULL , USERNAME VARCHAR(45) NOT NULL, @@ -197,7 +196,7 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( +CREATE TABLE DM_DEVICE_POLICY_APPLIED ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL , ENROLMENT_ID INTEGER NOT NULL, @@ -220,13 +219,13 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_CRITERIA ( +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 ( +CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( ID BIGSERIAL NOT NULL PRIMARY KEY, CRITERIA_ID INT NOT NULL, POLICY_ID INT NOT NULL, @@ -242,7 +241,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( +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, @@ -256,8 +255,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( ); COMMENT ON COLUMN DM_POLICY_CRITERIA_PROPERTIES.CONTENT IS 'This is used to '; - -CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( +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, @@ -276,16 +274,14 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( ); CREATE UNIQUE INDEX DEVICE_ID_UNIQUE ON DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID ASC); - -CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( +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 ( +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, @@ -298,8 +294,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); - -CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( +CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OWNER VARCHAR(50) NOT NULL, @@ -312,8 +307,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); - -CREATE TABLE IF NOT EXISTS DM_APPLICATION ( +CREATE TABLE IF NOT EXISTS DM_APPLICATION ( ID BIGSERIAL NOT NULL PRIMARY KEY, NAME VARCHAR(50) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL, @@ -330,7 +324,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( -- POLICY RELATED TABLES FINISHED -- -- NOTIFICATION TABLE -- -CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( +CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, @@ -342,5 +336,5 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); --- NOTIFICATION TABLE END -- +-- NOTIFICATION TABLE END -- \ No newline at end of file From 7c0996270f363b30c1240df29a5a0241c4447d3d Mon Sep 17 00:00:00 2001 From: harshanl Date: Thu, 29 Oct 2015 17:53:09 +0530 Subject: [PATCH 23/27] Fixed EMM-887 --- .../DynamicClientRegistrationServiceImpl.java | 4 ++-- .../DynamicClientWebAppRegistrationManager.java | 12 ++++++------ .../DynamicClientWebAppRegistrationUtil.java | 2 +- .../authenticator/OAuthAuthenticator.java | 16 ++++++---------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationServiceImpl.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationServiceImpl.java index 0679b5f1e2..859a0d8c55 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationServiceImpl.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.registration/src/main/java/org/wso2/carbon/dynamic/client/registration/impl/DynamicClientRegistrationServiceImpl.java @@ -123,7 +123,7 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist boolean isSaaSApp = profile.isSaasApp(); String audience = profile.getAudience(); String assertionConsumerURL = profile.getAssertionConsumerURL(); - String recepientValidationURL = profile.getRecepientValidationURL(); + String recipientValidationURL = profile.getRecepientValidationURL(); if (userId == null || userId.isEmpty()) { return null; @@ -223,7 +223,7 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist samlssoServiceProviderDTO.setDoSignResponse(true); samlssoServiceProviderDTO.setRequestedAudiences(new String[] { audience }); samlssoServiceProviderDTO.setDefaultAssertionConsumerUrl(assertionConsumerURL); - samlssoServiceProviderDTO.setRequestedRecipients(new String[] {recepientValidationURL}); + samlssoServiceProviderDTO.setRequestedRecipients(new String[] {recipientValidationURL}); samlssoServiceProviderDTO.setDoSignAssertions(true); diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicClientWebAppRegistrationManager.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicClientWebAppRegistrationManager.java index fbb6023251..14e2ca00b6 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicClientWebAppRegistrationManager.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/DynamicClientWebAppRegistrationManager.java @@ -117,7 +117,7 @@ public class DynamicClientWebAppRegistrationManager { } public void initiateDynamicClientRegistration() { - String requiredDynamicClientRegistration, webAppName; + String requiredDynamicClientRegistration, webAppName, serviceProviderName; ServletContext servletContext; RegistrationProfile registrationProfile; OAuthAppDetails oAuthAppDetails; @@ -131,15 +131,15 @@ public class DynamicClientWebAppRegistrationManager { while (enumeration.hasMoreElements()) { oAuthAppDetails = new OAuthAppDetails(); webAppName = (String) enumeration.nextElement(); + serviceProviderName = DynamicClientWebAppRegistrationUtil.getUserName() + "_" + webAppName; servletContext = DynamicClientWebAppRegistrationManager.webAppContexts.get(webAppName); requiredDynamicClientRegistration = servletContext.getInitParameter( DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG); //Java web-app section - if ((requiredDynamicClientRegistration != null) && (Boolean. - parseBoolean( - requiredDynamicClientRegistration))) { + if ((requiredDynamicClientRegistration != null) && (Boolean.parseBoolean( + requiredDynamicClientRegistration))) { //Check whether this is an already registered application - if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { + if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) { //Construct the RegistrationProfile registrationProfile = DynamicClientWebAppRegistrationUtil. constructRegistrationProfile(servletContext, webAppName); @@ -155,7 +155,7 @@ public class DynamicClientWebAppRegistrationManager { JaggeryOAuthConfigurationSettings jaggeryOAuthConfigurationSettings = DynamicClientWebAppRegistrationUtil.getJaggeryAppOAuthSettings(servletContext); if (jaggeryOAuthConfigurationSettings.isRequireDynamicClientRegistration()) { - if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(webAppName)) { + if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) { registrationProfile = DynamicClientWebAppRegistrationUtil. constructRegistrationProfile(jaggeryOAuthConfigurationSettings, webAppName); diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java index 9540d0e9e8..034e1e3f8c 100644 --- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java +++ b/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/src/main/java/org/wso2/carbon/dynamic/client/web/app/registration/util/DynamicClientWebAppRegistrationUtil.java @@ -116,7 +116,7 @@ public class DynamicClientWebAppRegistrationUtil { resource.setContent(writer.toString()); resource.setMediaType(DynamicClientWebAppRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); String resourcePath = DynamicClientWebAppRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + - oAuthAppDetails.getWebAppName(); + oAuthAppDetails.getClientName(); status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); } catch (RegistryException e) { throw new DynamicClientRegistrationException( diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java index da7734a046..abe4eac0c4 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java @@ -102,7 +102,8 @@ public class OAuthAuthenticator implements WebappAuthenticator { resourceContextParam.setValue(requestUri + ":" + requestMethod); OAuth2TokenValidationRequestDTO.TokenValidationContextParam[] - tokenValidationContextParams = new OAuth2TokenValidationRequestDTO.TokenValidationContextParam[1]; + tokenValidationContextParams = + new OAuth2TokenValidationRequestDTO.TokenValidationContextParam[1]; tokenValidationContextParams[0] = resourceContextParam; dto.setContext(tokenValidationContextParams); @@ -110,14 +111,9 @@ public class OAuthAuthenticator implements WebappAuthenticator { AuthenticatorFrameworkDataHolder.getInstance().getoAuth2TokenValidationService().validate(dto); if (oAuth2TokenValidationResponseDTO.isValid()) { String username = oAuth2TokenValidationResponseDTO.getAuthorizedUser(); - // try { - authenticationInfo.setUsername(username); - authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username)); - authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username)); -// } catch (AuthenticationException e) { -// throw new AuthenticationException( -// "Error occurred while retrieving the tenant ID of user '" + username + "'", e); -// } + authenticationInfo.setUsername(username); + authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username)); + authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username)); if (oAuth2TokenValidationResponseDTO.isValid()) { authenticationInfo.setStatus(Status.CONTINUE); } @@ -148,7 +144,7 @@ public class OAuthAuthenticator implements WebappAuthenticator { tokenValue = tokenValue.substring(matcher.end()); } } - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Oauth Token : " + tokenValue); } return tokenValue; From c00b1ee713e74b48cf5646711106c615a7838b8e Mon Sep 17 00:00:00 2001 From: Kasun Delgolla Date: Thu, 29 Oct 2015 20:46:48 +0530 Subject: [PATCH 24/27] Committing fix for JIRA- EMM-860 --- .../carbon/device/mgt/core/dao/DeviceDAO.java | 9 ++++++ .../core/dao/impl/GenericDeviceDAOImpl.java | 29 ++++++++++++++++++- .../core/dao/impl/OracleDeviceDAOImpl.java | 27 ++++++++++++++++- .../dao/impl/PostgreSQLDeviceDAOImpl.java | 27 ++++++++++++++++- .../core/dao/impl/SQLServerDeviceDAOImpl.java | 28 +++++++++++++++++- .../dao/util/DeviceManagementDAOUtil.java | 8 +++++ .../DeviceManagementProviderService.java | 4 +++ .../DeviceManagementProviderServiceImpl.java | 18 +++++++++++- 8 files changed, 145 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 6b593e85c6..f3d878393f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -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.Status; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.HashMap; import java.util.List; @@ -163,6 +164,14 @@ public interface DeviceDAO { */ 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 getDeviceTypes() throws DeviceManagementDAOException; + /** * This method is used to retrieve devices of a given device name. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GenericDeviceDAOImpl.java index f24b3c761e..4df319c577 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GenericDeviceDAOImpl.java @@ -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.DeviceManagementDAOFactory; 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.PreparedStatement; @@ -120,7 +121,33 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { return result; } - private Connection getConnection() throws SQLException { + @Override + public List getDeviceTypes() + throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + List 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(); } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/OracleDeviceDAOImpl.java index 2524945f59..92d790fe60 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/OracleDeviceDAOImpl.java @@ -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.DeviceManagementDAOFactory; 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.PreparedStatement; @@ -116,7 +117,31 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { return result; } - private Connection getConnection() throws SQLException { + @Override public List getDeviceTypes() throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + List 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(); } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/PostgreSQLDeviceDAOImpl.java index 5a65c807c2..26b0d34d9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/PostgreSQLDeviceDAOImpl.java @@ -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.DeviceManagementDAOFactory; 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.PreparedStatement; @@ -116,7 +117,31 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { return result; } - private Connection getConnection() throws SQLException { + @Override public List getDeviceTypes() throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + List 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(); } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/SQLServerDeviceDAOImpl.java index 224c7ee280..21c3ef8848 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/SQLServerDeviceDAOImpl.java @@ -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.DeviceManagementDAOFactory; 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.PreparedStatement; @@ -116,7 +117,32 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { return result; } - private Connection getConnection() throws SQLException { + @Override + public List getDeviceTypes() throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + List 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(); } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 201265f4d5..c7bc50eb2b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -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.EnrolmentInfo; 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.user.api.UserStoreException; import org.wso2.carbon.user.core.tenant.TenantManager; @@ -153,4 +154,11 @@ public final class DeviceManagementDAOUtil { device.setEnrolmentInfo(loadEnrolment(rs)); 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; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index aead0bda52..5f0677756a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -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.LicenseManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; + import java.util.List; /** @@ -127,6 +129,8 @@ public interface DeviceManagementProviderService extends OperationManager { Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; + List getAvailableDeviceTypes() throws DeviceManagementException; + boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException; boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index f28c7f8bcf..054e4c5e3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -617,7 +617,23 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return device; } - @Override + @Override + public List getAvailableDeviceTypes() throws DeviceManagementException { + List 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 { DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) { From d2b8224f318291254fbdcfd9f3f8568a17b15fa5 Mon Sep 17 00:00:00 2001 From: mharindu Date: Fri, 30 Oct 2015 11:28:57 +0530 Subject: [PATCH 25/27] Changed the VARCHAR size of application identifier --- .../src/main/resources/dbscripts/cdm/h2.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/mssql.sql | 2 +- .../src/main/resources/dbscripts/cdm/mysql.sql | 2 +- .../src/main/resources/dbscripts/cdm/oracle.sql | 2 +- .../src/main/resources/dbscripts/cdm/postgresql.sql | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 1959c2f241..10e15533ed 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -355,8 +355,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( CREATE TABLE IF NOT EXISTS DM_APPLICATION ( ID INTEGER AUTO_INCREMENT NOT NULL, - NAME VARCHAR(50) NOT NULL, - APP_IDENTIFIER VARCHAR(50) 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, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index f71fbdd52c..c61879a5e3 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -358,7 +358,7 @@ CREATE TABLE DM_ENROLMENT ( CREATE TABLE DM_APPLICATION ( ID INTEGER IDENTITY NOT NULL, - NAME VARCHAR(50) NOT NULL, + NAME VARCHAR(150) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL, PLATFORM VARCHAR(50) DEFAULT NULL, CATEGORY VARCHAR(50) NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index a8a64597d6..00a519c65e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -352,7 +352,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( CREATE TABLE IF NOT EXISTS DM_APPLICATION ( ID INTEGER AUTO_INCREMENT NOT NULL, - NAME VARCHAR(50) NOT NULL, + NAME VARCHAR(150) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL, PLATFORM VARCHAR(50) DEFAULT NULL, CATEGORY VARCHAR(50) NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index fa522c3dc7..51c6900506 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -551,7 +551,7 @@ END; CREATE TABLE DM_APPLICATION ( ID NUMBER(10) NOT NULL, - NAME VARCHAR2(50) NOT NULL, + NAME VARCHAR2(150) NOT NULL, APP_IDENTIFIER VARCHAR2(150) NOT NULL, PLATFORM VARCHAR2(50) DEFAULT NULL, CATEGORY VARCHAR2(50) NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index e68e127f06..d874edf690 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -309,7 +309,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( CREATE TABLE IF NOT EXISTS DM_APPLICATION ( ID BIGSERIAL NOT NULL PRIMARY KEY, - NAME VARCHAR(50) NOT NULL, + NAME VARCHAR(150) NOT NULL, APP_IDENTIFIER VARCHAR(150) NOT NULL, PLATFORM VARCHAR(50) DEFAULT NULL, CATEGORY VARCHAR(50) NULL, From 20122b3f1e2d498df0bb591656a5fc5c083d07bc Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 30 Oct 2015 17:48:30 +0530 Subject: [PATCH 26/27] Fixing the roles and users adding issue --- .../carbon/policy/mgt/core/dao/PolicyDAO.java | 6 + .../mgt/core/dao/impl/PolicyDAOImpl.java | 150 ++++++++++++++++-- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 8 +- 3 files changed, 151 insertions(+), 13 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java index 9fa1259b31..d1065e17a5 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -41,6 +41,8 @@ public interface PolicyDAO { */ Policy addPolicyToRole(List roleNames, Policy policy) throws PolicyManagerDAOException; + Policy updateRolesOfPolicy(List rolesToAdd, Policy policy) throws PolicyManagerDAOException; + /** * This method is used to add/update the users associated with the policy. * @param usernameList - List of the users that needs to be applied @@ -50,6 +52,8 @@ public interface PolicyDAO { */ Policy addPolicyToUser(List usernameList, Policy policy) throws PolicyManagerDAOException; + Policy updateUserOfPolicy(List usersToAdd, Policy policy) throws PolicyManagerDAOException; + Policy addPolicyToDevice(List devices, Policy policy) throws PolicyManagerDAOException; boolean updatePolicyPriorities(List policies) throws PolicyManagerDAOException; @@ -114,6 +118,8 @@ public interface PolicyDAO { boolean deleteAllPolicyRelatedConfigs(int policyId) throws PolicyManagerDAOException; + boolean deleteCriteriaAndDeviceRelatedConfigs(int policyId) throws PolicyManagerDAOException; + List getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException; List getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index 322b57918c..9cc11640d6 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -71,8 +71,52 @@ public class PolicyDAOImpl implements PolicyDAO { public Policy addPolicyToRole(List rolesToAdd, Policy policy) throws PolicyManagerDAOException { Connection conn; PreparedStatement insertStmt = null; +// PreparedStatement deleteStmt = null; +// final List currentRoles = this.getPolicy(policy.getId()).getRoles(); +// +// SetReferenceTransformer transformer = new SetReferenceTransformer(); +// +// transformer.transform(currentRoles, rolesToAdd); +// rolesToAdd = transformer.getObjectsToAdd(); +// List 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 rolesToAdd, Policy previousPolicy) throws PolicyManagerDAOException { + Connection conn; + PreparedStatement insertStmt = null; PreparedStatement deleteStmt = null; - final List currentRoles = policy.getRoles(); + + final List currentRoles = previousPolicy.getRoles(); SetReferenceTransformer transformer = new SetReferenceTransformer(); @@ -81,22 +125,22 @@ public class PolicyDAOImpl implements PolicyDAO { List rolesToDelete = transformer.getObjectsToRemove(); try { conn = this.getConnection(); - if (rolesToAdd.size() > 0){ + 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.setInt(2, previousPolicy.getId()); insertStmt.addBatch(); } insertStmt.executeBatch(); } - if (rolesToAdd.size() > 0){ + 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.setInt(2, previousPolicy.getId()); deleteStmt.addBatch(); } 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); } finally { PolicyManagementDAOUtil.cleanupResources(insertStmt, null); + PolicyManagementDAOUtil.cleanupResources(deleteStmt, null); } - return policy; + return previousPolicy; } @Override public Policy addPolicyToUser(List usersToAdd, Policy policy) throws PolicyManagerDAOException { Connection conn; PreparedStatement insertStmt = null; +// PreparedStatement deleteStmt = null; +// final List currentUsers = this.getPolicy(policy.getId()).getUsers(); +// +// SetReferenceTransformer transformer = new SetReferenceTransformer(); +// +// transformer.transform(currentUsers, usersToAdd); +// usersToAdd = transformer.getObjectsToAdd(); +// List 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 usersToAdd, Policy policy) throws PolicyManagerDAOException { + Connection conn; + PreparedStatement insertStmt = null; PreparedStatement deleteStmt = null; final List currentUsers = policy.getUsers(); @@ -123,7 +213,7 @@ public class PolicyDAOImpl implements PolicyDAO { List usersToDelete = transformer.getObjectsToRemove(); try { conn = this.getConnection(); - if (usersToAdd.size() > 0){ + if (usersToAdd.size() > 0) { String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)"; insertStmt = conn.prepareStatement(query); for (String username : usersToAdd) { @@ -133,7 +223,7 @@ public class PolicyDAOImpl implements PolicyDAO { } insertStmt.executeBatch(); } - if (usersToDelete.size() > 0){ + if (usersToDelete.size() > 0) { String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?"; deleteStmt = conn.prepareStatement(deleteQuery); for (String username : usersToDelete) { @@ -153,6 +243,7 @@ public class PolicyDAOImpl implements PolicyDAO { return policy; } + @Override public Policy addPolicyToDevice(List devices, Policy policy) throws PolicyManagerDAOException { 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 { return PolicyManagementDAOFactory.getConnection(); } @@ -1345,7 +1476,8 @@ public class PolicyDAOImpl implements PolicyDAO { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { 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.setInt(1, deviceId); stmt.setInt(2, tenantId); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index e563d8c631..06b71d071a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -180,15 +180,15 @@ public class PolicyManagerImpl implements PolicyManager { if (!newFeaturesList.isEmpty()) { featureDAO.addProfileFeatures(newFeaturesList, profileId); } - policyDAO.deleteAllPolicyRelatedConfigs(policy.getId()); + policyDAO.deleteCriteriaAndDeviceRelatedConfigs(policy.getId()); if (policy.getUsers() != null) { - policyDAO.addPolicyToUser(policy.getUsers(), previousPolicy); + policyDAO.updateUserOfPolicy(policy.getUsers(), previousPolicy); } if (policy.getRoles() != null) { - policyDAO.addPolicyToRole(policy.getRoles(), previousPolicy); + policyDAO.updateRolesOfPolicy(policy.getRoles(), previousPolicy); } if (policy.getDevices() != null) { @@ -539,7 +539,7 @@ public class PolicyManagerImpl implements PolicyManager { policy.setDevices(deviceList); try { - // PolicyManagementDAOFactory.openConnection(); + // PolicyManagementDAOFactory.openConnection(); Profile profile = profileManager.getProfile(policy.getProfileId()); policy.setProfile(profile); } catch (ProfileManagementException e) { From 8f982722fb75b99b5646076048e3f372fb341d4a Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 30 Oct 2015 18:29:32 +0530 Subject: [PATCH 27/27] Added oauth response messages --- .../authenticator/framework/AuthenticationInfo.java | 9 +++++++++ .../framework/WebappAuthenticationValve.java | 12 ++++++++---- .../framework/authenticator/OAuthAuthenticator.java | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/AuthenticationInfo.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/AuthenticationInfo.java index a65c99fa39..d7a0ec1c61 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/AuthenticationInfo.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/AuthenticationInfo.java @@ -26,6 +26,7 @@ import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthen public class AuthenticationInfo { private WebappAuthenticator.Status status = WebappAuthenticator.Status.FAILURE; + private String message; private String username; private String tenantDomain; private int tenantId = -1; @@ -43,6 +44,14 @@ public class AuthenticationInfo { return username; } + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + public void setUsername(String username) { this.username = username; } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java index c416444682..bdc5428984 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java @@ -74,12 +74,12 @@ public class WebappAuthenticationValve extends CarbonTomcatValve { privilegedCarbonContext.setTenantId(authenticationInfo.getTenantId()); privilegedCarbonContext.setTenantDomain(authenticationInfo.getTenantDomain()); privilegedCarbonContext.setUsername(authenticationInfo.getUsername()); - this.processRequest(request, response, compositeValve, authenticationInfo.getStatus()); + this.processRequest(request, response, compositeValve, authenticationInfo); } finally { PrivilegedCarbonContext.endTenantFlow(); } } 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, - WebappAuthenticator.Status status) { - switch (status) { + AuthenticationInfo authenticationInfo) { + switch (authenticationInfo.getStatus()) { case SUCCESS: case CONTINUE: this.getNext().invoke(request, response, compositeValve); break; case FAILURE: 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); AuthenticationFrameworkUtil .handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java index abe4eac0c4..6064fe8c8f 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java @@ -117,6 +117,8 @@ public class OAuthAuthenticator implements WebappAuthenticator { if (oAuth2TokenValidationResponseDTO.isValid()) { authenticationInfo.setStatus(Status.CONTINUE); } + } else { + authenticationInfo.setMessage(oAuth2TokenValidationResponseDTO.getErrorMsg()); } } } catch (AuthenticationException e) {