Improve code.
parent
ede2fb7622
commit
1e548136ff
|
@ -56,7 +56,7 @@ public class OAuth2Controller extends BaseController {
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "googlecallback", produces = {"application/json"})
|
@RequestMapping(method = RequestMethod.POST, value = "googlecallback", produces = {"application/json"})
|
||||||
@ResponseStatus(value = HttpStatus.OK)
|
@ResponseStatus(value = HttpStatus.OK)
|
||||||
public RestOath2CallbackResponse processGoogleCallback(@NotNull @RequestParam String code, @NotNull HttpServletResponse response, @NotNull HttpServletRequest request) throws WiseMappingException {
|
public RestOath2CallbackResponse processGoogleCallback(@NotNull @RequestParam String code, @NotNull HttpServletResponse response, @NotNull HttpServletRequest request) throws WiseMappingException {
|
||||||
logger.debug("processGoogleCallback:" + code);
|
logger.debug("ProcessGoogleCallback:" + code);
|
||||||
if (code == null) {
|
if (code == null) {
|
||||||
throw new WiseMappingException("Illegal argument exception: " + code);
|
throw new WiseMappingException("Illegal argument exception: " + code);
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,7 @@ public class OAuth2Controller extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response ...
|
// Response ...
|
||||||
final RestOath2CallbackResponse result = new RestOath2CallbackResponse();
|
return new RestOath2CallbackResponse(user, jwtToken);
|
||||||
result.setEmail(user.getEmail());
|
|
||||||
result.setGoogleSync(user.getGoogleSync());
|
|
||||||
result.setSyncCode(code);
|
|
||||||
result.setJwtToken(jwtToken);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.PUT, value = "confirmaccountsync", produces = {"application/json"})
|
@RequestMapping(method = RequestMethod.PUT, value = "confirmaccountsync", produces = {"application/json"})
|
||||||
|
@ -84,21 +79,13 @@ public class OAuth2Controller extends BaseController {
|
||||||
throw new WiseMappingException("Illegal argument exception: " + email + " - " + code);
|
throw new WiseMappingException("Illegal argument exception: " + email + " - " + code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authenticate ...
|
|
||||||
final Account user = userService.createAndAuthUserFromGoogle(code);
|
|
||||||
|
|
||||||
// Update login
|
// Update login
|
||||||
userService.confirmAccountSync(user.getEmail(), code);
|
final Account user = userService.confirmGoogleAccountSync(email, code);
|
||||||
|
|
||||||
// Add header ...
|
// Add header ...
|
||||||
final String jwtToken = jwtTokenUtil.doLogin(response, email);
|
final String jwtToken = jwtTokenUtil.doLogin(response, email);
|
||||||
|
|
||||||
// Response ...
|
// Response ...
|
||||||
final RestOath2CallbackResponse result = new RestOath2CallbackResponse();
|
return new RestOath2CallbackResponse(user, jwtToken);
|
||||||
result.setEmail(user.getEmail());
|
|
||||||
result.setGoogleSync(user.getGoogleSync());
|
|
||||||
result.setSyncCode(user.getSyncCode());
|
|
||||||
result.setJwtToken(jwtToken);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ package com.wisemapping.rest.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.wisemapping.model.Account;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@JsonAutoDetect(
|
@JsonAutoDetect(
|
||||||
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
@ -17,6 +20,13 @@ public class RestOath2CallbackResponse {
|
||||||
private String syncCode;
|
private String syncCode;
|
||||||
private String jwtToken;
|
private String jwtToken;
|
||||||
|
|
||||||
|
public RestOath2CallbackResponse(@NotNull Account user, @Nullable String jwtToken) {
|
||||||
|
this.setEmail(user.getEmail());
|
||||||
|
this.setGoogleSync(user.getGoogleSync());
|
||||||
|
this.setSyncCode(user.getSyncCode());
|
||||||
|
this.setJwtToken(jwtToken);
|
||||||
|
}
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public interface UserService {
|
||||||
|
|
||||||
Account createAndAuthUserFromGoogle(@NotNull String callbackCode) throws WiseMappingException;
|
Account createAndAuthUserFromGoogle(@NotNull String callbackCode) throws WiseMappingException;
|
||||||
|
|
||||||
Account confirmAccountSync(@NotNull String email, @NotNull String code) throws WiseMappingException;
|
Account confirmGoogleAccountSync(@NotNull String email, @NotNull String code) throws WiseMappingException;
|
||||||
|
|
||||||
void changePassword(@NotNull Account user);
|
void changePassword(@NotNull Account user);
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ public class UserServiceImpl
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Account confirmAccountSync(@NotNull String email, @NotNull String code) throws WiseMappingException {
|
public Account confirmGoogleAccountSync(@NotNull String email, @NotNull String code) throws WiseMappingException {
|
||||||
final Account existingUser = userManager.getUserBy(email);
|
final Account existingUser = userManager.getUserBy(email);
|
||||||
// additional security check
|
// additional security check
|
||||||
if (existingUser == null || !existingUser.getSyncCode().equals(code)) {
|
if (existingUser == null || !existingUser.getSyncCode().equals(code)) {
|
||||||
|
|
Loading…
Reference in New Issue