diff --git a/wise-api/src/main/java/com/wisemapping/rest/OAuth2Controller.java b/wise-api/src/main/java/com/wisemapping/rest/OAuth2Controller.java index c725cb6a..dbcc4489 100644 --- a/wise-api/src/main/java/com/wisemapping/rest/OAuth2Controller.java +++ b/wise-api/src/main/java/com/wisemapping/rest/OAuth2Controller.java @@ -25,6 +25,8 @@ import com.wisemapping.security.JwtTokenUtil; import com.wisemapping.service.UserService; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -37,6 +39,8 @@ import org.springframework.web.bind.annotation.*; @RequestMapping("/api/restful/oauth2/") @CrossOrigin public class OAuth2Controller extends BaseController { + final private static Logger logger = LogManager.getLogger(); + @Qualifier("userService") @Autowired private UserService userService; @@ -68,6 +72,8 @@ public class OAuth2Controller extends BaseController { @RequestMapping(method = RequestMethod.PUT, value = "confirmaccountsync", produces = {"application/json"}) @ResponseStatus(value = HttpStatus.OK) public void confirmAccountSync(@NotNull @RequestParam String email, @NotNull @RequestParam String code, @NotNull HttpServletResponse response) throws WiseMappingException { + logger.debug("confirmAccountSync:" + email + "-" + code); + // Authenticate ... userService.createAndAuthUserFromGoogle(code); diff --git a/wise-api/src/main/java/com/wisemapping/service/UserServiceImpl.java b/wise-api/src/main/java/com/wisemapping/service/UserServiceImpl.java index c3f3ff50..e0768353 100755 --- a/wise-api/src/main/java/com/wisemapping/service/UserServiceImpl.java +++ b/wise-api/src/main/java/com/wisemapping/service/UserServiceImpl.java @@ -30,6 +30,8 @@ import com.wisemapping.service.google.GoogleService; import com.wisemapping.service.google.http.HttpInvokerException; import com.wisemapping.util.VelocityEngineUtils; import com.wisemapping.util.VelocityEngineWrapper; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; @@ -46,6 +48,7 @@ import java.util.*; public class UserServiceImpl implements UserService { + @Autowired private UserManager userManager; @Autowired @@ -59,6 +62,8 @@ public class UserServiceImpl @Autowired private GoogleService googleService; + final private static Logger logger = LogManager.getLogger(); + @Override public void activateAccount(long code) throws InvalidActivationCodeException { @@ -178,11 +183,12 @@ public class UserServiceImpl try { data = googleService.processCallback(callbackCode); } catch (HttpInvokerException e) { + logger.debug(e.getMessage(), e); throw new OAuthAuthenticationException(e); } - Account existingUser = userManager.getUserBy(data.getEmail()); - if (existingUser == null) { + Account result = userManager.getUserBy(data.getEmail()); + if (result == null) { Account newUser = new Account(); // new registrations from google starts sync newUser.setGoogleSync(true); @@ -191,18 +197,18 @@ public class UserServiceImpl newUser.setLastname(data.getLastName()); newUser.setAuthenticationType(AuthenticationType.GOOGLE_OAUTH2); newUser.setGoogleToken(data.getAccessToken()); - existingUser = this.createUser(newUser, false, true); + result = this.createUser(newUser, false, true); } else { // user exists and doesn't have confirmed account linking, I must wait for confirmation - if (existingUser.getGoogleSync() == null) { - existingUser.setGoogleSync(false); - existingUser.setSyncCode(callbackCode); - existingUser.setGoogleToken(data.getAccessToken()); - userManager.updateUser(existingUser); + if (result.getGoogleSync() == null) { + result.setGoogleSync(false); + result.setSyncCode(callbackCode); + result.setGoogleToken(data.getAccessToken()); + userManager.updateUser(result); } } - return existingUser; + return result; } diff --git a/wise-api/src/main/java/com/wisemapping/util/VelocityEngineUtils.java b/wise-api/src/main/java/com/wisemapping/util/VelocityEngineUtils.java index acded03b..37d67166 100644 --- a/wise-api/src/main/java/com/wisemapping/util/VelocityEngineUtils.java +++ b/wise-api/src/main/java/com/wisemapping/util/VelocityEngineUtils.java @@ -19,6 +19,8 @@ package com.wisemapping.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.VelocityException; @@ -28,7 +30,7 @@ import java.io.Writer; import java.util.Map; public class VelocityEngineUtils { - private static final Log logger = LogFactory.getLog(VelocityEngineUtils.class); + final private static Logger logger = LogManager.getLogger(); public static void mergeTemplate( VelocityEngine velocityEngine, String templateLocation,