mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
adding some more files
This commit is contained in:
parent
918ddff25e
commit
300905df84
56
core/src/com/cloud/certificate/CertificateVO.java
Normal file
56
core/src/com/cloud/certificate/CertificateVO.java
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.certificate;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="certificate")
|
||||
public class CertificateVO {
|
||||
|
||||
public CertificateVO(String cert)
|
||||
{
|
||||
this.certificate = cert;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private Long id = null;
|
||||
|
||||
@Column(name="certificate")
|
||||
private String certificate;
|
||||
|
||||
public CertificateVO() {}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getCertificate() {
|
||||
return certificate;
|
||||
}
|
||||
public void setCertificate(String certificate) {
|
||||
this.certificate = certificate;
|
||||
}
|
||||
}
|
||||
26
core/src/com/cloud/certificate/dao/CertificateDao.java
Normal file
26
core/src/com/cloud/certificate/dao/CertificateDao.java
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.certificate.dao;
|
||||
|
||||
import com.cloud.certificate.CertificateVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface CertificateDao extends GenericDao<CertificateVO, Long> {
|
||||
public boolean persistCustomCertToDb(String certPath);
|
||||
}
|
||||
51
core/src/com/cloud/certificate/dao/CertificateDaoImpl.java
Normal file
51
core/src/com/cloud/certificate/dao/CertificateDaoImpl.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.cloud.certificate.dao;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.certificate.CertificateVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
@Local(value={CertificateDao.class}) @DB(txn=false)
|
||||
public class CertificateDaoImpl extends GenericDaoBase<CertificateVO, Long> implements CertificateDao {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(CertificateDaoImpl.class);
|
||||
|
||||
@Override
|
||||
public boolean persistCustomCertToDb(String certPath){
|
||||
|
||||
String certStr = null;
|
||||
byte[] buffer = new byte[(int) new File(certPath).length()];
|
||||
BufferedInputStream f = null;
|
||||
try
|
||||
{
|
||||
f = new BufferedInputStream(new FileInputStream(certPath));
|
||||
f.read(buffer);
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.warn("Unable to read the certificate: "+e);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Unable to read the certificate: "+e);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (f != null)
|
||||
try { f.close(); } catch (IOException ignored) { }
|
||||
}
|
||||
certStr = new String(buffer);
|
||||
|
||||
CertificateVO certRec = new CertificateVO(certStr);
|
||||
this.persist(certRec);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user