Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#getSmtpServer()
The following examples show how to use
org.keycloak.representations.idm.RealmRepresentation#getSmtpServer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportSimpleRealmIT.java From keycloak-config-cli with Apache License 2.0 | 6 votes |
@Test @Order(6) void shouldUpdateSmtpSettings() { doImport("6_update_simple-realm_with_smtp-settings.json"); RealmRepresentation updatedRealm = keycloakProvider.get().realm("simple").toRepresentation(); assertThat(updatedRealm.getRealm(), is("simple")); assertThat(updatedRealm.isEnabled(), is(true)); Map<String, String> config = updatedRealm.getSmtpServer(); assertThat(config.get("from"), is("[email protected]")); assertThat(config.get("fromDisplayName"), is("keycloak-config-cli")); assertThat(config.get("host"), is("mta")); assertThat(config.get("auth"), is("true")); assertThat(config.get("envelopeFrom"), is("[email protected]")); assertThat(config.get("user"), is("username")); assertThat(config.get("password"), is("**********")); }
Example 2
Source File: SMTPConnectionTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test @AuthServerContainerExclude(AuthServer.REMOTE) public void testAuthEnabledAndSavedCredentials() throws Exception { RealmRepresentation realmRep = realm.toRepresentation(); Map<String, String> oldSmtp = realmRep.getSmtpServer(); try { realmRep.setSmtpServer(smtpMap("127.0.0.1", "3025", "[email protected]", "true", null, null, "admin@localhost", SMTP_PASSWORD, null, null)); realm.update(realmRep); greenMailRule.credentials("admin@localhost", "admin"); Response response = realm.testSMTPConnection(settings("127.0.0.1", "3025", "[email protected]", "true", null, null, "admin@localhost", SECRET_VALUE)); assertStatus(response, 204); } finally { // Revert SMTP back realmRep.setSmtpServer(oldSmtp); realm.update(realmRep); } }
Example 3
Source File: ResetPasswordTest.java From keycloak with Apache License 2.0 | 5 votes |
@Test public void resetPasswordWrongSmtp() throws IOException, MessagingException, InterruptedException { final String[] host = new String[1]; Map<String, String> smtpConfig = new HashMap<>(); smtpConfig.putAll(testRealm().toRepresentation().getSmtpServer()); host[0] = smtpConfig.get("host"); smtpConfig.put("host", "invalid_host"); RealmRepresentation realmRep = testRealm().toRepresentation(); Map<String, String> oldSmtp = realmRep.getSmtpServer(); try { realmRep.setSmtpServer(smtpConfig); testRealm().update(realmRep); loginPage.open(); loginPage.resetPassword(); resetPasswordPage.assertCurrent(); resetPasswordPage.changePassword("login-test"); errorPage.assertCurrent(); assertEquals("Failed to send email, please try again later.", errorPage.getError()); assertEquals(0, greenMail.getReceivedMessages().length); events.expectRequiredAction(EventType.SEND_RESET_PASSWORD_ERROR).user(userId) .session((String)null) .detail(Details.USERNAME, "login-test").removeDetail(Details.CODE_ID).error(Errors.EMAIL_SEND_FAILED).assertEvent(); } finally { // Revert SMTP back realmRep.setSmtpServer(oldSmtp); testRealm().update(realmRep); } }
Example 4
Source File: StripSecretsUtils.java From keycloak with Apache License 2.0 | 4 votes |
public static RealmRepresentation strip(RealmRepresentation rep) { if (rep.getSmtpServer() != null && rep.getSmtpServer().containsKey("password")) { rep.getSmtpServer().put("password", maskNonVaultValue(rep.getSmtpServer().get("password"))); } return rep; }
Example 5
Source File: RealmTest.java From keycloak with Apache License 2.0 | 4 votes |
public static void assertRealm(RealmRepresentation realm, RealmRepresentation storedRealm) { if (realm.getId() != null) { assertEquals(realm.getId(), storedRealm.getId()); } if (realm.getRealm() != null) { assertEquals(realm.getRealm(), storedRealm.getRealm()); } if (realm.isEnabled() != null) assertEquals(realm.isEnabled(), storedRealm.isEnabled()); if (realm.isBruteForceProtected() != null) assertEquals(realm.isBruteForceProtected(), storedRealm.isBruteForceProtected()); if (realm.getMaxFailureWaitSeconds() != null) assertEquals(realm.getMaxFailureWaitSeconds(), storedRealm.getMaxFailureWaitSeconds()); if (realm.getMinimumQuickLoginWaitSeconds() != null) assertEquals(realm.getMinimumQuickLoginWaitSeconds(), storedRealm.getMinimumQuickLoginWaitSeconds()); if (realm.getWaitIncrementSeconds() != null) assertEquals(realm.getWaitIncrementSeconds(), storedRealm.getWaitIncrementSeconds()); if (realm.getQuickLoginCheckMilliSeconds() != null) assertEquals(realm.getQuickLoginCheckMilliSeconds(), storedRealm.getQuickLoginCheckMilliSeconds()); if (realm.getMaxDeltaTimeSeconds() != null) assertEquals(realm.getMaxDeltaTimeSeconds(), storedRealm.getMaxDeltaTimeSeconds()); if (realm.getFailureFactor() != null) assertEquals(realm.getFailureFactor(), storedRealm.getFailureFactor()); if (realm.isRegistrationAllowed() != null) assertEquals(realm.isRegistrationAllowed(), storedRealm.isRegistrationAllowed()); if (realm.isRegistrationEmailAsUsername() != null) assertEquals(realm.isRegistrationEmailAsUsername(), storedRealm.isRegistrationEmailAsUsername()); if (realm.isRememberMe() != null) assertEquals(realm.isRememberMe(), storedRealm.isRememberMe()); if (realm.isVerifyEmail() != null) assertEquals(realm.isVerifyEmail(), storedRealm.isVerifyEmail()); if (realm.isLoginWithEmailAllowed() != null) assertEquals(realm.isLoginWithEmailAllowed(), storedRealm.isLoginWithEmailAllowed()); if (realm.isDuplicateEmailsAllowed() != null) assertEquals(realm.isDuplicateEmailsAllowed(), storedRealm.isDuplicateEmailsAllowed()); if (realm.isResetPasswordAllowed() != null) assertEquals(realm.isResetPasswordAllowed(), storedRealm.isResetPasswordAllowed()); if (realm.isEditUsernameAllowed() != null) assertEquals(realm.isEditUsernameAllowed(), storedRealm.isEditUsernameAllowed()); if (realm.getSslRequired() != null) assertEquals(realm.getSslRequired(), storedRealm.getSslRequired()); if (realm.getAccessCodeLifespan() != null) assertEquals(realm.getAccessCodeLifespan(), storedRealm.getAccessCodeLifespan()); if (realm.getAccessCodeLifespanUserAction() != null) assertEquals(realm.getAccessCodeLifespanUserAction(), storedRealm.getAccessCodeLifespanUserAction()); if (realm.getActionTokenGeneratedByAdminLifespan() != null) assertEquals(realm.getActionTokenGeneratedByAdminLifespan(), storedRealm.getActionTokenGeneratedByAdminLifespan()); if (realm.getActionTokenGeneratedByUserLifespan() != null) assertEquals(realm.getActionTokenGeneratedByUserLifespan(), storedRealm.getActionTokenGeneratedByUserLifespan()); else assertEquals(realm.getAccessCodeLifespanUserAction(), storedRealm.getActionTokenGeneratedByUserLifespan()); if (realm.getNotBefore() != null) assertEquals(realm.getNotBefore(), storedRealm.getNotBefore()); if (realm.getAccessTokenLifespan() != null) assertEquals(realm.getAccessTokenLifespan(), storedRealm.getAccessTokenLifespan()); if (realm.getAccessTokenLifespanForImplicitFlow() != null) assertEquals(realm.getAccessTokenLifespanForImplicitFlow(), storedRealm.getAccessTokenLifespanForImplicitFlow()); if (realm.getSsoSessionIdleTimeout() != null) assertEquals(realm.getSsoSessionIdleTimeout(), storedRealm.getSsoSessionIdleTimeout()); if (realm.getSsoSessionMaxLifespan() != null) assertEquals(realm.getSsoSessionMaxLifespan(), storedRealm.getSsoSessionMaxLifespan()); if (realm.getSsoSessionIdleTimeoutRememberMe() != null) Assert.assertEquals(realm.getSsoSessionIdleTimeoutRememberMe(), storedRealm.getSsoSessionIdleTimeoutRememberMe()); if (realm.getSsoSessionMaxLifespanRememberMe() != null) Assert.assertEquals(realm.getSsoSessionMaxLifespanRememberMe(), storedRealm.getSsoSessionMaxLifespanRememberMe()); if (realm.getClientSessionIdleTimeout() != null) Assert.assertEquals(realm.getClientSessionIdleTimeout(), storedRealm.getClientSessionIdleTimeout()); if (realm.getClientSessionMaxLifespan() != null) Assert.assertEquals(realm.getClientSessionMaxLifespan(), storedRealm.getClientSessionMaxLifespan()); if (realm.getClientOfflineSessionIdleTimeout() != null) Assert.assertEquals(realm.getClientOfflineSessionIdleTimeout(), storedRealm.getClientOfflineSessionIdleTimeout()); if (realm.getClientOfflineSessionMaxLifespan() != null) Assert.assertEquals(realm.getClientOfflineSessionMaxLifespan(), storedRealm.getClientOfflineSessionMaxLifespan()); if (realm.getRequiredCredentials() != null) { assertNotNull(storedRealm.getRequiredCredentials()); for (String cred : realm.getRequiredCredentials()) { assertTrue(storedRealm.getRequiredCredentials().contains(cred)); } } if (realm.getLoginTheme() != null) assertEquals(realm.getLoginTheme(), storedRealm.getLoginTheme()); if (realm.getAccountTheme() != null) assertEquals(realm.getAccountTheme(), storedRealm.getAccountTheme()); if (realm.getAdminTheme() != null) assertEquals(realm.getAdminTheme(), storedRealm.getAdminTheme()); if (realm.getEmailTheme() != null) assertEquals(realm.getEmailTheme(), storedRealm.getEmailTheme()); if (realm.getPasswordPolicy() != null) assertEquals(realm.getPasswordPolicy(), storedRealm.getPasswordPolicy()); if (realm.getDefaultRoles() != null) { assertNotNull(storedRealm.getDefaultRoles()); for (String role : realm.getDefaultRoles()) { assertTrue(storedRealm.getDefaultRoles().contains(role)); } } if (realm.getSmtpServer() != null) { assertEquals(realm.getSmtpServer(), storedRealm.getSmtpServer()); } if (realm.getBrowserSecurityHeaders() != null) { assertEquals(realm.getBrowserSecurityHeaders(), storedRealm.getBrowserSecurityHeaders()); } if (realm.getAttributes() != null) { HashMap<String, String> attributes = new HashMap<>(); attributes.putAll(storedRealm.getAttributes()); attributes.entrySet().retainAll(realm.getAttributes().entrySet()); assertEquals(realm.getAttributes(), attributes); } if (realm.isUserManagedAccessAllowed() != null) assertEquals(realm.isUserManagedAccessAllowed(), storedRealm.isUserManagedAccessAllowed()); }