forked from community/device-mgt-core
parent
13126fe398
commit
08ff70bb3c
6
components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/util/DeviceMgtAPIUtils.java → components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/util/CertificateMgtAPIUtils.java
6
components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/util/DeviceMgtAPIUtils.java → components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/util/CertificateMgtAPIUtils.java
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.config;
|
||||
|
||||
import org.wso2.carbon.certificate.mgt.core.util.CertificateManagementConstants;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding CertificateKeystore data.
|
||||
*/
|
||||
@XmlRootElement(name = "CertificateKeystore")
|
||||
public class CertificateKeystoreConfig {
|
||||
|
||||
private String certificateKeystoreLocation;
|
||||
private String certificateKeystoreType;
|
||||
private String certificateKeystorePassword;
|
||||
private String caCertAlias;
|
||||
private String caPrivateKeyPassword;
|
||||
private String raCertAlias;
|
||||
private String raPrivateKeyPassword;
|
||||
|
||||
@XmlElement(name = "CertificateKeystoreLocation", required = true)
|
||||
public String getCertificateKeystoreLocation() {
|
||||
return certificateKeystoreLocation;
|
||||
}
|
||||
|
||||
public void setCertificateKeystoreLocation(String certificateKeystoreLocation) {
|
||||
if (certificateKeystoreLocation != null && certificateKeystoreLocation.toLowerCase().
|
||||
contains(CertificateManagementConstants.CARBON_HOME_ENTRY)) {
|
||||
certificateKeystoreLocation = certificateKeystoreLocation.replace(CertificateManagementConstants.CARBON_HOME_ENTRY,
|
||||
System.getProperty(CertificateManagementConstants.CARBON_HOME));
|
||||
}
|
||||
this.certificateKeystoreLocation = certificateKeystoreLocation;
|
||||
}
|
||||
|
||||
@XmlElement(name = "CertificateKeystoreType", required = true)
|
||||
public String getCertificateKeystoreType() {
|
||||
return certificateKeystoreType;
|
||||
}
|
||||
|
||||
public void setCertificateKeystoreType(String certificateKeystoreType) {
|
||||
this.certificateKeystoreType = certificateKeystoreType;
|
||||
}
|
||||
|
||||
@XmlElement(name = "CertificateKeystorePassword", required = true)
|
||||
public String getCertificateKeystorePassword() {
|
||||
return certificateKeystorePassword;
|
||||
}
|
||||
|
||||
public void setCertificateKeystorePassword(String certificateKeystorePassword) {
|
||||
this.certificateKeystorePassword = certificateKeystorePassword;
|
||||
}
|
||||
|
||||
@XmlElement(name = "CACertAlias", required = true)
|
||||
public String getCACertAlias() {
|
||||
return caCertAlias;
|
||||
}
|
||||
|
||||
public void setCACertAlias(String caCertAlias) {
|
||||
this.caCertAlias = caCertAlias;
|
||||
}
|
||||
|
||||
@XmlElement(name = "CAPrivateKeyPassword", required = true)
|
||||
public String getCAPrivateKeyPassword() {
|
||||
return caPrivateKeyPassword;
|
||||
}
|
||||
|
||||
public void setCAPrivateKeyPassword(String caPrivateKeyPassword) {
|
||||
this.caPrivateKeyPassword = caPrivateKeyPassword;
|
||||
}
|
||||
|
||||
@XmlElement(name = "RACertAlias", required = true)
|
||||
public String getRACertAlias() {
|
||||
return raCertAlias;
|
||||
}
|
||||
|
||||
public void setRACertAlias(String raCertAlias) {
|
||||
this.raCertAlias = raCertAlias;
|
||||
}
|
||||
|
||||
@XmlElement(name = "RAPrivateKeyPassword", required = true)
|
||||
public String getRAPrivateKeyPassword() {
|
||||
return raPrivateKeyPassword;
|
||||
}
|
||||
|
||||
public void setRAPrivateKeyPassword(String raPrivateKeyPassword) {
|
||||
this.raPrivateKeyPassword = raPrivateKeyPassword;
|
||||
}
|
||||
}
|
@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.bean.Certificate;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateDAO;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||
import org.wso2.carbon.certificate.mgt.core.util.Serializer;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the generic implementation of CertificateDAO which can be used to support ANSI db syntax.
|
||||
*/
|
||||
public abstract class AbstractCertificateDAOImpl implements CertificateDAO{
|
||||
|
||||
private static final Log log = LogFactory.getLog(GenericCertificateDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public void addCertificate(List<Certificate> certificates)
|
||||
throws CertificateManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement(
|
||||
"INSERT INTO DM_DEVICE_CERTIFICATE (SERIAL_NUMBER, CERTIFICATE, TENANT_ID, USERNAME)"
|
||||
+ " VALUES (?,?,?,?)");
|
||||
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.
|
||||
getThreadLocalCarbonContext();
|
||||
String username = threadLocalCarbonContext.getUsername();
|
||||
for (Certificate certificate : certificates) {
|
||||
// the serial number of the certificate used for its creation is set as its alias.
|
||||
String serialNumber = certificate.getSerial();
|
||||
if (serialNumber == null || serialNumber.isEmpty()) {
|
||||
serialNumber = String.valueOf(certificate.getCertificate().getSerialNumber());
|
||||
}
|
||||
byte[] bytes = Serializer.serialize(certificate.getCertificate());
|
||||
|
||||
stmt.setString(1, serialNumber);
|
||||
stmt.setBytes(2, bytes);
|
||||
stmt.setInt(3, certificate.getTenantId());
|
||||
stmt.setString(4, username);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
} catch (SQLException | IOException e) {
|
||||
throw new CertificateManagementDAOException("Error occurred while saving certificates. "
|
||||
, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CertificateResponse retrieveCertificate(String serialNumber)
|
||||
throws CertificateManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
CertificateResponse certificateResponse = null;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query =
|
||||
"SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM"
|
||||
+ " DM_DEVICE_CERTIFICATE WHERE SERIAL_NUMBER = ? AND TENANT_ID = ? ";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, serialNumber);
|
||||
stmt.setInt(2, tenantId);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
certificateResponse = new CertificateResponse();
|
||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||
certificateResponse.setCertificate(certificateBytes);
|
||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errorMsg =
|
||||
"Unable to get the read the certificate with serial" + serialNumber;
|
||||
log.error(errorMsg, e);
|
||||
throw new CertificateManagementDAOException(errorMsg, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return certificateResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CertificateResponse> searchCertificate(String serialNumber)
|
||||
throws CertificateManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
CertificateResponse certificateResponse = null;
|
||||
List<CertificateResponse> certificates = new ArrayList<>();
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query =
|
||||
"SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM DM_DEVICE_CERTIFICATE "
|
||||
+ "WHERE SERIAL_NUMBER LIKE ? AND TENANT_ID = ? ";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, "%" + serialNumber + "%");
|
||||
stmt.setInt(2, tenantId);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
certificateResponse = new CertificateResponse();
|
||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||
certificates.add(certificateResponse);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errorMsg =
|
||||
"Unable to get the read the certificate with serial" + serialNumber;
|
||||
log.error(errorMsg, e);
|
||||
throw new CertificateManagementDAOException(errorMsg, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return certificates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CertificateResponse> getAllCertificates() throws CertificateManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
CertificateResponse certificateResponse;
|
||||
List<CertificateResponse> certificates = new ArrayList<>();
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME"
|
||||
+ " FROM DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
certificateResponse = new CertificateResponse();
|
||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||
certificates.add(certificateResponse);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||
log.error(errorMsg, e);
|
||||
throw new CertificateManagementDAOException(errorMsg, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return certificates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query =
|
||||
"DELETE FROM DM_DEVICE_CERTIFICATE WHERE SERIAL_NUMBER = ?" +
|
||||
" AND TENANT_ID = ? ";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, serialNumber);
|
||||
stmt.setInt(2, tenantId);
|
||||
|
||||
return stmt.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to get the read the certificate with serial" + serialNumber;
|
||||
log.error(msg, e);
|
||||
throw new CertificateManagementDAOException(msg, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return CertificateManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||
import org.wso2.carbon.certificate.mgt.core.service.PaginationResult;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the oracle sql implementation of CertificateDAO which can be used to support Oracle specific
|
||||
* db syntax.
|
||||
*/
|
||||
public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
||||
|
||||
private static final Log log = LogFactory.getLog(OracleCertificateDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
CertificateResponse certificateResponse;
|
||||
List<CertificateResponse> certificates = new ArrayList<>();
|
||||
PaginationResult paginationResult;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM "
|
||||
+ "DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC WHERE OFFSET >= ? AND ROWNUM <= ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, rowNum);
|
||||
stmt.setInt(3, limit);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
int resultCount = 0;
|
||||
while (resultSet.next()) {
|
||||
certificateResponse = new CertificateResponse();
|
||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||
certificates.add(certificateResponse);
|
||||
resultCount++;
|
||||
}
|
||||
paginationResult = new PaginationResult();
|
||||
paginationResult.setData(certificates);
|
||||
paginationResult.setRecordsTotal(resultCount);
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||
log.error(errorMsg, e);
|
||||
throw new CertificateManagementDAOException(errorMsg, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return paginationResult;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return CertificateManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||
import org.wso2.carbon.certificate.mgt.core.service.PaginationResult;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the PostgreSQL implementation of CertificateDAO which can be used to support PostgreSQL specific
|
||||
* db syntax.
|
||||
*/
|
||||
public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PostgreSQLCertificateDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
CertificateResponse certificateResponse;
|
||||
List<CertificateResponse> certificates = new ArrayList<>();
|
||||
PaginationResult paginationResult;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM "
|
||||
+ "DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC LIMIT ? OFFSET ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, limit);
|
||||
stmt.setInt(3, rowNum);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
int resultCount = 0;
|
||||
while (resultSet.next()) {
|
||||
certificateResponse = new CertificateResponse();
|
||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||
certificates.add(certificateResponse);
|
||||
resultCount++;
|
||||
}
|
||||
paginationResult = new PaginationResult();
|
||||
paginationResult.setData(certificates);
|
||||
paginationResult.setRecordsTotal(resultCount);
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||
log.error(errorMsg, e);
|
||||
throw new CertificateManagementDAOException(errorMsg, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return paginationResult;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return CertificateManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||
import org.wso2.carbon.certificate.mgt.core.service.PaginationResult;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the SQLServer implementation of CertificateDAO which can be used to support SQLServer specific
|
||||
* db syntax.
|
||||
*/
|
||||
public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SQLServerCertificateDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
CertificateResponse certificateResponse;
|
||||
List<CertificateResponse> certificates = new ArrayList<>();
|
||||
PaginationResult paginationResult;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM "
|
||||
+ "DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, rowNum);
|
||||
stmt.setInt(3, limit);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
int resultCount = 0;
|
||||
while (resultSet.next()) {
|
||||
certificateResponse = new CertificateResponse();
|
||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||
certificates.add(certificateResponse);
|
||||
resultCount++;
|
||||
}
|
||||
paginationResult = new PaginationResult();
|
||||
paginationResult.setData(certificates);
|
||||
paginationResult.setRecordsTotal(resultCount);
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||
log.error(errorMsg, e);
|
||||
throw new CertificateManagementDAOException(errorMsg, e);
|
||||
} finally {
|
||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
}
|
||||
return paginationResult;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return CertificateManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.certificate.mgt.core.exception;
|
||||
|
||||
public class IllegalTransactionStateException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279331929070297L;
|
||||
|
||||
public IllegalTransactionStateException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public IllegalTransactionStateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IllegalTransactionStateException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public IllegalTransactionStateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IllegalTransactionStateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.certificate.mgt.core.exception;
|
||||
|
||||
public class TransactionManagementException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279321929070297L;
|
||||
|
||||
public TransactionManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public TransactionManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public TransactionManagementException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public TransactionManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TransactionManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.exception;
|
||||
|
||||
/**
|
||||
* This runtime exception will be thrown if the server has configured with unsupported DB engine.
|
||||
*/
|
||||
public class UnsupportedDatabaseEngineException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070297L;
|
||||
|
||||
public UnsupportedDatabaseEngineException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UnsupportedDatabaseEngineException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.service;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds necessary data to represent a paginated result.
|
||||
*/
|
||||
@ApiModel(value = "PaginationResult", description = "This class carries all information related Pagination Result")
|
||||
public class PaginationResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1998101711L;
|
||||
|
||||
@ApiModelProperty(name = "recordsTotal", value = "The total number of records that are given before filtering", required = true)
|
||||
private int recordsTotal;
|
||||
|
||||
@ApiModelProperty(name = "recordsFiltered", value = "The total number of records that are given after filtering", required = true)
|
||||
private int recordsFiltered;
|
||||
|
||||
@ApiModelProperty(name = "draw", value = "The draw counter that this object is a response to, from the draw parameter sent as part of the data request", required = true)
|
||||
private int draw;
|
||||
|
||||
@ApiModelProperty(name = "data", value = "This holds the db records that matches given criteria", required = true)
|
||||
private List<?> data;
|
||||
|
||||
public int getRecordsTotal() {
|
||||
return recordsTotal;
|
||||
}
|
||||
|
||||
public int getRecordsFiltered() {
|
||||
return recordsFiltered;
|
||||
}
|
||||
|
||||
public void setRecordsFiltered(int recordsFiltered) {
|
||||
this.recordsFiltered = recordsFiltered;
|
||||
}
|
||||
|
||||
public void setRecordsTotal(int recordsTotal) {
|
||||
this.recordsTotal = recordsTotal;
|
||||
|
||||
}
|
||||
|
||||
public List<?> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<?> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getDraw() {
|
||||
return draw;
|
||||
}
|
||||
|
||||
public void setDraw(int draw) {
|
||||
this.draw = draw;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.certificate.mgt.core.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class CertificateMgtSchemaInitializer extends DatabaseCreator {
|
||||
|
||||
private static final Log log = LogFactory.getLog(CertificateMgtSchemaInitializer.class);
|
||||
private static final String setupSQLScriptBaseLocation =
|
||||
CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "certMgt" + File.separator;
|
||||
|
||||
public CertificateMgtSchemaInitializer(DataSourceConfig config) {
|
||||
super(CertificateManagerUtil.resolveDataSource(config));
|
||||
}
|
||||
|
||||
protected String getDbScriptLocation(String databaseType) {
|
||||
String scriptName = databaseType + ".sql";
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Loading database script from :" + scriptName);
|
||||
}
|
||||
return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
|
||||
}
|
||||
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.certificate.mgt.core.util;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfigurationUtil {
|
||||
|
||||
public static final String PATH_CERTIFICATE_KEYSTORE = "CertificateKeystoreLocation";
|
||||
public static final String CERTIFICATE_KEYSTORE_PASSWORD = "CertificateKeystorePassword";
|
||||
public static final String KEYSTORE_CA_CERT_PRIV_PASSWORD = "CAPrivateKeyPassword";
|
||||
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 SIGNATURE_ALGORITHM = "SHA1withRSA";
|
||||
public static final String PROVIDER = "BC";
|
||||
public static final String KEYSTORE = "Type";
|
||||
public static final String CERTIFICATE_KEYSTORE = "CertificateKeystoreType";
|
||||
public static final String RSA = "RSA";
|
||||
public static final String UTF_8 = "UTF-8";
|
||||
public static final String SHA256_RSA = "SHA256WithRSAEncryption";
|
||||
public static final String X_509 = "X.509";
|
||||
public static final String POST_BODY_CA_CAPS = "POSTPKIOperation\nSHA-1\nDES3\n";
|
||||
public static final String DES_EDE = "DESede";
|
||||
public static final String CONF_LOCATION = "conf.location";
|
||||
public static final String DEFAULT_PRINCIPAL = "O=WSO2, OU=Mobile, C=LK";
|
||||
public static final String RSA_PRIVATE_KEY_BEGIN_TEXT = "-----BEGIN RSA PRIVATE KEY-----\n";
|
||||
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 final String CARBON_HOME = "carbon.home";
|
||||
private static final String CERTIFICATE_CONFIG_XML = "certificate-config.xml";
|
||||
private static final String CARBON_HOME_ENTRY = "${carbon.home}";
|
||||
private static final String[] certificateConfigEntryNames = { CA_CERT_ALIAS, RA_CERT_ALIAS,
|
||||
CERTIFICATE_KEYSTORE, PATH_CERTIFICATE_KEYSTORE, CERTIFICATE_KEYSTORE_PASSWORD,
|
||||
KEYSTORE_CA_CERT_PRIV_PASSWORD, KEYSTORE_RA_CERT_PRIV_PASSWORD };
|
||||
private static ConfigurationUtil configurationUtil;
|
||||
private static Map<String, String> configMap;
|
||||
|
||||
private static Map<String, String> readCertificateConfigurations() throws KeystoreException {
|
||||
|
||||
String certConfLocation = System.getProperty(CONF_LOCATION) + File.separator + CERTIFICATE_CONFIG_XML;
|
||||
|
||||
if (configurationUtil == null || configMap == null) {
|
||||
|
||||
configurationUtil = new ConfigurationUtil();
|
||||
configMap = new HashMap<String, String>();
|
||||
|
||||
Document document;
|
||||
try {
|
||||
File fXmlFile = new File(certConfLocation);
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
document = documentBuilder.parse(fXmlFile);
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new KeystoreException("Error parsing configuration in certificate-config.xml file");
|
||||
} catch (SAXException e) {
|
||||
throw new KeystoreException("SAX exception in certificate-config.xml file");
|
||||
} catch (IOException e) {
|
||||
throw new KeystoreException("Error reading certificate-config.xml file");
|
||||
}
|
||||
|
||||
for (String configEntry : certificateConfigEntryNames) {
|
||||
NodeList elements = document.getElementsByTagName(configEntry);
|
||||
if (elements != null && elements.getLength() > 0) {
|
||||
configMap.put(configEntry, elements.item(0).getTextContent());
|
||||
}
|
||||
}
|
||||
|
||||
String certKeyStoreLocation = replaceCarbonHomeEnvEntry(configMap.get(PATH_CERTIFICATE_KEYSTORE));
|
||||
if (certKeyStoreLocation != null) {
|
||||
configMap.put(PATH_CERTIFICATE_KEYSTORE, certKeyStoreLocation);
|
||||
}
|
||||
}
|
||||
|
||||
return configMap;
|
||||
}
|
||||
|
||||
public static String getConfigEntry(final String entry) throws KeystoreException {
|
||||
|
||||
Map<String, String> configurationMap = readCertificateConfigurations();
|
||||
String configValue = configurationMap.get(entry);
|
||||
|
||||
if (configValue == null) {
|
||||
throw new KeystoreException(String.format("Configuration entry %s not available", entry));
|
||||
}
|
||||
|
||||
return configValue.trim();
|
||||
}
|
||||
|
||||
private static String replaceCarbonHomeEnvEntry(String entry) {
|
||||
if (entry != null && entry.toLowerCase().contains(CARBON_HOME_ENTRY)) {
|
||||
return entry.replace(CARBON_HOME_ENTRY, System.getProperty(CARBON_HOME));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ConfigurationUtil getInstance() {
|
||||
if (configurationUtil == null) {
|
||||
synchronized (ConfigurationUtil.class) {
|
||||
if (configurationUtil == null) {
|
||||
configurationUtil = new ConfigurationUtil();
|
||||
}
|
||||
}
|
||||
}
|
||||
return configurationUtil;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package org.wso2.carbon.certificate.mgt.core.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
public class TenantUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TenantUtil.class);
|
||||
|
||||
public static int getTenanntId(String tenantDomain) throws CertificateManagementException {
|
||||
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
instructions.configure = \
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/wso2certs.jks,target:${installFolder}/../../resources/security/wso2certs.jks,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/certificate-config.xml,target:${installFolder}/../../conf/certificate-config.xml,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/dbscripts/cdm/,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts,overwrite:true);\
|
Loading…
Reference in new issue