use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class CertPolicyDaoImpl method addPolicy.
@Override
@Transactional(readOnly = false)
public void addPolicy(CertPolicy policy) throws ConfigurationStoreException {
validateState();
try {
final CertPolicy existingPolicy = this.getPolicyByName(policy.getPolicyName());
if (existingPolicy != null)
throw new ConfigurationStoreException("Certificate policy " + policy.getPolicyName() + " already exists");
policy.setCreateTime(Calendar.getInstance(Locale.getDefault()));
entityManager.persist(policy);
entityManager.flush();
} catch (ConfigurationStoreException cse) {
throw cse;
}///CLOVER:OFF
catch (Exception e) {
throw new ConfigurationStoreException("Failed to add certificate policy " + policy.getPolicyName(), e);
}
///CLOVER:ON
}
use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method deleteTrustBundles.
/**
* {@inheritDoc}
*/
@Transactional(readOnly = false)
@Override
public void deleteTrustBundles(long[] trustBundleIds) throws ConfigurationStoreException {
validateState();
if (trustBundleIds == null || trustBundleIds.length == 0)
return;
for (long id : trustBundleIds) {
try {
final TrustBundle bundle = this.getTrustBundleById(id);
this.disassociateTrustBundleFromDomains(id);
entityManager.remove(bundle);
entityManager.flush();
} catch (ConfigurationStoreException e) {
log.warn(e.getMessage(), e);
}
}
}
use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method disassociateTrustBundleFromDomain.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void disassociateTrustBundleFromDomain(long domainId, long trustBundleId) throws ConfigurationStoreException {
validateState();
// make sure the domain exists
final Domain domain = domainDao.getDomain(domainId);
if (domain == null)
throw new ConfigurationStoreException("Domain with id " + domainId + " does not exist");
// make sure the trust bundle exists
final TrustBundle trustBundle = this.getTrustBundleById(trustBundleId);
if (trustBundle == null)
throw new ConfigurationStoreException("Trust budnel with id " + trustBundle + " does not exist");
try {
final Query select = entityManager.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain = ?1 " + " and tbd.trustBundle = ?2 ");
select.setParameter(1, domain);
select.setParameter(2, trustBundle);
final TrustBundleDomainReltn reltn = (TrustBundleDomainReltn) select.getSingleResult();
entityManager.remove(reltn);
entityManager.flush();
} catch (NoResultException e) {
throw new ConfigurationStoreException("Association between domain id " + domainId + " and trust bundle id" + trustBundleId + " does not exist", e);
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to delete trust bundle to domain relation.", e);
}
}
use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method associateTrustBundleToDomain.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void associateTrustBundleToDomain(long domainId, long trustBundleId, boolean incoming, boolean outgoing) throws ConfigurationStoreException {
validateState();
// make sure the domain exists
final Domain domain = domainDao.getDomain(domainId);
if (domain == null)
throw new ConfigurationStoreException("Domain with id " + domainId + " does not exist");
// make sure the trust bundle exists
final TrustBundle trustBundle = this.getTrustBundleById(trustBundleId);
if (trustBundle == null)
throw new ConfigurationStoreException("Trust budnel with id " + trustBundle + " does not exist");
try {
final TrustBundleDomainReltn domainTrustBundleAssoc = new TrustBundleDomainReltn();
domainTrustBundleAssoc.setDomain(domain);
domainTrustBundleAssoc.setTrustBundle(trustBundle);
domainTrustBundleAssoc.setIncoming(incoming);
domainTrustBundleAssoc.setOutgoing(outgoing);
entityManager.persist(domainTrustBundleAssoc);
entityManager.flush();
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to associate trust bundle to domain.", e);
}
}
use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class DNSRecordUtils method createX509CERTRecord.
/**
* Creates a DNS CERT record containing an X509 public certificate.
* @param address The name or address corresponding to the certificate.
* @param ttl The time to live in seconds.
* @param cert The X509 public certificate to be stored with the name/address.
* @return A DNSRecord representing a CERT type record.
* @throws ConfigurationStoreException
*/
public static DNSRecord createX509CERTRecord(String address, long ttl, X509Certificate cert) throws ConfigurationStoreException {
if (!address.endsWith("."))
address = address + ".";
try {
int keyTag = 0;
if (cert.getPublicKey() instanceof RSAKey) {
RSAKey key = (RSAKey) cert.getPublicKey();
byte[] modulus = key.getModulus().toByteArray();
keyTag = (modulus[modulus.length - 2] << 8) & 0xFF00;
keyTag |= modulus[modulus.length - 1] & 0xFF;
}
CERTRecord rec = new CERTRecord(Name.fromString(address), DClass.IN, ttl, CERTRecord.PKIX, keyTag, 5, /*public key alg, RFC 4034*/
cert.getEncoded());
return DNSRecord.fromWire(rec.toWireCanonical());
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to create DNS CERT record: " + e.getMessage(), e);
}
}
Aggregations