use of org.jboss.as.clustering.jgroups.auth.CipherAuthToken in project wildfly by wildfly.
the class CipherAuthTokenServiceConfigurator method apply.
@Override
public CipherAuthToken apply(String authValue) {
KeyStore store = this.keyStore.get();
String alias = this.keyAlias;
try {
if (!store.containsAlias(alias)) {
throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias);
}
if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, KeyStore.PrivateKeyEntry.class.getSimpleName());
}
PasswordCredential credential = this.keyCredentialSource.get().getCredential(PasswordCredential.class);
if (credential == null) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
}
ClearPassword password = credential.getPassword(ClearPassword.class);
if (password == null) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
}
KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
KeyPair pair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
Cipher cipher = Cipher.getInstance(this.transformation);
return new CipherAuthToken(cipher, pair, authValue.getBytes(StandardCharsets.UTF_8));
} catch (GeneralSecurityException | IOException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations