Skip to content

Commit c6756dd

Browse files
committed
updating to last version of 1.4.5
1 parent 7c45c14 commit c6756dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1405
-437
lines changed

src/main/java/com/ec/survey/controller/BasicController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public class BasicController implements BeanFactoryAware {
135135
public @Value("${ecashost}") String ecashost;
136136
public @Value("${sender}") String sender;
137137
public @Value("${captcha.bypass:@null}") String bypassCaptcha;
138+
public @Value("${ui.enablepublicsurveys}") String enablepublicsurveys;
139+
138140
//OCAS
139141
public @Value("${casoss}") String cassOss;
140142
protected @Value("${contextpath}") String contextpath;
@@ -200,6 +202,14 @@ public ModelAndView handleBad2faCredentialsException(Exception e, HttpServletReq
200202
return model;
201203
}
202204

205+
@ExceptionHandler(com.ec.survey.tools.FrozenCredentialsException.class)
206+
public ModelAndView handleFrozenCredentialsException(Exception e, HttpServletRequest request) {
207+
logger.info(e.getLocalizedMessage(), e);
208+
ModelAndView model = new ModelAndView("redirect:/errors/frozen.html");
209+
model.addObject("contextpath", contextpath);
210+
return model;
211+
}
212+
203213
@ExceptionHandler(InvalidURLException.class)
204214
public ModelAndView handleInvalidURLException(Exception e, HttpServletRequest request) {
205215
logger.info(e.getLocalizedMessage(), e);

src/main/java/com/ec/survey/controller/HomeController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,11 @@ public ModelAndView publicsurveysrunner(HttpServletRequest request) throws Excep
671671

672672
public ModelAndView publicsurveys(HttpServletRequest request) throws Exception {
673673

674+
if (!enablepublicsurveys.equalsIgnoreCase("true"))
675+
{
676+
throw new InvalidURLException();
677+
}
678+
674679
SurveyFilter filter = sessionService.getSurveyFilter(request, false);
675680
filter.setUser(null);
676681
String newPage = request.getParameter("newPage");
@@ -724,6 +729,11 @@ else if (sortKey.equalsIgnoreCase("popularity"))
724729
@RequestMapping(value = "/home/publicsurveysjson", method = {RequestMethod.GET, RequestMethod.HEAD})
725730
public @ResponseBody List<Survey> publicsurveysjson(HttpServletRequest request) throws Exception {
726731

732+
if (!enablepublicsurveys.equalsIgnoreCase("true"))
733+
{
734+
throw new InvalidURLException();
735+
}
736+
727737
int itemsPerPage = 10;
728738
int newPage = 1;
729739

src/main/java/com/ec/survey/controller/HttpErrorController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public ModelAndView handleException(HttpServletRequest request){
5757
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
5858
public ModelAndView handle2fa(HttpServletRequest request){
5959
return new ModelAndView("error/2fa","error","exception" );
60+
}
61+
62+
@RequestMapping(value = "/frozen.html")
63+
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
64+
public ModelAndView handlefrozen(HttpServletRequest request){
65+
return new ModelAndView("error/frozen","error","exception" );
6066
}
6167

6268
}

src/main/java/com/ec/survey/controller/ManagementController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public class ManagementController extends BasicController {
6060
public @Value("${opc.users}") String opcusers;
6161
public @Value("${opc.department:@null}") String opcdepartments;
6262
public @Value("${opc.template}") String opctemplatesurvey;
63-
public @Value("${ui.enablepublicsurveys}") String enablepublicsurveys;
64-
63+
6564
@InitBinder
6665
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
6766
SimpleDateFormat dateFormat = new SimpleDateFormat(ConversionTools.DateFormat);

src/main/java/com/ec/survey/controller/SettingsController.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,30 @@ public String root(HttpServletRequest request, Locale locale, Model model) throw
6060
}
6161

6262
@RequestMapping(value = "/myAccount", method = {RequestMethod.GET, RequestMethod.HEAD})
63-
public String myAccount(ModelMap model){
63+
public String myAccount(HttpServletRequest request, ModelMap model, Locale locale) throws NotAgreedToTosException, WeakAuthenticationException{
6464
model.addAttribute("languages", surveyService.getLanguages());
65+
66+
String message = request.getParameter("message");
67+
if (message != null)
68+
{
69+
switch(message)
70+
{
71+
case "password":
72+
model.addAttribute("message", resources.getMessage("info.PasswordChanged", null, "The password has been changed", locale));
73+
break;
74+
case "email":
75+
model.addAttribute("message", resources.getMessage("message.NewEmailAddressSend", null, "The email address will be changed after confirmation", locale));
76+
break;
77+
case "language":
78+
User user = sessionService.getCurrentUser(request);
79+
model.addAttribute("message", resources.getMessage("message.LanguageChanged", null, "The language has been changed", new Locale(user.getLanguage())));
80+
break;
81+
case "pivot":
82+
model.addAttribute("message", resources.getMessage("message.LanguageChanged", null, "The language has been changed", locale));
83+
break;
84+
}
85+
}
86+
6587
return "settings/myAccount";
6688
}
6789

@@ -107,10 +129,9 @@ public String changePassword(HttpServletRequest request, ModelMap model, Locale
107129
user.setPassword(Tools.hash(newPassword + user.getPasswordSalt()));
108130

109131
administrationService.updateUser(user);
110-
sessionService.setCurrentUser(request, user);
132+
sessionService.setCurrentUser(request, user);
111133

112-
model.addAttribute("message", resources.getMessage("info.PasswordChanged", null, "The password has been changed", locale));
113-
return "settings/myAccount";
134+
return "redirect:/settings/myAccount?message=password";
114135
}
115136

116137
@RequestMapping(value = "/changeEmail", method = RequestMethod.POST)
@@ -161,8 +182,7 @@ public String changeEmail(HttpServletRequest request, ModelMap model, Locale loc
161182
return "settings/myAccount";
162183
}
163184

164-
model.addAttribute("message", resources.getMessage("message.NewEmailAddressSend", null, "The email address will be changed after confirmation", locale));
165-
return "settings/myAccount";
185+
return "redirect:/settings/myAccount?message=email";
166186
}
167187

168188
@RequestMapping(value = "/changeLanguage", method = RequestMethod.POST)
@@ -177,9 +197,8 @@ public String changeLanguage(HttpServletRequest request, HttpServletResponse res
177197
sessionService.setCurrentUser(request, user);
178198

179199
localeResolver.setLocale(request, response, new Locale(user.getLanguage()));
180-
model.addAttribute("languages", surveyService.getLanguages());
181-
model.addAttribute("message", resources.getMessage("message.LanguageChanged", null, "The language has been changed", new Locale(user.getLanguage())));
182-
return "settings/myAccount";
200+
201+
return "redirect:/settings/myAccount?message=language";
183202
}
184203

185204
@RequestMapping(value = "/changePivotLanguage", method = RequestMethod.POST)
@@ -192,9 +211,7 @@ public String changePivotLanguage(HttpServletRequest request, ModelMap model, Lo
192211
administrationService.updateUser(user);
193212

194213
sessionService.setCurrentUser(request, user);
195-
model.addAttribute("languages", surveyService.getLanguages());
196-
model.addAttribute("message", resources.getMessage("message.LanguageChanged", null, "The language has been changed", locale));
197-
return "settings/myAccount";
214+
return "redirect:/settings/myAccount?message=pivot";
198215
}
199216

200217
@RequestMapping(value = "/shares")

src/main/java/com/ec/survey/controller/SystemController.java

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,148 @@ public ModelAndView system(HttpServletRequest request, Model model) {
155155
m.addObject("reportMessageText", settingsService.get(Setting.ReportText));
156156
m.addObject("reportRecipients", settingsService.get(Setting.ReportRecipients));
157157

158+
m.addObject("banUserMessageText", settingsService.get(Setting.FreezeUserTextAdminBan));
159+
m.addObject("unbanUserMessageText", settingsService.get(Setting.FreezeUserTextAdminUnban));
160+
m.addObject("bannedUserRecipients", settingsService.get(Setting.BannedUserRecipients));
161+
162+
m.addObject("bannedUserMessageText", settingsService.get(Setting.FreezeUserTextBan));
163+
m.addObject("unbannedUserMessageText", settingsService.get(Setting.FreezeUserTextUnban));
164+
165+
m.addObject("trustIndicatorCreatorInternal", settingsService.get(Setting.TrustValueCreatorInternal));
166+
m.addObject("trustIndicatorMinimumPassMark", settingsService.get(Setting.TrustValueMinimumPassMark));
167+
m.addObject("trustIndicatorPastSurveys", settingsService.get(Setting.TrustValuePastSurveys));
168+
m.addObject("trustIndicatorPrivilegedUser", settingsService.get(Setting.TrustValuePrivilegedUser));
169+
m.addObject("trustIndicatorNbContributions", settingsService.get(Setting.TrustValueNbContributions));
170+
158171
return m;
159172
}
160173

174+
@RequestMapping(value ="/configureBanUsers", method = RequestMethod.POST)
175+
public ModelAndView configureBanUsers( HttpServletRequest request, Locale locale) throws Exception {
176+
String banUserMessageText = request.getParameter("banUserMessageText");
177+
178+
if (banUserMessageText == null || banUserMessageText.length() == 0)
179+
{
180+
throw new Exception("banUserMessageText must not be empty");
181+
}
182+
183+
String unbanUserMessageText = request.getParameter("unbanUserMessageText");
184+
185+
if (unbanUserMessageText == null || unbanUserMessageText.length() == 0)
186+
{
187+
throw new Exception("unbanUserMessageText must not be empty");
188+
}
189+
190+
String bannedUserMessageText = request.getParameter("bannedUserMessageText");
191+
192+
if (bannedUserMessageText == null || bannedUserMessageText.length() == 0)
193+
{
194+
throw new Exception("bannedUserMessageText must not be empty");
195+
}
196+
197+
String unbannedUserMessageText = request.getParameter("unbannedUserMessageText");
198+
199+
if (unbannedUserMessageText == null || unbannedUserMessageText.length() == 0)
200+
{
201+
throw new Exception("unbannedUserMessageText must not be empty");
202+
}
203+
204+
String[] emails = request.getParameterValues("messageEmail");
205+
String recipients = "";
206+
if (emails != null)
207+
{
208+
for (String email : emails) {
209+
if (email.trim().length() > 0)
210+
{
211+
if (!MailService.isValidEmailAddress(email))
212+
{
213+
throw new Exception("invalid email address:" + email);
214+
}
215+
216+
if (recipients.length() > 0)
217+
{
218+
recipients += ";";
219+
}
220+
recipients += email;
221+
}
222+
}
223+
}
224+
225+
settingsService.update(Setting.BannedUserRecipients, recipients);
226+
settingsService.update(Setting.FreezeUserTextAdminBan, banUserMessageText);
227+
settingsService.update(Setting.FreezeUserTextAdminUnban, unbanUserMessageText);
228+
settingsService.update(Setting.FreezeUserTextBan, bannedUserMessageText);
229+
settingsService.update(Setting.FreezeUserTextUnban, unbannedUserMessageText);
230+
231+
return new ModelAndView("redirect:/administration/system");
232+
}
233+
234+
@RequestMapping(value ="/configureTrustIndicator", method = RequestMethod.POST)
235+
public ModelAndView configureTrustIndicator( HttpServletRequest request, Locale locale) throws Exception {
236+
String trustIndicatorCreatorInternal = request.getParameter("trustIndicatorCreatorInternal");
237+
238+
if (trustIndicatorCreatorInternal == null || trustIndicatorCreatorInternal.length() == 0)
239+
{
240+
throw new Exception("trustIndicatorCreatorInternal must not be empty");
241+
}
242+
if (!Tools.isInteger(trustIndicatorCreatorInternal))
243+
{
244+
throw new Exception("trustIndicatorCreatorInternal must be an integer");
245+
}
246+
247+
String trustIndicatorMinimumPassMark = request.getParameter("trustIndicatorMinimumPassMark");
248+
249+
if (trustIndicatorMinimumPassMark == null || trustIndicatorMinimumPassMark.length() == 0)
250+
{
251+
throw new Exception("trustIndicatorMinimumPassMark must not be empty");
252+
}
253+
if (!Tools.isInteger(trustIndicatorMinimumPassMark))
254+
{
255+
throw new Exception("trustIndicatorMinimumPassMark must be an integer");
256+
}
257+
258+
String trustIndicatorPastSurveys = request.getParameter("trustIndicatorPastSurveys");
259+
260+
if (trustIndicatorPastSurveys == null || trustIndicatorPastSurveys.length() == 0)
261+
{
262+
throw new Exception("trustIndicatorPastSurveys must not be empty");
263+
}
264+
if (!Tools.isInteger(trustIndicatorPastSurveys))
265+
{
266+
throw new Exception("trustIndicatorPastSurveys must be an integer");
267+
}
268+
269+
String trustIndicatorPrivilegedUser = request.getParameter("trustIndicatorPrivilegedUser");
270+
271+
if (trustIndicatorPrivilegedUser == null || trustIndicatorPrivilegedUser.length() == 0)
272+
{
273+
throw new Exception("trustIndicatorPrivilegedUser must not be empty");
274+
}
275+
if (!Tools.isInteger(trustIndicatorPrivilegedUser))
276+
{
277+
throw new Exception("trustIndicatorPrivilegedUser must be an integer");
278+
}
279+
280+
String trustIndicatorNbContributions = request.getParameter("trustIndicatorNbContributions");
281+
282+
if (trustIndicatorNbContributions == null || trustIndicatorNbContributions.length() == 0)
283+
{
284+
throw new Exception("trustIndicatorNbContributions must not be empty");
285+
}
286+
if (!Tools.isInteger(trustIndicatorNbContributions))
287+
{
288+
throw new Exception("trustIndicatorNbContributions must be an integer");
289+
}
290+
291+
settingsService.update(Setting.TrustValueCreatorInternal, trustIndicatorCreatorInternal);
292+
settingsService.update(Setting.TrustValuePastSurveys, trustIndicatorPastSurveys);
293+
settingsService.update(Setting.TrustValuePrivilegedUser, trustIndicatorPrivilegedUser);
294+
settingsService.update(Setting.TrustValueMinimumPassMark, trustIndicatorMinimumPassMark);
295+
settingsService.update(Setting.TrustValueNbContributions, trustIndicatorNbContributions);
296+
297+
return new ModelAndView("redirect:/administration/system");
298+
}
299+
161300
@RequestMapping(value ="/configureReports", method = RequestMethod.POST)
162301
public ModelAndView configureReports( HttpServletRequest request, Locale locale) throws Exception {
163302
String number = request.getParameter("maxNumber");

src/main/java/com/ec/survey/controller/UserController.java

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ec.survey.controller;
22

33
import com.ec.survey.model.Paging;
4+
import com.ec.survey.model.Setting;
45
import com.ec.survey.model.SqlPagination;
56
import com.ec.survey.model.UserFilter;
67
import com.ec.survey.model.UsersConfiguration;
@@ -79,7 +80,36 @@ public ModelAndView users(HttpServletRequest request, Model model) throws Except
7980
if (usersConfiguration == null) usersConfiguration = new UsersConfiguration();
8081
m.addObject("usersConfiguration", usersConfiguration);
8182

82-
return m;
83+
m.addObject("freezeusertext", settingsService.get(Setting.FreezeUserTextBan));
84+
m.addObject("unfreezeusertext", settingsService.get(Setting.FreezeUserTextUnban));
85+
86+
return m;
87+
}
88+
89+
@RequestMapping(value = "/banuser", method = RequestMethod.POST)
90+
public ModelAndView banuser(@RequestParam("userId") String userId, @RequestParam("emailText") String emailText, HttpServletRequest request, Model model) throws Exception {
91+
92+
if (userId == null || userId.length() == 0 || emailText == null || emailText.length() == 0)
93+
{
94+
throw new Exception("invalid input data");
95+
}
96+
97+
administrationService.banUser(userId, emailText);
98+
99+
return new ModelAndView("redirect:/administration/users?frozen=1");
100+
}
101+
102+
@RequestMapping(value = "/unbanuser", method = RequestMethod.POST)
103+
public ModelAndView unbanuser(@RequestParam("userId") String userId, HttpServletRequest request, Model model) throws Exception {
104+
105+
if (userId == null || userId.length() == 0)
106+
{
107+
throw new Exception("invalid input data");
108+
}
109+
110+
administrationService.unbanUser(userId);
111+
112+
return new ModelAndView("redirect:/administration/users?unfrozen=1");
83113
}
84114

85115
@RequestMapping(value = "/createUser", method = RequestMethod.POST)
@@ -100,7 +130,7 @@ public ModelAndView createUser(@RequestParam("add-login") String login, @Request
100130
if (Tools.isPasswordWeak(password))
101131
{
102132
model.addAttribute("error", resources.getMessage("error.PasswordWeak", null, "This password does not fit our password policy. Please choose a password between 8 and 16 characters with at least one digit and one non-alphanumeric characters (e.g. !?$&%...).", locale));
103-
} else {
133+
} else {
104134
User user = new User();
105135
user.setValidated(true);
106136
user.setLogin(login);
@@ -114,19 +144,24 @@ public ModelAndView createUser(@RequestParam("add-login") String login, @Request
114144
user.setLanguage(language);
115145
user.setType(User.SYSTEM);
116146

117-
if (roles != null && roles.length() > 0)
147+
if (!administrationService.checkEmailsNotBanned(user.getAllEmailAddresses()))
118148
{
119-
String[] ids = roles.split(";");
120-
Map<Integer, Role> rolesById = administrationService.getAllRolesAsMap();
121-
for (String id : ids) {
122-
if (rolesById.containsKey(Integer.parseInt(id)))
123-
{
124-
user.getRoles().add(rolesById.get(Integer.parseInt(id)));
125-
}
126-
}
149+
model.addAttribute("error", resources.getMessage("error.EmailBanned", null, "This email adress belongs to a banned user.", locale));
150+
} else {
151+
if (roles != null && roles.length() > 0)
152+
{
153+
String[] ids = roles.split(";");
154+
Map<Integer, Role> rolesById = administrationService.getAllRolesAsMap();
155+
for (String id : ids) {
156+
if (rolesById.containsKey(Integer.parseInt(id)))
157+
{
158+
user.getRoles().add(rolesById.get(Integer.parseInt(id)));
159+
}
160+
}
161+
}
162+
163+
administrationService.createUser(user);
127164
}
128-
129-
administrationService.createUser(user);
130165
}
131166
} else {
132167
model.addAttribute("error", resources.getMessage("error.LoginExists", null, "This login already exists. Please choose a unique login.", locale));
@@ -201,5 +236,5 @@ public ModelAndView deleteUser(@RequestParam("id") String id, HttpServletRequest
201236
}
202237
return users(request, model);
203238
}
204-
239+
205240
}

0 commit comments

Comments
 (0)