merge
This commit is contained in:
@@ -2,6 +2,7 @@ package com.xwbing.configuration;
|
||||
|
||||
import com.alibaba.druid.support.http.StatViewServlet;
|
||||
import com.alibaba.druid.support.http.WebStatFilter;
|
||||
import com.xwbing.handler.FormSaveFilter;
|
||||
import com.xwbing.util.captcha.CaptchaServlet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -53,4 +54,13 @@ public class ServletFilterConfig {
|
||||
filterRegistrationBean.addInitParameter("profileEnable", "true");//监控单个url调用的sql列表
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean formSaveFilter() {
|
||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new FormSaveFilter());
|
||||
filterRegistrationBean.addUrlPatterns("/*");
|
||||
filterRegistrationBean.addInitParameter("excludePath", "/doc,/captcha,/v2/api-docs,/swagger-resources,/configuration/ui,/configuration/security,/druid");
|
||||
filterRegistrationBean.addInitParameter("excludeType", ".js,.css,.gif,.jpg,.png,.ico,.jsp,.html,/druid/");
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.xwbing.controller.sys;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.domain.entity.vo.RestMessageVo;
|
||||
import com.xwbing.service.rest.CommonService;
|
||||
import com.xwbing.util.JsonResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2018/5/7 9:57
|
||||
* 作者: xiangwb
|
||||
* 说明:
|
||||
*/
|
||||
@Api(tags = "commonApi", description = "公共相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/common/")
|
||||
public class CommonControl {
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
||||
@LogInfo("获取签名")
|
||||
@ApiOperation(value = "获取签名", response = RestMessageVo.class)
|
||||
@GetMapping("getSign")
|
||||
public JSONObject getSign(HttpServletRequest request) {
|
||||
String sign = commonService.getSign(request);
|
||||
return JsonResult.toJSONObj(sign, "");
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ public class SysAuthorityControl {
|
||||
|
||||
@LogInfo("添加权限")
|
||||
@ApiOperation(value = "添加权限", response = RestMessageVo.class)
|
||||
@ApiImplicitParam(name = "sign", value = "签名", paramType = "header", dataType = "string")
|
||||
@PostMapping("save")
|
||||
public JSONObject save(@RequestBody SysAuthority sysAuthority) {
|
||||
RestMessage save = sysAuthorityService.save(sysAuthority);
|
||||
|
||||
@@ -42,6 +42,7 @@ public class SysRoleControl {
|
||||
|
||||
@LogInfo("添加角色")
|
||||
@ApiOperation(value = "添加角色", response = RestMessageVo.class)
|
||||
@ApiImplicitParam(name = "sign", value = "签名", paramType = "header", dataType = "string")
|
||||
@PostMapping("save")
|
||||
public JSONObject save(@RequestBody SysRole sysRole) {
|
||||
RestMessage result = sysRoleService.save(sysRole);
|
||||
|
||||
@@ -51,6 +51,7 @@ public class SysUserControl {
|
||||
|
||||
@LogInfo("添加用户")
|
||||
@ApiOperation(value = "添加用户", response = RestMessageVo.class)
|
||||
@ApiImplicitParam(name = "sign", value = "签名", paramType = "header", dataType = "string")
|
||||
@PostMapping("save")
|
||||
public JSONObject save(@RequestBody @Valid SysUser sysUser) {
|
||||
RestMessage result = sysUserService.save(sysUser);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.xwbing.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xwbing.util.RestMessage;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2018/5/7 10:11
|
||||
* 作者: xiangwb
|
||||
* 说明:
|
||||
*/
|
||||
public class FormSaveFilter implements Filter {
|
||||
private String[] paths;
|
||||
private String[] types;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
String excludePath = filterConfig.getInitParameter("excludePath");
|
||||
paths = excludePath.split(",");
|
||||
String excludeType = filterConfig.getInitParameter("excludeType");
|
||||
types = excludeType.split(",");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
String path = request.getServletPath();
|
||||
for (String p : paths) {
|
||||
if (path.equals(p)) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (String p : types) {
|
||||
if (path.contains(p)) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (path.contains("save")) {
|
||||
HttpSession session = request.getSession();
|
||||
Object sign = session.getAttribute("sign");
|
||||
String signValue = request.getHeader("sign");
|
||||
if (sign != null && sign.equals(signValue)) {
|
||||
session.removeAttribute("sign");
|
||||
chain.doFilter(request, response);
|
||||
} else {
|
||||
getOutputStream(response,"请不要重复提交");
|
||||
}
|
||||
|
||||
} else {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
private void getOutputStream(HttpServletResponse response, String msg) {
|
||||
try {
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
RestMessage restMessage = new RestMessage();
|
||||
restMessage.setMessage(msg);
|
||||
outputStream.write(JSON.toJSONString(restMessage).getBytes("utf-8"));
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user