Skip to content

Commit f5218bd

Browse files
committed
Issue #1615: fix and refactor URL parameters frontend and backend
1 parent 5a7d5a5 commit f5218bd

File tree

20 files changed

+233
-123
lines changed

20 files changed

+233
-123
lines changed

OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/controller/ClientInit.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public Response command(InitRequest fullRequest, @Context HttpServletRequest htt
7878
AliveData.rememberClientCall();
7979
new ClientLogger().log(ClientInit.LOG, fullRequest.getLog());
8080
ClientInit.LOG.info("INIT command. Trying to build a new HttpSessionState");
81-
httpSessionState = HttpSessionState.init(this.robotPluginMap, this.serverProperties, getCountryCode(httpRequest, this.ipToCountry));
81+
String url = httpRequest.getRequestURL().toString().replace(httpRequest.getRequestURI(), "");
82+
httpSessionState = HttpSessionState.init(this.robotPluginMap, this.serverProperties, getCountryCode(httpRequest, this.ipToCountry), url);
8283
MDC.put("sessionId", String.valueOf(httpSessionState.getSessionNumber()));
8384
MDC.put("userId", String.valueOf(httpSessionState.getUserId()));
8485
MDC.put("robotName", String.valueOf(httpSessionState.getRobotName()));

OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/controller/ClientUser.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public Response createUser(@OraData DbSession dbSession, FullRestRequest fullReq
366366
PendingEmailConfirmationsProcessor pendingConfirmationProcessor = new PendingEmailConfirmationsProcessor(dbSession, httpSessionState.getUserId());
367367
String lang = request.getLanguage();
368368
PendingEmailConfirmations confirmation = pendingConfirmationProcessor.createEmailConfirmation(newUser);
369-
sendActivationMail(up, confirmation.getUrlPostfix(), account, email, lang, isYoungerThen14);
369+
sendActivationMail(up, confirmation.getUrlPostfix(), account, email, lang, isYoungerThen14, httpSessionState.getUrl());
370370
}
371371
Statistics.info("UserCreate", "success", up.succeeded());
372372
UtilForREST.addResultInfo(response, up);
@@ -430,7 +430,7 @@ public Response updateUser(@OraData DbSession dbSession, FullRestRequest fullReq
430430
up.updateUser(user, userName, role, email, null, isYoungerThen14, deactivateAccount);
431431
if ( deactivateAccount && up.succeeded() ) {
432432
PendingEmailConfirmations confirmation = pendingConfirmationProcessor.createEmailConfirmation(user);
433-
sendActivationMail(up, confirmation.getUrlPostfix(), account, email, request.getLanguage(), isYoungerThen14);
433+
sendActivationMail(up, confirmation.getUrlPostfix(), account, email, request.getLanguage(), isYoungerThen14, httpSessionState.getUrl());
434434
}
435435
UtilForREST.addResultInfo(response, up);
436436
}
@@ -513,7 +513,7 @@ public Response passwordRecovery(@OraData DbSession dbSession, FullRestRequest f
513513
lostPassword.getUrlPostfix()
514514
};
515515
try {
516-
this.mailManagement.send(user.getEmail(), "reset", body, lang, false);
516+
this.mailManagement.send(user.getEmail(), "reset", body, lang, false, httpSessionState.getUrl());
517517
up.setStatus(ProcessorStatus.SUCCEEDED, Key.USER_PASSWORD_RECOVERY_SENT_MAIL_SUCCESS, responseParameters);
518518
} catch ( MessagingException e ) {
519519
up.setStatus(ProcessorStatus.FAILED, Key.USER_PASSWORD_RECOVERY_SENT_MAIL_FAIL, responseParameters);
@@ -691,7 +691,7 @@ public Response resendActivation(@OraData DbSession dbSession, FullRestRequest f
691691
if ( !email.equals("") ) {
692692
PendingEmailConfirmations confirmation = pendingConfirmationProcessor.createEmailConfirmation(user);
693693
// TODO ask here again for the age
694-
sendActivationMail(up, confirmation.getUrlPostfix(), account, email, lang, false);
694+
sendActivationMail(up, confirmation.getUrlPostfix(), account, email, lang, false, httpSessionState.getUrl());
695695
}
696696
}
697697
UtilForREST.addResultInfo(response, up);
@@ -800,15 +800,22 @@ public Response setStatusText(FullRestRequest fullRequest) throws Exception {
800800
}
801801
}
802802

803-
private void sendActivationMail(UserProcessor up, String urlPostfix, String account, String email, String lang, boolean isYoungerThen14) throws Exception {
803+
private void sendActivationMail(
804+
UserProcessor up,
805+
String urlPostfix,
806+
String account,
807+
String email,
808+
String lang,
809+
boolean isYoungerThen14,
810+
String url) throws Exception {
804811
Map<String, String> responseParameters = new HashMap<>();
805812
String[] body =
806813
{
807814
account,
808815
urlPostfix
809816
};
810817
try {
811-
this.mailManagement.send(email, "activate", body, lang, isYoungerThen14);
818+
this.mailManagement.send(email, "activate", body, lang, isYoungerThen14, url);
812819
up.setStatus(ProcessorStatus.SUCCEEDED, Key.USER_ACTIVATION_SENT_MAIL_SUCCESS, responseParameters);
813820
} catch ( Exception e ) {
814821
up.setStatus(ProcessorStatus.FAILED, Key.USER_ACTIVATION_SENT_MAIL_FAIL, responseParameters);

OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/MailManagement.java

+4-15
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ public MailManagement(
2424
@Named("mail.smtp.starttls.enable") String starttls,
2525
@Named("mail.smtp.host") String host,
2626
@Named("mail.smtp.port") String port,
27-
@Named("reset.url") String resetUrl,
2827
@Named("reset.text.de") String resetTextDe,
2928
@Named("reset.text.en") String resetTextEn,
3029
@Named("reset.subject.de") String resetSubjectDe,
3130
@Named("reset.subject.en") String resetSubjectEn,
32-
@Named("activate.url") String activateUrl,
3331
@Named("activate.text.young.de") String activateTextYoungDe,
3432
@Named("activate.text.young.en") String activateTextYoungEn,
3533
@Named("activate.text.old.de") String activateTextOldDe,
@@ -43,12 +41,10 @@ public MailManagement(
4341
this.props.put("mail.smtp.host", host);
4442
this.props.put("mail.smtp.ssl.trust", host);
4543
this.props.put("mail.smtp.port", port);
46-
this.props.put("reset.url", resetUrl);
4744
this.props.put("reset.text.de", resetTextDe);
4845
this.props.put("reset.text.en", resetTextEn);
4946
this.props.put("reset.subject.de", resetSubjectDe);
5047
this.props.put("reset.subject.en", resetSubjectEn);
51-
this.props.put("activate.url", activateUrl);
5248
this.props.put("activate.text.old.de", activateTextOldDe);
5349
this.props.put("activate.text.old.en", activateTextOldEn);
5450
this.props.put("activate.text.young.de", activateTextYoungDe);
@@ -76,19 +72,16 @@ protected PasswordAuthentication getPasswordAuthentication() {
7672
* @throws AddressException
7773
* @throws MessagingException
7874
*/
79-
public void send(String to, String subject, String[] body, String lang, boolean isYoungerThen14) throws AddressException, MessagingException {
75+
public void send(String to, String subject, String[] body, String lang, boolean isYoungerThen14, String url) throws AddressException, MessagingException {
8076
String language = lang.toLowerCase().equals("de") ? "DE" : "en";
8177
String mailText = body[0];
8278
String mailSubject = "";
79+
String mailUrl = url != null ? url : "https://lab.open-roberta.org/";
8380
if ( subject.equals("reset") ) {
8481
mailSubject = this.props.getProperty("reset.subject." + language.toLowerCase());
8582
mailText = this.props.getProperty("reset.text." + language.toLowerCase());
86-
String url =
87-
this.props.getProperty("reset.url") != null && !this.props.getProperty("reset.url").isEmpty()
88-
? this.props.getProperty("reset.url")
89-
: "https://lab.open-roberta.org/";
9083
mailText = mailText.replace("$1", body[0]);
91-
mailText = mailText.replace("$2", url);
84+
mailText = mailText.replace("$2", mailUrl);
9285
mailText = mailText.replace("$3", body[1]);
9386
} else if ( subject.equals("activate") ) {
9487
mailSubject = this.props.getProperty("activate.subject." + language.toLowerCase());
@@ -97,12 +90,8 @@ public void send(String to, String subject, String[] body, String lang, boolean
9790
} else {
9891
mailText = this.props.getProperty("activate.text.old." + language.toLowerCase());
9992
}
100-
String url =
101-
this.props.getProperty("activate.url") != null && !this.props.getProperty("activate.url").isEmpty()
102-
? this.props.getProperty("activate.url")
103-
: "https://lab.open-roberta.org/";
10493
mailText = mailText.replace("$1", body[0]);
105-
mailText = mailText.replace("$2", url);
94+
mailText = mailText.replace("$2", mailUrl);
10695
mailText = mailText.replace("$3", body[1]);
10796
}
10897
Message message = new MimeMessage(this.session);

OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/HttpSessionState.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class HttpSessionState implements Serializable {
4242
private final long sessionNumber;
4343
private final Map<String, RobotFactory> robotPluginMap;
4444
private final String countryCode;
45+
private final String url;
4546

4647
private final long initTime;
4748
private long lastAccessTime;
@@ -61,12 +62,12 @@ private HttpSessionState(
6162
long sessionNumber,
6263
Map<String, RobotFactory> robotPluginMap,
6364
ServerProperties serverProperties,
64-
String countryCode) //
65-
{
65+
String countryCode, String url) {
6666
this.initToken = initToken;
6767
this.sessionNumber = sessionNumber;
6868
this.robotPluginMap = robotPluginMap;
6969
this.countryCode = countryCode;
70+
this.url = url;
7071
this.initTime = new Date().getTime();
7172
this.lastAccessTime = 0;
7273

@@ -91,15 +92,15 @@ private HttpSessionState(
9192
*
9293
* @param robotPluginMap
9394
* @param serverProperties
94-
* @param sessionNumber
9595
* @param countryCode
96+
* @param url
9697
* @return
9798
*/
98-
public static HttpSessionState init(Map<String, RobotFactory> robotPluginMap, ServerProperties serverProperties, String countryCode) //
99+
public static HttpSessionState init(Map<String, RobotFactory> robotPluginMap, ServerProperties serverProperties, String countryCode, String url) //
99100
{
100101
String initTokenString = RandomUrlPostfix.generate(12, 12, 3, 3, 3);
101102
long sessionNumber = SESSION_COUNTER.incrementAndGet();
102-
HttpSessionState httpSessionState = new HttpSessionState(initTokenString, sessionNumber, robotPluginMap, serverProperties, countryCode);
103+
HttpSessionState httpSessionState = new HttpSessionState(initTokenString, sessionNumber, robotPluginMap, serverProperties, countryCode, url);
103104
LOG.info("session " + sessionNumber + " created");
104105
return httpSessionState;
105106
}
@@ -120,7 +121,7 @@ public static HttpSessionState initOnlyLegalForDebugging(
120121
ServerProperties serverProperties,
121122
long sessionNumber) //
122123
{
123-
HttpSessionState state = new HttpSessionState(initTokenString, sessionNumber, robotPluginMap, serverProperties, "..");
124+
HttpSessionState state = new HttpSessionState(initTokenString, sessionNumber, robotPluginMap, serverProperties, "..", "");
124125
return state;
125126
}
126127

@@ -256,6 +257,10 @@ public String getCountryCode() {
256257
return this.countryCode;
257258
}
258259

260+
public String getUrl() {
261+
return this.url;
262+
}
263+
259264
public static HttpSessionState get(String initToken) {
260265
HttpSessionState httpSessionState = initToken2HttpSessionstate.get(initToken);
261266
if ( httpSessionState != null ) {

0 commit comments

Comments
 (0)