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);
}
}
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");
}
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;
}
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;
}
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");
}
Aggregations