|
@ -17,9 +17,6 @@ package org.nl.modules.security.rest; |
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
import cn.hutool.core.util.IdUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import com.alicp.jetcache.Cache; |
|
|
|
|
|
import com.alicp.jetcache.anno.CacheType; |
|
|
|
|
|
import com.alicp.jetcache.anno.CreateCache; |
|
|
|
|
|
import com.wf.captcha.base.Captcha; |
|
|
import com.wf.captcha.base.Captcha; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
@ -77,21 +74,15 @@ public class AuthorizationController { |
|
|
@Resource |
|
|
@Resource |
|
|
private LoginProperties loginProperties; |
|
|
private LoginProperties loginProperties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@CreateCache(cacheType = CacheType.LOCAL) |
|
|
|
|
|
private Cache<String, Object> authCache; |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("登录授权") |
|
|
@ApiOperation("登录授权") |
|
|
@AnonymousPostMapping(value = "/login") |
|
|
@AnonymousPostMapping(value = "/login") |
|
|
public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception { |
|
|
public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception { |
|
|
// 密码解密
|
|
|
// 密码解密
|
|
|
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); |
|
|
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); |
|
|
// 查询验证码
|
|
|
// 查询验证码
|
|
|
// String code = (String) redisUtils.get(authUser.getUuid());
|
|
|
String code = (String) redisUtils.get(authUser.getUuid()); |
|
|
String code = (String) authCache.get(authUser.getUuid()); |
|
|
|
|
|
// 清除验证码
|
|
|
// 清除验证码
|
|
|
// redisUtils.del(authUser.getUuid());
|
|
|
redisUtils.del(authUser.getUuid()); |
|
|
authCache.remove(authUser.getUuid()); |
|
|
|
|
|
if (StrUtil.isEmpty(code)) { |
|
|
if (StrUtil.isEmpty(code)) { |
|
|
throw new BadRequestException("验证码不存在或已过期"); |
|
|
throw new BadRequestException("验证码不存在或已过期"); |
|
|
} |
|
|
} |
|
@ -137,8 +128,7 @@ public class AuthorizationController { |
|
|
captchaValue = captchaValue.split("\\.")[0]; |
|
|
captchaValue = captchaValue.split("\\.")[0]; |
|
|
} |
|
|
} |
|
|
// 保存
|
|
|
// 保存
|
|
|
// redisUtils.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES);
|
|
|
redisUtils.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES); |
|
|
authCache.put(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES); |
|
|
|
|
|
// 验证码信息
|
|
|
// 验证码信息
|
|
|
Map<String, Object> imgResult = new HashMap<String, Object>(2) {{ |
|
|
Map<String, Object> imgResult = new HashMap<String, Object>(2) {{ |
|
|
put("img", captcha.toBase64()); |
|
|
put("img", captcha.toBase64()); |
|
|