use of java.security.GeneralSecurityException in project ignite by apache.
the class SslContextFactory method loadKeyStore.
/**
* Loads key store with configured parameters.
*
* @param keyStoreType Type of key store.
* @param storeFilePath Path to key store file.
* @param keyStorePwd Store password.
* @return Initialized key store.
* @throws SSLException If key store could not be initialized.
*/
private KeyStore loadKeyStore(String keyStoreType, String storeFilePath, char[] keyStorePwd) throws SSLException {
InputStream input = null;
try {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
input = openFileInputStream(storeFilePath);
keyStore.load(input, keyStorePwd);
return keyStore;
} catch (GeneralSecurityException e) {
throw new SSLException("Failed to initialize key store (security exception occurred) [type=" + keyStoreType + ", keyStorePath=" + storeFilePath + ']', e);
} catch (FileNotFoundException e) {
throw new SSLException("Failed to initialize key store (key store file was not found): [path=" + storeFilePath + ", msg=" + e.getMessage() + ']');
} catch (IOException e) {
throw new SSLException("Failed to initialize key store (I/O error occurred): " + storeFilePath, e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException ignored) {
}
}
}
}
use of java.security.GeneralSecurityException in project AndLang by wugemu.
the class EncryptUtil method encryptSHA.
public static String encryptSHA(String data) throws IOException {
byte[] bytes = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
bytes = md.digest(data.getBytes(CHARSET_UTF8));
} catch (GeneralSecurityException gse) {
String msg = getStringFromException(gse);
throw new IOException(msg, gse);
}
return byte2hex(bytes);
}
use of java.security.GeneralSecurityException in project AndLang by wugemu.
the class EncryptUtil method encryptMD5.
public static String encryptMD5(String data) throws IOException {
byte[] bytes = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
bytes = md.digest(data.getBytes(CHARSET_UTF8));
} catch (GeneralSecurityException gse) {
String msg = getStringFromException(gse);
throw new IOException(msg, gse);
}
return byte2hex(bytes);
}
use of java.security.GeneralSecurityException in project cas by apereo.
the class DuoAuthenticationHandler method authenticateDuoCredential.
private AuthenticationHandlerExecutionResult authenticateDuoCredential(final Credential credential) throws FailedLoginException {
try {
final DuoCredential duoCredential = (DuoCredential) credential;
if (!duoCredential.isValid()) {
throw new GeneralSecurityException("Duo credential validation failed. Ensure a username " + " and the signed Duo response is configured and passed. Credential received: " + duoCredential);
}
final DuoSecurityAuthenticationService duoAuthenticationService = getDuoAuthenticationService();
final String duoVerifyResponse = duoAuthenticationService.authenticate(duoCredential).getValue();
LOGGER.debug("Response from Duo verify: [{}]", duoVerifyResponse);
final String primaryCredentialsUsername = duoCredential.getUsername();
final boolean isGoodAuthentication = duoVerifyResponse.equals(primaryCredentialsUsername);
if (isGoodAuthentication) {
LOGGER.info("Successful Duo authentication for [{}]", primaryCredentialsUsername);
final Principal principal = this.principalFactory.createPrincipal(duoVerifyResponse);
return createHandlerResult(credential, principal, new ArrayList<>());
}
throw new FailedLoginException("Duo authentication username " + primaryCredentialsUsername + " does not match Duo response: " + duoVerifyResponse);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
throw new FailedLoginException(e.getMessage());
}
}
use of java.security.GeneralSecurityException in project cas by apereo.
the class CouchbaseClientFactory method query.
/**
* Query and get a result by username.
*
* @param usernameAttribute the username attribute
* @param usernameValue the username value
* @return the n1ql query result
* @throws GeneralSecurityException the general security exception
*/
public N1qlQueryResult query(final String usernameAttribute, final String usernameValue) throws GeneralSecurityException {
final Statement statement = Select.select("*").from(Expression.i(getBucket().name())).where(Expression.x(usernameAttribute).eq('\'' + usernameValue + '\''));
LOGGER.debug("Running query [{}] on bucket [{}]", statement.toString(), getBucket().name());
final SimpleN1qlQuery query = N1qlQuery.simple(statement);
final N1qlQueryResult result = getBucket().query(query, timeout, TimeUnit.MILLISECONDS);
if (!result.finalSuccess()) {
LOGGER.error("Couchbase query failed with [{}]", result.errors().stream().map(JsonObject::toString).collect(Collectors.joining(",")));
throw new GeneralSecurityException("Could not locate account for user " + usernameValue);
}
return result;
}
Aggregations