KEYCLOAK-11246 Use the transcription object for SMTP password
This commit is contained in:
parent
9eb2e1d845
commit
4235422798
6 changed files with 29 additions and 3 deletions
|
@ -24,6 +24,7 @@ import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.services.ServicesLogger;
|
import org.keycloak.services.ServicesLogger;
|
||||||
import org.keycloak.truststore.HostnameVerificationPolicy;
|
import org.keycloak.truststore.HostnameVerificationPolicy;
|
||||||
import org.keycloak.truststore.JSSETruststoreConfigurator;
|
import org.keycloak.truststore.JSSETruststoreConfigurator;
|
||||||
|
import org.keycloak.vault.VaultStringSecret;
|
||||||
|
|
||||||
import javax.mail.Address;
|
import javax.mail.Address;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
|
@ -135,7 +136,9 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider {
|
||||||
|
|
||||||
transport = session.getTransport("smtp");
|
transport = session.getTransport("smtp");
|
||||||
if (auth) {
|
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 {
|
} else {
|
||||||
transport.connect();
|
transport.connect();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
admin
|
|
@ -221,6 +221,7 @@
|
||||||
<include>master_smtp__key</include>
|
<include>master_smtp__key</include>
|
||||||
<include>test_smtp__key</include>
|
<include>test_smtp__key</include>
|
||||||
<include>consumer_oidc__idp</include>
|
<include>consumer_oidc__idp</include>
|
||||||
|
<include>master_smtp__password</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -43,6 +43,8 @@ import static org.keycloak.util.JsonSerialization.writeValueAsPrettyString;
|
||||||
*/
|
*/
|
||||||
public class SMTPConnectionTest extends AbstractKeycloakTest {
|
public class SMTPConnectionTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
|
public final String SMTP_PASSWORD = setSmtpPassword();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public GreenMailRule greenMailRule = new GreenMailRule();
|
public GreenMailRule greenMailRule = new GreenMailRule();
|
||||||
private RealmResource realm;
|
private RealmResource realm;
|
||||||
|
@ -51,6 +53,10 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
|
||||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String setSmtpPassword() {
|
||||||
|
return "admin";
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
realm = adminClient.realm("master");
|
realm = adminClient.realm("master");
|
||||||
|
@ -107,7 +113,7 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
|
||||||
public void testWithAuthEnabledValidCredentials() throws Exception {
|
public void testWithAuthEnabledValidCredentials() throws Exception {
|
||||||
greenMailRule.credentials("admin@localhost", "admin");
|
greenMailRule.credentials("admin@localhost", "admin");
|
||||||
Response response = realm.testSMTPConnection(settings("127.0.0.1", "3025", "auto@keycloak.org", "true", null, null,
|
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);
|
assertStatus(response, 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +123,7 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
|
||||||
Map<String, String> oldSmtp = realmRep.getSmtpServer();
|
Map<String, String> oldSmtp = realmRep.getSmtpServer();
|
||||||
try {
|
try {
|
||||||
realmRep.setSmtpServer(smtpMap("127.0.0.1", "3025", "auto@keycloak.org", "true", null, null,
|
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);
|
realm.update(realmRep);
|
||||||
|
|
||||||
greenMailRule.credentials("admin@localhost", "admin");
|
greenMailRule.credentials("admin@localhost", "admin");
|
||||||
|
|
|
@ -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}";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
admin
|
Loading…
Reference in a new issue