同步代码
This commit is contained in:
parent
0654ee094a
commit
d1acab14e5
|
@ -2,6 +2,7 @@ package com.chint.application.out;
|
|||
|
||||
|
||||
import com.chint.application.commands.OrderCreateCommand;
|
||||
import com.chint.application.services.login.strategy.PailaLoginStrategy;
|
||||
import com.chint.domain.aggregates.user.User;
|
||||
import com.chint.domain.exceptions.OrderException;
|
||||
import com.chint.domain.service.SystemDomainService;
|
||||
|
@ -16,6 +17,7 @@ import com.chint.infrastructure.util.Digest;
|
|||
import com.chint.infrastructure.util.Result;
|
||||
import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest;
|
||||
import com.chint.interfaces.rest.ly.LYUserRequest;
|
||||
import com.chint.interfaces.rest.ly.dto.login.LoginParam;
|
||||
import com.chint.interfaces.rest.user.UserHttpRequest;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -43,6 +45,9 @@ public class LoginController {
|
|||
@Autowired
|
||||
private SystemDomainService systemDomainService;
|
||||
|
||||
@Autowired
|
||||
private PailaLoginStrategy pailaLoginStrategy;
|
||||
|
||||
@ApiOperation("财务共享登录")
|
||||
@Transactional
|
||||
@GetMapping("/login")
|
||||
|
@ -98,9 +103,11 @@ public class LoginController {
|
|||
@ApiOperation("商旅平台单点")
|
||||
@Transactional
|
||||
@PostMapping("/login/sso")
|
||||
public Result<UserLoginResult> loginSSO(){
|
||||
UserLoginParam userLoginParam = new UserLoginParam();
|
||||
userLoginParam.setSfno("170717012");
|
||||
public Result<UserLoginResult> loginSSO(@RequestBody UserLoginParam userLoginParam){
|
||||
|
||||
String employeeNo = pailaLoginStrategy.login(userLoginParam.getCode());
|
||||
|
||||
userLoginParam.setSfno(employeeNo);
|
||||
UserLoginResult userLoginResult = authenticateService
|
||||
.authenticateEmployeeNo(userLoginParam);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public class LocalLoginStrategy implements LoginStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public User getUserInfo(String accessToken) {
|
||||
public String getUserInfo(String accessToken) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,14 @@ import java.util.regex.Pattern;
|
|||
public interface LoginStrategy {
|
||||
Logger log = LoggerFactory.getLogger("UserService");
|
||||
|
||||
default User login(String code) {
|
||||
default String login(String code) {
|
||||
Optional<String> accessToken = getAccessToken(code);
|
||||
return getUserInfo(accessToken.orElseThrow(()-> new AuthException("Failed to obtain access token")));
|
||||
}
|
||||
|
||||
Optional<String> getAccessToken(String code);
|
||||
|
||||
User getUserInfo(String accessToken);
|
||||
String getUserInfo(String accessToken);
|
||||
|
||||
static Optional<String> getAccessTokenMethod(HttpRequestBase request, String tokenName) {
|
||||
String responseBody = null;
|
||||
|
|
|
@ -3,8 +3,7 @@ package com.chint.application.services.login.strategy;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.chint.application.dtos.UserDTO;
|
||||
import com.chint.application.services.login.LoginStrategy;
|
||||
import com.chint.domain.aggregates.user.User;
|
||||
import com.chint.domain.exceptions.AuthException;
|
||||
import com.chint.domain.exceptions.NotFoundException;
|
||||
import com.chint.domain.factoriy.user.UserFactory;
|
||||
import com.chint.domain.repository.UserRepository;
|
||||
import com.chint.interfaces.rest.user.UserHttpRequest;
|
||||
|
@ -71,7 +70,7 @@ public class PailaLoginStrategy implements LoginStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public User getUserInfo(String accessToken) {
|
||||
public String getUserInfo(String accessToken) {
|
||||
|
||||
|
||||
List<NameValuePair> userInfoParams = Collections.singletonList(
|
||||
|
@ -89,18 +88,10 @@ public class PailaLoginStrategy implements LoginStrategy {
|
|||
log.error(e.getMessage());
|
||||
}
|
||||
UserDTO userDTO = JSON.parseObject(userInfoResBody, UserDTO.class);
|
||||
User user;
|
||||
if (userDTO != null) {
|
||||
user = userRepository.findByUserEmployeeNo(userDTO.getUid());
|
||||
if (user == null) {
|
||||
user = userFactory.create(userDTO.getUid());
|
||||
userHttpRequest.loadUserInfo(user);
|
||||
userRepository.save(user);
|
||||
if (userDTO == null) {
|
||||
throw new NotFoundException(NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
throw new AuthException(NOT_FOUND);
|
||||
}
|
||||
return user;
|
||||
return userDTO.getUid();
|
||||
}
|
||||
|
||||
private HttpGet getRequest(String path, List<NameValuePair> parameters) {
|
||||
|
|
|
@ -121,7 +121,7 @@ class RouteApplicationTests {
|
|||
|
||||
// @Test
|
||||
void ssoLogin(){
|
||||
User login = pailaLoginStrategy.login("OC-5909-zRqrWjZGNThNXJiAV1kA7dPXTojGzVxK3nE");
|
||||
String login = pailaLoginStrategy.login("OC-5909-zRqrWjZGNThNXJiAV1kA7dPXTojGzVxK3nE");
|
||||
System.out.println(login);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue