revert-70aa11f8
prabathabey 9 years ago
commit 2f22d1c82a

@ -27,7 +27,6 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
<version>0.9.2-SNAPSHOT</version>
<packaging>bundle</packaging>

@ -64,7 +64,6 @@ 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;
@ -77,6 +76,7 @@ import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateExpiredException;
@ -157,10 +157,9 @@ public class CertificateGenerator {
keyPairGenerator.initialize(ConfigurationUtil.RSA_KEY_LENGTH, new SecureRandom());
KeyPair pair = keyPairGenerator.generateKeyPair();
X500Principal principal = new X500Principal(ConfigurationUtil.DEFAULT_PRINCIPAL);
BigInteger serial = BigInteger.valueOf(System.currentTimeMillis());
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(
principal, serial, validityBeginDate, validityEndDate,
principal, CommonUtil.generateSerialNumber(), validityBeginDate, validityEndDate,
principal, pair.getPublic());
ContentSigner contentSigner = new JcaContentSignerBuilder(ConfigurationUtil.SHA256_RSA)
.setProvider(ConfigurationUtil.PROVIDER).build(
@ -283,6 +282,58 @@ public class CertificateGenerator {
}
}
public boolean verifySignature(String headerSignature) throws KeystoreException {
Certificate certificate = extractCertificateFromSignature(headerSignature);
return (certificate != null);
}
public X509Certificate extractCertificateFromSignature(String headerSignature) throws KeystoreException {
if (headerSignature == null || headerSignature.isEmpty()) {
return null;
}
try {
KeyStoreReader keyStoreReader = new KeyStoreReader();
CMSSignedData signedData = new CMSSignedData(Base64.decodeBase64(headerSignature.getBytes()));
Store reqStore = signedData.getCertificates();
@SuppressWarnings("unchecked")
Collection<X509CertificateHolder> reqCerts = reqStore.getMatches(null);
if (reqCerts != null && reqCerts.size() > 0) {
CertificateFactory certificateFactory = CertificateFactory.getInstance(ConfigurationUtil.X_509);
X509CertificateHolder holder = reqCerts.iterator().next();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(holder.getEncoded());
X509Certificate reqCert = (X509Certificate) certificateFactory.
generateCertificate(byteArrayInputStream);
if(reqCert != null && reqCert.getSerialNumber() != null) {
Certificate lookUpCertificate = keyStoreReader.getCertificateByAlias(
reqCert.getSerialNumber().toString());
if (lookUpCertificate != null && (lookUpCertificate instanceof X509Certificate)) {
return (X509Certificate)lookUpCertificate;
}
}
}
} catch (CMSException e) {
String errorMsg = "CMSException when decoding certificate signature";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (IOException e) {
String errorMsg = "IOException when decoding certificate signature";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (CertificateException e) {
String errorMsg = "CertificateException when decoding certificate signature";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
}
return null;
}
public X509Certificate generateCertificateFromCSR(PrivateKey privateKey,
PKCS10CertificationRequest request,
String issueSubject)
@ -305,7 +356,7 @@ public class CertificateGenerator {
}
X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
new X500Name(issueSubject), BigInteger.valueOf(System.currentTimeMillis()),
new X500Name(issueSubject), CommonUtil.generateSerialNumber(),
validityBeginDate, validityEndDate, certSubject, request.getSubjectPublicKeyInfo());
ContentSigner sigGen;

@ -204,6 +204,25 @@ public class KeyStoreReader {
return raCertificate;
}
public Certificate getCertificateByAlias(String alias) throws KeystoreException {
KeyStore keystore = loadCertificateKeyStore();
Certificate raCertificate;
try {
raCertificate = keystore.getCertificate(alias);
} catch (KeyStoreException e) {
String errorMsg = "KeyStore issue occurred when retrieving RA private key";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
}
if (raCertificate == null) {
throw new KeystoreException("RA certificate not found in KeyStore");
}
return raCertificate;
}
PrivateKey getRAPrivateKey() throws KeystoreException {
KeyStore keystore = loadCertificateKeyStore();

@ -33,17 +33,22 @@ public interface CertificateManagementService {
Certificate getRACertificate() throws KeystoreException;
public List<X509Certificate> getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException;
List<X509Certificate> getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException;
public X509Certificate generateX509Certificate() throws KeystoreException;
X509Certificate generateX509Certificate() throws KeystoreException;
public SCEPResponse getCACertSCEP() throws KeystoreException;
SCEPResponse getCACertSCEP() throws KeystoreException;
public byte[] getCACapsSCEP();
byte[] getCACapsSCEP();
public byte[] getPKIMessageSCEP(InputStream inputStream) throws KeystoreException;
byte[] getPKIMessageSCEP(InputStream inputStream) throws KeystoreException;
public X509Certificate generateCertificateFromCSR(PrivateKey privateKey,
PKCS10CertificationRequest request,
X509Certificate generateCertificateFromCSR(PrivateKey privateKey, PKCS10CertificationRequest request,
String issueSubject) throws KeystoreException;
Certificate getCertificateByAlias(String alias) throws KeystoreException;
boolean verifySignature(String headerSignature) throws KeystoreException;
public X509Certificate extractCertificateFromSignature(String headerSignature) throws KeystoreException;
}

@ -84,4 +84,16 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
String issueSubject) throws KeystoreException {
return certificateGenerator.generateCertificateFromCSR(privateKey, request, issueSubject);
}
public Certificate getCertificateByAlias(String alias) throws KeystoreException {
return keyStoreReader.getCertificateByAlias(alias);
}
public boolean verifySignature(String headerSignature) throws KeystoreException {
return certificateGenerator.verifySignature(headerSignature);
}
public X509Certificate extractCertificateFromSignature(String headerSignature) throws KeystoreException {
return certificateGenerator.extractCertificateFromSignature(headerSignature);
}
}

@ -17,6 +17,7 @@
*/
package org.wso2.carbon.certificate.mgt.core.util;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Date;
@ -40,4 +41,8 @@ public class CommonUtil {
return calendar.getTime();
}
public static synchronized BigInteger generateSerialNumber() {
return BigInteger.valueOf(System.currentTimeMillis());
}
}

@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.common;
import java.io.Serializable;
public class EnrolmentInfo implements Serializable{
public class EnrolmentInfo implements Serializable {
private static final long serialVersionUID = 1998101712L;
@ -40,7 +40,8 @@ public class EnrolmentInfo implements Serializable{
private Status status;
private String owner;
public EnrolmentInfo() {}
public EnrolmentInfo() {
}
public EnrolmentInfo(Device device, String owner, OwnerShip ownership, Status status) {
this.device = device;
@ -109,19 +110,12 @@ public class EnrolmentInfo implements Serializable{
public boolean equals(Object obj) {
if (obj instanceof EnrolmentInfo) {
EnrolmentInfo tempInfo = (EnrolmentInfo) obj;
if (owner != null && ownership != null
&& tempInfo.getOwner() != null && tempInfo.getOwnership() != null) {
if (owner.equals(tempInfo.getOwner()) && ownership.equals(tempInfo.getOwnership())) {
if (this.owner != null && this.ownership != null) {
if (this.owner.equals(tempInfo.getOwner()) && this.ownership.equals(tempInfo.getOwnership())) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
return false;
}
}

@ -31,38 +31,160 @@ import java.util.List;
*/
public interface DeviceDAO {
/**
* This method is used to add a device.
*
* @param typeId device type id.
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of the persisted device record.
* @throws DeviceManagementDAOException
*/
int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to update a given device.
*
* @param typeId device type id.
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of updated device.
* @throws DeviceManagementDAOException
*/
int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to remove a device.
*
* @param deviceId id of the device that should be removed.
* @param tenantId tenant id.
* @return returns the id of removed device.
* @throws DeviceManagementDAOException
*/
int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve a device of a given id.
*
* @param deviceId device id.
* @param tenantId tenant id.
* @return returns the device object.
* @throws DeviceManagementDAOException
*/
Device getDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve all the devices of a given tenant.
*
* @param tenantId tenant id.
* @return returns a list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevices(int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve all the devices of a given tenant and device type.
*
* @param type device type.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevices(String type, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve devices of a given user.
* @param username user name.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the device count of a given tenant.
*
* @param tenantId tenant id.
* @return returns the device count.
* @throws DeviceManagementDAOException
*/
int getDeviceCount(int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve devices of a given device name.
* @param deviceName device name.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to add an enrollment information of a given device.
*
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of the enrollment.
* @throws DeviceManagementDAOException
*/
int addEnrollment(Device device, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to set the current enrollment status of given device and user.
*
* @param deviceId device id.
* @param currentOwner current user name.
* @param status device status.
* @param tenantId tenant id.
* @return returns true if success.
* @throws DeviceManagementDAOException
*/
boolean setEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner, Status status,
int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to get the status of current enrollment of a given user and device.
*
* @param deviceId device id.
* @param currentOwner device owner.
* @param tenantId tenant id.
* @return returns current enrollment status.
* @throws DeviceManagementDAOException
*/
Status getEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner,
int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve current enrollment of a given device and user.
*
* @param deviceId device id.
* @param currentUser user name.
* @param tenantId tenant id.
* @return returns EnrolmentInfo object.
* @throws DeviceManagementDAOException
*/
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve devices of a given enrollment status.
*
* @param status enrollment status.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the enrollment id of a given device and status.
*
* @param deviceId device id.
* @param status enrollment status.
* @param tenantId tenant id.
* @return returns the id of current enrollment.
* @throws DeviceManagementDAOException
*/
int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status,
int tenantId) throws DeviceManagementDAOException;
}

@ -42,8 +42,7 @@ public class DeviceDAOImpl implements DeviceDAO {
int deviceId = -1;
try {
conn = this.getConnection();
String sql =
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " +
String sql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " +
"VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, device.getDescription());
@ -74,8 +73,7 @@ public class DeviceDAOImpl implements DeviceDAO {
int deviceId = -1;
try {
conn = this.getConnection();
String sql =
"UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " +
String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " +
"DEVICE_TYPE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, device.getDescription());
@ -111,10 +109,9 @@ public class DeviceDAOImpl implements DeviceDAO {
Device device = null;
try {
conn = this.getConnection();
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ?";
@ -144,12 +141,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null;
try {
conn = this.getConnection();
String sql =
"SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
"FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," +
"d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, " +
"d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
"WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
@ -176,12 +173,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null;
try {
conn = this.getConnection();
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
"AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
"AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " +
"d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
"AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, type);
stmt.setInt(2, tenantId);
@ -207,11 +204,10 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<>();
try {
conn = this.getConnection();
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT , e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, d.ID, d.DESCRIPTION, " +
"d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, " +
"d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?";
stmt = conn.prepareStatement(sql);
@ -281,12 +277,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<>();
try {
conn = this.getConnection();
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DESCRIPTION, t.NAME AS DEVICE_TYPE, " +
"d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
"d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceName + "%");
stmt.setInt(2, tenantId);
@ -314,9 +310,8 @@ public class DeviceDAOImpl implements DeviceDAO {
int enrolmentId = -1;
try {
conn = this.getConnection();
String sql =
"INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " +
"TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " +
"DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setInt(1, device.getId());
stmt.setString(2, device.getEnrolmentInfo().getOwner());
@ -346,10 +341,9 @@ public class DeviceDAOImpl implements DeviceDAO {
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String sql =
"UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
"AND OWNER = ? AND TENANT_ID = ?";
String sql = "UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? " +
"AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, status.toString());
stmt.setString(2, deviceId.getId());
@ -375,10 +369,9 @@ public class DeviceDAOImpl implements DeviceDAO {
Status status = null;
try {
conn = this.getConnection();
String sql =
"SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = " +
"(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND " +
"d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? " +
"AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getId());
stmt.setString(2, deviceId.getType());
@ -407,10 +400,10 @@ public class DeviceDAOImpl implements DeviceDAO {
EnrolmentInfo enrolmentInfo = null;
try {
conn = this.getConnection();
String sql =
"SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " +
"TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
"AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getId());
@ -438,10 +431,10 @@ public class DeviceDAOImpl implements DeviceDAO {
ResultSet rs = null;
try {
conn = this.getConnection();
String sql =
"SELECT ID AS ENROLMENT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? " +
"AND d.TENANT_ID = ?) AND STATUS = ? AND TENANT_ID = ?";
String sql = "SELECT ID AS ENROLMENT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
"AND STATUS = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getId());
stmt.setString(2, deviceId.getType());
@ -491,13 +484,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<>();
try {
conn = this.getConnection();
String sql =
"SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " +
"AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " +
"AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
"e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
"WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());

@ -120,9 +120,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
List<CommandOperation> commandOperations = new ArrayList<>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
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 ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID";
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 " +
"ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId);

@ -93,7 +93,7 @@ public interface DeviceManagementProviderService extends OperationManager {
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException;
/**
* This method is used to retrieve list of devices based on the device status
* This method is used to retrieve list of devices based on the device status.
*
* @param status Device status
* @return List of devices

@ -748,10 +748,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection();
}
for (Device device : userDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
@ -792,10 +790,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection();
}
for (Device device : allDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
@ -865,10 +861,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
for (Device device : allDevices) {
Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
Device dmsDevice = this.getDeviceManager(device.getType()).
getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());

@ -128,6 +128,10 @@ public class DynamicClientRegistrationUtil {
serviceProvider.setDescription("Service Provider for application " + applicationName);
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
if (appMgtService == null) {
throw new IllegalStateException("Error occurred while retrieving Application Management" +
"Service");
}
appMgtService.createApplication(serviceProvider);
ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName);
@ -228,6 +232,11 @@ public class DynamicClientRegistrationUtil {
oAuthAdminService.removeOAuthApplicationData(consumerKey);
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
if (appMgtService == null) {
throw new IllegalStateException("Error occurred while retrieving Application Management" +
"Service");
}
ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName);
if (createdServiceProvider == null) {

@ -45,9 +45,24 @@ public interface RegistrationService {
}
}
/**
* This method is used to register an Oauth application.
*
* @param profile contains the necessary attributes that are
* needed in order to register an app.
* @return Status 200 if success including consumerKey and consumerSecret.
*/
@POST
Response register(RegistrationProfile profile);
/**
* This method is used to remove already registered Oauth application.
*
* @param applicationName name of the application.
* @param userId name of the application owner.
* @param consumerKey provided consumerKey for the registered application.
* @return Status 200 if success.
*/
@DELETE
public Response unregister(@QueryParam("applicationName") String applicationName,
@QueryParam("userId") String userId,

@ -164,6 +164,4 @@ public class RegistrationProfile {
public void setGrantType(String grantType) {
this.grantType = grantType;
}
}

@ -25,34 +25,102 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.List;
/**
* This interface represents the key operations related to profile features of device policies.
*/
public interface FeatureDAO {
/* Feature addFeature(Feature feature) throws FeatureManagerDAOException;
List<Feature> addFeatures(List<Feature> feature) throws FeatureManagerDAOException;
Feature updateFeature(Feature feature) throws FeatureManagerDAOException;*/
/**
* This method is used to add a feature related to given profile.
*
* @param feature consists of device specific configurations.
* @param profileId id of the profile.
* @return returns ProfileFeature object.
* @throws FeatureManagerDAOException
*/
ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;
/**
* This method is used to update a feature related to given profile.
* @param feature consists of device specific configurations.
* @param profileId id of the profile.
* @return returns updated ProfileFeature object.
* @throws FeatureManagerDAOException
*/
ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;
/**
* This method is used to add set of features to a given profile.
*
* @param features consists of device specific configurations.
* @param profileId id of the profile.
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException;
/**
* This method is used to update set of features to a given profile.
*
* @param features consists of device specific configurations.
* @param profileId id of the profile.
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException;
/**
* This method is used to retrieve all the profile features.
*
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException;
/**
* This method is used to retrieve all the profile features based on device type.
*
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<Feature> getAllFeatures(String deviceType) throws FeatureManagerDAOException;
List<ProfileFeature> getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException;
/**
* This method is used to retrieve all the profile features of given profile.
*
* @param profileId id of the profile.
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagerDAOException;
/**
* This method is used remove a feature.
*
* @param featureId id of the removing feature.
* @return returns true if success.
* @throws FeatureManagerDAOException
*/
boolean deleteFeature(int featureId) throws FeatureManagerDAOException;
/**
* This method is used to remove set of features of given profile.
*
* @param profile that contains features to be removed.
* @return returns true if success.
* @throws FeatureManagerDAOException
*/
boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException;
/**
* This method is used to remove set of features of given profile id.
*
* @param profileId id of the profile.
* @return returns true if success.
* @throws FeatureManagerDAOException
*/
boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException;
}

@ -24,20 +24,67 @@ import org.wso2.carbon.policy.mgt.common.Profile;
import java.util.List;
/**
* This interface represents the key operations related to policy profile.
*/
public interface ProfileDAO {
/**
* This method is used to add a profile.
*
* @param profile profile object.
* @return returns added profile object.
* @throws ProfileManagerDAOException
*/
Profile addProfile(Profile profile) throws ProfileManagerDAOException;
/**
* This method is used to update a profile
* @param profile profile object.
* @return returns updated profile object.
* @throws ProfileManagerDAOException
*/
Profile updateProfile(Profile profile) throws ProfileManagerDAOException;
/**
* This method is used to remove a profile.
* @param profile profile object
* @return returns true if success.
* @throws ProfileManagerDAOException
*/
boolean deleteProfile(Profile profile) throws ProfileManagerDAOException;
/**
* This method is used to remove a profile of given policy id.
* @param policyId policy id.
* @return returns true if success.
* @throws ProfileManagerDAOException
*/
boolean deleteProfile(int policyId) throws ProfileManagerDAOException;
Profile getProfiles(int profileId) throws ProfileManagerDAOException;
/**
* This method is used to retrieve a profile when id is given.
* @param profileId profile id.
* @return returns profile object.
* @throws ProfileManagerDAOException
*/
Profile getProfile(int profileId) throws ProfileManagerDAOException;
/**
* This method is used to retrieve all the profiles.
*
* @return returns a list of profile objects.
* @throws ProfileManagerDAOException
*/
List<Profile> getAllProfiles() throws ProfileManagerDAOException;
/**
* This method is used to retrieve all the profile of given device type.
*
* @param deviceType device type object.
* @return retruns list of profiles.
* @throws ProfileManagerDAOException
*/
List<Profile> getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException;
}

@ -43,115 +43,6 @@ public class FeatureDAOImpl implements FeatureDAO {
private static final Log log = LogFactory.getLog(FeatureDAOImpl.class);
/* @Override
public Feature addFeature(Feature feature) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
try {
conn = this.getConnection();
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
stmt.setString(3, feature.getDescription());
int affectedRows = stmt.executeUpdate();
if (log.isDebugEnabled()) {
log.debug(affectedRows + " feature is added.");
}
generatedKeys = stmt.getGeneratedKeys();
while (generatedKeys.next()) {
feature.setId(generatedKeys.getInt(1));
}
} catch (SQLException e) {
String msg = "Error occurred while adding feature to the database.";
log.error(msg, e);
throw new FeatureManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
}
return feature;
}*/
/* @Override
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
List<Feature> featureList = new ArrayList<Feature>();
try {
conn = this.getConnection();
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
for (Feature feature : features) {
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
stmt.setString(3, feature.getDescription());
stmt.addBatch();
}
int[] affectedRows = stmt.executeBatch();
generatedKeys = stmt.getGeneratedKeys();
if (log.isDebugEnabled()) {
log.debug(affectedRows.length + " features are added to the database.");
}
generatedKeys = stmt.getGeneratedKeys();
int i = 0;
while (generatedKeys.next()) {
features.get(i).setId(generatedKeys.getInt(1));
i++;
}
} catch (SQLException e) {
String msg = "Error occurred while adding feature to the database.";
log.error(msg, e);
throw new FeatureManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
}
return featureList;
}*/
/* @Override
public Feature updateFeature(Feature feature) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ? WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
stmt.setString(3, feature.getDescription());
stmt.setInt(4, feature.getId());
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the
database.";
log.error(msg, e);
throw new FeatureManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
return feature;
}*/
@Override
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
return null;
@ -247,7 +138,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -258,9 +148,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query);
stmt.setInt(1, profile.getProfileId());
stmt.setInt(2, tenantId);
stmt.executeUpdate();
if (stmt.executeUpdate() > 0) {
return true;
}
return false;
} catch (SQLException e) {
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
} finally {
@ -270,7 +161,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -280,9 +170,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
if (stmt.executeUpdate() > 0) {
return true;
}
return false;
} catch (SQLException e) {
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
} finally {
@ -448,7 +339,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override
public boolean deleteFeature(int featureId) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -459,9 +349,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query);
stmt.setInt(1, featureId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
if(stmt.executeUpdate() > 0) {
return true;
}
return false;
} catch (SQLException e) {
throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " +
"from database.", e);

@ -132,7 +132,6 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override
public boolean deleteProfile(Profile profile) throws ProfileManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
@ -141,9 +140,10 @@ public class ProfileDAOImpl implements ProfileDAO {
String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profile.getProfileId());
stmt.executeUpdate();
if (stmt.executeUpdate() > 0) {
return true;
}
return false;
} catch (SQLException e) {
String msg = "Error occurred while deleting the profile from the data base.";
log.error(msg);
@ -163,9 +163,10 @@ public class ProfileDAOImpl implements ProfileDAO {
String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);
stmt.executeUpdate();
if (stmt.executeUpdate() > 0) {
return true;
}
return false;
} catch (SQLException e) {
String msg = "Error occurred while deleting the profile from the data base.";
log.error(msg);
@ -177,8 +178,7 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override
public Profile getProfiles(int profileId) throws ProfileManagerDAOException {
public Profile getProfile(int profileId) throws ProfileManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
@ -216,7 +216,6 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override
public List<Profile> getAllProfiles() throws ProfileManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;

@ -362,7 +362,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
service.addOperation(monitoringOperation, deviceIdentifiers);
}
private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) {

@ -439,7 +439,7 @@ public class PolicyManagerImpl implements PolicyManager {
policy = policyDAO.getPolicyByProfileID(profileId);
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
profile = profileDAO.getProfiles(profileId);
profile = profileDAO.getProfile(profileId);
policy.setProfile(profile);
policy.setRoles(roleNames);
@ -474,7 +474,7 @@ public class PolicyManagerImpl implements PolicyManager {
policy = policyDAO.getPolicy(policyId);
roleNames = policyDAO.getPolicyAppliedRoles(policyId);
Profile profile = profileDAO.getProfiles(policy.getProfileId());
Profile profile = profileDAO.getProfile(policy.getProfileId());
policy.setProfile(profile);
policy.setRoles(roleNames);
@ -871,12 +871,9 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public int getPolicyCount() throws PolicyManagementException {
int policyCount;
try {
PolicyManagementDAOFactory.openConnection();
policyCount = policyDAO.getPolicyCount();
return policyCount;
return policyDAO.getPolicyCount();
} catch (PolicyManagerDAOException e) {
throw new PolicyManagementException("Error occurred while getting policy count", e);
} catch (SQLException e) {

@ -147,7 +147,7 @@ public class ProfileManagerImpl implements ProfileManager {
try {
PolicyManagementDAOFactory.openConnection();
profile = profileDAO.getProfiles(profileId);
profile = profileDAO.getProfile(profileId);
featureList = featureDAO.getFeaturesForProfile(profileId);
profile.setProfileFeaturesList(featureList);
} catch (ProfileManagerDAOException e) {

@ -88,7 +88,11 @@
org.wso2.carbon.user.core.tenant,
org.wso2.carbon.utils,
org.wso2.carbon.utils.multitenancy,
org.xml.sax
org.xml.sax,
javax.servlet.http,
javax.xml,
org.apache.axis2.transport.http,
org.wso2.carbon.apimgt.impl
</Import-Package>
<!--<Fragment-Host>tomcat</Fragment-Host>-->
</instructions>

@ -37,14 +37,6 @@
<description>This feature contains oauth functionality
</description>
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>org.wso2.mdm</groupId>-->
<!--<artifactId>dynamic-client-manager</artifactId>-->
<!--</dependency>-->
<!--</dependencies>-->
<build>
<plugins>
<plugin>
@ -101,8 +93,6 @@
</executions>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
@ -123,20 +113,6 @@
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
</properties>
</adviceFile>
<!--<bundles>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.core:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.common:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.simple.policy.decision.point:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.information.point:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--</bundles>-->
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
</importFeatureDef>
@ -145,10 +121,6 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Loading…
Cancel
Save