Commit 8a79f0cd authored by 李丛阳's avatar 李丛阳

license

parent 1bdf080f
...@@ -384,6 +384,12 @@ ...@@ -384,6 +384,12 @@
<version>5.5.13</version> <version>5.5.13</version>
</dependency> </dependency>
<dependency>
<groupId>org.yxyqcy</groupId>
<artifactId>eduLi</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -3,8 +3,7 @@ package org.rcisoft.business.component; ...@@ -3,8 +3,7 @@ package org.rcisoft.business.component;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.quartz.*; import org.quartz.*;
import org.rcisoft.business.bcode.task.ClearLxcJob; import org.rcisoft.business.bcode.task.ClearLxcJob;
import org.rcisoft.core.exception.SystemException; import org.rcisoft.core.component.RcVerify;
import org.rcisoft.core.result.ResultExceptionEnum;
import org.rcisoft.core.util.TaskUtil; import org.rcisoft.core.util.TaskUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
...@@ -34,13 +33,13 @@ public class RcApplicationRunner implements ApplicationRunner { ...@@ -34,13 +33,13 @@ public class RcApplicationRunner implements ApplicationRunner {
@Autowired @Autowired
private SchedulerFactoryBean schedulerFactoryBean; private SchedulerFactoryBean schedulerFactoryBean;
@Autowired
private RcVerify rcVerify;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
//验证 //验证
if( 2 - 1 == 0) rcVerify.verify();
throw new SystemException(ResultExceptionEnum.LICENSE_EXPIRED);
JobDetail job = JobBuilder.newJob(ClearLxcJob.class). JobDetail job = JobBuilder.newJob(ClearLxcJob.class).
withIdentity(IDENTITY_LXC_GROUP, JOB_LXC_GROUP). withIdentity(IDENTITY_LXC_GROUP, JOB_LXC_GROUP).
usingJobData(new JobDataMap(new HashMap())).build(); usingJobData(new JobDataMap(new HashMap())).build();
......
package org.rcisoft.config; package org.rcisoft.config;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -8,6 +7,7 @@ import org.rcisoft.core.exception.ServiceException; ...@@ -8,6 +7,7 @@ import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.exception.SystemException; import org.rcisoft.core.exception.SystemException;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultCode; import org.rcisoft.core.result.ResultCode;
import org.rcisoft.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -27,7 +27,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -27,7 +27,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -118,7 +117,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -118,7 +117,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
} }
} }
log.error(e.getMessage()); log.error(e.getMessage());
responseResult(response, result); ResponseUtil.responseResult(response, result);
return new ModelAndView(); return new ModelAndView();
} }
); );
...@@ -156,16 +155,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -156,16 +155,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
private void responseResult(HttpServletResponse response, Result result) {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8");
response.setStatus(200);
try {
response.getWriter().write(JSON.toJSONString(result));
} catch (IOException ex) {
log.error(ex.getMessage());
}
}
/** /**
* 一个简单的签名认证,规则:请求参数按ASCII码排序后,拼接为a=value&b=value...这样的字符串后进行MD5 * 一个简单的签名认证,规则:请求参数按ASCII码排序后,拼接为a=value&b=value...这样的字符串后进行MD5
......
package org.rcisoft.core.bean;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Created by lcy on 18/1/8.
*/
@Component
@ConfigurationProperties(prefix = "global.lk")
@Data
public class RcLkConfigBean {
private String publicalias;
private String storePwd;
private String subject;
private String licPath;
private String pubPath;
}
package org.rcisoft.core.component;
import org.rcisoft.core.bean.RcLkConfigBean;
import org.rcisoft.core.lk.VerifyLi;
import org.rcisoft.core.service.RcRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by lcy on 18/3/19.
*/
@Component
public class RcVerify {
@Autowired
private VerifyLi verifyLi;
@Autowired
private RcLkConfigBean rcLkConfigBean;
@Autowired
private RcRedisService rcRedisServiceImpl;
public boolean verify() throws Exception {
boolean result = verifyLi.verify(rcLkConfigBean);
//验证
if(result)
rcRedisServiceImpl.set("lk","1");
else
rcRedisServiceImpl.set("lk","0");
return result;
}
}
package org.rcisoft.core.controller; package org.rcisoft.core.controller;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.core.component.RcVerify;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.model.UserAuthDTO; import org.rcisoft.core.model.UserAuthDTO;
...@@ -18,6 +20,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -18,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
*/ */
@RestController @RestController
@RequestMapping("/auth") @RequestMapping("/auth")
@Slf4j
public class AuthenticationController { public class AuthenticationController {
@Value("${jwt.header}") @Value("${jwt.header}")
...@@ -26,6 +29,9 @@ public class AuthenticationController { ...@@ -26,6 +29,9 @@ public class AuthenticationController {
@Autowired @Autowired
private AuthenticationService authenticationServiceImpl; private AuthenticationService authenticationServiceImpl;
@Autowired
private RcVerify rcVerify;
/** /**
* 登录 * 登录
* @param username * @param username
...@@ -44,6 +50,21 @@ public class AuthenticationController { ...@@ -44,6 +50,21 @@ public class AuthenticationController {
userAuthDTO); userAuthDTO);
} }
@PostMapping(value = "lk")
public Result lk(){
String mess = "fai";
try {
if(rcVerify.verify())
mess = "true";
} catch (Exception e) {
log.error(e.getMessage());
}
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
mess);
}
/** /**
* 注册 * 注册
* @param addedUser * @param addedUser
......
package org.rcisoft.core.lk;
import org.rcisoft.zkl.de.schlichtherle.license.LicenseManager;
import org.rcisoft.zkl.de.schlichtherle.license.LicenseParam;
/**
* @author cy
*/
public class LkManagerHolder {
private static LicenseManager licenseManager;
public static synchronized LicenseManager getLicenseManager(LicenseParam licenseParams) {
if (licenseManager == null) {
licenseManager = new LicenseManager(licenseParams);
}
return licenseManager;
}
}
\ No newline at end of file
package org.rcisoft.core.lk;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.common.component.Global;
import org.rcisoft.core.bean.RcLkConfigBean;
import org.rcisoft.zkl.de.schlichtherle.license.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.util.prefs.Preferences;
/**
* Created by lcy on 18/3/19.
*/
@Slf4j
@Component
public class VerifyLi {
@Autowired
private Global global;
//common param
private static String PUBLICALIAS = "";
private static String STOREPWD = "";
private static String SUBJECT = "";
private static String licPath = "";
private static String pubPath = "";
private void setParam(RcLkConfigBean lk) throws IOException {
PUBLICALIAS = lk.getPublicalias();
STOREPWD = lk.getStorePwd();
SUBJECT = lk.getSubject();
licPath = lk.getLicPath();
pubPath = lk.getPubPath();
}
public boolean verify(RcLkConfigBean lk) throws Exception {
this.setParam(lk);
LicenseManager licenseManager = LkManagerHolder
.getLicenseManager(this.initLicenseParams());
// install license file
try {
licenseManager.install(new File(global.getBASE_UPLOAD_SERVER_LOCATION() + licPath));
log.info("License file instal successfully!");
} catch (Exception e) {
log.error("License file instal failure");
//throw e ;
return false;
}
// verify license file
try {
licenseManager.verify();
log.info("License file instal successfully!");
} catch (Exception e) {
log.error("License file verify failure");
//throw e ;
return false;
}
return true;
}
private LicenseParam initLicenseParams() {
Preferences preference = Preferences
.userNodeForPackage(VerifyLi.class);
CipherParam cipherParam = new DefaultCipherParam(STOREPWD);
KeyStoreParam privateStoreParam = new DefaultKeyStoreParam(
VerifyLi.class, global.getBASE_UPLOAD_SERVER_LOCATION() + pubPath, PUBLICALIAS, STOREPWD, null);
LicenseParam licenseParams = new DefaultLicenseParam(SUBJECT,
preference, privateStoreParam, cipherParam);
return licenseParams;
}
}
package org.rcisoft.core.security; package org.rcisoft.core.security;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.util.JwtUtil; import org.rcisoft.core.util.JwtUtil;
import org.rcisoft.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
...@@ -34,12 +38,23 @@ public class JwtAuthenTokenFilter extends OncePerRequestFilter { ...@@ -34,12 +38,23 @@ public class JwtAuthenTokenFilter extends OncePerRequestFilter {
@Autowired @Autowired
private UserDetailsService jwtUserDetailServiceImpl; private UserDetailsService jwtUserDetailServiceImpl;
@Autowired
private RcRedisService rcRedisServiceImpl;
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT");
response.setHeader("Access-Control-Allow-Headers","Authorization,Origin,X-Requested-With,X-File-Name,Content-Type, Accept"); response.setHeader("Access-Control-Allow-Headers","Authorization,Origin,X-Requested-With,X-File-Name,Content-Type, Accept");
log.info("*********************************过滤器被使用**************************"); log.info("*********************************过滤器被使用**************************");
/**/
String lk = rcRedisServiceImpl.get("lk");
if(StringUtils.isBlank(lk) || !"1".equals(lk)){
Result result = new Result();
result.setCode(202);
ResponseUtil.responseResult(response, result);
return;
}
// 取得header // 取得header
String authHeader = request.getHeader(this.tokenHeader); String authHeader = request.getHeader(this.tokenHeader);
//判断header头 //判断header头
......
package org.rcisoft.core.task;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.core.component.RcVerify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created by lcy on 18/3/19.
*/
@Component
@Slf4j
public class SystemTask {
@Autowired
private RcVerify rcVerify;
@Scheduled(cron = "0 0 0/1 * * ?")
public void work() throws Exception {
rcVerify.verify();
}
}
package org.rcisoft.core.util;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.core.result.Result;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created by lcy on 18/3/19.
*/
@Slf4j
public class ResponseUtil {
public static void responseResult(HttpServletResponse response, Result result) {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8");
response.setStatus(200);
try {
response.getWriter().write(JSON.toJSONString(result));
} catch (IOException ex) {
log.error(ex.getMessage());
}
}
}
...@@ -13,7 +13,7 @@ server: ...@@ -13,7 +13,7 @@ server:
druid: druid:
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username: root username: root
password: root password: cy
initial-size: 1 initial-size: 1
min-idle: 1 min-idle: 1
max-active: 20 max-active: 20
...@@ -55,7 +55,7 @@ spring: ...@@ -55,7 +55,7 @@ spring:
add-mappings: false add-mappings: false
redis: redis:
host: 106.2.3.134 host: 106.2.3.134
port: 7481 port: 7482
pool: pool:
max-idle: 50 max-idle: 50
max-active: 1000 max-active: 1000
...@@ -103,11 +103,17 @@ global: ...@@ -103,11 +103,17 @@ global:
student: /default/student.png student: /default/student.png
teacher: /default/teacher.png teacher: /default/teacher.png
carousel: /default/carousel.jpg carousel: /default/carousel.jpg
lk:
publicalias: publiccert
storePwd: rcrtcyedu2
subject: edu2
licPath: /lk/license.lic
pubPath: /lk/publicCerts.store
password: password:
min_password: 6 min_password: 6
max_password: 16 max_password: 16
path: path:
base_upload_server_location: E:\\eduServer base_upload_server_location: /working/resource/eduServer
physical_upload_server_location: /working/resource/eduServer physical_upload_server_location: /working/resource/eduServer
course_location: course course_location: course
lesson_location: lesson lesson_location: lesson
......
...@@ -103,6 +103,12 @@ global: ...@@ -103,6 +103,12 @@ global:
student: /default/student.png student: /default/student.png
teacher: /default/teacher.png teacher: /default/teacher.png
carousel: /default/carousel.jpg carousel: /default/carousel.jpg
lk:
publicalias: publiccert
storePwd: rcrtcyedu2
subject: edu2
licPath: /lk/license.lic
pubPath: /lk/publicCerts.store
password: password:
min_password: 6 min_password: 6
max_password: 16 max_password: 16
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<logger name="org.springframework.aop.aspectj" level="ERROR"/> <logger name="org.springframework.aop.aspectj" level="ERROR"/>
<springProfile name="dev"> <springProfile name="dev">
<root level="debug"> <root level="info">
<appender-ref ref="consoleLog" /> <appender-ref ref="consoleLog" />
<appender-ref ref="fileInfoLog" /> <appender-ref ref="fileInfoLog" />
<appender-ref ref="fileErrorLog" /> <appender-ref ref="fileErrorLog" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment