bjang03
6 months ago
7 changed files with 122 additions and 54 deletions
@ -0,0 +1,40 @@ |
|||||
|
package com.win.framework.web.core.filter; |
||||
|
|
||||
|
import cn.hutool.json.JSONObject; |
||||
|
import com.win.framework.web.core.util.ModuleAuthenUtils; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.web.servlet.HandlerInterceptor; |
||||
|
import org.springframework.web.servlet.ModelAndView; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
@Slf4j |
||||
|
public class ModuleAuthenInterceptor implements HandlerInterceptor { |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
||||
|
LocalDateTime endTime = LocalDateTime.parse(ModuleAuthenUtils.decrypt(ModuleAuthenUtils.moduleExpire.getStr(request.getRequestURI().split("/")[1],null))); |
||||
|
if (endTime == null || endTime.isBefore(LocalDateTime.now())){ |
||||
|
throw new Exception("权限到期或没有当前模块使用权限,请联系服务商缴费"); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 请求处理之后进行调用,但是在视图被渲染之前(Controller方法调用之后) |
||||
|
*/ |
||||
|
@Override |
||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 在整个请求结束之后被调用,也就是在DispatcherServlet 渲染了对应的视图之后执行(主要是用于进行资源清理工作) |
||||
|
*/ |
||||
|
@Override |
||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package com.win.framework.web.core.util; |
||||
|
|
||||
|
import cn.hutool.core.codec.Base64; |
||||
|
import cn.hutool.json.JSONObject; |
||||
|
|
||||
|
import javax.crypto.Cipher; |
||||
|
import javax.crypto.KeyGenerator; |
||||
|
import javax.crypto.spec.SecretKeySpec; |
||||
|
import java.nio.charset.StandardCharsets; |
||||
|
import java.security.NoSuchAlgorithmException; |
||||
|
|
||||
|
public class ModuleAuthenUtils { |
||||
|
private static final String ALGORITHM = "AES"; |
||||
|
private static final int KEY_SIZE = 128; |
||||
|
public static String secretKey; |
||||
|
public static JSONObject moduleExpire; |
||||
|
public static String decrypt(String encryptedData) throws Exception { |
||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM); |
||||
|
Cipher cipher = Cipher.getInstance(ALGORITHM); |
||||
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); |
||||
|
byte[] decryptedBytes = cipher.doFinal(Base64.decode(encryptedData)); |
||||
|
return new String(decryptedBytes, StandardCharsets.UTF_8); |
||||
|
} |
||||
|
public static String encrypt(String data) throws Exception { |
||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ModuleAuthenUtils.ALGORITHM); |
||||
|
Cipher cipher = Cipher.getInstance(ModuleAuthenUtils.ALGORITHM); |
||||
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); |
||||
|
byte[] encryptedBytes = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)); |
||||
|
return Base64.encode(encryptedBytes); |
||||
|
} |
||||
|
public static String generateKey() throws NoSuchAlgorithmException { |
||||
|
KeyGenerator keyGenerator = KeyGenerator.getInstance(ModuleAuthenUtils.ALGORITHM); |
||||
|
keyGenerator.init(ModuleAuthenUtils.KEY_SIZE); |
||||
|
return Base64.encode(keyGenerator.generateKey().getEncoded()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.win.module.eam.mq.consumer; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.win.framework.mq.core.stream.AbstractStreamMessageListener; |
||||
|
import com.win.module.eam.mq.message.LicencesMessage; |
||||
|
import com.win.module.eam.service.licences.LicencesService; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
@Component |
||||
|
public class LicencesConsumer { |
||||
|
@Resource |
||||
|
private LicencesService licencesService; |
||||
|
} |
@ -1,13 +1,10 @@ |
|||||
package com.win.module.eam.mq.message; |
package com.win.module.eam.mq.message; |
||||
|
|
||||
import lombok.Data; |
import lombok.Data; |
||||
import lombok.ToString; |
import lombok.ToString; |
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
@Data |
@Data |
||||
@ToString(callSuper = true) |
@ToString(callSuper = true) |
||||
public class LicencesMessage { |
public class LicencesMessage{ |
||||
private String secretKey; |
private String secretKey; |
||||
private String data; |
private String data; |
||||
} |
} |
Loading…
Reference in new issue