Search in sources :

Example 36 with ConfigurationStoreException

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
}
Also used : CertPolicy(org.nhindirect.config.store.CertPolicy) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with ConfigurationStoreException

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);
        }
    }
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with ConfigurationStoreException

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);
    }
}
Also used : Query(javax.persistence.Query) TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with ConfigurationStoreException

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);
    }
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with ConfigurationStoreException

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);
    }
}
Also used : RSAKey(java.security.interfaces.RSAKey) CERTRecord(org.xbill.DNS.CERTRecord) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) IOException(java.io.IOException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException)

Aggregations

ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)45 Transactional (org.springframework.transaction.annotation.Transactional)39 NoResultException (javax.persistence.NoResultException)32 Query (javax.persistence.Query)21 TrustBundle (org.nhindirect.config.store.TrustBundle)15 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)10 Domain (org.nhindirect.config.store.Domain)10 CertPolicy (org.nhindirect.config.store.CertPolicy)8 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)6 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)5 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)4 File (java.io.File)3 CertPolicyGroupReltn (org.nhindirect.config.store.CertPolicyGroupReltn)3 DNSRecord (org.nhindirect.config.store.DNSRecord)2 ApplicationContext (org.springframework.context.ApplicationContext)2 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 X509Certificate (java.security.cert.X509Certificate)1 RSAKey (java.security.interfaces.RSAKey)1