use of org.wildfly.security.password.interfaces.ClearPassword in project wildfly by wildfly.
the class SingleSignOnSessionFactoryBuilder method getValue.
@Override
public SingleSignOnSessionFactory getValue() {
KeyStore store = this.keyStore.getValue();
String alias = this.keyAlias;
CredentialSource source = this.credentialSource.getValue();
try {
if (!store.containsAlias(alias)) {
UndertowLogger.ROOT_LOGGER.missingKeyStoreEntry(alias);
}
if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
UndertowLogger.ROOT_LOGGER.keyStoreEntryNotPrivate(alias);
}
PasswordCredential credential = source.getCredential(PasswordCredential.class);
if (credential == null) {
UndertowLogger.ROOT_LOGGER.missingCredential(source.toString());
}
ClearPassword password = credential.getPassword(ClearPassword.class);
if (password == null) {
UndertowLogger.ROOT_LOGGER.credentialNotClearPassword(credential.toString());
}
KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
KeyPair keyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
Optional<SSLContext> context = Optional.ofNullable(this.sslContext).map(dependency -> dependency.getValue());
return new DefaultSingleSignOnSessionFactory(this.manager.getValue(), keyPair, connection -> context.ifPresent(ctx -> connection.setSSLSocketFactory(ctx.getSocketFactory())));
} catch (GeneralSecurityException | IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.wildfly.security.password.interfaces.ClearPassword in project wildfly by wildfly.
the class EncryptProtocolConfigurationBuilder method accept.
@Override
public void accept(P protocol) {
KeyStore store = this.keyStore.getValue();
String alias = this.keyAlias;
try {
if (!store.containsAlias(alias)) {
throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias);
}
PasswordCredential credential = this.credentialSource.getValue().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();
}
protocol.setKeyStore(this.keyStore.getValue());
protocol.setKeyAlias(this.keyAlias);
protocol.setKeyPassword(new KeyStore.PasswordProtection(password.getPassword()));
} catch (KeyStoreException | IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.wildfly.security.password.interfaces.ClearPassword in project fuse-karaf by jboss-fuse.
the class Activator method replaced.
/**
* Replaces any value that is given in Credential Store reference format with the value from the Credential Store by
* using {@link System#setProperty(String, String)}.
*
* @param credentialStore
* {@link CredentialStore} containing the secret values
* @param key
* property key
* @param value
* property value, expected to be in Credential store reference format
* @return true if any replacement was done
*/
boolean replaced(final CredentialStore credentialStore, final String key, final String value) {
if (!CredentialStoreHelper.couldBeCredentialStoreAlias(value)) {
return false;
}
final String alias = CredentialStoreHelper.toCredentialStoreAlias(value);
final PasswordCredential passwordCredential;
try {
passwordCredential = credentialStore.retrieve(alias, PasswordCredential.class);
} catch (final CredentialStoreException e) {
return false;
}
if (passwordCredential == null) {
return false;
}
final Password password = passwordCredential.getPassword();
final ClearPassword clearPassword = password.castAs(ClearPassword.class);
final char[] rawClearPassword = clearPassword.getPassword();
System.setProperty(key, String.valueOf(rawClearPassword));
return true;
}
use of org.wildfly.security.password.interfaces.ClearPassword 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);
}
}
use of org.wildfly.security.password.interfaces.ClearPassword in project wildfly by wildfly.
the class SingleSignOnSessionFactoryServiceConfigurator method get.
@Override
public SingleSignOnSessionFactory get() {
KeyStore store = this.keyStore.get();
String alias = this.keyAlias;
CredentialSource source = this.credentialSource.get();
try {
if (!store.containsAlias(alias)) {
throw UndertowLogger.ROOT_LOGGER.missingKeyStoreEntry(alias);
}
if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
throw UndertowLogger.ROOT_LOGGER.keyStoreEntryNotPrivate(alias);
}
PasswordCredential credential = source.getCredential(PasswordCredential.class);
if (credential == null) {
throw UndertowLogger.ROOT_LOGGER.missingCredential(source.toString());
}
ClearPassword password = credential.getPassword(ClearPassword.class);
if (password == null) {
throw UndertowLogger.ROOT_LOGGER.credentialNotClearPassword(credential.toString());
}
KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
KeyPair keyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
Optional<SSLContext> context = Optional.ofNullable(this.sslContext).map(dependency -> dependency.get());
return new DefaultSingleSignOnSessionFactory(this.manager.get(), keyPair, connection -> context.ifPresent(ctx -> connection.setSSLSocketFactory(ctx.getSocketFactory())));
} catch (GeneralSecurityException | IOException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations