redis调整
This commit is contained in:
@@ -18,6 +18,12 @@
|
|||||||
<version>0.0.1</version>
|
<version>0.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.njcn</groupId>
|
||||||
|
<artifactId>common-redis</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- <dependency>
|
<!-- <dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package com.njcn.gather.event.transientes.security;
|
package com.njcn.gather.event.transientes.security;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.PubUtils;
|
import com.njcn.common.utils.PubUtils;
|
||||||
import com.njcn.gather.event.transientes.utils.JwtUtil;
|
import com.njcn.gather.event.transientes.utils.JwtUtil;
|
||||||
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
import com.njcn.web.utils.HttpResultUtil;
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
@@ -23,13 +27,22 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class AuthController extends BaseController {
|
public class AuthController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
private final String eventRedisKey = "event_smart_";
|
||||||
private AuthenticationManager authenticationManager;
|
|
||||||
|
|
||||||
|
private final AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
|
|
||||||
|
private final JwtUtil jwtUtil;
|
||||||
|
|
||||||
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JwtUtil jwtUtil;
|
|
||||||
|
|
||||||
@PostMapping("/cn_authenticate")
|
@PostMapping("/cn_authenticate")
|
||||||
@ApiOperation("登录认证")
|
@ApiOperation("登录认证")
|
||||||
@@ -37,10 +50,12 @@ public class AuthController extends BaseController {
|
|||||||
String methodDescribe = getMethodDescribe("createAuthenticationToken");
|
String methodDescribe = getMethodDescribe("createAuthenticationToken");
|
||||||
//log.info("Authentication request - username: {}, password: {}",authRequest.getUsername(),authRequest.getPassword());
|
//log.info("Authentication request - username: {}, password: {}",authRequest.getUsername(),authRequest.getPassword());
|
||||||
try {
|
try {
|
||||||
|
boolean hasFlag = redisUtil.hasKey(eventRedisKey+authRequest.getUsername());
|
||||||
|
if(hasFlag){
|
||||||
|
String pass = redisUtil.getRawValue(eventRedisKey+authRequest.getUsername());
|
||||||
|
|
||||||
// 执行认证,内部会调用 UserDetailsService 加载用户信息
|
// 执行认证,内部会调用 UserDetailsService 加载用户信息
|
||||||
Authentication authentication = authenticationManager.authenticate(
|
Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(authRequest.getUsername(),pass));
|
||||||
new UsernamePasswordAuthenticationToken(authRequest.getUsername(), authRequest.getPassword())
|
|
||||||
);
|
|
||||||
|
|
||||||
// 将认证信息存入 SecurityContext
|
// 将认证信息存入 SecurityContext
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
@@ -57,6 +72,9 @@ public class AuthController extends BaseController {
|
|||||||
authResponse.setToken(jwt);
|
authResponse.setToken(jwt);
|
||||||
authResponse.setDeptId(department);
|
authResponse.setDeptId(department);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, authResponse, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, authResponse, methodDescribe);
|
||||||
|
}else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package com.njcn.gather.event.transientes.security;
|
package com.njcn.gather.event.transientes.security;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
import com.njcn.gather.event.transientes.mapper.PqsUserMapper;
|
import com.njcn.gather.event.transientes.mapper.PqsUserMapper;
|
||||||
import com.njcn.gather.event.transientes.mapper.PqsUserSetMapper;
|
import com.njcn.gather.event.transientes.mapper.PqsUserSetMapper;
|
||||||
import com.njcn.gather.event.transientes.pojo.po.PqsUser;
|
import com.njcn.gather.event.transientes.pojo.po.PqsUser;
|
||||||
import com.njcn.gather.event.transientes.pojo.po.PqsUserSet;
|
import com.njcn.gather.event.transientes.pojo.po.PqsUserSet;
|
||||||
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import netscape.javascript.JSObject;
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
@@ -26,40 +29,36 @@ public class MyUserDetailsService implements UserDetailsService {
|
|||||||
|
|
||||||
private final PqsUserSetMapper pqsUserSetMapper;
|
private final PqsUserSetMapper pqsUserSetMapper;
|
||||||
|
|
||||||
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MyUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public MyUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
|
||||||
|
|
||||||
/* LambdaQueryWrapper<PqsUser> userWrapper = new LambdaQueryWrapper<>();
|
|
||||||
userWrapper.eq(PqsUser::getLoginname,username);
|
|
||||||
PqsUser pqsUser = pqsUserMapper.selectOne(userWrapper);
|
|
||||||
if(Objects.isNull(pqsUser)){
|
|
||||||
throw new UsernameNotFoundException("User not found with username: " + username);
|
|
||||||
}
|
|
||||||
|
|
||||||
LambdaQueryWrapper<PqsUserSet> userSetWrapper = new LambdaQueryWrapper<>();
|
|
||||||
userSetWrapper.eq(PqsUserSet::getUserIndex,pqsUser.getUserIndex());
|
|
||||||
PqsUserSet pqsUserSet = pqsUserSetMapper.selectOne(userSetWrapper);
|
|
||||||
String deptId = pqsUserSet.getDeptsIndex();*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(redisUtil.hasKey("event_smart_"+username)){
|
||||||
|
String password = redisUtil.getRawValue("event_smart_"+username);
|
||||||
// 这里应该从数据库中获取用户信息,本示例使用硬编码用户
|
// 这里应该从数据库中获取用户信息,本示例使用硬编码用户
|
||||||
if ("cdf".equals(username)) {
|
|
||||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
String encodedPassword = passwordEncoder.encode("@#001njcnpqs");
|
String encodedPassword = passwordEncoder.encode(password);
|
||||||
return new MyUserDetails("1","cdf", encodedPassword,"10001",
|
|
||||||
new ArrayList<>());
|
LambdaQueryWrapper<PqsUser> userWrapper = new LambdaQueryWrapper<>();
|
||||||
}else if("screen".equals(username)){
|
userWrapper.eq(PqsUser::getLoginname,username);
|
||||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
PqsUser pqsUser = pqsUserMapper.selectOne(userWrapper);
|
||||||
String encodedPassword = passwordEncoder.encode("@#001njcnpqs");
|
if(Objects.isNull(pqsUser)){
|
||||||
return new MyUserDetails("2","screen", encodedPassword,"10001",
|
throw new UsernameNotFoundException("User not found with username: " + username);
|
||||||
new ArrayList<>());
|
}
|
||||||
} else if("test".equals(username)){
|
|
||||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
LambdaQueryWrapper<PqsUserSet> userSetWrapper = new LambdaQueryWrapper<>();
|
||||||
String encodedPassword = passwordEncoder.encode("@#001njcnpqs");
|
userSetWrapper.eq(PqsUserSet::getUserIndex,pqsUser.getUserIndex());
|
||||||
return new MyUserDetails("3","test", encodedPassword,"10001",
|
PqsUserSet pqsUserSet = pqsUserSetMapper.selectOne(userSetWrapper);
|
||||||
|
String deptId = pqsUserSet.getDeptsIndex();
|
||||||
|
|
||||||
|
|
||||||
|
return new MyUserDetails(pqsUser.getUserIndex(),pqsUser.getLoginname(), encodedPassword,deptId,
|
||||||
new ArrayList<>());
|
new ArrayList<>());
|
||||||
}else {
|
}else {
|
||||||
throw new UsernameNotFoundException("User not found with username: " + username);
|
throw new UsernameNotFoundException("User not found with username: " + username);
|
||||||
|
|||||||
@@ -593,11 +593,11 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService {
|
|||||||
if(!CollectionUtils.isEmpty(eveIdndex)){
|
if(!CollectionUtils.isEmpty(eveIdndex)){
|
||||||
temp =msgEventInfoService.getMsgByIds(eveIdndex);
|
temp =msgEventInfoService.getMsgByIds(eveIdndex);
|
||||||
}
|
}
|
||||||
// List<EventDetailVO> change = change(eventdetails,temp);
|
List<EventDetailVO> change = change(eventdetails,temp);
|
||||||
|
|
||||||
// mapCountVO.setEventList(change);
|
mapCountVO.setEventList(change);
|
||||||
mapCountVO.setNoticeCount(temp.size());
|
mapCountVO.setNoticeCount(temp.size());
|
||||||
// mapCountVO.setNoticeList(temp);
|
mapCountVO.setNoticeList(temp);
|
||||||
result.add(mapCountVO);
|
result.add(mapCountVO);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -37,13 +37,28 @@ spring:
|
|||||||
#url: jdbc:oracle:thin:@192.168.10.34:11521:pqsbase
|
#url: jdbc:oracle:thin:@192.168.10.34:11521:pqsbase
|
||||||
#username: pqsadmin
|
#username: pqsadmin
|
||||||
#password: Pqsadmin_123
|
#password: Pqsadmin_123
|
||||||
driver-class-name: oracle.jdbc.driver.OracleDriver
|
driver-class-name: oracle.jdbc.OracleDriver
|
||||||
# salve:
|
# salve:
|
||||||
# driver-class-name: dm.jdbc.driver.DmDriver
|
# driver-class-name: dm.jdbc.driver.DmDriver
|
||||||
# url: jdbc:dm://192.168.1.21:5236/PQSADMIN?useUnicode=true&characterEncoding=utf-8
|
# url: jdbc:dm://192.168.1.21:5236/PQSADMIN?useUnicode=true&characterEncoding=utf-8
|
||||||
# username: PQSADMINLN
|
# username: PQSADMINLN
|
||||||
# password: Pqsadmin123
|
# password: Pqsadmin123
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
redis:
|
||||||
|
database: 10
|
||||||
|
host: localhost
|
||||||
|
port: 6379
|
||||||
|
timeout: 5000
|
||||||
|
lettuce:
|
||||||
|
pool:
|
||||||
|
max-active: 8
|
||||||
|
max-wait: -1
|
||||||
|
max-idle: 8
|
||||||
|
min-idle: 0
|
||||||
|
|
||||||
|
|
||||||
#mybatis配置信息
|
#mybatis配置信息
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
mapper-locations: classpath*:com/njcn/**/mapping/*.xml
|
mapper-locations: classpath*:com/njcn/**/mapping/*.xml
|
||||||
|
|||||||
Reference in New Issue
Block a user