Search in sources :

Example 1 with ConfigurationServiceException

use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.

the class TrustBundleServiceImpl method updateTrustBundleAttributes.

/**
     * {@inheritDoc}
     */
@Override
public void updateTrustBundleAttributes(long trustBundleId, String bundleName, String bundleUrl, Certificate signingCert, int refreshInterval) throws ConfigurationServiceException {
    final TrustBundle oldBundle = dao.getTrustBundleById(trustBundleId);
    String oldBundleURL = "";
    X509Certificate newSigningCert = null;
    // need to know if the URL changed... store off the old URL
    if (oldBundle != null)
        oldBundleURL = oldBundle.getBundleURL();
    try {
        // make sure the cert isn't null before converting to an X509Certificate
        if (signingCert != null && signingCert.toCredential() != null)
            newSigningCert = signingCert.toCredential().getCert();
        dao.updateTrustBundleAttributes(trustBundleId, bundleName, bundleUrl, newSigningCert, refreshInterval);
        // if the URL changed, the bundle needs to be refreshed
        if (!oldBundleURL.equals(bundleUrl)) {
            final TrustBundle bundle = dao.getTrustBundleById(trustBundleId);
            if (bundle != null)
                template.sendBody(bundle);
        }
    } catch (CertificateException e) {
        throw new ConfigurationServiceException(e);
    }
}
Also used : ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) TrustBundle(org.nhindirect.config.store.TrustBundle) CertificateException(org.nhindirect.config.store.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Example 2 with ConfigurationServiceException

use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.

the class DomainController method removeBundles.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removeBundles", method = RequestMethod.POST)
public ModelAndView removeBundles(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AnchorForm anchorForm, Model model, @RequestParam(value = "domainId") String domainId, @RequestParam(value = "bundles") String bundles) {
    ModelAndView mav = new ModelAndView();
    // DEBUG
    if (log.isDebugEnabled()) {
        log.debug("Enter domain/removeBundles");
    }
    String[] bundleIds = bundles.split(":");
    for (String bundle : bundleIds) {
        try {
            configSvc.disassociateTrustBundleFromDomain(Long.parseLong(domainId), Long.parseLong(bundle));
        } catch (ConfigurationServiceException cse) {
        }
    }
    return new ModelAndView("redirect:/config/domain?id=" + domainId + "&action=update#tab3");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ConfigurationServiceException

use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.

the class DNSController method toCertContainer.

public CertContainer toCertContainer(byte[] data) throws Exception {
    CertContainer certContainer = null;
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        // lets try this a as a PKCS12 data stream first
        try {
            final KeyStore localKeyStore = KeyStore.getInstance("PKCS12", getJCEProviderName());
            localKeyStore.load(bais, "".toCharArray());
            final Enumeration<String> aliases = localKeyStore.aliases();
            // we are really expecting only one alias
            if (aliases.hasMoreElements()) {
                String alias = aliases.nextElement();
                X509Certificate cert = (X509Certificate) localKeyStore.getCertificate(alias);
                // check if there is private key
                final Key key = localKeyStore.getKey(alias, "".toCharArray());
                if (key != null && key instanceof PrivateKey) {
                    certContainer = new CertContainer(cert, key);
                }
            }
        } catch (Exception e) {
        // must not be a PKCS12 stream, go on to next step
        }
        if (certContainer == null) {
            //try X509 certificate factory next
            bais.reset();
            bais = new ByteArrayInputStream(data);
            X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(bais);
            certContainer = new CertContainer(cert, null);
        }
        bais.close();
    } catch (Exception e) {
        throw new ConfigurationServiceException("Data cannot be converted to a valid X.509 Certificate", e);
    }
    return certContainer;
}
Also used : PrivateKey(java.security.PrivateKey) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) Key(java.security.Key) PrivateKey(java.security.PrivateKey) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TextParseException(org.xbill.DNS.TextParseException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException)

Example 4 with ConfigurationServiceException

use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.

the class CertificateServiceImpl method toCertContainer.

public CertContainer toCertContainer(byte[] data) throws ConfigurationServiceException {
    CertContainer certContainer = null;
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        // lets try this a as a PKCS12 data stream first
        try {
            KeyStore localKeyStore = KeyStore.getInstance("PKCS12", Certificate.getJCEProviderName());
            localKeyStore.load(bais, "".toCharArray());
            Enumeration<String> aliases = localKeyStore.aliases();
            // we are really expecting only one alias 
            if (aliases.hasMoreElements()) {
                String alias = aliases.nextElement();
                X509Certificate cert = (X509Certificate) localKeyStore.getCertificate(alias);
                // check if there is private key
                Key key = localKeyStore.getKey(alias, "".toCharArray());
                if (key != null && key instanceof PrivateKey) {
                    certContainer = new CertContainer(cert, key);
                }
            }
        } catch (Exception e) {
        // must not be a PKCS12 stream, go on to next step
        }
        if (certContainer == null) {
            //try X509 certificate factory next       
            bais.reset();
            bais = new ByteArrayInputStream(data);
            X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(bais);
            certContainer = new CertContainer(cert, null);
        }
        bais.close();
    } catch (Exception e) {
        throw new ConfigurationServiceException("Data cannot be converted to a valid X.509 Certificate", e);
    }
    return certContainer;
}
Also used : PrivateKey(java.security.PrivateKey) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) Key(java.security.Key) PrivateKey(java.security.PrivateKey) CertificateParsingException(java.security.cert.CertificateParsingException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException)

Example 5 with ConfigurationServiceException

use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.

the class DomainController method addBundle.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addBundle", method = RequestMethod.POST)
public ModelAndView addBundle(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AnchorForm anchorForm, Model model, @RequestParam(value = "domainId") String domainId, @RequestParam(value = "bundles") String bundles) {
    ModelAndView mav = new ModelAndView();
    // DEBUG
    if (log.isDebugEnabled()) {
        log.debug("Enter domain/addBundle");
    }
    String[] bundleIds = bundles.split(":");
    for (String bundle : bundleIds) {
        String[] bundleArray = bundle.split("_");
        try {
            if (bundleArray[1].equals("both")) {
                configSvc.associateTrustBundleToDomain(Long.parseLong(domainId), Integer.parseInt(bundleArray[0]), true, true);
            } else if (bundleArray[1].equals("in")) {
                configSvc.associateTrustBundleToDomain(Long.parseLong(domainId), Integer.parseInt(bundleArray[0]), true, false);
            } else if (bundleArray[1].equals("out")) {
                configSvc.associateTrustBundleToDomain(Long.parseLong(domainId), Integer.parseInt(bundleArray[0]), false, true);
            } else {
                configSvc.associateTrustBundleToDomain(Long.parseLong(domainId), Integer.parseInt(bundleArray[0]), false, false);
            }
        } catch (ConfigurationServiceException cse) {
        }
    }
    return new ModelAndView("redirect:/config/domain?id=" + domainId + "&action=update#tab3");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)14 X509Certificate (java.security.cert.X509Certificate)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 TextParseException (org.xbill.DNS.TextParseException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 Key (java.security.Key)5 KeyStore (java.security.KeyStore)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 PrivateKey (java.security.PrivateKey)5 CertificateEncodingException (javax.security.cert.CertificateEncodingException)5 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)5 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)4 ArrayList (java.util.ArrayList)3 Certificate (org.nhindirect.config.model.Certificate)2 Certificate (org.nhindirect.config.store.Certificate)2 DNSRecord (org.nhindirect.config.store.DNSRecord)2 AddressForm (org.nhindirect.config.ui.form.AddressForm)2