use of java.security.NoSuchProviderException in project gerrit by GerritCodeReview.
the class SshKeyCreatorImpl method create.
@Override
public AccountSshKey create(AccountSshKey.Id id, String encoded) throws InvalidSshKeyException {
try {
AccountSshKey key = new AccountSshKey(id, SshUtil.toOpenSshPublicKey(encoded));
SshUtil.parse(key);
return key;
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new InvalidSshKeyException();
} catch (NoSuchProviderException e) {
log.error("Cannot parse SSH key", e);
throw new InvalidSshKeyException();
}
}
use of java.security.NoSuchProviderException in project sling by apache.
the class DelegatingLoginModule method initialize.
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
Configuration config = null;
try {
config = Configuration.getInstance(JAAS_CONFIG_ALGO_NAME, null, providerName);
} catch (NoSuchProviderException e) {
logger.debug("No provider " + providerName + "found so far", e);
} catch (NoSuchAlgorithmException e) {
logger.debug("No provider " + providerName + "found so far for fetching JAAS " + "config with algorithm name " + JAAS_CONFIG_ALGO_NAME, e);
}
if (config != null) {
final Thread current = Thread.currentThread();
final ClassLoader orig = current.getContextClassLoader();
try {
current.setContextClassLoader(DelegatingLoginModule.class.getClassLoader());
loginContext = new LoginContext(appName, subject, callbackHandler, config);
} catch (LoginException e) {
loginException = e;
} finally {
current.setContextClassLoader(orig);
}
} else {
//No support so far from OSGi so would use default logic used by Jackrabbit
//to construct the LoginModule
Properties p = new Properties();
p.putAll(options);
BeanConfig bc = new BeanConfig(delegateLoginModuleClass, p);
LoginModuleConfig lmc = new LoginModuleConfig(bc);
try {
delegate = lmc.getLoginModule();
delegate.initialize(subject, callbackHandler, sharedState, options);
logger.info("No JAAS Configuration provider found would be directly invoking LoginModule {}", delegateLoginModuleClass);
} catch (ConfigurationException e) {
//Behaviour is same as org.apache.jackrabbit.core.security.authentication.LocalAuthContext.login()
loginException = new LoginException(e.getMessage());
}
}
}
use of java.security.NoSuchProviderException in project cloudstack by apache.
the class SAML2AuthManagerImpl method initSP.
protected boolean initSP() {
KeystoreVO keyStoreVO = _ksDao.findByName(SAMLPluginConstants.SAMLSP_KEYPAIR);
if (keyStoreVO == null) {
try {
KeyPair keyPair = SAMLUtils.generateRandomKeyPair();
_ksDao.save(SAMLPluginConstants.SAMLSP_KEYPAIR, SAMLUtils.savePrivateKey(keyPair.getPrivate()), SAMLUtils.savePublicKey(keyPair.getPublic()), "samlsp-keypair");
keyStoreVO = _ksDao.findByName(SAMLPluginConstants.SAMLSP_KEYPAIR);
s_logger.info("No SAML keystore found, created and saved a new Service Provider keypair");
} catch (NoSuchProviderException | NoSuchAlgorithmException e) {
s_logger.error("Unable to create and save SAML keypair: " + e.toString());
}
}
String spId = SAMLServiceProviderID.value();
String spSsoUrl = SAMLServiceProviderSingleSignOnURL.value();
String spSloUrl = SAMLServiceProviderSingleLogOutURL.value();
String spOrgName = SAMLServiceProviderOrgName.value();
String spOrgUrl = SAMLServiceProviderOrgUrl.value();
String spContactPersonName = SAMLServiceProviderContactPersonName.value();
String spContactPersonEmail = SAMLServiceProviderContactEmail.value();
KeyPair spKeyPair = null;
X509Certificate spX509Key = null;
if (keyStoreVO != null) {
PrivateKey privateKey = SAMLUtils.loadPrivateKey(keyStoreVO.getCertificate());
PublicKey publicKey = SAMLUtils.loadPublicKey(keyStoreVO.getKey());
if (privateKey != null && publicKey != null) {
spKeyPair = new KeyPair(publicKey, privateKey);
KeystoreVO x509VO = _ksDao.findByName(SAMLPluginConstants.SAMLSP_X509CERT);
if (x509VO == null) {
try {
spX509Key = SAMLUtils.generateRandomX509Certificate(spKeyPair);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(spX509Key);
out.flush();
_ksDao.save(SAMLPluginConstants.SAMLSP_X509CERT, Base64.encodeBase64String(bos.toByteArray()), "", "samlsp-x509cert");
bos.close();
} catch (NoSuchAlgorithmException | NoSuchProviderException | CertificateEncodingException | SignatureException | InvalidKeyException | IOException e) {
s_logger.error("SAML Plugin won't be able to use X509 signed authentication");
}
} else {
try {
ByteArrayInputStream bi = new ByteArrayInputStream(Base64.decodeBase64(x509VO.getCertificate()));
ObjectInputStream si = new ObjectInputStream(bi);
spX509Key = (X509Certificate) si.readObject();
bi.close();
} catch (IOException | ClassNotFoundException ignored) {
s_logger.error("SAML Plugin won't be able to use X509 signed authentication. Failed to load X509 Certificate from Database.");
}
}
}
}
if (spKeyPair != null && spX509Key != null && spId != null && spSsoUrl != null && spSloUrl != null && spOrgName != null && spOrgUrl != null && spContactPersonName != null && spContactPersonEmail != null) {
_spMetadata.setEntityId(spId);
_spMetadata.setOrganizationName(spOrgName);
_spMetadata.setOrganizationUrl(spOrgUrl);
_spMetadata.setContactPersonName(spContactPersonName);
_spMetadata.setContactPersonEmail(spContactPersonEmail);
_spMetadata.setSsoUrl(spSsoUrl);
_spMetadata.setSloUrl(spSloUrl);
_spMetadata.setKeyPair(spKeyPair);
_spMetadata.setSigningCertificate(spX509Key);
_spMetadata.setEncryptionCertificate(spX509Key);
return true;
}
return false;
}
use of java.security.NoSuchProviderException in project cloudstack by apache.
the class SAMLUtils method getKeyFactory.
public static KeyFactory getKeyFactory() {
KeyFactory keyFactory = null;
try {
Security.addProvider(new BouncyCastleProvider());
keyFactory = KeyFactory.getInstance("RSA", "BC");
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
s_logger.error("Unable to create KeyFactory:" + e.getMessage());
}
return keyFactory;
}
use of java.security.NoSuchProviderException in project robovm by robovm.
the class KeyStore4Test method testGetInstanceStringString.
public void testGetInstanceStringString() {
try {
KeyStore ks = KeyStore.getInstance("TestKeyStore", provider.getName());
assertNotNull("keystore is null", ks);
assertEquals("KeyStore is not of expected type", "TestKeyStore", ks.getType());
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
try {
KeyStore.getInstance("UnknownKeyStore", provider.getName());
fail("expected KeyStoreException");
} catch (KeyStoreException e) {
// ok
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
try {
KeyStore.getInstance("TestKeyStore", (String) null);
fail("expected IllegalArgumentException");
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
} catch (IllegalArgumentException e) {
// ok
}
try {
KeyStore.getInstance("TestKeyStore", "");
fail("expected IllegalArgumentException");
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
} catch (IllegalArgumentException e) {
// ok
}
try {
KeyStore.getInstance(null, provider.getName());
fail("expected KeyStoreException");
} catch (KeyStoreException e) {
// ok
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
} catch (NullPointerException e) {
// also ok
}
try {
KeyStore.getInstance("TestKeyStore", "UnknownProvider");
fail("expected NoSuchProviderException");
} catch (NoSuchProviderException e) {
// ok
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
}
}
Aggregations