revert-70aa11f8
mharindu 9 years ago
commit cd853c9ee8

@ -52,9 +52,9 @@ import org.jscep.transaction.Nonce;
import org.jscep.transaction.TransactionId; import org.jscep.transaction.TransactionId;
import org.wso2.carbon.certificate.mgt.core.dto.CAStatus; import org.wso2.carbon.certificate.mgt.core.dto.CAStatus;
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import org.wso2.carbon.certificate.mgt.core.util.CommonUtil; 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.security.auth.x500.X500Principal;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -292,9 +292,21 @@ public class CertificateGenerator {
Date validityBeginDate = commonUtil.getValidityStartDate(); Date validityBeginDate = commonUtil.getValidityStartDate();
Date validityEndDate = commonUtil.getValidityEndDate(); Date validityEndDate = commonUtil.getValidityEndDate();
X500Name certSubject = request.getSubject();
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( X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
new X500Name(issueSubject), BigInteger.valueOf(System.currentTimeMillis()), new X500Name(issueSubject), BigInteger.valueOf(System.currentTimeMillis()),
validityBeginDate, validityEndDate, request.getSubject(), request.getSubjectPublicKeyInfo()); validityBeginDate, validityEndDate, certSubject, request.getSubjectPublicKeyInfo());
ContentSigner sigGen; ContentSigner sigGen;
X509Certificate issuedCert; X509Certificate issuedCert;
@ -461,6 +473,8 @@ public class CertificateGenerator {
KeyStoreReader keyStoreReader = new KeyStoreReader(); KeyStoreReader keyStoreReader = new KeyStoreReader();
KeyStore keyStore = keyStoreReader.loadCertificateKeyStore(); KeyStore keyStore = keyStoreReader.loadCertificateKeyStore();
keyStore.setCertificateEntry(certificate.getSerialNumber().toString(), certificate); keyStore.setCertificateEntry(certificate.getSerialNumber().toString(), certificate);
keyStoreReader.saveCertificateKeyStore(keyStore);
} catch (KeyStoreException e) { } catch (KeyStoreException e) {
String errorMsg = "KeySKeyStoreException occurred when saving the generated certificate"; String errorMsg = "KeySKeyStoreException occurred when saving the generated certificate";
log.error(errorMsg, e); log.error(errorMsg, e);

@ -24,6 +24,7 @@ import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.KeyStore; import java.security.KeyStore;
@ -62,7 +63,7 @@ public class KeyStoreReader {
log.error(errorMsg, e); log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CertificateException e) { } catch (CertificateException e) {
String errorMsg = "Certificate expired when loading KeyStore"; String errorMsg = "CertificateException when loading KeyStore";
log.error(errorMsg, e); log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (IOException e) { } catch (IOException e) {
@ -82,11 +83,59 @@ public class KeyStoreReader {
return keystore; return keystore;
} }
private synchronized void saveKeyStore(KeyStore keyStore, String configEntryKeyStorePath,
String configEntryKeyStorePassword) throws KeystoreException {
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(
ConfigurationUtil.getConfigEntry(configEntryKeyStorePath));
keyStore.store(outputStream, ConfigurationUtil.getConfigEntry(configEntryKeyStorePassword).toCharArray());
outputStream.close();
} catch (KeyStoreException e) {
String errorMsg = "KeyStore issue occurred when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (FileNotFoundException e) {
String errorMsg = "KeyStore file not found when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (NoSuchAlgorithmException e) {
String errorMsg = "Algorithm not found when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (CertificateException e) {
String errorMsg = "CertificateException when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (IOException e) {
String errorMsg = "Input output issue occurred when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
log.error("Error closing KeyStore output stream", e);
}
}
}
KeyStore loadCertificateKeyStore() throws KeystoreException { KeyStore loadCertificateKeyStore() throws KeystoreException {
return loadKeyStore(ConfigurationUtil.CERTIFICATE_KEYSTORE, ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE, return loadKeyStore(ConfigurationUtil.CERTIFICATE_KEYSTORE, ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE,
ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD); ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD);
} }
void saveCertificateKeyStore(KeyStore keyStore) throws KeystoreException {
saveKeyStore(keyStore, ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE,
ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD);
}
public Certificate getCACertificate() throws KeystoreException { public Certificate getCACertificate() throws KeystoreException {
KeyStore keystore = loadCertificateKeyStore(); KeyStore keystore = loadCertificateKeyStore();

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl;
/** /**
@ -38,7 +39,7 @@ public class CertificateManagementServiceComponent {
} }
BundleContext bundleContext = componentContext.getBundleContext(); BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(CertificateManagementServiceImpl.class.getName(), bundleContext.registerService(CertificateManagementService.class.getName(),
CertificateManagementServiceImpl.getInstance(), null); CertificateManagementServiceImpl.getInstance(), null);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -23,6 +23,7 @@ import org.w3c.dom.Document;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
@ -35,6 +36,7 @@ import javax.sql.DataSource;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File; import java.io.File;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
@ -97,6 +99,7 @@ public final class DeviceManagerUtil {
public static boolean registerDeviceType(String typeName) throws DeviceManagementException { public static boolean registerDeviceType(String typeName) throws DeviceManagementException {
boolean status; boolean status;
try { try {
DeviceManagementDAOFactory.beginTransaction();
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName); DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName);
if (deviceType == null) { if (deviceType == null) {
@ -104,10 +107,18 @@ public final class DeviceManagerUtil {
dt.setName(typeName); dt.setName(typeName);
deviceTypeDAO.addDeviceType(dt); deviceTypeDAO.addDeviceType(dt);
} }
DeviceManagementDAOFactory.commitTransaction();
status = true; status = true;
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceManagementException("Error occurred while registering the device type '" + throw new DeviceManagementException("Error occurred while registering the device type '" +
typeName + "'", e); typeName + "'", e);
} catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceManagementException("SQL occurred while registering the device type '" +
typeName + "'", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
} }
return status; return status;
} }
@ -120,6 +131,7 @@ public final class DeviceManagerUtil {
*/ */
public static boolean unregisterDeviceType(String typeName) throws DeviceManagementException { public static boolean unregisterDeviceType(String typeName) throws DeviceManagementException {
try { try {
DeviceManagementDAOFactory.beginTransaction();
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName); DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName);
if (deviceType != null) { if (deviceType != null) {
@ -127,10 +139,18 @@ public final class DeviceManagerUtil {
dt.setName(typeName); dt.setName(typeName);
deviceTypeDAO.removeDeviceType(typeName); deviceTypeDAO.removeDeviceType(typeName);
} }
DeviceManagementDAOFactory.commitTransaction();
return true; return true;
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceManagementException("Error occurred while registering the device type '" + throw new DeviceManagementException("Error occurred while registering the device type '" +
typeName + "'", e); typeName + "'", e);
} catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceManagementException("SQL occurred while registering the device type '" +
typeName + "'", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
} }
} }

@ -420,11 +420,7 @@ public class PolicyDAOImpl implements PolicyDAO {
stmt.setString(1, name); stmt.setString(1, name);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery(); resultSet = stmt.executeQuery();
exist = resultSet.next();
if (resultSet.next()) {
//TODO: FIXME
exist = resultSet.getBoolean(1);
}
} catch (SQLException e) { } catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while checking whether criterion (" + name + throw new PolicyManagerDAOException("Error occurred while checking whether criterion (" + name +
") exists", e); ") exists", e);

@ -59,7 +59,7 @@ import java.util.Map;
public class MonitoringManagerImpl implements MonitoringManager { public class MonitoringManagerImpl implements MonitoringManager {
private PolicyDAO policyDAO; private PolicyDAO policyDAO;
// private DeviceDAO deviceDAO; // private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private MonitoringDAO monitoringDAO; private MonitoringDAO monitoringDAO;
private ComplianceDecisionPoint complianceDecisionPoint; private ComplianceDecisionPoint complianceDecisionPoint;
@ -226,8 +226,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
@Override @Override
public void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException { public void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException {
ComplianceDecisionPoint decisionPoint = new ComplianceDecisionPointImpl();
//int tenantId = PolicyManagerUtil.getTenantId(); //int tenantId = PolicyManagerUtil.getTenantId();
Map<Integer, Device> deviceIds = new HashMap<>(); Map<Integer, Device> deviceIds = new HashMap<>();
List<ComplianceData> complianceDatas; List<ComplianceData> complianceDatas;
@ -327,10 +325,11 @@ public class MonitoringManagerImpl implements MonitoringManager {
} }
} }
// TODO : This should be uncommented, this is to mark the device as unreachable, But given the current implementation // TODO : This should be uncommented, this is to mark the device as unreachable, But given the current
// we are not able to do so. // implementation we are not able to do so.
// if(!deviceToMarkUnreachable.isEmpty()) { // if(!deviceToMarkUnreachable.isEmpty()) {
// ComplianceDecisionPoint decisionPoint = new ComplianceDecisionPointImpl();
// decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices( // decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices(
// new ArrayList<>(deviceToMarkUnreachable.values()))); // new ArrayList<>(deviceToMarkUnreachable.values())));
// } // }

@ -48,7 +48,6 @@ public class PolicyManagerImpl implements PolicyManager {
private ProfileDAO profileDAO; private ProfileDAO profileDAO;
private FeatureDAO featureDAO; private FeatureDAO featureDAO;
private ProfileManager profileManager; private ProfileManager profileManager;
private PolicyCacheManager policyCacheManager;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private static Log log = LogFactory.getLog(PolicyManagerImpl.class); private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
@ -109,6 +108,9 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias()); policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
} }
if(policy.isActive()){
policyDAO.activatePolicy(policy.getId());
}
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
@ -715,20 +717,6 @@ public class PolicyManagerImpl implements PolicyManager {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
try {
DeviceManagementDAOFactory.openConnection();
for (int deviceId : deviceIds) {
//TODO FIX ME
deviceList.add(deviceDAO.getDevice(new DeviceIdentifier(Integer.toString(deviceId), ""), tenantId));
}
} catch (SQLException e) {
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
} catch (DeviceManagementDAOException e) {
throw new PolicyManagementException("Error occurred while retrieving device metadata", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
return deviceList; return deviceList;
} }

Loading…
Cancel
Save