Skip to content

Commit edda14b

Browse files
committed
Bug #13873
Fix the bug by specifying the id of the sender as system (id -1), so the email and same properties will be fetched from the org/silverpeas/notificationserver/channel/smtp/smtpSettings.properties configuration file.
1 parent 608ef4c commit edda14b

File tree

11 files changed

+45
-66
lines changed

11 files changed

+45
-66
lines changed

core-library/src/main/java/org/silverpeas/core/admin/user/UserRegistrationServiceLegacy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private void sendCredentialsToUser(UserFull user, String password, String silver
189189
template.setAttribute("url", url.toString());
190190
templates.put(DisplayI18NHelper.getDefaultLanguage(), template);
191191
notifMetaData.addLanguage(DisplayI18NHelper.getDefaultLanguage(), subject, "");
192-
notifMetaData.setSender("0");
192+
notifMetaData.setSender(UserDetail.SYSTEM_USER_ID);
193193
notifMetaData.addUserRecipients(new UserRecipient(user.getId()));
194194

195195
notifyUser(notifMetaData);

core-library/src/main/java/org/silverpeas/core/util/MailSettings.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
import javax.mail.internet.AddressException;
3232
import javax.mail.internet.InternetAddress;
3333
import java.io.UnsupportedEncodingException;
34-
import java.util.*;
34+
import java.util.HashSet;
35+
import java.util.Set;
3536

3637
/**
3738
* @author ehugonnet
@@ -46,36 +47,16 @@ public class MailSettings {
4647
private static final String SMTP_DEBUG = "SMTPDebug";
4748
private static final String SMTP_SECURE = "SMTPSecure";
4849

49-
private static final String mailhost;
50-
private static final boolean authenticated;
51-
private static final boolean secure;
52-
private static final boolean debug;
53-
private static final int port;
54-
private static final String login;
55-
private static final String password;
56-
private static final String notificationAddress;
57-
private static final String notificationPersonalName;
58-
private static final boolean forceReplyToSenderField;
5950
private static Set<String> domains;
6051
public static final SettingBundle configuration = ResourceLocator.getSettingBundle(
6152
"org.silverpeas.notificationserver.channel.smtp.smtpSettings");
6253

6354
static {
64-
mailhost = configuration.getString(SMTP_SERVER);
65-
authenticated = configuration.getBoolean(SMTP_AUTH, false);
66-
port = configuration.getInteger(SMTP_PORT, 25);
67-
login = configuration.getString(SMTP_LOGIN);
68-
password = configuration.getString(SMTP_PASSWORD);
69-
debug = configuration.getBoolean(SMTP_DEBUG, false);
70-
secure = configuration.getBoolean(SMTP_SECURE, false);
71-
notificationAddress = configuration.getString("NotificationAddress");
72-
notificationPersonalName = configuration.getString("NotificationPersonalName");
73-
forceReplyToSenderField = configuration.getBoolean("ForceReplyToSenderField", false);
7455
reloadConfiguration(configuration.getString("AuthorizedDomains", ""));
7556
}
7657

7758
public static boolean isForceReplyToSenderField() {
78-
return forceReplyToSenderField;
59+
return configuration.getBoolean("ForceReplyToSenderField", false);
7960
}
8061

8162
/**
@@ -115,7 +96,8 @@ public static synchronized InternetAddress getAuthorizedEmailAddress(String pFro
11596
// - If email is authorized (senderAddress.equals(pFrom)), use it as it (personalName)
11697
// - If email is not authorized (!senderAddress.equals(pFrom)), use default one and default
11798
// personal name too (notificationPersonalName)
118-
String personal = senderAddress.equals(pFrom) ? personalName : notificationPersonalName;
99+
String personal = senderAddress.equals(pFrom) ? personalName :
100+
configuration.getString("NotificationPersonalName");
119101
if (StringUtil.isDefined(personal)) {
120102
address.setPersonal(personal, Charsets.UTF_8.name());
121103
}
@@ -126,35 +108,35 @@ public static synchronized String getAuthorizedEmail(String email) {
126108
if (isDomainAuthorized(email)) {
127109
return email;
128110
}
129-
return notificationAddress;
111+
return configuration.getString("NotificationAddress");
130112
}
131113

132114
public static String getMailServer() {
133-
return mailhost;
115+
return configuration.getString(SMTP_SERVER);
134116
}
135117

136118
public static boolean isAuthenticated() {
137-
return authenticated;
119+
return configuration.getBoolean(SMTP_AUTH, false);
138120
}
139121

140122
public static boolean isDebug() {
141-
return debug;
123+
return configuration.getBoolean(SMTP_DEBUG, false);
142124
}
143125

144126
public static String getLogin() {
145-
return login;
127+
return configuration.getString(SMTP_LOGIN);
146128
}
147129

148130
public static String getPassword() {
149-
return password;
131+
return configuration.getString(SMTP_PASSWORD);
150132
}
151133

152134
public static int getPort() {
153-
return port;
135+
return configuration.getInteger(SMTP_PORT, 25);
154136
}
155137

156138
public static boolean isSecure() {
157-
return secure;
139+
return configuration.getBoolean(SMTP_SECURE, false);
158140
}
159141

160142
private MailSettings() {

core-library/src/test/java/org/silverpeas/core/util/MailSettingsTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@
2323
*/
2424
package org.silverpeas.core.util;
2525

26-
import org.junit.jupiter.api.Test;
2726
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.Test;
2828
import org.silverpeas.kernel.test.UnitTest;
2929

3030
import javax.mail.internet.InternetAddress;
3131

32-
import static org.hamcrest.Matchers.is;
3332
import static org.hamcrest.MatcherAssert.assertThat;
33+
import static org.hamcrest.Matchers.is;
3434

3535
/**
3636
* @author ehugonnet
3737
*/
3838
@UnitTest
39-
public class MailSettingsTest {
39+
class MailSettingsTest {
4040

4141
@AfterEach
42-
public void tearDown() {
42+
void tearDown() {
4343
MailSettings.reloadConfiguration(null);
4444
}
4545

4646
/**
4747
* Test of isDomainAuthorized method, of class MailSettings.
4848
*/
4949
@Test
50-
public void testIsDomainAuthorized() {
50+
void testIsDomainAuthorized() {
5151
String email = "toto@silverpeas.com";
5252
boolean result = MailSettings.isDomainAuthorized(email);
5353
assertThat(result, is(true));
@@ -63,7 +63,7 @@ public void testIsDomainAuthorized() {
6363
* Test of getAuthorizedEmail method, of class MailSettings.
6464
*/
6565
@Test
66-
public void testGetAuthorizedEmail() {
66+
void testGetAuthorizedEmail() {
6767
MailSettings.reloadConfiguration("Silverpeas.COM,silverpeas.org");
6868
String authorizedEmail = "toto@silverpeas.com";
6969
String result = MailSettings.getAuthorizedEmail(authorizedEmail);
@@ -77,7 +77,7 @@ public void testGetAuthorizedEmail() {
7777
* Test of getAuthorizedEmail method, of class MailSettings.
7878
*/
7979
@Test
80-
public void testGetAuthorizedEmailWithNoDomain() {
80+
void testGetAuthorizedEmailWithNoDomain() {
8181
MailSettings.reloadConfiguration(null);
8282
String authorizedEmail = "toto@silverpeas.com";
8383
String result = MailSettings.getAuthorizedEmail(authorizedEmail);
@@ -89,7 +89,7 @@ public void testGetAuthorizedEmailWithNoDomain() {
8989
}
9090

9191
@Test
92-
public void testGetAuthorizedEmailAddress() throws Exception {
92+
void testGetAuthorizedEmailAddress() throws Exception {
9393
MailSettings.reloadConfiguration("Silverpeas.COM,silverpeas.org");
9494
String authorizedEmail = "toto@silverpeas.com";
9595
InternetAddress result = MailSettings.getAuthorizedEmailAddress(authorizedEmail, "Toto");

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/ChangeExpiredPasswordHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
import org.silverpeas.core.annotation.Service;
2727
import org.silverpeas.core.security.authentication.AuthenticationCredential;
28-
import org.silverpeas.core.security.authentication.AuthenticationService;
29-
import org.silverpeas.core.security.authentication.AuthenticationServiceProvider;
3028
import org.silverpeas.core.security.authentication.exception.AuthenticationException;
3129
import org.silverpeas.kernel.bundle.ResourceLocator;
3230
import org.silverpeas.kernel.bundle.SettingBundle;

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/ChangePasswordFunctionHandler.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.silverpeas.core.web.authentication.credentials;
2525

26+
import org.silverpeas.core.admin.service.AdminException;
2627
import org.silverpeas.core.admin.user.model.User;
2728
import org.silverpeas.core.admin.user.model.UserDetail;
2829
import org.silverpeas.core.security.authentication.AuthenticationCredential;
@@ -33,6 +34,7 @@
3334

3435
import javax.inject.Inject;
3536
import javax.servlet.http.HttpServletRequest;
37+
import javax.servlet.http.HttpSession;
3638

3739
/**
3840
* User: Yohann Chastagnier Date: 06/02/13
@@ -42,6 +44,19 @@ public abstract class ChangePasswordFunctionHandler extends ChangeCredentialFunc
4244
@Inject
4345
private AuthenticationService authenticator;
4446

47+
/**
48+
* Gets the current user behind the incoming HTTP request.
49+
* @param request the HTTP request
50+
* @return the requester.
51+
* @throws AdminException if the user behind the HTTP request cannot be identified.
52+
*/
53+
protected UserDetail getRequester(HttpServletRequest request) throws AdminException {
54+
HttpSession session = request.getSession(true);
55+
String key = (String) session.getAttribute("svplogin_Key");
56+
String userId = getAdminService().identify(key, session.getId(), false, false);
57+
return getAdminService().getUserDetail(userId);
58+
}
59+
4560
/**
4661
* Handle bad credential error.
4762
*
@@ -91,6 +106,7 @@ protected void assertPasswordHasBeenCorrectlyChecked(String checkId, String pass
91106

92107
/**
93108
* Changes the password of the specified user with the new one passed in the given request.
109+
*
94110
* @param request the incoming HTTP request with the new password.
95111
* @param user the user requesting the password modification.
96112
* @return the new password of the user.

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/ChangePasswordHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
import org.silverpeas.core.annotation.Service;
2727
import org.silverpeas.core.security.authentication.AuthenticationCredential;
28-
import org.silverpeas.core.security.authentication.AuthenticationService;
29-
import org.silverpeas.core.security.authentication.AuthenticationServiceProvider;
3028
import org.silverpeas.kernel.logging.SilverLogger;
3129

3230
import javax.servlet.http.HttpServletRequest;

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/EffectiveChangePasswordBeforeExpirationHandler.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@
2525

2626
import org.silverpeas.core.admin.user.model.UserDetail;
2727
import org.silverpeas.core.annotation.Service;
28-
import org.silverpeas.core.security.authentication.AuthenticationCredential;
29-
import org.silverpeas.core.security.authentication.AuthenticationService;
30-
import org.silverpeas.core.security.authentication.AuthenticationServiceProvider;
3128
import org.silverpeas.core.security.authentication.exception.AuthenticationException;
29+
import org.silverpeas.core.web.mvc.controller.MainSessionController;
30+
import org.silverpeas.core.web.util.viewgenerator.html.GraphicElementFactory;
3231
import org.silverpeas.kernel.bundle.ResourceLocator;
3332
import org.silverpeas.kernel.bundle.SettingBundle;
3433
import org.silverpeas.kernel.logging.SilverLogger;
35-
import org.silverpeas.core.web.mvc.controller.MainSessionController;
36-
import org.silverpeas.core.web.util.viewgenerator.html.GraphicElementFactory;
3734

3835
import javax.servlet.http.HttpServletRequest;
3936
import javax.servlet.http.HttpSession;

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/EffectiveChangePasswordFromLoginHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525

2626
import org.silverpeas.core.annotation.Service;
2727
import org.silverpeas.core.security.authentication.AuthenticationCredential;
28-
import org.silverpeas.core.security.authentication.AuthenticationService;
29-
import org.silverpeas.core.security.authentication.AuthenticationServiceProvider;
3028
import org.silverpeas.core.security.authentication.exception.AuthenticationException;
3129
import org.silverpeas.kernel.bundle.ResourceLocator;
3230
import org.silverpeas.kernel.bundle.SettingBundle;
33-
import org.silverpeas.kernel.util.StringUtil;
3431
import org.silverpeas.kernel.logging.SilverLogger;
32+
import org.silverpeas.kernel.util.StringUtil;
3533

3634
import javax.servlet.http.HttpServletRequest;
3735

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/EffectiveChangePasswordHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import javax.inject.Inject;
3333
import javax.servlet.http.HttpServletRequest;
34-
import javax.servlet.http.HttpSession;
3534

3635
/**
3736
* Navigation case : user has committed change password form.
@@ -51,11 +50,8 @@ public String getFunction() {
5150

5251
@Override
5352
public String doAction(HttpServletRequest request) {
54-
HttpSession session = request.getSession(true);
55-
String key = (String) session.getAttribute("svplogin_Key");
5653
try {
57-
String userId = getAdminService().identify(key, session.getId(), false, false);
58-
UserDetail ud = getAdminService().getUserDetail(userId);
54+
UserDetail ud = getRequester(request);
5955
return doPasswordChange(request, ud);
6056
} catch (AdminException e) {
6157
SilverLogger.getLogger(this).error(e);

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/ForcePasswordChangeHandler.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@
2929
import org.silverpeas.kernel.logging.SilverLogger;
3030

3131
import javax.servlet.http.HttpServletRequest;
32-
import javax.servlet.http.HttpSession;
3332

3433
/**
3534
* Navigation case : force user to change his password.
3635
* @author ehugonnet
3736
*/
3837
@Service
39-
public class ForcePasswordChangeHandler extends CredentialsFunctionHandler {
38+
public class ForcePasswordChangeHandler extends ChangePasswordFunctionHandler {
4039

4140
@Override
4241
public String getFunction() {
@@ -45,16 +44,12 @@ public String getFunction() {
4544

4645
@Override
4746
public String doAction(HttpServletRequest request) {
48-
HttpSession session = request.getSession(true);
49-
String key = (String) session.getAttribute("svplogin_Key");
5047
try {
51-
String userId = getAdminService().identify(key, session.getId(), false, false);
52-
UserDetail ud = getAdminService().getUserDetail(userId);
48+
UserDetail ud = getRequester(request);
5349
request.setAttribute("userDetail", ud);
5450
return getGeneral().getString("userLoginForcePasswordChangePage");
5551
} catch (AdminException e) {
56-
SilverLogger.getLogger(this)
57-
.error("force change password error with key {0}", new String[]{key}, e);
52+
SilverLogger.getLogger(this).error("force change password error", e);
5853
return "/Login?ErrorCode=2";
5954
}
6055
}

core-web/src/main/java/org/silverpeas/core/web/authentication/credentials/ResetPasswordHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.silverpeas.core.annotation.Service;
2929
import org.silverpeas.core.security.authentication.AuthenticationCredential;
3030
import org.silverpeas.core.security.authentication.AuthenticationService;
31-
import org.silverpeas.core.security.authentication.AuthenticationServiceProvider;
3231
import org.silverpeas.core.security.authentication.exception.AuthenticationException;
3332
import org.silverpeas.core.security.authentication.password.ForgottenPasswordException;
3433
import org.silverpeas.core.security.authentication.password.ForgottenPasswordMailParameters;

0 commit comments

Comments
 (0)