|
@@ -2,10 +2,16 @@ package com.dayou.controller;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.dayou.bo.LoginCacheUserBO;
|
|
import com.dayou.bo.LoginCacheUserBO;
|
|
|
|
+import com.dayou.bo.SimpleParentModel;
|
|
import com.dayou.constants.JwtConstants;
|
|
import com.dayou.constants.JwtConstants;
|
|
|
|
+import com.dayou.dto.OALoginDTO;
|
|
|
|
+import com.dayou.dto.SimplePostModel;
|
|
|
|
+import com.dayou.entity.User;
|
|
|
|
+import com.dayou.service.IUserService;
|
|
import com.dayou.utils.JwtTokenUtil;
|
|
import com.dayou.utils.JwtTokenUtil;
|
|
import com.google.common.cache.Cache;
|
|
import com.google.common.cache.Cache;
|
|
import io.jsonwebtoken.Claims;
|
|
import io.jsonwebtoken.Claims;
|
|
|
|
+import io.jsonwebtoken.ExpiredJwtException;
|
|
import io.jsonwebtoken.MalformedJwtException;
|
|
import io.jsonwebtoken.MalformedJwtException;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -15,34 +21,56 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/auth")
|
|
@RequestMapping("/auth")
|
|
@Slf4j
|
|
@Slf4j
|
|
-public class AuthController extends BaseController{
|
|
|
|
|
|
+public class AuthController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@Qualifier("loginCache")
|
|
@Qualifier("loginCache")
|
|
private Cache<Long, LoginCacheUserBO> loginCache;
|
|
private Cache<Long, LoginCacheUserBO> loginCache;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserService userService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 判断token是否有效
|
|
|
|
|
|
+ * 根据token返回用户信息
|
|
|
|
+ *
|
|
* @param token token
|
|
* @param token token
|
|
* @return Boolean
|
|
* @return Boolean
|
|
*/
|
|
*/
|
|
@PostMapping("/checkOaToken")
|
|
@PostMapping("/checkOaToken")
|
|
- public Boolean checkOaToken(String token) {
|
|
|
|
- // 判断token是否过期(true:有效,false:无效)
|
|
|
|
|
|
+ public OALoginDTO checkOaToken(String token) {
|
|
|
|
+ // 根据token返回用户信息
|
|
if (StringUtils.isNotBlank(token)) {
|
|
if (StringUtils.isNotBlank(token)) {
|
|
try {
|
|
try {
|
|
Claims claims = JwtTokenUtil.getClaimFromToken(token, JwtConstants.SECRET);
|
|
Claims claims = JwtTokenUtil.getClaimFromToken(token, JwtConstants.SECRET);
|
|
String subject = claims.getSubject();
|
|
String subject = claims.getSubject();
|
|
Long userId = Long.valueOf(subject);
|
|
Long userId = Long.valueOf(subject);
|
|
- return ObjectUtil.isNotNull(loginCache.getIfPresent(userId));
|
|
|
|
- }catch (MalformedJwtException exception){
|
|
|
|
- return false;
|
|
|
|
|
|
+ LoginCacheUserBO loginCacheUserBO = loginCache.getIfPresent(userId);
|
|
|
|
+ if (ObjectUtil.isNotNull(loginCacheUserBO)){
|
|
|
|
+ // 返回用户信息
|
|
|
|
+ User user = userService.getById(userId);
|
|
|
|
+ return new OALoginDTO()
|
|
|
|
+ .setUserOaId(loginCacheUserBO.getId())
|
|
|
|
+ .setName(loginCacheUserBO.getName())
|
|
|
|
+ .setDepartmentNameList(loginCacheUserBO.getDepartmentList().stream()
|
|
|
|
+ .map(SimpleParentModel::getName)
|
|
|
|
+ .collect(Collectors.toList()))
|
|
|
|
+ .setPostNameList(loginCacheUserBO.getPostList().stream()
|
|
|
|
+ .map(SimplePostModel::getName)
|
|
|
|
+ .collect(Collectors.toList()))
|
|
|
|
+ .setLastUpdateTime(user.getModified())
|
|
|
|
+ .setStaffNo(user.getStaffNo());
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ } catch (MalformedJwtException | ExpiredJwtException exception) {
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- return false;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|