feat: There is no way the idm and oa
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.adc.da.FeignClient;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: super_liu
|
||||
* @date: 2021年10月11日 13:33
|
||||
*/
|
||||
|
||||
/**
|
||||
* Feign配置
|
||||
* 使用FeignClient进行服务间调用,传递headers信息
|
||||
*/
|
||||
@Configuration
|
||||
public class FeignConfig implements RequestInterceptor {
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
//添加token
|
||||
requestTemplate.header("token", request.getHeader("token"));
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.adc.da.http;
|
||||
public enum ResponseMessageCodeEnum {
|
||||
SUCCESS("0"),
|
||||
ERROR("-1"),
|
||||
ERROR_TOKEN("LE505"),
|
||||
VALID_ERROR("1000"),
|
||||
SAVE_SUCCESS("r0001"),
|
||||
UPDATE_SUCCESS("r0002"),
|
||||
|
||||
@@ -18,7 +18,7 @@ public class TokenRuntimeException extends RuntimeException{
|
||||
private String msg;
|
||||
|
||||
public TokenRuntimeException(String msg) {
|
||||
this.msg = msg;
|
||||
super(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,10 +64,9 @@ public class LoginRestController {
|
||||
}
|
||||
if (PasswordUtils.validatePassword(password, userEO.getPassword())) {
|
||||
String token = jwtUtils.generateToken(userEO.getUsid());
|
||||
response.setHeader("Authorization", token);
|
||||
response.addHeader("Access-Control-Allow-Headers", "Authorization");
|
||||
// 加密重要信息
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
userEO.setToken(token);
|
||||
String userStr = JSON.toJSONString(userEO);
|
||||
String userStr2 = URLEncoder.encode(userStr,"UTF-8");
|
||||
userStr = encoder.encode(userStr2.getBytes());
|
||||
@@ -87,14 +86,17 @@ public class LoginRestController {
|
||||
if(StringUtils.isBlank(account)){
|
||||
return Result.error("r0011", "用户不存在");
|
||||
}
|
||||
UserEO userEO = userService.getUserByLoginNameNotDeleted("wenxianshun");
|
||||
/**
|
||||
* TODO OA 用户不全 待同步
|
||||
*/
|
||||
UserEO userEO = userService.getUserByLoginNameNotDeleted("admin");
|
||||
if (null == userEO) {
|
||||
return Result.error("r0011", "用户不存在");
|
||||
}
|
||||
if(userEO.getDisableFlag()==1){
|
||||
return Result.error("r0011", "帐号已禁用");
|
||||
}
|
||||
String token = jwtUtils.generateToken("wenxianshun");
|
||||
String token = jwtUtils.generateToken(account);
|
||||
userEO.setToken(token);
|
||||
// 加密重要信息
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TokenInterceptor extends HandlerInterceptorAdapter {
|
||||
if (null == claim) {
|
||||
System.out.println("token 解析错误");
|
||||
// 这里可以自定义 抛出 token 异常
|
||||
throw new TokenRuntimeException("token 解析错误");
|
||||
throw new TokenRuntimeException("token解析错误");
|
||||
}
|
||||
|
||||
// 4、判断 token 是否过期
|
||||
@@ -58,7 +58,7 @@ public class TokenInterceptor extends HandlerInterceptorAdapter {
|
||||
if (tokenExpired) {
|
||||
System.out.println("token已过期,请重新登录");
|
||||
// 这里可以自定义 抛出 token 异常
|
||||
throw new TokenRuntimeException("token已过期,请重新登录");
|
||||
throw new TokenRuntimeException("token已过期");
|
||||
}
|
||||
|
||||
// 5、 从 token 中获取员工信息
|
||||
|
||||
@@ -26,11 +26,17 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
InterceptorRegistration addInterceptor = registry.addInterceptor(getSecurityInterceptor());
|
||||
|
||||
addInterceptor.excludePathPatterns("/api/loginIdm");
|
||||
/**
|
||||
* TODO 测试流程 开放 login 接口 正式环境 关闭
|
||||
*/
|
||||
addInterceptor.excludePathPatterns("/api/login");
|
||||
addInterceptor.excludePathPatterns("/v2/api-docs");
|
||||
addInterceptor.excludePathPatterns("/webjars/**");
|
||||
addInterceptor.excludePathPatterns("/swagger-resources/**");
|
||||
addInterceptor.excludePathPatterns("/swagger-ui.html");
|
||||
addInterceptor.excludePathPatterns("/doc.html");
|
||||
addInterceptor.excludePathPatterns("/api/lawss/activiti/get_verify_by_instance");
|
||||
addInterceptor.excludePathPatterns("/api/sys/user/getById");
|
||||
|
||||
// 添加自定义拦截器,并拦截对应 url
|
||||
addInterceptor.addPathPatterns("/**");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.adc.da.login.util;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -42,12 +43,16 @@ public class JwtUtils {
|
||||
* 解析token
|
||||
*/
|
||||
public Claims getClaimsByToken(String token) {
|
||||
Claims claims;
|
||||
try {
|
||||
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
||||
} catch (Exception e) {
|
||||
System.out.println("validate is token error");
|
||||
return null;
|
||||
claims = Jwts.parser()
|
||||
.setSigningKey(secret) // 设置标识名
|
||||
.parseClaimsJws(token) //解析token
|
||||
.getBody();
|
||||
} catch (ExpiredJwtException e) {
|
||||
claims = e.getClaims();
|
||||
}
|
||||
return claims;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,11 @@ public class AdcDaBaseExceptionAdvice {
|
||||
public ResponseMessage handlerAdcDaBaseException(Exception exception) {
|
||||
log.error(exception.getMessage(), exception);
|
||||
// TODO 在数据库中记录程序异常,这个地方的异常是未处理的异常,需要管理员查看并进行处理以防重复出现
|
||||
if(exception.getStackTrace() != null){
|
||||
if(exception.getMessage().equals("token已过期")){
|
||||
return Result.error(ResponseMessageCodeEnum.ERROR_TOKEN.getCode(), "token已过期,请重新登录");
|
||||
}
|
||||
}
|
||||
return Result.error(ResponseMessageCodeEnum.ERROR.getCode(), "程序异常,请重试。如果重复出现请联系管理员处理!");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user