|
|
|
@ -18,16 +18,14 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
|
|
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
@Api(tags = "用户管理模块")
|
|
|
|
|
@RestController
|
|
|
|
@ -35,9 +33,6 @@ import java.util.Collections;
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class UserController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AuthenticationManager authenticationManager;
|
|
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@OperateLog(description = "用户登录")
|
|
|
|
|
@ApiOperation(value = "用户登录", httpMethod = "POST")
|
|
|
|
@ -51,9 +46,8 @@ public class UserController {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new IllegalArgumentException("密码错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String md5Pwd = calculateMD5(password);
|
|
|
|
|
String hashPwd = formatHash(md5Pwd);
|
|
|
|
|
String md5Pwd =RsaUtil.calculateMD5(password);
|
|
|
|
|
String hashPwd = RsaUtil.formatHash(md5Pwd);
|
|
|
|
|
JwtUser jwtUser = TzApi.foreignExchangeTradingLogin(username, hashPwd);
|
|
|
|
|
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
|
@ -61,31 +55,20 @@ public class UserController {
|
|
|
|
|
return new ResultEntity<LoginResult>(LoginResult.create(jwtUser, token));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String calculateMD5(String input) {
|
|
|
|
|
try {
|
|
|
|
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
|
|
byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
for (byte b : hashBytes) {
|
|
|
|
|
sb.append(String.format("%02X", b));
|
|
|
|
|
}
|
|
|
|
|
return sb.toString();
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String formatHash(String hash) {
|
|
|
|
|
StringBuilder formattedHash = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < hash.length(); i += 2) {
|
|
|
|
|
formattedHash.append(hash.substring(i, i + 2));
|
|
|
|
|
if (i < hash.length() - 2) {
|
|
|
|
|
formattedHash.append("-");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return formattedHash.toString();
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@OperateLog(description = "通过智云平台token单点登录")
|
|
|
|
|
@ApiOperation(value = "通过智云平台token单点登录", httpMethod = "POST")
|
|
|
|
|
@PostMapping("loginByZhiYunToken")
|
|
|
|
|
public ResultEntity<LoginResult> loginByZhiYunToken(@ApiParam("智云平台token") @RequestParam String zhiYunToken) {
|
|
|
|
|
Assert.isTrue(StringUtils.hasText(zhiYunToken), "token不能为空");
|
|
|
|
|
JwtUser jwtUser = TokenProvider.getJWTUserByZhiYun(zhiYunToken);
|
|
|
|
|
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
|
|
String token = TokenProvider.createToken(jwtUser);
|
|
|
|
|
return new ResultEntity<LoginResult>(LoginResult.create(jwtUser, token));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|