Skip to content

Commit 1abec2a

Browse files
authored
Merge pull request #2 from EUSurvey/develop
Develop
2 parents 74ee669 + c6756dd commit 1abec2a

File tree

86 files changed

+5482
-2695
lines changed

Some content is hidden

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

86 files changed

+5482
-2695
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>eusurvey</artifactId>
88
<name>eusurvey</name>
99
<packaging>war</packaging>
10-
<version>1.4.4</version>
10+
<version>1.4.5</version>
1111
<properties>
1212
<java-version>1.8</java-version>
1313
<org.springframework-version>4.3.20.RELEASE</org.springframework-version>

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sonar.projectKey=EUSURVEY
22
sonar.projectName=eusurvey
3-
sonar.projectVersion=1.4.4
3+
sonar.projectVersion=1.4.5
44

55
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
66
# Since SonarQube 4.2, this property is optional if sonar.modules is set.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public ModelAndView batchEdit(HttpServletRequest request) throws Exception {
316316
}
317317

318318
@RequestMapping(value = "/batchEdit", method = RequestMethod.POST)
319-
public ModelAndView batchEditPOST(HttpServletRequest request, Locale locale) throws IntrusionException, NotAgreedToTosException {
319+
public ModelAndView batchEditPOST(HttpServletRequest request, Locale locale) throws IntrusionException, NotAgreedToTosException, WeakAuthenticationException {
320320
User user = sessionService.getCurrentUser(request);
321321
boolean userChanged = false;
322322

@@ -1349,7 +1349,7 @@ public ModelAndView edit(@PathVariable("id") String id, HttpServletRequest reque
13491349
}
13501350

13511351
@RequestMapping( value = "/configureAttributes", method = RequestMethod.POST)
1352-
public String configureAttributes(HttpServletRequest request) throws NotAgreedToTosException {
1352+
public String configureAttributes(HttpServletRequest request) throws NotAgreedToTosException, WeakAuthenticationException {
13531353
User user = sessionService.getCurrentUser(request);
13541354
Map<String, String[]> parameterMap = Ucs2Utf8.requestToHashMap(request);
13551355

@@ -1389,7 +1389,7 @@ public String configureAttributes(HttpServletRequest request) throws NotAgreedTo
13891389
}
13901390

13911391
@RequestMapping(value = "/configureAttributesJSON", headers="Accept=*/*", method=RequestMethod.GET)
1392-
public @ResponseBody List<AttributeName> configureAttributesJSON(HttpServletRequest request, HttpServletResponse response ) throws NotAgreedToTosException {
1392+
public @ResponseBody List<AttributeName> configureAttributesJSON(HttpServletRequest request, HttpServletResponse response ) throws NotAgreedToTosException, WeakAuthenticationException {
13931393
User user = sessionService.getCurrentUser(request);
13941394
Map<String, String[]> parameterMap = Ucs2Utf8.requestToHashMap(request);
13951395

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.ec.survey.tools.RecreateAllOLAPTablesExecutor;
1313
import com.ec.survey.tools.Tools;
1414
import com.ec.survey.tools.UpdateAllOLAPTablesExecutor;
15+
import com.ec.survey.tools.WeakAuthenticationException;
1516

1617
import org.apache.commons.lang.StringUtils;
1718
import org.apache.poi.hssf.usermodel.HSSFRow;
@@ -116,7 +117,7 @@ public class AdministrationController extends BasicController {
116117
}
117118

118119
@RequestMapping(value = "/saveUserConfiguration", method = {RequestMethod.POST})
119-
public @ResponseBody String saveUserConfiguration(HttpServletRequest request) throws NotAgreedToTosException {
120+
public @ResponseBody String saveUserConfiguration(HttpServletRequest request) throws NotAgreedToTosException, WeakAuthenticationException {
120121
int userId = sessionService.getCurrentUser(request).getId();
121122
UsersConfiguration usersConfiguration = administrationService.getUsersConfiguration(userId);
122123

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.web.servlet.ModelAndView;
2929

3030
import com.ec.survey.exception.ForbiddenURLException;
31+
import com.ec.survey.exception.FrozenSurveyException;
3132
import com.ec.survey.exception.InvalidURLException;
3233
import com.ec.survey.exception.MessageException;
3334
import com.ec.survey.exception.NoFormLoadedException;
@@ -58,6 +59,7 @@
5859
import com.ec.survey.tools.ConversionTools;
5960
import com.ec.survey.tools.InvalidXHTMLException;
6061
import com.ec.survey.tools.NotAgreedToTosException;
62+
import com.ec.survey.tools.WeakAuthenticationException;
6163
import com.octo.captcha.service.CaptchaServiceException;
6264
import com.octo.captcha.service.multitype.MultiTypeCaptchaService;
6365

@@ -133,6 +135,8 @@ public class BasicController implements BeanFactoryAware {
133135
public @Value("${ecashost}") String ecashost;
134136
public @Value("${sender}") String sender;
135137
public @Value("${captcha.bypass:@null}") String bypassCaptcha;
138+
public @Value("${ui.enablepublicsurveys}") String enablepublicsurveys;
139+
136140
//OCAS
137141
public @Value("${casoss}") String cassOss;
138142
protected @Value("${contextpath}") String contextpath;
@@ -190,6 +194,22 @@ public boolean isByPassCaptcha(){
190194
return bypassCaptcha !=null && bypassCaptcha.equalsIgnoreCase("true");
191195
}
192196

197+
@ExceptionHandler(com.ec.survey.tools.Bad2faCredentialsException.class)
198+
public ModelAndView handleBad2faCredentialsException(Exception e, HttpServletRequest request) {
199+
logger.info(e.getLocalizedMessage(), e);
200+
ModelAndView model = new ModelAndView("redirect:/errors/2fa.html");
201+
model.addObject("contextpath", contextpath);
202+
return model;
203+
}
204+
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+
193213
@ExceptionHandler(InvalidURLException.class)
194214
public ModelAndView handleInvalidURLException(Exception e, HttpServletRequest request) {
195215
logger.info(e.getLocalizedMessage(), e);
@@ -199,6 +219,16 @@ public ModelAndView handleInvalidURLException(Exception e, HttpServletRequest re
199219
return model;
200220
}
201221

222+
@ExceptionHandler(FrozenSurveyException.class)
223+
public ModelAndView handleFrozenSurveyException(Exception e, HttpServletRequest request, Locale locale) {
224+
logger.error(e.getLocalizedMessage(), e);
225+
ModelAndView model = new ModelAndView("error/generic");
226+
String message = resources.getMessage("error.FrozenSurvey", null, "This survey has been blocked due to an infringement to our policy. We are sorry for the inconvenience this may cause. Please try again later.", locale);
227+
model.addObject("message", message);
228+
model.addObject("contextpath", contextpath);
229+
return model;
230+
}
231+
202232
@ExceptionHandler(ForbiddenURLException.class)
203233
public ModelAndView handleForbiddenURLException(Exception e, HttpServletRequest request) {
204234
logger.info(e.getLocalizedMessage(), e);
@@ -214,6 +244,16 @@ public ModelAndView handleNotAgreedToTosException(Exception e, HttpServletReques
214244
return model;
215245
}
216246

247+
@ExceptionHandler(WeakAuthenticationException.class)
248+
public ModelAndView handleWeakAuthenticationException(Exception e, HttpServletRequest request, Locale locale) {
249+
logger.error(e.getLocalizedMessage(), e);
250+
ModelAndView model = new ModelAndView("error/generic");
251+
String message = resources.getMessage("error.WeakAuthentication", null, "Please log in using two factor authentication in order to access the system.", locale);
252+
model.addObject("message", message);
253+
model.addObject("contextpath", contextpath);
254+
return model;
255+
}
256+
217257
@ExceptionHandler(TooManyFiltersException.class)
218258
public ModelAndView handleTooManyFiltersException(Exception e, HttpServletRequest request, Locale locale) {
219259
logger.error(e.getLocalizedMessage(), e);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.ec.survey.tools.QuizHelper;
2020
import com.ec.survey.tools.SurveyHelper;
2121
import com.ec.survey.tools.Tools;
22+
import com.ec.survey.tools.WeakAuthenticationException;
23+
2224
import org.springframework.beans.factory.annotation.Value;
2325
import org.springframework.stereotype.Controller;
2426
import org.springframework.web.bind.annotation.PathVariable;
@@ -57,7 +59,7 @@ public class ContributionController extends BasicController {
5759
private @Value("${export.fileDir}") String fileDir;
5860
private @Value("${server.prefix}") String serverPrefix;
5961

60-
public AnswerSet getAnswerSet(String code, HttpServletRequest request) throws NotAgreedToTosException
62+
public AnswerSet getAnswerSet(String code, HttpServletRequest request) throws NotAgreedToTosException, WeakAuthenticationException
6163
{
6264
AnswerSet answerSet = null;
6365
User user = sessionService.getCurrentUser(request);

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public ModelAndView dashboard(HttpServletRequest request, Locale locale, Model m
6868
archiveService.delete(archive);
6969
}
7070

71+
//check user (e.g. weak authentication)
72+
sessionService.getCurrentUser(request);
7173
ModelAndView result = new ModelAndView("dashboard");
7274

7375
if (request.getParameter("archived") != null)
@@ -82,6 +84,12 @@ public ModelAndView dashboard(HttpServletRequest request, Locale locale, Model m
8284
result.addObject("deleted", shortname);
8385
}
8486

87+
if (request.getParameter("frozen") != null)
88+
{
89+
String shortname = request.getParameter("frozen");
90+
result.addObject("frozen", shortname);
91+
}
92+
8593
result.addObject("filter", new ArchiveFilter());
8694

8795
return result;
@@ -281,8 +289,18 @@ public ModelAndView dashboard(HttpServletRequest request, Locale locale, Model m
281289
filter.setSortOrder(request.getParameter("asc") != null && request.getParameter("asc").equalsIgnoreCase("true") ? "ASC" : "DESC");
282290
}
283291

292+
if (request.getParameter("reported") != null)
293+
{
294+
filter.setSurveys("REPORTED");
295+
}
296+
297+
if (request.getParameter("frozen") != null)
298+
{
299+
filter.setSurveys("FROZEN");
300+
}
301+
284302
SqlPagination paging = new SqlPagination(page, 10);
285-
List<Survey> result = surveyService.getSurveysIncludingTranslationLanguages(filter, paging, false);
303+
List<Survey> result = surveyService.getSurveysIncludingTranslationLanguages(filter, paging, false, false);
286304

287305
surveyService.generateAccessInformation(result, u);
288306

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.ec.survey.service.SurveyService;
1414
import com.ec.survey.tools.NotAgreedToTosException;
1515
import com.ec.survey.tools.Tools;
16+
import com.ec.survey.tools.WeakAuthenticationException;
1617

1718
import org.apache.maven.surefire.shade.org.apache.maven.shared.utils.StringUtils;
1819
import org.apache.poi.util.IOUtils;
@@ -225,7 +226,7 @@ public class ExportsController extends BasicController {
225226

226227

227228
@RequestMapping(value = "/list")
228-
public ModelAndView root(HttpServletRequest request) throws NotAgreedToTosException {
229+
public ModelAndView root(HttpServletRequest request) throws NotAgreedToTosException, WeakAuthenticationException {
229230
sessionService.getCurrentUser(request);
230231

231232
//default
@@ -251,7 +252,7 @@ public ModelAndView root(HttpServletRequest request) throws NotAgreedToTosExcept
251252
}
252253

253254
@RequestMapping(value = "/exportsjson", method = {RequestMethod.GET, RequestMethod.HEAD})
254-
public @ResponseBody List<Export> exportsjson(HttpServletRequest request) throws NotAgreedToTosException {
255+
public @ResponseBody List<Export> exportsjson(HttpServletRequest request) throws NotAgreedToTosException, WeakAuthenticationException {
255256

256257
int itemsPerPage = -1;
257258
int page = -1;
@@ -396,7 +397,7 @@ public ResponseEntity<byte[]> downloadExport(@PathVariable int exportId, HttpSer
396397
}
397398

398399
@RequestMapping(value = "/recreate/{exportId}", method = {RequestMethod.GET, RequestMethod.HEAD})
399-
public ModelAndView recreateExport(@PathVariable int exportId, HttpServletRequest request, Locale locale) throws NotAgreedToTosException {
400+
public ModelAndView recreateExport(@PathVariable int exportId, HttpServletRequest request, Locale locale) throws NotAgreedToTosException, WeakAuthenticationException {
400401
Export export = exportService.getExport(exportId, true);
401402
if (export == null || !(sessionService.checkUser(export.getUserId(), request) || sessionService.getCurrentUser(request).getGlobalPrivileges().get(GlobalPrivilege.FormManagement).equals(2))) {
402403
return new ModelAndView("error/generic", "message", "Access denied");
@@ -406,7 +407,7 @@ public ModelAndView recreateExport(@PathVariable int exportId, HttpServletReques
406407
}
407408

408409
@RequestMapping(value = "/recreateMany/{exportIdList}", method = {RequestMethod.GET, RequestMethod.HEAD})
409-
public ModelAndView recreateExport(@PathVariable String exportIdList, HttpServletRequest request, Locale locale) throws NotAgreedToTosException {
410+
public ModelAndView recreateExport(@PathVariable String exportIdList, HttpServletRequest request, Locale locale) throws NotAgreedToTosException, WeakAuthenticationException {
410411
String[] exportIds = exportIdList.split("-");
411412
List<Export> exports = new ArrayList<>();
412413

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

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

3+
import com.ec.survey.exception.InvalidURLException;
34
import com.ec.survey.model.*;
45
import com.ec.survey.model.administration.User;
56
import com.ec.survey.model.survey.Survey;
@@ -626,7 +627,7 @@ public ModelAndView processSubmit(HttpServletRequest request, Locale locale) {
626627

627628
Survey survey = surveyService.getSurvey(Integer.parseInt(request.getParameter("survey.id")), false, true);
628629

629-
User user = sessionService.getCurrentUser(request, false);
630+
User user = sessionService.getCurrentUser(request, false, false);
630631
AnswerSet answerSet = SurveyHelper.parseAndMergeAnswerSet(request, survey, fileDir, uniqueCode, oldAnswerSet, oldAnswerSet.getLanguageCode(), user, fileService);
631632

632633
saveAnswerSet(answerSet, fileDir, null, -1);
@@ -670,6 +671,11 @@ public ModelAndView publicsurveysrunner(HttpServletRequest request) throws Excep
670671

671672
public ModelAndView publicsurveys(HttpServletRequest request) throws Exception {
672673

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

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

@@ -753,7 +764,7 @@ else if (sortKey.equalsIgnoreCase("popularity"))
753764
SurveyFilter filter = (SurveyFilter) request.getSession().getAttribute("lastPublicSurveyFilter");
754765

755766
SqlPagination sqlPagination = new SqlPagination(newPage, itemsPerPage);
756-
return surveyService.getSurveysIncludingTranslationLanguages(filter, sqlPagination, false);
767+
return surveyService.getSurveysIncludingTranslationLanguages(filter, sqlPagination, false, false);
757768
}
758769

759770
@RequestMapping(value = "/validate/{id}/{code}", method = {RequestMethod.GET, RequestMethod.HEAD})
@@ -811,4 +822,82 @@ public void notifyError(HttpServletRequest request, Locale locale, HttpServletRe
811822
machineTranslationService.saveErrorResponse(requestId,targetLanguage,errorCode,errorMessage);
812823
}
813824

825+
@RequestMapping(value = "/home/reportAbuse", method = RequestMethod.GET)
826+
public String reportAbuse (HttpServletRequest request, Locale locale, Model model) throws InvalidURLException {
827+
model.addAttribute("lang", locale.getLanguage());
828+
model.addAttribute("runnermode", true);
829+
830+
String surveyid = request.getParameter("survey");
831+
if (surveyid == null || surveyid.trim().length() == 0)
832+
{
833+
throw new InvalidURLException();
834+
}
835+
836+
try {
837+
int id = Integer.parseInt(surveyid);
838+
839+
Survey survey = surveyService.getSurvey(id);
840+
841+
if (survey == null)
842+
{
843+
throw new InvalidURLException();
844+
}
845+
846+
model.addAttribute("AbuseSurvey", survey.getUniqueId());
847+
model.addAttribute("AbuseType", "");
848+
model.addAttribute("AbuseText", "");
849+
model.addAttribute("AbuseEmail", "");
850+
851+
} catch (NumberFormatException e)
852+
{
853+
throw new InvalidURLException();
854+
}
855+
856+
return "home/reportabuse";
857+
}
858+
859+
@RequestMapping(value = "home/reportAbuse", method = RequestMethod.POST)
860+
public ModelAndView reportAbusePOST(HttpServletRequest request, Locale locale, HttpServletResponse response) throws NumberFormatException, Exception {
861+
ModelAndView model = new ModelAndView("home/reportabuse");
862+
863+
String uid = request.getParameter("abuseSurvey");
864+
String type = request.getParameter("abuseType");
865+
String text = request.getParameter("abuseText");
866+
String email = request.getParameter("abuseEmail");
867+
868+
Survey survey = surveyService.getSurveyByUniqueId(uid, false, true);
869+
870+
if (survey == null)
871+
{
872+
throw new InvalidURLException();
873+
}
874+
875+
if (!checkCaptcha(request)) {
876+
model.addObject("wrongcaptcha", true);
877+
model.addObject("contextpath", contextpath);
878+
879+
model.addObject("AbuseSurvey", uid);
880+
model.addObject("AbuseType", type);
881+
model.addObject("AbuseText", text);
882+
model.addObject("AbuseEmail", email);
883+
884+
return model;
885+
}
886+
887+
logger.info("HomeController.reportAbuse called with abuseType " + type);
888+
889+
surveyService.reportAbuse(survey, type, text, email);
890+
891+
model = new ModelAndView("error/info");
892+
String message = resources.getMessage("info.ReportAbuseSent", null, "The abuse has been reported to the team in charge of the service.", locale);
893+
894+
model.addObject("message", message);
895+
model.addObject("contextpath", contextpath);
896+
897+
String link = serverPrefix + "runner/" + survey.getShortname();
898+
model.addObject("SurveyLink", link);
899+
900+
return model;
901+
}
902+
814903
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ public ModelAndView handleException(HttpServletRequest request){
5151
request.getSession().setAttribute("lastErrorTime", new Date());
5252
request.getSession().setAttribute("lastErrorURL", request.getAttribute("javax.servlet.error.request_uri"));
5353
return new ModelAndView("error/500","error","exception" );
54+
}
55+
56+
@RequestMapping(value = "/2fa.html")
57+
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
58+
public ModelAndView handle2fa(HttpServletRequest request){
59+
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" );
5466
}
5567

5668
}

0 commit comments

Comments
 (0)