main
HuangHai 3 months ago
parent 90ac6af693
commit 139b5e60fd

@ -1,9 +1,9 @@
package com.dsideal.gw;
import cn.hutool.core.io.FileUtil;
import com.dsideal.gw.Contoller.IndexController;
import com.dsideal.gw.Handler.RouterHandler;
import com.dsideal.gw.Plugin.YamlProp;
import com.dsideal.gw.Util.CommonUtil;
import com.dsideal.gw.Util.LogBackLogFactory;
import com.jfinal.config.*;
import com.jfinal.kit.Prop;
@ -14,6 +14,7 @@ import lombok.SneakyThrows;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import java.nio.charset.StandardCharsets;
import java.util.*;
import org.slf4j.Logger;
public class GwApplication extends JFinalConfig {
@ -122,6 +123,6 @@ public class GwApplication extends JFinalConfig {
@Override
public void onStart() {
//打印 启动Logo
System.out.println(CommonUtil.txt2String("logo.txt"));
System.out.println(FileUtil.readString("logo.txt", StandardCharsets.UTF_8));
}
}

@ -1,65 +0,0 @@
package com.dsideal.gw.Util;
import cn.hutool.core.io.IoUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
@SuppressWarnings("unchecked")
public class CommonUtil {
//在独立的main函数中使用下面的方式进行声明logback对象
private static final Logger log = LoggerFactory.getLogger(CommonUtil.class);
/**
* jar
*
* @return /
*/
public static boolean isRunInJar() {
String resourcePath = "/" + CommonUtil.class.getPackageName().replace(".", "/");
URL url = CommonUtil.class.getResource(resourcePath);
if (url.getProtocol().equals("jar")) {
return true;
}
return false;
}
/**
* jar
*
* @param path
* @return
* @throws IOException
*/
public static String txt2String(String path) {
InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path);
return IoUtil.read(is, "UTF-8");
}
/**
*
*
* @param map
* @return
*/
public static String Sign(Map<String, Object> map, String signKey) {
if (map == null) {
return null;
}
List<String> keyList = new ArrayList<>(map.keySet());
Collections.sort(keyList);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
Object value = map.get(key);
sb.append(key + "=" + value + "&");
}
String signStr = sb.substring(0, sb.length() - 1) + signKey;
String md5Str = DigestUtils.md5Hex(signStr);
return md5Str;
}
}

@ -3,7 +3,6 @@ package com.dsideal.resource.Base.Controller;
import com.dsideal.resource.Base.Model.BaseModel;
import com.dsideal.resource.Interceptor.EmptyInterface;
import com.dsideal.resource.Interceptor.IsNumericInterface;
import com.dsideal.resource.Interceptor.JwtCheckInterface;
import com.dsideal.resource.Util.RetKit;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
@ -11,7 +10,6 @@ import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import io.github.yedaxia.apidocs.ApiDoc;
import java.util.List;
@ -22,7 +20,6 @@ public class BaseController extends Controller {
*
*/
@Before({GET.class})
@JwtCheckInterface({})
public void getStageList() {
List<Record> list = bm.getStageList();
Page<Record> page = new Page<>();
@ -42,7 +39,6 @@ public class BaseController extends Controller {
* @param sort_id
*/
@Before({POST.class})
@JwtCheckInterface({})
@EmptyInterface({"subject_name", "subject_code"})
@IsNumericInterface({"sort_id", "stage_id"})
public void addSubject(String subject_name, String subject_code, int stage_id, int sort_id) {
@ -68,7 +64,6 @@ public class BaseController extends Controller {
*/
@Before({POST.class})
@IsNumericInterface({"subject_id"})
@JwtCheckInterface({})
public void delSubject(int subject_id) {
bm.delSubject(subject_id);
renderJson(RetKit.renderSuccess("操作成功"));
@ -84,7 +79,6 @@ public class BaseController extends Controller {
* @param sort_id
*/
@Before({POST.class})
@JwtCheckInterface({})
@EmptyInterface({"subject_name", "subject_code"})
@IsNumericInterface({"sort_id", "stage_id", "subject_id"})
public void updateSubject(int subject_id, String subject_name, String subject_code, int stage_id, int sort_id) {
@ -112,7 +106,6 @@ public class BaseController extends Controller {
*/
@Before({GET.class})
@IsNumericInterface({"pageNum", "pageSize"})
@JwtCheckInterface({})
public void listSubject(int stage_id, int pageNum, int pageSize) {
Page<Record> listPage = bm.listSubject(stage_id, pageNum, pageSize);
renderJson(RetKit.renderSuccess(listPage));
@ -125,7 +118,6 @@ public class BaseController extends Controller {
*/
@Before({GET.class})
@IsNumericInterface({"subject_id"})
@JwtCheckInterface({})
public void getSubject(int subject_id) {
Record record = bm.getSubject(subject_id);
renderJson(RetKit.renderSuccess(record));
@ -143,7 +135,6 @@ public class BaseController extends Controller {
* @param sort_id
*/
@Before({POST.class})
@JwtCheckInterface({})
@EmptyInterface({"scheme_name"})
@IsNumericInterface({"stage_id", "subject_id", "type_id", "sort_id", "owner_id"})
public void addScheme(String scheme_name, int stage_id, int subject_id, int owner_id, int type_id, int sort_id) {
@ -164,7 +155,6 @@ public class BaseController extends Controller {
*/
@Before({POST.class})
@IsNumericInterface({"scheme_id"})
@JwtCheckInterface({})
public void delScheme(int scheme_id) {
bm.delScheme(scheme_id);
renderJson(RetKit.renderSuccess("操作成功"));
@ -202,7 +192,6 @@ public class BaseController extends Controller {
* @param pageSize
*/
@Before({GET.class})
@JwtCheckInterface({})
@IsNumericInterface({"pageNum", "pageSize"})
public void listScheme(int stage_id, int subject_id, int pageNum, int pageSize) {
Page<Record> listPage = bm.listScheme(stage_id, subject_id, pageNum, pageSize);
@ -215,7 +204,6 @@ public class BaseController extends Controller {
* @param scheme_id ID
*/
@Before({GET.class})
@JwtCheckInterface({})
@IsNumericInterface({"scheme_id"})
public void getScheme(int scheme_id) {
Record record = bm.getScheme(scheme_id);
@ -231,7 +219,6 @@ public class BaseController extends Controller {
* @param sort_id
*/
@Before({POST.class})
@JwtCheckInterface({})
public void addResourceStructure(String structure_name, int parent_id, int scheme_id, int sort_id) {
bm.addResourceStructure(structure_name, parent_id, scheme_id, sort_id);
renderJson(RetKit.renderSuccess("操作成功"));
@ -243,7 +230,6 @@ public class BaseController extends Controller {
* @param structure_id
*/
@Before({POST.class})
@JwtCheckInterface({})
@IsNumericInterface({"structure_id"})
public void delResourceStructureById(int structure_id) {
bm.delResourceStructureById(structure_id);
@ -260,7 +246,6 @@ public class BaseController extends Controller {
* @param sort_id
*/
@Before({POST.class})
@JwtCheckInterface({})
@IsNumericInterface({"structure_id"})
public void updateResourceStructureById(int structure_id, String structure_name, int parent_id, int scheme_id, int sort_id) {
bm.updateResourceStructureById(structure_id, structure_name, parent_id, scheme_id, sort_id);
@ -273,7 +258,6 @@ public class BaseController extends Controller {
* @param structure_id
*/
@Before({GET.class})
@JwtCheckInterface({})
@IsNumericInterface({"structure_id"})
public void getResourceStructureById(int structure_id) {
renderJson(RetKit.renderSuccess(bm.getResourceStructureById(structure_id)));
@ -285,7 +269,6 @@ public class BaseController extends Controller {
* @param scheme_id ID
*/
@Before({GET.class})
@JwtCheckInterface({})
public void fetchStructure(int scheme_id) {
List<Record> list = bm.fetchStructure(scheme_id, -1);
renderJson(RetKit.renderSuccess("成功", list));

@ -1,60 +0,0 @@
package com.dsideal.resource.Interceptor;
import com.dsideal.resource.Util.RetKit;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import io.jsonwebtoken.Claims;
import javax.servlet.http.HttpServletRequest;
import com.dsideal.resource.Util.JwtUtil;
/**
*
*
* @author Administrator
*/
public class JwtCheckInterceptor implements Interceptor {
@Override
public void intercept(Invocation inv) {
//正常的登录验证逻辑代码
JwtCheckInterface annotation = inv.getMethod().getAnnotation(JwtCheckInterface.class);
if (annotation != null) {
checkLogin(annotation, inv);
} else {
inv.invoke();
}
}
public void checkLogin(JwtCheckInterface annotation, Invocation inv) {
Controller con = inv.getController();
String header = con.getHeader("Content-Type"); //取出head头
if (header != null && header.indexOf("multipart/form-data") != -1) { //判断是否是form-data
inv.invoke();
}
boolean isTrue = true;
HttpServletRequest request = con.getRequest();
//从Http请求头中获取Authorization
String Authorization = request.getHeader("Authorization");
//如果为空则拒绝进入
if (StrKit.isBlank(Authorization)) {
isTrue = false;
} else {
String secret = JwtUtil.SECRET;
String token = Authorization.replaceFirst(JwtUtil.AUTHORIZATION_STARTER, "");
Claims cs = JwtUtil.getClaimsFromToken(token, secret);
if (cs == null || cs.isEmpty() || (Boolean) cs.get("expired")) {
isTrue = false;
}
}
if (isTrue) {
inv.invoke();
} else {
con.renderJson(RetKit.renderFail("此接口需要登录后操作!"));
}
}
}

@ -1,10 +0,0 @@
package com.dsideal.resource.Interceptor;
import java.lang.annotation.*;
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface JwtCheckInterface {
String[] value();
}

@ -3,7 +3,6 @@ package com.dsideal.resource.Res.Controller;
import com.dsideal.resource.Base.Model.BaseModel;
import com.dsideal.resource.Interceptor.EmptyInterface;
import com.dsideal.resource.Interceptor.IsNumericInterface;
import com.dsideal.resource.Interceptor.JwtCheckInterface;
import com.dsideal.resource.Res.Model.ResourceModel;
import com.dsideal.resource.Util.CommonUtil;
import com.dsideal.resource.Util.JwtUtil;
@ -35,7 +34,6 @@ public class ResourceController extends Controller {
* @param extension
*/
@Before(GET.class)
@JwtCheckInterface({})
@EmptyInterface({"extension"})
public void getSignature(String extension) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
if (!extension.equals(extension.toLowerCase())) {
@ -58,7 +56,6 @@ public class ResourceController extends Controller {
* @param file_md5 md5
*/
@Before(GET.class)
@JwtCheckInterface({})
@EmptyInterface({"extension"})
public void getSignatureByMd5(String extension, String file_md5) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
if (!extension.equals(extension.toLowerCase())) {
@ -93,7 +90,6 @@ public class ResourceController extends Controller {
* @param subject_id id
*/
@Before({POST.class})
@JwtCheckInterface({})
@EmptyInterface({"resource_title", "file_name", "file_md5"})
@IsNumericInterface({"resource_size_int", "scheme_id", "structure_id", "stage_id", "subject_id"})
public void addResourceBase(String resource_title, long resource_size_int, String extension, String file_name, String file_md5,
@ -116,7 +112,6 @@ public class ResourceController extends Controller {
* @param resource_id_int
*/
@Before({POST.class})
@JwtCheckInterface({})
@IsNumericInterface({"resource_id_int"})
public void delResourceBaseById(int resource_id_int) {
rm.delResourceBaseById(resource_id_int);
@ -136,7 +131,6 @@ public class ResourceController extends Controller {
* @param subject_id id
*/
@Before({POST.class})
@JwtCheckInterface({})
@IsNumericInterface({"resource_id_int"})
public void updateResourceBaseById(int resource_id_int, String resource_title,
long resource_size_int, String person_id,
@ -155,7 +149,6 @@ public class ResourceController extends Controller {
* @param resource_id_int
*/
@Before({GET.class})
@JwtCheckInterface({})
@IsNumericInterface("{resource_id_int}")
public void getResourceBaseById(int resource_id_int) {
renderJson(RetKit.renderSuccess(rm.getResourceBaseById(resource_id_int)));
@ -173,7 +166,6 @@ public class ResourceController extends Controller {
* @param pageSize
*/
@Before({GET.class})
@JwtCheckInterface({})
@IsNumericInterface({"pageNum", "pageSize", "structure_id"})
public void getResourceBaseList(int stage_id, int scheme_id, int subject_id, int structure_id, String keyword, int pageNum, int pageSize) {
Page<Record> listPage = rm.getResourceBaseList(stage_id, scheme_id, subject_id, structure_id, keyword, pageNum, pageSize);
@ -184,7 +176,6 @@ public class ResourceController extends Controller {
*
*/
@Before({GET.class})
@JwtCheckInterface({})
public void getThumbs() {
renderJson(RetKit.renderSuccess(rm.getThumbs()));
}

@ -121,8 +121,6 @@ public class ResApplication extends JFinalConfig {
//注册一个检查输入文本长度的拦截器
me.add(new LengthInterceptor());
//添加JWT拦截器
me.add(new JwtCheckInterceptor());
}
/**

Loading…
Cancel
Save