Upgrade Spring version.

Fix failing export tests
This commit is contained in:
Paulo Veiga
2018-09-14 17:50:27 -07:00
parent 57b2e79c0d
commit 4234ca7e38
30 changed files with 187 additions and 163 deletions

View File

@@ -167,6 +167,10 @@ public class ExporterFactory {
svgXml = svgXml.replaceFirst("<svg ", "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
}
if (!svgXml.contains("xmlns=\"http://www.w3.org/2000/svg\"")) {
svgXml = svgXml.replaceFirst("<svg ", "<svg xmlns=\"http://www.w3.org/2000/svg\" ");
}
// Hacks for some legacy cases ....
svgXml = svgXml.replaceAll("NaN,", "0");
svgXml = svgXml.replaceAll(",NaN", "0");

View File

@@ -41,7 +41,7 @@ public class TransformerController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = "/transform", produces = {"application/pdf"}, consumes = {"image/svg+xml"})
@ResponseBody
public ModelAndView transformPdf(@RequestBody @Nullable final String content) throws IOException {
public ModelAndView transformPdf(@RequestBody @Nullable final String content) {
final Map<String, Object> values = new HashMap<String, Object>();
if (content == null || content.length() == 0) {
throw new IllegalArgumentException("Body can not be null.");
@@ -53,7 +53,7 @@ public class TransformerController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = "/transform", produces = {"image/svg+xml"}, consumes = {"image/svg+xml"})
@ResponseBody
public ModelAndView transformSvg(@RequestBody @Nullable final String content) throws IOException {
public ModelAndView transformSvg(@RequestBody @Nullable final String content) {
final Map<String, Object> values = new HashMap<String, Object>();
if (content == null || content.length() == 0) {
throw new IllegalArgumentException("Body can not be null.");
@@ -65,7 +65,7 @@ public class TransformerController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = "/transform", produces = {"image/png"}, consumes = {"image/svg+xml"})
@ResponseBody
public ModelAndView transformPng(@RequestBody @Nullable final String content) throws IOException {
public ModelAndView transformPng(@RequestBody @Nullable final String content) {
final Map<String, Object> values = new HashMap<String, Object>();
if (content == null || content.length() == 0) {
throw new IllegalArgumentException("Body can not be null.");

View File

@@ -0,0 +1,92 @@
package com.wisemapping.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.fluent.Form;
import org.apache.http.client.fluent.Request;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RecaptchaService {
final private static Logger logger = Logger.getLogger(RecaptchaService.class);
final private static String GOOGLE_RECAPTCHA_VERIFY_URL =
"https://www.google.com/recaptcha/api/siteverify";
private final static ObjectMapper objectMapper = new ObjectMapper();
private String recaptchaSecret;
public String verifyRecaptcha(String ip, String recaptchaResponse) {
final List<NameValuePair> build = Form.form()
.add("secret", recaptchaSecret)
.add("response", recaptchaResponse)
.add("remoteip", ip)
.build();
// Add logs ...
logger.debug("Response from remoteip: " + ip);
logger.debug("Response from recaptchaSecret: " + recaptchaSecret);
logger.debug("Response from recaptchaResponse: " + recaptchaResponse);
String result = StringUtils.EMPTY;
HashMap bodyJson;
try {
final byte[] body = Request
.Post(GOOGLE_RECAPTCHA_VERIFY_URL)
.bodyForm(build)
.execute()
.returnContent()
.asBytes();
bodyJson = objectMapper
.readValue(body, HashMap.class);
logger.debug("Response from recaptcha after parse: " + bodyJson);
final Boolean success = (Boolean) bodyJson.get("success");
if (!success) {
final List<String> errorCodes = (List<String>) bodyJson
.get("error-codes");
result = RecaptchaUtil.RECAPTCHA_ERROR_CODE.get(errorCodes.get(0));
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
result = e.getMessage();
}
logger.debug("Captcha Result:" + result);
return result;
}
public void setRecaptchaSecret(String recaptchaSecret) {
this.recaptchaSecret = recaptchaSecret;
}
}
class RecaptchaUtil {
static final Map<String, String>
RECAPTCHA_ERROR_CODE = new HashMap<>();
static {
RECAPTCHA_ERROR_CODE.put("missing-input-secret",
"The secret parameter is missing");
RECAPTCHA_ERROR_CODE.put("invalid-input-secret",
"The secret parameter is invalid or malformed");
RECAPTCHA_ERROR_CODE.put("missing-input-response",
"The response parameter is missing");
RECAPTCHA_ERROR_CODE.put("invalid-input-response",
"The response parameter is invalid or malformed");
RECAPTCHA_ERROR_CODE.put("bad-request",
"The request is invalid or malformed");
}
}

View File

@@ -26,6 +26,5 @@ public interface Messages {
String MAP_TITLE_ALREADY_EXISTS = "MAP_TITLE_ALREADY_EXISTS";
String LABEL_TITLE_ALREADY_EXISTS = "LABEL_TITLE_ALREADY_EXISTS";
String PASSWORD_MISSMATCH = "PASSWORD_MISSMATCH";
String CAPTCHA_ERROR = "CAPTCHA_ERROR";
String CAPTCHA_LOADING_ERROR = "CAPTCHA_LOADING_ERROR";
}

View File

@@ -18,10 +18,10 @@
package com.wisemapping.validator;
import com.wisemapping.service.RecaptchaService;
import com.wisemapping.service.UserService;
import com.wisemapping.view.UserBean;
import com.wisemapping.model.Constants;
import net.tanesha.recaptcha.ReCaptcha;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.validation.Errors;
@@ -32,7 +32,7 @@ public class UserValidator
implements Validator {
private UserService userService;
private ReCaptcha captchaService;
private RecaptchaService captchaService;
public boolean supports(final Class clazz) {
@@ -92,11 +92,11 @@ public class UserValidator
this.userService = userService;
}
public void setCaptchaService(@NotNull final ReCaptcha captchaService) {
public void setCaptchaService(@NotNull final RecaptchaService captchaService) {
this.captchaService = captchaService;
}
public ReCaptcha getCaptchaService() {
public RecaptchaService getCaptchaService() {
return captchaService;
}
}

View File

@@ -1,36 +1,35 @@
/*
* Copyright [2015] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright [2015] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.webmvc;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.service.InvalidAuthSchemaException;
import com.wisemapping.validator.Messages;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.model.User;
import com.wisemapping.security.Utils;
import com.wisemapping.service.InvalidAuthSchemaException;
import com.wisemapping.service.InvalidUserEmailException;
import com.wisemapping.service.RecaptchaService;
import com.wisemapping.service.UserService;
import com.wisemapping.validator.Messages;
import com.wisemapping.validator.UserValidator;
import com.wisemapping.view.UserBean;
import net.tanesha.recaptcha.ReCaptcha;
import net.tanesha.recaptcha.ReCaptchaResponse;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -55,11 +54,13 @@ public class UsersController {
private UserService userService;
@Autowired
private ReCaptcha captchaService;
private RecaptchaService captchaService;
@Value("${google.recaptcha.enabled}")
@Value("${google.recaptcha2.enabled}")
private boolean captchaEnabled;
@Value("${google.recaptcha2.siteKey}")
private String recaptchaSiteKey;
@RequestMapping(value = "user/resetPassword", method = RequestMethod.GET)
public ModelAndView showResetPasswordPage() {
@@ -74,10 +75,7 @@ public class UsersController {
userService.resetPassword(email);
result = new ModelAndView("forgotPasswordSuccess");
} catch (InvalidUserEmailException e) {
result = new ModelAndView("forgotPasswordError");
}
catch (InvalidAuthSchemaException e) {
} catch (InvalidUserEmailException | InvalidAuthSchemaException e) {
result = new ModelAndView("forgotPasswordError");
}
return result;
@@ -89,10 +87,8 @@ public class UsersController {
// If captcha is enabled, generate it ...
final Properties prop = new Properties();
prop.put("theme", "white");
final String captchaHtml = captchaService.createRecaptchaHtml(null, prop);
request.setAttribute("captchaHtml", captchaHtml);
request.setAttribute("captchaEnabled", true);
request.setAttribute("recaptchaSiteKey", recaptchaSiteKey);
request.setAttribute("recaptchaEnabled", true);
}
return new ModelAndView("userRegistration", "user", new UserBean());
}
@@ -115,7 +111,7 @@ public class UsersController {
boolean confirmRegistrationByEmail = false;
user.setAuthenticationType(AuthenticationType.DATABASE);
userService.createUser(user, confirmRegistrationByEmail,true);
userService.createUser(user, confirmRegistrationByEmail, true);
// Forward to the success view ...
result = new ModelAndView("userRegistrationSuccess");
@@ -130,7 +126,7 @@ public class UsersController {
return "accountSettings";
}
private BindingResult validateRegistrationForm(@NotNull UserBean userBean, @NotNull HttpServletRequest request, @NotNull BindingResult bindingResult) {
private void validateRegistrationForm(@NotNull UserBean userBean, @NotNull HttpServletRequest request, @NotNull BindingResult bindingResult) {
final UserValidator userValidator = new UserValidator();
userValidator.setUserService(userService);
userValidator.setCaptchaService(captchaService);
@@ -138,21 +134,18 @@ public class UsersController {
// If captcha is enabled, generate it ...
if (captchaEnabled) {
final String challenge = request.getParameter("recaptcha_challenge_field");
final String uresponse = request.getParameter("recaptcha_response_field");
final String gReponse = request.getParameter("g-recaptcha-response");
if (challenge != null && uresponse != null) {
if (gReponse != null) {
final String remoteAddr = request.getRemoteAddr();
final ReCaptchaResponse reCaptchaResponse = captchaService.checkAnswer(remoteAddr, challenge, uresponse);
if (!reCaptchaResponse.isValid()) {
bindingResult.rejectValue("captcha", Messages.CAPTCHA_ERROR);
final String reCaptchaResponse = captchaService.verifyRecaptcha(remoteAddr, gReponse);
if (!reCaptchaResponse.isEmpty()) {
bindingResult.rejectValue("captcha", reCaptchaResponse);
}
} else {
bindingResult.rejectValue("captcha", Messages.CAPTCHA_LOADING_ERROR);
}
}
return bindingResult;
}
}