Fix major update integrating with external wisemapping frond end

This commit is contained in:
Paulo Gustavo Veiga
2021-12-24 18:03:23 -08:00
parent 76ff1cc83d
commit b3e26caee4
1042 changed files with 1160 additions and 73432 deletions

View File

@@ -18,8 +18,8 @@
package com.wisemapping.service;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class HibernateAppListener implements ServletContextListener {

View File

@@ -17,7 +17,7 @@ public interface LabelService {
@Nullable
Label getLabelById(int id, @NotNull final User user);
public Label getLabelByTitle(@NotNull String title, @NotNull final User user);
Label getLabelByTitle(@NotNull String title, @NotNull final User user);
void removeLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException;
}

View File

@@ -28,7 +28,7 @@ public class LockInfo {
final private User user;
private Calendar timeout;
private long session;
private static int EXPIRATION_MIN = 30;
private static final int EXPIRATION_MIN = 30;
private long timestamp = -1;
private long previousTimestamp;

View File

@@ -50,7 +50,7 @@ class LockManagerImpl implements LockManager {
public static final int ONE_MINUTE_MILLISECONDS = 1000 * 60;
final Map<Integer, LockInfo> lockInfoByMapId;
final static Timer expirationTimer = new Timer();
final private static Logger logger = Logger.getLogger("com.wisemapping.service.LockManager");
final private static Logger logger = Logger.getLogger(LockManagerImpl.class);
@Override
public boolean isLocked(@NotNull Mindmap mindmap) {

View File

@@ -18,8 +18,8 @@
package com.wisemapping.service;
import com.wisemapping.model.*;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -28,7 +28,7 @@ import java.util.List;
public interface MindmapService {
static final String TAG_SEPARATOR = " ";
String TAG_SEPARATOR = " ";
@Nullable
Mindmap findMindmapById(int id);

View File

@@ -7,6 +7,7 @@ import org.apache.http.client.fluent.Form;
import org.apache.http.client.fluent.Request;
import org.apache.log4j.Logger;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
@@ -22,21 +23,20 @@ public class RecaptchaService {
private final static ObjectMapper objectMapper = new ObjectMapper();
private String recaptchaSecret;
public String verifyRecaptcha(String ip, String recaptchaResponse) {
public String verifyRecaptcha(@NotNull String ip, @NotNull String recaptcha) {
final List<NameValuePair> build = Form.form()
.add("secret", recaptchaSecret)
.add("response", recaptchaResponse)
.add("response", recaptcha)
.add("remoteip", ip)
.build();
// Add logs ...
logger.debug("Response from remoteip: " + ip);
logger.debug("Response from recaptchaSecret: " + recaptchaSecret);
logger.debug("Response from recaptchaResponse: " + recaptchaResponse);
logger.debug("Response from recaptcha: " + recaptcha);
String result = StringUtils.EMPTY;
HashMap bodyJson;
try {
final byte[] body = Request
.Post(GOOGLE_RECAPTCHA_VERIFY_URL)
@@ -45,16 +45,13 @@ public class RecaptchaService {
.returnContent()
.asBytes();
bodyJson = objectMapper
.readValue(body, HashMap.class);
final Map responseBody = objectMapper.readValue(body, HashMap.class);
logger.warn("Response from recaptcha after parse: " + responseBody);
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));
final Boolean success = (Boolean) responseBody.get("success");
if (success!=null && !success) {
final List<String> errorCodes = (List<String>) responseBody.get("error-codes");
result = RecaptchaUtil.codeToDescription(errorCodes.get(0));
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
@@ -73,9 +70,14 @@ public class RecaptchaService {
class RecaptchaUtil {
static final Map<String, String>
private static final Map<String, String>
RECAPTCHA_ERROR_CODE = new HashMap<>();
static String codeToDescription(final String code)
{
return RECAPTCHA_ERROR_CODE.getOrDefault(code,"Unexpected error validating code. Please, refresh the page and try again.");
}
static {
RECAPTCHA_ERROR_CODE.put("missing-input-secret",
"The secret parameter is missing");
@@ -87,5 +89,7 @@ class RecaptchaUtil {
"The response parameter is invalid or malformed");
RECAPTCHA_ERROR_CODE.put("bad-request",
"The request is invalid or malformed");
RECAPTCHA_ERROR_CODE.put("timeout-or-duplicate",
"Please, refresh the page and try again.");
}
}

View File

@@ -0,0 +1,9 @@
package com.wisemapping.service;
import org.springframework.validation.BindException;
public class RegistrationException extends BindException {
public RegistrationException(Object target, String objectName) {
super(target, objectName);
}
}

View File

@@ -18,29 +18,29 @@
package com.wisemapping.service;
import com.wisemapping.model.User;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull;
public interface UserService {
public void activateAccount(long code) throws InvalidActivationCodeException;
void activateAccount(long code) throws InvalidActivationCodeException;
public User createUser(@NotNull User user, boolean emailConfirmEnabled,boolean welcomeEmail) throws WiseMappingException;
User createUser(@NotNull User user, boolean emailConfirmEnabled, boolean welcomeEmail) throws WiseMappingException;
public void changePassword(@NotNull User user);
void changePassword(@NotNull User user);
public User getUserBy(String email);
User getUserBy(String email);
public User getUserBy(long id);
User getUserBy(long id);
public void updateUser(User user);
void updateUser(User user);
public void resetPassword(@NotNull String email) throws InvalidUserEmailException, InvalidAuthSchemaException;
void resetPassword(@NotNull String email) throws InvalidUserEmailException, InvalidAuthSchemaException;
public void removeUser(@NotNull User user);
void removeUser(@NotNull User user);
public void auditLogin(@NotNull User user);
void auditLogin(@NotNull User user);
public User getCasUserBy(String uid);
User getCasUserBy(String uid);
}

View File

@@ -78,7 +78,7 @@ public class UserServiceImpl
private String randomstring(int lo, int hi) {
int n = rand(lo, hi);
byte b[] = new byte[n];
byte[] b = new byte[n];
for (int i = 0; i < n; i++)
b[i] = (byte) rand('@', 'Z');
return new String(b);