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