use of java.security.NoSuchProviderException in project jackrabbit-oak by apache.
the class LoginContextProviderImpl method getConfiguration.
@Nonnull
private Configuration getConfiguration() {
if (configuration == null) {
Configuration loginConfig = null;
String configSpiName = params.getConfigValue(PARAM_CONFIG_SPI_NAME, null, String.class);
if (configSpiName != null) {
try {
/*
Create a configuration instance with the following characteristics
- Algorithm name : "JavaLoginConfig"
- Extra parameters : 'null' for this impl
- Name of the config provider : 'configSpiName' as retrieved from the PARAM_CONFIG_SPI_NAME configuration (default: null)
*/
loginConfig = Configuration.getInstance("JavaLoginConfig", null, configSpiName);
if (loginConfig.getAppConfigurationEntry(appName) == null) {
log.warn("No configuration found for application {} though fetching JAAS " + "configuration from SPI {} is enabled.", appName, configSpiName);
}
} catch (NoSuchAlgorithmException e) {
log.warn("Error fetching JAAS config from SPI {}", configSpiName, e);
} catch (NoSuchProviderException e) {
log.warn("Error fetching JAAS config from SPI {}", configSpiName, e);
}
}
if (loginConfig == null) {
try {
loginConfig = Configuration.getConfiguration();
// NOTE: workaround for Java7 behavior (see OAK-497)
if (loginConfig.getAppConfigurationEntry(appName) == null) {
loginConfig = null;
}
} catch (SecurityException e) {
log.info("Failed to retrieve login configuration: using default. " + e);
}
}
if (loginConfig == null) {
log.debug("No login configuration available for {}; using default", appName);
loginConfig = ConfigurationUtil.getDefaultConfiguration(params);
}
configuration = loginConfig;
}
return configuration;
}
use of java.security.NoSuchProviderException in project sic by belluccifranco.
the class AfipWebServiceSOAPClient method crearCMS.
public byte[] crearCMS(byte[] p12file, String p12pass, String signer, String service, long ticketTime) {
PrivateKey pKey = null;
X509Certificate pCertificate = null;
byte[] asn1_cms = null;
CertStore cstore = null;
try {
KeyStore ks = KeyStore.getInstance("pkcs12");
InputStream is;
is = Utilidades.convertirByteArrayToInputStream(p12file);
ks.load(is, p12pass.toCharArray());
is.close();
pKey = (PrivateKey) ks.getKey(signer, p12pass.toCharArray());
pCertificate = (X509Certificate) ks.getCertificate(signer);
ArrayList<X509Certificate> certList = new ArrayList<>();
certList.add(pCertificate);
if (Security.getProvider("BC") == null) {
Security.addProvider(new BouncyCastleProvider());
}
cstore = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList), "BC");
} catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | UnrecoverableKeyException | InvalidAlgorithmParameterException | NoSuchProviderException ex) {
LOGGER.error(ex.getMessage());
throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_certificado_error"));
}
String loginTicketRequest_xml = this.crearTicketRequerimientoAcceso(service, ticketTime);
try {
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
generator.addSigner(pKey, pCertificate, CMSSignedDataGenerator.DIGEST_SHA1);
generator.addCertificatesAndCRLs(cstore);
CMSProcessable data = new CMSProcessableByteArray(loginTicketRequest_xml.getBytes());
CMSSignedData signed = generator.generate(data, true, "BC");
asn1_cms = signed.getEncoded();
} catch (IllegalArgumentException | CertStoreException | CMSException | NoSuchAlgorithmException | NoSuchProviderException | IOException ex) {
LOGGER.error(ex.getMessage());
throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_firmando_certificado_error"));
}
return asn1_cms;
}
use of java.security.NoSuchProviderException in project ddf by codice.
the class KeystoreEditor method importASN1CertificatesToStore.
private boolean importASN1CertificatesToStore(KeyStore store, boolean setEntry, ASN1Set certificates) throws KeystoreEditorException {
Enumeration certificateEnumeration = certificates.getObjects();
try {
while (certificateEnumeration.hasMoreElements()) {
ASN1Primitive asn1Primitive = ((ASN1Encodable) certificateEnumeration.nextElement()).toASN1Primitive();
org.bouncycastle.asn1.x509.Certificate instance = org.bouncycastle.asn1.x509.Certificate.getInstance(asn1Primitive);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", "BC");
Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(instance.getEncoded()));
X500Name x500name = new JcaX509CertificateHolder((X509Certificate) certificate).getSubject();
RDN cn = x500name.getRDNs(BCStyle.CN)[0];
store.setCertificateEntry(IETFUtils.valueToString(cn.getFirst().getValue()), certificate);
setEntry = true;
}
} catch (CertificateException | NoSuchProviderException | KeyStoreException | IOException e) {
throw new KeystoreEditorException("Unable to import ASN1 certificates to store", e);
}
return setEntry;
}
Aggregations