更新
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package org.nl;
|
package org.nl;
|
||||||
|
|
||||||
import com.alicp.jetcache.Cache;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.nl.annotation.rest.AnonymousGetMapping;
|
import org.nl.annotation.rest.AnonymousGetMapping;
|
||||||
import org.nl.utils.SpringContextHolder;
|
import org.nl.utils.SpringContextHolder;
|
||||||
@@ -32,11 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@ServletComponentScan
|
@ServletComponentScan
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
|
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
|
||||||
|
|
||||||
public class AppRun implements CommandLineRunner {
|
public class AppRun implements CommandLineRunner {
|
||||||
|
|
||||||
private Cache<String, Object> userCache;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SpringApplication.run(AppRun.class, args);
|
SpringApplication.run(AppRun.class, args);
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
package org.nl.modules.cache;
|
|
||||||
|
|
||||||
import com.alicp.jetcache.Cache;
|
|
||||||
import com.alicp.jetcache.anno.CacheType;
|
|
||||||
import com.alicp.jetcache.anno.CreateCache;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class BothCacheManager extends NlCacheManager {
|
|
||||||
/**
|
|
||||||
* 使用 @CreateCache 注解创建Cache实例;
|
|
||||||
* 未定义默认值的参数,将使用yml中指定的全局配置;
|
|
||||||
* 缓存在 Local,也可以配置成 both 开启两级缓存
|
|
||||||
*/
|
|
||||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.BOTH, localLimit = 10)
|
|
||||||
private Cache<Object, Object> defaultCache;
|
|
||||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.BOTH, localLimit = 10)
|
|
||||||
private Cache<Object, Object> systemCache;
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package org.nl.modules.cache;
|
|
||||||
|
|
||||||
import com.alicp.jetcache.anno.CacheConsts;
|
|
||||||
import com.alicp.jetcache.anno.CacheType;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class CacheConfig {
|
|
||||||
@Value("${jetcache.defaultCacheType}")
|
|
||||||
private String cacheType;
|
|
||||||
|
|
||||||
@Bean(name = "sysCacheManager")
|
|
||||||
public NlCacheManager sysCacheManager() {
|
|
||||||
CacheConsts.isUndefined(2);
|
|
||||||
if (CacheType.BOTH.name().equals(cacheType)) return new BothCacheManager();
|
|
||||||
if (CacheType.LOCAL.name().equals(cacheType)) return new LocalCacheManager();
|
|
||||||
if (CacheType.REMOTE.name().equals(cacheType)) return new RemoteCacheManager();
|
|
||||||
return new LocalCacheManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package org.nl.modules.cache;
|
|
||||||
|
|
||||||
import com.alicp.jetcache.Cache;
|
|
||||||
import com.alicp.jetcache.anno.CacheType;
|
|
||||||
import com.alicp.jetcache.anno.CreateCache;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class LocalCacheManager extends NlCacheManager {
|
|
||||||
/**
|
|
||||||
* 使用 @CreateCache 注解创建Cache实例;
|
|
||||||
* 未定义默认值的参数,将使用yml中指定的全局配置;
|
|
||||||
* 缓存在 Local,也可以配置成 both 开启两级缓存
|
|
||||||
*/
|
|
||||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.LOCAL, localLimit = 10)
|
|
||||||
private Cache<Object, Object> defaultCache;
|
|
||||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.LOCAL, localLimit = 10)
|
|
||||||
private Cache<Object, Object> systemCache;
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package org.nl.modules.cache;
|
|
||||||
|
|
||||||
import com.alicp.jetcache.Cache;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public abstract class NlCacheManager {
|
|
||||||
private Cache<Object, Object> defaultCache;
|
|
||||||
private Cache<Object, Object> systemCache;
|
|
||||||
public void test(){
|
|
||||||
System.out.println(this.getClass().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package org.nl.modules.cache;
|
|
||||||
|
|
||||||
import com.alicp.jetcache.Cache;
|
|
||||||
import com.alicp.jetcache.anno.CacheType;
|
|
||||||
import com.alicp.jetcache.anno.CreateCache;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class RemoteCacheManager extends NlCacheManager {
|
|
||||||
/**
|
|
||||||
* 使用 @CreateCache 注解创建Cache实例;
|
|
||||||
* 未定义默认值的参数,将使用yml中指定的全局配置;
|
|
||||||
* 缓存在 Local,也可以配置成 both 开启两级缓存
|
|
||||||
*/
|
|
||||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.REMOTE, localLimit = 10)
|
|
||||||
private Cache<Object, Object> defaultCache;
|
|
||||||
@CreateCache(expire = 5 * 60, cacheType = CacheType.REMOTE, localLimit = 10)
|
|
||||||
private Cache<Object, Object> systemCache;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void test() {
|
|
||||||
System.out.println(this.getClass().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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());
|
||||||
|
|||||||
Reference in New Issue
Block a user