KEYCLOAK-11246 Use the transcription object for SMTP password

This commit is contained in:
Martin Kanis 2019-09-06 14:16:14 +02:00 committed by Hynek Mlnařík
parent 9eb2e1d845
commit 4235422798
6 changed files with 29 additions and 3 deletions

View file

@ -24,6 +24,7 @@ import org.keycloak.models.UserModel;
import org.keycloak.services.ServicesLogger;
import org.keycloak.truststore.HostnameVerificationPolicy;
import org.keycloak.truststore.JSSETruststoreConfigurator;
import org.keycloak.vault.VaultStringSecret;
import javax.mail.Address;
import javax.mail.MessagingException;
@ -135,7 +136,9 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider {
transport = session.getTransport("smtp");
if (auth) {
transport.connect(config.get("user"), config.get("password"));
try (VaultStringSecret vaultStringSecret = this.session.vault().getStringSecret(config.get("password"))) {
transport.connect(config.get("user"), vaultStringSecret.get().orElse(config.get("password")));
}
} else {
transport.connect();
}

View file

@ -221,6 +221,7 @@
<include>master_smtp__key</include>
<include>test_smtp__key</include>
<include>consumer_oidc__idp</include>
<include>master_smtp__password</include>
</includes>
</resource>
</resources>

View file

@ -43,6 +43,8 @@ import static org.keycloak.util.JsonSerialization.writeValueAsPrettyString;
*/
public class SMTPConnectionTest extends AbstractKeycloakTest {
public final String SMTP_PASSWORD = setSmtpPassword();
@Rule
public GreenMailRule greenMailRule = new GreenMailRule();
private RealmResource realm;
@ -51,6 +53,10 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
public void addTestRealms(List<RealmRepresentation> testRealms) {
}
public String setSmtpPassword() {
return "admin";
}
@Before
public void before() {
realm = adminClient.realm("master");
@ -107,7 +113,7 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
public void testWithAuthEnabledValidCredentials() throws Exception {
greenMailRule.credentials("admin@localhost", "admin");
Response response = realm.testSMTPConnection(settings("127.0.0.1", "3025", "auto@keycloak.org", "true", null, null,
"admin@localhost", "admin"));
"admin@localhost", SMTP_PASSWORD));
assertStatus(response, 204);
}
@ -117,7 +123,7 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
Map<String, String> oldSmtp = realmRep.getSmtpServer();
try {
realmRep.setSmtpServer(smtpMap("127.0.0.1", "3025", "auto@keycloak.org", "true", null, null,
"admin@localhost", "admin", null, null));
"admin@localhost", SMTP_PASSWORD, null, null));
realm.update(realmRep);
greenMailRule.credentials("admin@localhost", "admin");

View file

@ -0,0 +1,14 @@
package org.keycloak.testsuite.admin;
/**
* @author Martin Kanis <mkanis@redhat.com>
*/
public class SMTPConnectionVaultTest extends SMTPConnectionTest {
public final String SMTP_PASSWORD = setSmtpPassword();
@Override
public String setSmtpPassword() {
return "${vault.smtp_password}";
}
}