use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.
the class ConfigurationServiceTest method testContains.
/**
* Test the contains method.
*/
public void testContains() throws Exception {
final CertificateService certificateService = context.mock(CertificateService.class);
final Certificate certificate = new Certificate();
context.checking(new Expectations() {
{
oneOf(certificateService).contains(certificate);
}
});
ConfigurationServiceImpl service = new ConfigurationServiceImpl();
service.setCertSvc(certificateService);
try {
service.contains(certificate);
} catch (Exception e) {
fail("Exception thrown");
}
}
use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.
the class CertificateServiceTest method testGetCertificates.
/**
* Test the getCertificates method.
*/
public void testGetCertificates() {
final CertificateDao certificateDao = context.mock(CertificateDao.class);
final Collection<Long> certificateIds = Arrays.asList(7L, 8L);
final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
context.checking(new Expectations() {
{
oneOf(certificateDao).list(new ArrayList<Long>(certificateIds));
will(returnValue(Collections.<Certificate>emptyList()));
}
});
CertificateServiceImpl service = new CertificateServiceImpl();
service.setDao(certificateDao);
try {
Collection<Certificate> output = service.getCertificates(certificateIds, certificateOptions);
assertEquals("Output does not match expected", Collections.<Certificate>emptyList(), output);
} catch (Exception e) {
fail("Exception thrown");
}
}
use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.
the class TrustBundleServiceTest method testUpdateTrustBundleSigningCertificate.
public void testUpdateTrustBundleSigningCertificate() throws Exception {
X509Certificate cert = mock(X509Certificate.class);
CertContainer container = mock(CertContainer.class);
when(container.getCert()).thenReturn(cert);
Certificate confCert = mock(Certificate.class);
when(confCert.toCredential()).thenReturn(container);
impl.updateTrustBundleSigningCertificate(1234, confCert);
verify(dao, times(1)).updateTrustBundleSigningCertificate(eq((long) 1234), (X509Certificate) any());
}
use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.
the class CertificateDaoImpl method save.
/*
* (non-Javadoc)
*
* @see org.nhindirect.config.store.dao.CertificateDao#save(java.util.List)
*/
@Transactional(readOnly = false)
public void save(List<Certificate> certList) {
if (log.isDebugEnabled())
log.debug("Enter");
if (certList != null && certList.size() > 0) {
for (Certificate cert : certList) {
cert.setCreateTime(Calendar.getInstance());
try {
CertUtils.CertContainer container = null;
X509Certificate xcert = null;
try {
// this might be an X509Certificate or a P12 key store.. assume there is no protection for P12 key stores...
container = CertUtils.toCertContainer(cert.getData());
xcert = container.getCert();
} catch (Exception e) {
// probably not a certificate but an IPKIX URL
}
if (cert.getValidStartDate() == null && xcert != null) {
Calendar startDate = Calendar.getInstance();
startDate.setTime(xcert.getNotBefore());
cert.setValidStartDate(startDate);
}
if (cert.getValidEndDate() == null && xcert != null) {
Calendar endDate = Calendar.getInstance();
endDate.setTime(xcert.getNotAfter());
cert.setValidEndDate(endDate);
}
if (cert.getStatus() == null)
cert.setStatus(EntityStatus.NEW);
cert.setPrivateKey(container != null && (container.getKey() != null || container.getWrappedKeyData() != null));
// if the key store protection manager is set and this is a P12 file, convert the cert data into a protected P12 file
if (cert.isPrivateKey() && kspMgr != null && container.getKey() != null) {
try {
final String newKeystorePassPhrase = new String(kspMgr.getKeyStoreProtectionKey().getEncoded());
final String newPrivateKeyPassPhrase = new String(kspMgr.getPrivateKeyProtectionKey().getEncoded());
cert.setRawData(CertUtils.changePkcs12Protection(cert.getData(), "".toCharArray(), "".toCharArray(), newKeystorePassPhrase.toCharArray(), newPrivateKeyPassPhrase.toCharArray()));
} catch (Exception e) {
throw new RuntimeException("Error converting P12 to encrypted/protected format", e);
}
}
} catch (CertificateException e) {
}
if (log.isDebugEnabled())
log.debug("Calling JPA to persist the Certificate");
entityManager.persist(cert);
if (log.isDebugEnabled())
log.debug("Returned from JPA: Certificate ID=" + cert.getId());
}
entityManager.flush();
}
if (log.isDebugEnabled())
log.debug("Exit");
}
use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.
the class CertificateDaoImpl method list.
/*
* (non-Javadoc)
*
* @see org.nhindirect.config.store.dao.CertificateDao#list(java.lang.String)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Transactional(readOnly = true)
public List<Certificate> list(String owner) {
if (log.isDebugEnabled())
log.debug("Enter");
List<Certificate> result = Collections.emptyList();
Query select = null;
if (owner == null) {
select = entityManager.createQuery("SELECT c from Certificate c");
} else if (owner != null) {
select = entityManager.createQuery("SELECT c from Certificate c WHERE UPPER(c.owner) = ?1");
select.setParameter(1, owner.toUpperCase(Locale.getDefault()));
}
List rs = select.getResultList();
if ((rs.size() != 0) && (rs.get(0) instanceof Certificate)) {
result = (List<Certificate>) rs;
}
for (Certificate cert : result) stripP12Protection(cert);
if (log.isDebugEnabled())
log.debug("Exit");
return result;
}
Aggregations