代码整理
This commit is contained in:
58
pom.xml
58
pom.xml
@@ -4,74 +4,35 @@
|
||||
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>zyplayer-doc</name>
|
||||
<description>定位为所有文档的管理项目,swagger文档、数据库文档、、、、等</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.6.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<mybatis.plus.boot.starter.version>3.0.6</mybatis.plus.boot.starter.version>
|
||||
<fastjson.version>1.2.53</fastjson.version>
|
||||
<swagger.mg.ui.version>2.0.1</swagger.mg.ui.version>
|
||||
<velocity.engine.core.version>2.0</velocity.engine.core.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis.plus.boot.starter.version}</version>
|
||||
</dependency>
|
||||
<!-- json -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<!-- 在线文档解析页面 -->
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-swagger</artifactId>
|
||||
<version>${swagger.mg.ui.version}</version>
|
||||
</dependency>
|
||||
<!-- velocity 模板引擎, 默认 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>${velocity.engine.core.version}</version>
|
||||
</dependency>
|
||||
<!-- freemarker 模板引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -85,6 +46,7 @@
|
||||
<modules>
|
||||
<module>zyplayer-doc-db</module>
|
||||
<module>zyplayer-doc-manage</module>
|
||||
<module>zyplayer-doc-swagger</module>
|
||||
</modules>
|
||||
<module>zyplayer-doc-swagger</module>
|
||||
<module>zyplayer-doc-core</module>
|
||||
</modules>
|
||||
</project>
|
||||
30
zyplayer-doc-core/pom.xml
Normal file
30
zyplayer-doc-core/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-core</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>zyplayer-doc-core</name>
|
||||
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.zyplayer.doc.core.exception;
|
||||
|
||||
/**
|
||||
* 前端提示异常
|
||||
*/
|
||||
public class ConfirmException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -7084066605197111614L;
|
||||
|
||||
public ConfirmException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ConfirmException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public ConfirmException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ConfirmException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ConfirmException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.zyplayer.doc.core.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* 文档返回数据格式
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
public class DocResponseJson<T> implements ResponseJson<T> {
|
||||
private static SerializeConfig mapping = new SerializeConfig();
|
||||
static {
|
||||
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
@ApiModelProperty(value = "状态码")
|
||||
private Integer errCode;
|
||||
@ApiModelProperty(value = "返回值说明")
|
||||
private String errMsg;
|
||||
@ApiModelProperty(value = "返回数据")
|
||||
private T data;
|
||||
|
||||
public DocResponseJson() {
|
||||
this.errCode = 200;
|
||||
}
|
||||
|
||||
public DocResponseJson(T data) {
|
||||
this.setData(data);
|
||||
this.errCode = 200;
|
||||
}
|
||||
|
||||
public DocResponseJson(int errCode, String errMsg) {
|
||||
super();
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public DocResponseJson(int errCode, String errMsg, T data) {
|
||||
super();
|
||||
this.setData(data);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public DocResponseJson(Integer errCode) {
|
||||
super();
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public Integer getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
public void setErrCode(Integer errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
public void setErrMsg(String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示语
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static <T> DocResponseJson<T> warn(String errMsg) {
|
||||
return new DocResponseJson<>(300, errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static <T> DocResponseJson<T> error(String errMsg) {
|
||||
return new DocResponseJson<>(500, errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功的返回方法
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static <T> DocResponseJson<T> ok() {
|
||||
return new DocResponseJson<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功的返回方法
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static <T> DocResponseJson<T> ok(T data) {
|
||||
if (data == null) {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
DocResponseJson<T> responseJson = new DocResponseJson<>();
|
||||
responseJson.setData(data);
|
||||
return responseJson;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return JSON.toJSONString(this, mapping);
|
||||
}
|
||||
|
||||
public void send(HttpServletResponse response) {
|
||||
try {
|
||||
response.setStatus(200);
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Cache-Control", "no-cache, must-revalidate");
|
||||
response.getWriter().write(toJson());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultResponseJson [errCode=" + errCode + ", errMsg=" + errMsg + ", data=" + data + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.framework.json;
|
||||
package com.zyplayer.doc.core.json;
|
||||
|
||||
/**
|
||||
* json视图
|
||||
@@ -6,6 +6,6 @@ package com.mg.swagger.framework.json;
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
public interface ResponseJson {
|
||||
public interface ResponseJson<T> {
|
||||
|
||||
}
|
||||
@@ -84,9 +84,9 @@
|
||||
</license>
|
||||
</licenses>
|
||||
<scm>
|
||||
<connection>scm:git@git.oschina.net:zyplayer/swagger-mg-ui.git</connection>
|
||||
<developerConnection>scm:git@git.oschina.net:zyplayer/swagger-mg-ui.git</developerConnection>
|
||||
<url>git@git.oschina.net:zyplayer/swagger-mg-ui.git</url>
|
||||
<connection>scm:git@git.oschina.net:zyplayer/zyplayer-doc.git</connection>
|
||||
<developerConnection>scm:git@git.oschina.net:zyplayer/zyplayer-doc.git</developerConnection>
|
||||
<url>git@git.oschina.net:zyplayer/zyplayer-doc.git</url>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-manage</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.1</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<name>zyplayer-doc-manage</name>
|
||||
<description>定位为所有文档的管理项目,swagger文档、数据库文档、、、、等</description>
|
||||
@@ -22,7 +22,8 @@
|
||||
<java.version>1.8</java.version>
|
||||
<mybatis.plus.boot.starter.version>3.0.6</mybatis.plus.boot.starter.version>
|
||||
<fastjson.version>1.2.53</fastjson.version>
|
||||
<swagger.mg.ui.version>2.0.1</swagger.mg.ui.version>
|
||||
<zyplayer.doc.swagger.version>2.0.1</zyplayer.doc.swagger.version>
|
||||
<zyplayer.doc.core.version>1.0.0</zyplayer.doc.core.version>
|
||||
<velocity.engine.core.version>2.0</velocity.engine.core.version>
|
||||
</properties>
|
||||
|
||||
@@ -68,7 +69,12 @@
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-swagger</artifactId>
|
||||
<version>${swagger.mg.ui.version}</version>
|
||||
<version>${zyplayer.doc.swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-core</artifactId>
|
||||
<version>${zyplayer.doc.core.version}</version>
|
||||
</dependency>
|
||||
<!-- velocity 模板引擎, 默认 -->
|
||||
<dependency>
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 程序启动器
|
||||
@@ -27,11 +28,14 @@ public class Application extends SpringBootServletInitializer {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
|
||||
Environment env = application.getEnvironment();
|
||||
String contextPath = env.getProperty("server.servlet.context-path");
|
||||
contextPath = Optional.ofNullable(contextPath).orElse("").replaceFirst("/", "");
|
||||
contextPath = (contextPath.length() <= 0 || contextPath.endsWith("/")) ? contextPath : contextPath + "/";
|
||||
logger.info("\n----------------------------------------------------------\n\t" +
|
||||
"\t\t地址列表\n\t" +
|
||||
"文档地址:http://{}:{}/document.html\n" +
|
||||
"文档地址:http://{}:{}/{}document.html\n" +
|
||||
"----------------------------------------------------------",
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import org.springframework.boot.web.server.ErrorPage;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Configuration
|
||||
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableServletWebServerFactory factory) {
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/statics/common/403.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/statics/common/404.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/statics/common/500.html"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.mg.swagger.framework.service.MgStorageService;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
|
||||
import com.zyplayer.doc.manage.service.manage.ZyplayerStorageService;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorage;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 申明为@Service之后网页上才能使用存储能力,同时需要在@EnableSwagger2的地方添加@EnableSwaggerMgUi注解,
|
||||
@@ -31,7 +37,7 @@ public class MgStorageServiceImpl implements MgStorageService {
|
||||
@Override
|
||||
public String get(String key) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(true, "doc_key", key);
|
||||
wrapper.eq("doc_key", key);
|
||||
ZyplayerStorage zyplayerStorage = zyplayerStorageService.getOne(wrapper);
|
||||
if (zyplayerStorage == null) {
|
||||
return null;
|
||||
@@ -39,6 +45,21 @@ public class MgStorageServiceImpl implements MgStorageService {
|
||||
return zyplayerStorage.getDocValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MgStorage> like(String key, String value) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.like(StringUtils.isNotBlank(key), "doc_key", key);
|
||||
wrapper.like(StringUtils.isNotBlank(value), "doc_value", value);
|
||||
List<ZyplayerStorage> storageList = zyplayerStorageService.list(wrapper);
|
||||
if (storageList == null || storageList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<MgStorage> resultList = storageList.stream().map(val -> {
|
||||
return new MgStorage(val.getDocKey(), val.getDocValue());
|
||||
}).collect(Collectors.toList());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用数据库来存储,例: storageMapper.updateOrInsert(key, value);
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.zyplayer.doc.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 不需要管理本项目的文档,只需要开启@EnableSwaggerMgUi即可
|
||||
@@ -11,12 +23,34 @@ import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
* @since 2018年11月11日
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableSwaggerMgUi(
|
||||
selfDoc = false,// 不开启自身的文档,本项目只当管理文档的项目使用
|
||||
defaultResources = {// selfDoc=false时有用,启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
|
||||
selfDoc = true,// 是否开启自身的文档
|
||||
defaultResources = {// 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
|
||||
//"http://localhost:8080/swagger-resources"
|
||||
}
|
||||
)
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(Predicates.or(
|
||||
RequestHandlerSelectors.basePackage("com.zyplayer.doc.manage"),
|
||||
RequestHandlerSelectors.withClassAnnotation(Api.class)))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("zyplayer-doc-manage接口文档")
|
||||
.description("欢迎使用")
|
||||
.termsOfServiceUrl("")
|
||||
.contact(new Contact("", "", ""))
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -7,6 +8,8 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.DefaultRedirectStrategy;
|
||||
import org.springframework.security.web.RedirectStrategy;
|
||||
@@ -15,12 +18,11 @@ import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||
import org.springframework.security.web.savedrequest.RequestCache;
|
||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
||||
|
||||
/**
|
||||
* 备用
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
public class DocAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DocAuthenticationSuccessHandler.class);
|
||||
|
||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
||||
@@ -29,18 +31,16 @@ public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHand
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
||||
SavedRequest savedRequest = requestCache.getRequest(request, response);
|
||||
String targetUrl = savedRequest.getRedirectUrl();
|
||||
// boolean isAjax = HttpHelper.isAjaxRequest(request);
|
||||
boolean isAjax = true;
|
||||
boolean isAjax = "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
||||
if (isAjax) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("url", targetUrl);
|
||||
response.getWriter().print(result.toString());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
response.getWriter().flush();
|
||||
} else {
|
||||
redirectStrategy.sendRedirect(request, response, targetUrl);
|
||||
}
|
||||
|
||||
System.out.println("Redirecting to DefaultSavedRequest Url: " + targetUrl);
|
||||
logger.info("Redirecting to DefaultSavedRequest Url: " + targetUrl);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
import com.zyplayer.doc.manage.service.manage.UserAuthService;
|
||||
import com.zyplayer.doc.manage.service.manage.UserInfoService;
|
||||
|
||||
@Service
|
||||
public class DocDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
@Autowired
|
||||
private UserAuthService userAuthService;
|
||||
@Autowired
|
||||
private AuthInfoService authInfoService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String userNo) throws UsernameNotFoundException {
|
||||
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_no", userNo);
|
||||
UserInfo userInfo = userInfoService.getOne(queryWrapper);
|
||||
if (userInfo == null) {
|
||||
throw new UsernameNotFoundException("用户名'" + userNo + "'没有找到!");
|
||||
}
|
||||
QueryWrapper<UserAuth> authWrapper = new QueryWrapper<>();
|
||||
authWrapper.eq("user_id", userInfo.getId()).eq("del_flag", "0");
|
||||
List<UserAuth> userAuthList = userAuthService.list(authWrapper);
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
if (userAuthList != null && userAuthList.size() > 0) {
|
||||
List<Long> authIdList = userAuthList.stream().collect(Collectors.mapping(UserAuth::getAuthId, Collectors.toList()));
|
||||
Collection<AuthInfo> authInfoList = authInfoService.listByIds(authIdList);
|
||||
authInfoList.forEach(val -> {
|
||||
authorities.add(new SimpleGrantedAuthority(val.getAuthName()));
|
||||
});
|
||||
}
|
||||
//String pwdMd5 = DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes());
|
||||
DocUserDetails userDetails = new DocUserDetails(userInfo.getId(), userInfo.getUserNo(), userInfo.getPassword(), true, authorities);
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,16 @@ import java.util.Collection;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
public class MyUserDetails implements UserDetails {
|
||||
public class DocUserDetails implements UserDetails {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer userId;
|
||||
private Long userId;
|
||||
private String username;
|
||||
private String password;
|
||||
private boolean enabled;
|
||||
private Collection<? extends GrantedAuthority> authorities;
|
||||
|
||||
public MyUserDetails(Integer userId, String username, String password, boolean enabled) {
|
||||
public DocUserDetails(Long userId, String username, String password, boolean enabled) {
|
||||
super();
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
@@ -22,7 +22,7 @@ public class MyUserDetails implements UserDetails {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public MyUserDetails(Integer userId, String username, String password, boolean enabled,
|
||||
public DocUserDetails(Long userId, String username, String password, boolean enabled,
|
||||
Collection<? extends GrantedAuthority> authorities) {
|
||||
super();
|
||||
this.userId = userId;
|
||||
@@ -32,7 +32,7 @@ public class MyUserDetails implements UserDetails {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
public Long getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class DocUserFilter implements Filter{
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
Cookie[] cookies = httpRequest.getCookies();
|
||||
boolean haveCtx = false;
|
||||
Object ctxObj = httpRequest.getServletContext().getAttribute("ctx");
|
||||
String ctxStr = String.valueOf(ctxObj);
|
||||
if (cookies != null && cookies.length > 0) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if ("ctx".equals(cookie.getName()) && ctxStr.equals(cookie.getValue())) {
|
||||
haveCtx = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!haveCtx) {
|
||||
// 前后端分离的,前段拿不到项目名,直接写/是不对的,只有后端放到cookie里给前端
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
Cookie cookieAdd = new Cookie("ctx", ctxStr);
|
||||
cookieAdd.setPath("/");
|
||||
httpResponse.addCookie(cookieAdd);
|
||||
}
|
||||
chain.doFilter(httpRequest, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,20 +6,20 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
/**
|
||||
* 用户工具类
|
||||
*/
|
||||
public class UserUtil {
|
||||
public class DocUserUtil {
|
||||
|
||||
/**
|
||||
* 获取当前用户
|
||||
* @return
|
||||
*/
|
||||
public static MyUserDetails getCurrentUser() {
|
||||
public static DocUserDetails getCurrentUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Object principal = null;
|
||||
if (authentication != null) {
|
||||
principal = authentication.getPrincipal();
|
||||
}
|
||||
if (principal != null && principal instanceof MyUserDetails) {
|
||||
return (MyUserDetails) principal;
|
||||
if (principal != null && principal instanceof DocUserDetails) {
|
||||
return (DocUserDetails) principal;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
||||
public class DocUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
||||
// 是否开启验证码功能
|
||||
private boolean isOpenValidateCode = true;
|
||||
private boolean isOpenValidateCode = false;
|
||||
|
||||
public static final String VALIDATE_CODE = "validateCode";
|
||||
|
||||
@@ -25,13 +25,11 @@ public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuth
|
||||
|
||||
protected void checkValidateCode(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
String sessionValidateCode = obtainSessionValidateCode(session);
|
||||
sessionValidateCode = "1234";// 做个假的验证码;
|
||||
String sessionCode = this.obtainSessionValidateCode(session);
|
||||
// 让上一次的验证码失效
|
||||
session.setAttribute(VALIDATE_CODE, null);
|
||||
String validateCodeParameter = obtainValidateCodeParameter(request);
|
||||
if (StringUtils.isEmpty(validateCodeParameter) || !sessionValidateCode.equalsIgnoreCase(validateCodeParameter)) {
|
||||
String parameterCode = this.obtainValidateCodeParameter(request);
|
||||
if (StringUtils.isEmpty(sessionCode) || !sessionCode.equalsIgnoreCase(parameterCode)) {
|
||||
throw new AuthenticationServiceException("验证码错误!");
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
@Service
|
||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
if ("1".equals(username)) {
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(new SimpleGrantedAuthority("ROLE_1"));
|
||||
String pwd = DigestUtils.md5DigestAsHex("1".getBytes());
|
||||
return new MyUserDetails(1, "1", pwd, true, authorities);
|
||||
}
|
||||
throw new UsernameNotFoundException("用户名 '" + username + "'没有找到!");
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
//package com.zyplayer.doc.manage.framework.config.security;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.io.PrintWriter;
|
||||
//
|
||||
//import javax.servlet.ServletException;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
//import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
//import org.springframework.security.core.Authentication;
|
||||
//import org.springframework.security.core.AuthenticationException;
|
||||
//import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||
//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
//import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
|
||||
//import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
|
||||
//
|
||||
//@Configuration
|
||||
//@EnableWebSecurity // 注解开启Spring Security的功能
|
||||
//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
//
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http.authorizeRequests()//定义哪些url需要保护,哪些url不需要保护
|
||||
// .antMatchers("/statics/lib/**", "/message/").permitAll()//定义不需要认证就可以访问
|
||||
// .anyRequest()
|
||||
// .authenticated()
|
||||
// .and()
|
||||
// .formLogin()
|
||||
// .loginPage("/statics/manage/login.html")// 定义当需要用户登录时候,转到的登录页面
|
||||
// .successHandler(new AuthenticationSuccessHandler() {
|
||||
// @Override
|
||||
// public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
|
||||
// httpServletResponse.setContentType("application/json;charset=utf-8");
|
||||
// PrintWriter out = httpServletResponse.getWriter();
|
||||
// out.write("{\"status\":\"ok\",\"msg\":\"登录成功\"}");
|
||||
// out.flush();
|
||||
// out.close();
|
||||
// }
|
||||
// }).failureHandler(new AuthenticationFailureHandler() {
|
||||
// @Override
|
||||
// public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
|
||||
// httpServletResponse.setContentType("application/json;charset=utf-8");
|
||||
// PrintWriter out = httpServletResponse.getWriter();
|
||||
// out.write("{\"status\":\"error\",\"msg\":\"登录失败\"}");
|
||||
// out.flush();
|
||||
// out.close();
|
||||
// }
|
||||
// })
|
||||
// .permitAll()
|
||||
// .loginProcessingUrl("/user/login")
|
||||
// .usernameParameter("username")
|
||||
// .passwordParameter("password")
|
||||
// .permitAll()
|
||||
// .and()
|
||||
// .logout()
|
||||
// .permitAll()
|
||||
// .and()
|
||||
// .csrf()
|
||||
// .disable();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// auth.userDetailsService(userDetailsServiceImpl());//.passwordEncoder(new Md5PasswordEncoder());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public UserDetailsServiceImpl userDetailsServiceImpl() {
|
||||
// return new UserDetailsServiceImpl();
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public MyUsernamePasswordAuthenticationFilter myUsernamePasswordAuthenticationFilter() throws Exception {
|
||||
// MyUsernamePasswordAuthenticationFilter myFilter = new MyUsernamePasswordAuthenticationFilter();
|
||||
// myFilter.setAuthenticationManager(authenticationManagerBean());
|
||||
// myFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler());
|
||||
// myFilter.setAuthenticationFailureHandler(authenticationFailureHandler());
|
||||
// myFilter.setRememberMeServices(tokenBasedRememberMeServices());
|
||||
// return myFilter;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public AuthenticationSuccessHandler authenticationSuccessHandler() {
|
||||
// return new SimpleUrlAuthenticationSuccessHandler("/login/success");
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public AuthenticationFailureHandler authenticationFailureHandler() {
|
||||
// return new SimpleUrlAuthenticationFailureHandler("/login/failure");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void configure(WebSecurity web) throws Exception {
|
||||
// web.ignoring().antMatchers("/statics/lib/**", "**/css/**", "**/js/**", "**/img/**");
|
||||
// }
|
||||
//
|
||||
// @Autowired
|
||||
// public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// //在内存中创建了一个用户,该用户的名称为user,密码为password,用户角色为ADMIN
|
||||
// auth.inMemoryAuthentication()
|
||||
// .withUser("user").password("password").roles("ADMIN");
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -6,6 +6,7 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.RememberMeAuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
@@ -21,9 +22,10 @@ import org.springframework.security.web.authentication.rememberme.RememberMeAuth
|
||||
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
@Order(1)
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@Order(1)
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
@@ -37,38 +39,34 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
*/
|
||||
@Override
|
||||
public void configure(WebSecurity web) throws Exception {
|
||||
web.ignoring().antMatchers("/statics/lib/**", "/css/**", "/js/**", "/img/**");
|
||||
web.ignoring().antMatchers("/statics/lib/**", "/css/**", "/js/**", "/img/**", "/swagger-resources", "/v2/api-docs");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
String loginPage = "/statics/manage/login.html";
|
||||
|
||||
http.authorizeRequests().antMatchers("/login/**").permitAll()//为了测试其他功能,设置“ /** ”允许所有请求
|
||||
// user权限可以访问的请求
|
||||
.antMatchers("/security/user").hasRole("user")
|
||||
// admin权限可以访问的请求
|
||||
.antMatchers("/security/admin").hasRole("admin")
|
||||
// SpEL表达式:需要拥有user权限,且进行了完全认证
|
||||
.antMatchers("/user/account").access("hasRole('user') and isFullyAuthenticated()")
|
||||
// 其他地址的访问均需验证权限(需要登录)
|
||||
.antMatchers("/document.html").hasAuthority("DOC_ALL")
|
||||
// 其他地址的访问均需登录
|
||||
.anyRequest().authenticated().and()
|
||||
// 添加验证码验证
|
||||
.addFilterAt(myUsernamePasswordAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class).exceptionHandling()
|
||||
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/statics/manage/login.html")).and()
|
||||
.addFilterAt(rememberMeAuthenticationFilter(), RememberMeAuthenticationFilter.class)
|
||||
.addFilterAt(myUsernamePasswordAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint(loginPage))
|
||||
.and().addFilterAt(rememberMeAuthenticationFilter(), RememberMeAuthenticationFilter.class)
|
||||
// 指定登录页面的请求路径
|
||||
.formLogin().loginPage("/statics/manage/login.html")
|
||||
.formLogin().loginPage(loginPage)
|
||||
// 登陆处理路径
|
||||
.loginProcessingUrl("/login").permitAll().and()
|
||||
// 退出请求的默认路径为logout,下面改为signout,
|
||||
// 成功退出登录后的url可以用logoutSuccessUrl设置
|
||||
.logout().deleteCookies("remember-me")
|
||||
.logoutUrl("/signout")
|
||||
.logoutSuccessUrl("/statics/manage/login.html")
|
||||
.permitAll().and()
|
||||
.loginProcessingUrl("/login").permitAll()
|
||||
// 退出请求的默认路径为logout
|
||||
.and().logout().deleteCookies("remember-me")
|
||||
.logoutUrl("/logout").logoutSuccessUrl(loginPage)
|
||||
.permitAll()
|
||||
// 开启rememberMe,设置一个私钥专供testall项目使用,注意与下面TokenBasedRememberMeServices的key保持一致
|
||||
// .rememberMe().key("testallKey").and()
|
||||
// 关闭csrf
|
||||
.csrf().disable();
|
||||
.and().csrf().disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,19 +79,20 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
}
|
||||
@Override
|
||||
public boolean matches(CharSequence charSequence, String s) {
|
||||
return s.equals(DigestUtils.md5DigestAsHex(charSequence.toString().getBytes()));
|
||||
String digestAsHex = DigestUtils.md5DigestAsHex(charSequence.toString().getBytes());
|
||||
return s.equals(digestAsHex);
|
||||
}
|
||||
}).and().authenticationProvider(rememberMeAuthenticationProvider());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserDetailsServiceImpl userDetailsServiceImpl() {
|
||||
return new UserDetailsServiceImpl();
|
||||
public DocDetailsServiceImpl userDetailsServiceImpl() {
|
||||
return new DocDetailsServiceImpl();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MyUsernamePasswordAuthenticationFilter myUsernamePasswordAuthenticationFilter() throws Exception {
|
||||
MyUsernamePasswordAuthenticationFilter myFilter = new MyUsernamePasswordAuthenticationFilter();
|
||||
public DocUsernamePasswordAuthenticationFilter myUsernamePasswordAuthenticationFilter() throws Exception {
|
||||
DocUsernamePasswordAuthenticationFilter myFilter = new DocUsernamePasswordAuthenticationFilter();
|
||||
myFilter.setAuthenticationManager(authenticationManagerBean());
|
||||
myFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler());
|
||||
myFilter.setAuthenticationFailureHandler(authenticationFailureHandler());
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.zyplayer.doc.manage.framework.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
*/
|
||||
@Component
|
||||
public class GlobalHandlerExceptionResolver extends SimpleMappingExceptionResolver {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalHandlerExceptionResolver.class);
|
||||
|
||||
@Override
|
||||
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
LOGGER.error("---自定义异常处理---", ex);
|
||||
request.setAttribute("throwable", ex);
|
||||
ModelAndView mv = new ModelAndView();
|
||||
response.setStatus(HttpStatus.OK.value());// 设置状态码
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);// 设置ContentType
|
||||
response.setCharacterEncoding("UTF-8");// 避免乱码
|
||||
response.setHeader("Cache-Control", "no-cache, must-revalidate");
|
||||
DocResponseJson<Object> responseJson = null;
|
||||
if (ex instanceof ConfirmException) {// 提示性异常
|
||||
responseJson = DocResponseJson.warn(ex.getMessage());
|
||||
} else if (ex instanceof AccessDeniedException) {// 没权限
|
||||
responseJson = DocResponseJson.warn("您没有权限访问本接口");
|
||||
} else {// 其他异常
|
||||
responseJson = DocResponseJson.warn("系统错误");
|
||||
}
|
||||
boolean isResponseBody = isResponseBody(handler);// 是否返回body
|
||||
// 返回页面或者返回内容处理
|
||||
if (!isResponseBody) {
|
||||
mv.addObject("errJson", responseJson);
|
||||
String customErrPage = (String) request.getAttribute("customErrPage");
|
||||
// 有定义过错误页面的直接返回自定义的错误页面
|
||||
if(StringUtils.isNotBlank(customErrPage)) {
|
||||
mv.setViewName(customErrPage);
|
||||
} else {// 否则返回默认的错误页面
|
||||
mv.setViewName("/statics/common/500.html");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
String jsonStr = JSON.toJSONString(responseJson);
|
||||
response.getWriter().write(jsonStr);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是HttpMessageNotReadableException 则获取错误字段
|
||||
* @param exception
|
||||
* @return
|
||||
*/
|
||||
public static String getExceptionField(String exception) {
|
||||
Pattern pattern = Pattern.compile("Unrecognized field \"(\\w*)[$\"]");
|
||||
Matcher matcher = pattern.matcher(exception);
|
||||
String field = "";
|
||||
if (matcher.find()) {
|
||||
field = matcher.group(1);
|
||||
} else {
|
||||
pattern = Pattern.compile("Field error in object '.+' on field '(\\w+)'");
|
||||
matcher = pattern.matcher(exception);
|
||||
if (matcher.find()) {
|
||||
field = matcher.group(1);
|
||||
}
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否返回body
|
||||
* @author
|
||||
* @since 2017年5月11日
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
private boolean isResponseBody(Object handler){
|
||||
if (handler instanceof HandlerMethod) {
|
||||
HandlerMethod mathod = (HandlerMethod) handler;
|
||||
ResponseBody body = mathod.getMethodAnnotation(ResponseBody.class);
|
||||
if(body == null){
|
||||
RestController restController = mathod.getMethod().getDeclaringClass().getAnnotation(RestController.class);
|
||||
if(restController == null){
|
||||
if(!mathod.getMethod().getReturnType().isAssignableFrom(ResponseJson.class)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
public class AuthInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 权限名
|
||||
*/
|
||||
private String authName;
|
||||
|
||||
/**
|
||||
* 权限说明
|
||||
*/
|
||||
private String authDesc;
|
||||
|
||||
/**
|
||||
* 是否可编辑 0=否 1=是
|
||||
*/
|
||||
private Integer canEdit;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUid;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date creationTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getAuthName() {
|
||||
return authName;
|
||||
}
|
||||
|
||||
public void setAuthName(String authName) {
|
||||
this.authName = authName;
|
||||
}
|
||||
public String getAuthDesc() {
|
||||
return authDesc;
|
||||
}
|
||||
|
||||
public void setAuthDesc(String authDesc) {
|
||||
this.authDesc = authDesc;
|
||||
}
|
||||
public Integer getCanEdit() {
|
||||
return canEdit;
|
||||
}
|
||||
|
||||
public void setCanEdit(Integer canEdit) {
|
||||
this.canEdit = canEdit;
|
||||
}
|
||||
public Long getCreateUid() {
|
||||
return createUid;
|
||||
}
|
||||
|
||||
public void setCreateUid(Long createUid) {
|
||||
this.createUid = createUid;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthInfo{" +
|
||||
"id=" + id +
|
||||
", authName=" + authName +
|
||||
", authDesc=" + authDesc +
|
||||
", canEdit=" + canEdit +
|
||||
", createUid=" + createUid +
|
||||
", creationTime=" + creationTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
public class UserAuth implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
private Long authId;
|
||||
|
||||
/**
|
||||
* 创建用户ID
|
||||
*/
|
||||
private Long createUid;
|
||||
|
||||
/**
|
||||
* 更新用户ID
|
||||
*/
|
||||
private Long updateUid;
|
||||
|
||||
/**
|
||||
* 是否删除 0=未删除 1=已删除
|
||||
*/
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date creationTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public Long getAuthId() {
|
||||
return authId;
|
||||
}
|
||||
|
||||
public void setAuthId(Long authId) {
|
||||
this.authId = authId;
|
||||
}
|
||||
public Long getCreateUid() {
|
||||
return createUid;
|
||||
}
|
||||
|
||||
public void setCreateUid(Long createUid) {
|
||||
this.createUid = createUid;
|
||||
}
|
||||
public Long getUpdateUid() {
|
||||
return updateUid;
|
||||
}
|
||||
|
||||
public void setUpdateUid(Long updateUid) {
|
||||
this.updateUid = updateUid;
|
||||
}
|
||||
public Integer getDelFlag() {
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(Integer delFlag) {
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserAuth{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", authId=" + authId +
|
||||
", createUid=" + createUid +
|
||||
", updateUid=" + updateUid +
|
||||
", delFlag=" + delFlag +
|
||||
", creationTime=" + creationTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
public class UserInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户编号,用于登录等
|
||||
*/
|
||||
private String userNo;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 是否删除 0=未删除 1=已删除
|
||||
*/
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUid;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date creationTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getUserNo() {
|
||||
return userNo;
|
||||
}
|
||||
|
||||
public void setUserNo(String userNo) {
|
||||
this.userNo = userNo;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
public Integer getDelFlag() {
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(Integer delFlag) {
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
public Long getCreateUid() {
|
||||
return createUid;
|
||||
}
|
||||
|
||||
public void setCreateUid(Long createUid) {
|
||||
this.createUid = createUid;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"id=" + id +
|
||||
", userNo=" + userNo +
|
||||
", password=" + password +
|
||||
", userName=" + userName +
|
||||
", email=" + email +
|
||||
", avatar=" + avatar +
|
||||
", delFlag=" + delFlag +
|
||||
", createUid=" + createUid +
|
||||
", creationTime=" + creationTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface AuthInfoMapper extends BaseMapper<AuthInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserAuthMapper extends BaseMapper<UserAuth> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
||||
|
||||
}
|
||||
@@ -22,7 +22,8 @@ public class CodeGenerator {
|
||||
public static void main(String[] args) {
|
||||
|
||||
final String moduleName = "manage";
|
||||
final String[] tableName = { "zyplayer_storage" };
|
||||
final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info" };
|
||||
// final String[] tableName = { "zyplayer_storage" };
|
||||
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
@@ -34,6 +35,7 @@ public class CodeGenerator {
|
||||
gc.setOpen(false);
|
||||
gc.setDateType(DateType.ONLY_DATE);
|
||||
gc.setServiceName("%sService");
|
||||
gc.setControllerName("Generator%sController");
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
@@ -42,14 +44,14 @@ public class CodeGenerator {
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName("com.mysql.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("11111");
|
||||
dsc.setPassword("root");
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
final PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(null);
|
||||
pc.setParent("com.zyplayer.doc.manage");
|
||||
pc.setController("web");
|
||||
pc.setController("web.generator");
|
||||
pc.setEntity("repository.manage.entity");
|
||||
pc.setMapper("repository.manage.mapper");
|
||||
pc.setService("service.manage");
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.service.manage;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface AuthInfoService extends IService<AuthInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.service.manage;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserAuthService extends IService<UserAuth> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.service.manage;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserInfoService extends IService<UserInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.service.manage.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.AuthInfoMapper;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
public class AuthInfoServiceImpl extends ServiceImpl<AuthInfoMapper, AuthInfo> implements AuthInfoService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.service.manage.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.UserAuthMapper;
|
||||
import com.zyplayer.doc.manage.service.manage.UserAuthService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
public class UserAuthServiceImpl extends ServiceImpl<UserAuthMapper, UserAuth> implements UserAuthService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.service.manage.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.UserInfoMapper;
|
||||
import com.zyplayer.doc.manage.service.manage.UserInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/auth-info")
|
||||
public class GeneratorAuthInfoController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user-auth")
|
||||
public class GeneratorUserAuthController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user-info")
|
||||
public class GeneratorUserInfoController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-storage")
|
||||
public class GeneratorZyplayerStorageController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/auth/info")
|
||||
@PreAuthorize("hasAuthority('AUTH_MANAGE')")
|
||||
public class AuthInfoController {
|
||||
|
||||
@Autowired
|
||||
AuthInfoService authInfoService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<Object> list() {
|
||||
List<AuthInfo> authList = authInfoService.list();
|
||||
return DocResponseJson.ok(authList);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseJson<Object> delete(Long id) {
|
||||
AuthInfo authInfo = authInfoService.getById(id);
|
||||
if (authInfo == null || authInfo.getCanEdit() == 0) {
|
||||
return DocResponseJson.warn("该权限不允许删除");
|
||||
}
|
||||
authInfoService.removeById(id);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(Long id, String authName, String authDesc) {
|
||||
AuthInfo authInfo = new AuthInfo();
|
||||
authInfo.setAuthDesc(authDesc);
|
||||
authInfo.setAuthName(authName);
|
||||
if (id != null && id > 0) {
|
||||
AuthInfo authInfoSel = authInfoService.getById(id);
|
||||
if (authInfoSel == null || authInfoSel.getCanEdit() == 0) {
|
||||
return DocResponseJson.warn("该权限不允许编辑");
|
||||
}
|
||||
authInfo.setId(id);
|
||||
authInfoService.updateById(authInfo);
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
authInfo.setCreationTime(new Date());
|
||||
authInfo.setCreateUid(currentUser.getUserId());
|
||||
authInfoService.save(authInfo);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class HelloController {
|
||||
|
||||
// @RequestMapping("/")
|
||||
// public String index() {
|
||||
// return "manage/index";
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/hello")
|
||||
// public String hello() {
|
||||
// return "manage/hello";
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/login")
|
||||
// public String login() {
|
||||
// return "statics/manage/hello.html";
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.WebAttributes;
|
||||
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||
import org.springframework.security.web.savedrequest.RequestCache;
|
||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
|
||||
@RestController
|
||||
public class LoginController {
|
||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||
|
||||
@GetMapping(value = "/login")
|
||||
public ModelAndView loginPage(HttpServletRequest request) {
|
||||
return new ModelAndView("/statics/manage/login.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是访问受限页面后,跳转到登录页的,则在targetUrl保存之前受限页面的路径,供页面调用
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/login/success")
|
||||
public DocResponseJson<String> loginSuccess(HttpServletRequest request, HttpServletResponse response) {
|
||||
SavedRequest savedRequest = requestCache.getRequest(request, response);
|
||||
String targetUrl = null;
|
||||
if (savedRequest != null) {
|
||||
targetUrl = savedRequest.getRedirectUrl();
|
||||
}
|
||||
if (StringUtils.isBlank(targetUrl)) {
|
||||
targetUrl = "/";
|
||||
}
|
||||
return DocResponseJson.ok(targetUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取异常信息返回给页面
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/login/failure")
|
||||
public DocResponseJson<String> loginFailure(HttpServletRequest request, HttpServletResponse response) {
|
||||
AuthenticationException ae = (AuthenticationException) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
||||
return DocResponseJson.warn(ae.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
import com.zyplayer.doc.manage.service.manage.UserAuthService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/auth")
|
||||
@PreAuthorize("hasAuthority('AUTH_ASSIGN')")
|
||||
public class UserAuthController {
|
||||
|
||||
@Autowired
|
||||
AuthInfoService authInfoService;
|
||||
@Autowired
|
||||
UserAuthService userAuthService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<Object> list(Long userId) {
|
||||
QueryWrapper<UserAuth> userAuthWrapper = new QueryWrapper<>();
|
||||
userAuthWrapper.eq("user_id", userId);
|
||||
List<UserAuth> userAuthList = userAuthService.list(userAuthWrapper);
|
||||
if (userAuthList == null || userAuthList.isEmpty()) {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
QueryWrapper<AuthInfo> authQueryWrapper = new QueryWrapper<>();
|
||||
authQueryWrapper.in("id", userAuthList.stream().collect(Collectors.mapping(UserAuth::getAuthId, Collectors.toList())));
|
||||
List<AuthInfo> authList = authInfoService.list(authQueryWrapper);
|
||||
return DocResponseJson.ok(authList);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseJson<Object> delete(Long id) {
|
||||
userAuthService.removeById(id);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/insert")
|
||||
public ResponseJson<Object> insert(Long id, Long userId, Long authId) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
UserAuth userAuth = new UserAuth();
|
||||
userAuth.setAuthId(authId);
|
||||
userAuth.setUserId(userId);
|
||||
if (id != null && id > 0) {
|
||||
userAuth.setId(id);
|
||||
userAuthService.updateById(userAuth);
|
||||
} else {
|
||||
userAuth.setCreationTime(new Date());
|
||||
userAuth.setCreateUid(currentUser.getUserId());
|
||||
userAuthService.save(userAuth);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.web.WebAttributes;
|
||||
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||
import org.springframework.security.web.savedrequest.RequestCache;
|
||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.zyplayer.doc.manage.framework.config.security.MyUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.UserUtil;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||
|
||||
@RequestMapping(value = "/login_page", method = RequestMethod.GET)
|
||||
public ModelAndView loginPage(HttpServletRequest request) {
|
||||
if (true) {
|
||||
return new ModelAndView("/login/ajax");
|
||||
} else {
|
||||
return new ModelAndView("login.html");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是访问受限页面后,跳转到登录页的,则在targetUrl保存之前受限页面的路径,供页面调用
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/login/success", method = RequestMethod.GET)
|
||||
public Map<String, Object> loginSuccess(HttpServletRequest request, HttpServletResponse response) {
|
||||
SavedRequest savedRequest = requestCache.getRequest(request, response);
|
||||
String targetUrl = null;
|
||||
if (savedRequest != null) {
|
||||
targetUrl = savedRequest.getRedirectUrl();
|
||||
}
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("success", true);
|
||||
result.put("targetUrl", targetUrl);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取异常信息返回给页面
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/login/failure", method = RequestMethod.GET)
|
||||
public Map<String, Object> loginFailure(HttpServletRequest request, HttpServletResponse response) {
|
||||
AuthenticationException ae = (AuthenticationException) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("success", false);
|
||||
result.put("message", ae.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login/ajax", method = RequestMethod.GET)
|
||||
public Map<String, Object> loginAjax() {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("success", false);
|
||||
result.put("message", "you need login!");
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/security/user", method = RequestMethod.GET)
|
||||
public Map<String, Object> securityUser(HttpServletRequest request) {
|
||||
MyUserDetails user = UserUtil.getCurrentUser();
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
StringBuilder userRole = new StringBuilder();
|
||||
if (user != null) {
|
||||
result.put("userId", user.getUserId());
|
||||
result.put("userName", user.getUsername());
|
||||
Collection<? extends GrantedAuthority> roleLst = user.getAuthorities();
|
||||
for (GrantedAuthority sga : roleLst) {
|
||||
userRole.append(sga.toString() + "; ");
|
||||
}
|
||||
}
|
||||
result.put("userRole", userRole.toString());
|
||||
result.put("message", "This message is only visible to the user");
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/security/admin", method = RequestMethod.GET)
|
||||
public Map<String, Object> securityAdmin(HttpServletRequest request) {
|
||||
MyUserDetails user = UserUtil.getCurrentUser();
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
StringBuilder userRole = new StringBuilder();
|
||||
if (user != null) {
|
||||
result.put("userId", user.getUserId());
|
||||
result.put("userName", user.getUsername());
|
||||
Collection<? extends GrantedAuthority> roleLst = user.getAuthorities();
|
||||
for (GrantedAuthority sga : roleLst) {
|
||||
userRole.append(sga.toString() + "; ");
|
||||
}
|
||||
}
|
||||
result.put("userRole", userRole.toString());
|
||||
result.put("message", "This message is only visible to the admin");
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/user/account", method = RequestMethod.GET)
|
||||
public Map<String, Object> getUserAcctunt(HttpServletRequest request) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("message", "需要进行完整认证的请求(不是通过Remember-me功能进行的认证)");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.manage.service.manage.UserInfoService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/info")
|
||||
@PreAuthorize("hasAuthority('USER_MANAGE')")
|
||||
public class UserInfoController {
|
||||
|
||||
@Autowired
|
||||
UserInfoService userInfoService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<Object> list(String userName) {
|
||||
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
queryWrapper.like("user_name", userName);
|
||||
}
|
||||
List<UserInfo> userInfoList = userInfoService.list(queryWrapper);
|
||||
return DocResponseJson.ok(userInfoList);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseJson<Object> delete(Long id) {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(id);
|
||||
userInfo.setDelFlag(1);
|
||||
userInfo.setUpdateTime(new Date());
|
||||
userInfoService.updateById(userInfo);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(UserInfo userInfo) {
|
||||
if (userInfo.getId() != null && userInfo.getId() > 0) {
|
||||
userInfo.setUpdateTime(new Date());
|
||||
userInfoService.updateById(userInfo);
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
userInfo.setCreationTime(new Date());
|
||||
userInfo.setCreateUid(currentUser.getUserId());
|
||||
userInfoService.save(userInfo);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
@@ -6,16 +6,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.ZyplayerStorageMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-storage")
|
||||
@RequestMapping("/zyplayer/storage")
|
||||
public class ZyplayerStorageController {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -27,7 +27,7 @@ spring:
|
||||
server:
|
||||
port: 8082
|
||||
servlet:
|
||||
context-path: /
|
||||
context-path: /zyplayer-doc-manage
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zyplayer.doc.manage.repository.manage.mapper.AuthInfoMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zyplayer.doc.manage.repository.manage.mapper.UserAuthMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zyplayer.doc.manage.repository.manage.mapper.UserInfoMapper">
|
||||
|
||||
</mapper>
|
||||
14
zyplayer-doc-manage/src/main/webapp/statics/common/403.html
Normal file
14
zyplayer-doc-manage/src/main/webapp/statics/common/403.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<title>403错误页面</title>
|
||||
<style>
|
||||
</style>
|
||||
<div style="text-align: center;">您没有权限访问此页面</div>
|
||||
</body>
|
||||
</html>
|
||||
14
zyplayer-doc-manage/src/main/webapp/statics/common/404.html
Normal file
14
zyplayer-doc-manage/src/main/webapp/statics/common/404.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<title>404错误页面</title>
|
||||
<style>
|
||||
</style>
|
||||
<div style="text-align: center;">您访问的页面不存在</div>
|
||||
</body>
|
||||
</html>
|
||||
14
zyplayer-doc-manage/src/main/webapp/statics/common/500.html
Normal file
14
zyplayer-doc-manage/src/main/webapp/statics/common/500.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<title>500错误页面</title>
|
||||
<style>
|
||||
</style>
|
||||
<div style="text-align: center;">服务器错误</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,6 +4,14 @@
|
||||
* @since 2017年5月7日
|
||||
*/
|
||||
|
||||
var ctx = "/";
|
||||
var statics = "/statics/";
|
||||
|
||||
window.onload=function(){
|
||||
ctx = getCookie("ctx");
|
||||
statics = ctx + "statics/";
|
||||
}
|
||||
|
||||
function serialize(value) {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<div class="heading divider primary-pale">
|
||||
<div class="title">登录 <span class="reason"> 您没有权限访问该内容或需要登录</span></div>
|
||||
</div>
|
||||
<form action="/login" method="post">
|
||||
|
||||
<div class="content box">
|
||||
<div class="control has-label-left"><!-- has-error -->
|
||||
<input type="text" name="username" class="input" v-model="userId" placeholder="用户名">
|
||||
@@ -29,10 +29,10 @@
|
||||
<label for="account"><i class="icon-key"></i></label>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button type="submit" v-on:click="loginSubmit1" class="btn block primary">登录</button>
|
||||
<button type="submit" v-on:click="loginSubmit" class="btn block primary">登录</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -58,10 +58,10 @@
|
||||
password: app.password,
|
||||
validateCode: "1234"
|
||||
};
|
||||
post("/login", param, function(result) {
|
||||
post(ctx + "login", param, function(result) {
|
||||
console.log(result);
|
||||
if(result.errCode == 200) {
|
||||
//location.href = "/manage/web/home";
|
||||
alert("登录失败1," + result.errMsg);
|
||||
location.href = result.data;
|
||||
} else {
|
||||
alert("登录失败," + result.errMsg);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
# swagger-mg-ui
|
||||
# zyplayer-doc-swagger
|
||||
|
||||
#### 项目介绍
|
||||
swagger-mg-ui是swagger的一个前端实现,使用简单、解析速度快、走心的设计,支持多项目同时展示,多种文档目录的展示方案,多种自定义配置,满足各种使用习惯,使用中您有任何的意见和建议都可到源码地址处反馈哦!
|
||||
zyplayer-doc-swagger是swagger的一个前端实现,使用简单、解析速度快、走心的设计,支持多项目同时展示,多种文档目录的展示方案,多种自定义配置,满足各种使用习惯,使用中您有任何的意见和建议都可到源码地址处反馈哦!
|
||||
|
||||
每一行代码都是从头开始写的,所以每一个问题都能及时得到解决
|
||||
|
||||
欢迎多多Star!右上角↗
|
||||
|
||||
demo代码地址:
|
||||
[swagger-mg-ui-demo](https://gitee.com/zyplayer/swagger-mg-ui-demo)
|
||||
[zyplayer-doc-swagger-demo](https://gitee.com/zyplayer/zyplayer-doc-swagger-demo)
|
||||
|
||||
已上传至中央仓库,使用方法:
|
||||
|
||||
1、添加依赖
|
||||
```
|
||||
<!-- https://mvnrepository.com/artifact/com.zyplayer/swagger-mg-ui -->
|
||||
<!-- https://mvnrepository.com/artifact/com.zyplayer/zyplayer-doc-swagger -->
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>swagger-mg-ui</artifactId>
|
||||
<artifactId>zyplayer-doc-swagger</artifactId>
|
||||
<version>1.0.6</version>
|
||||
</dependency>
|
||||
```
|
||||
@@ -64,7 +64,7 @@ maven项目,前端由html、js、css组成的,后端使用java,前端框
|
||||
|
||||
#### 建议:
|
||||
1. 单项目文档不要添加@EnableSwaggerMgUi注解
|
||||
2. 多项目时建议不要引入文档UI包,只需要引入springfox-swagger2包,单独部署一个项目添加swagger-mg-ui包,增加@EnableSwaggerMgUi注解,再实现MgStorageService类,部署后用于专门的文档管理项目,再在文档页面“添加文档”,管理所有项目的文档,真正实现文档和项目分离管理!
|
||||
2. 多项目时建议不要引入文档UI包,只需要引入springfox-swagger2包,单独部署一个项目添加zyplayer-doc-swagger包,增加@EnableSwaggerMgUi注解,再实现MgStorageService类,部署后用于专门的文档管理项目,再在文档页面“添加文档”,管理所有项目的文档,真正实现文档和项目分离管理!
|
||||
|
||||
欢迎加入群聊讨论:
|
||||
|
||||
|
||||
@@ -29,6 +29,16 @@
|
||||
<version>1.4.2.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<!-- 打包跳过单元测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||
<zyplayer.doc.core.version>1.0.0</zyplayer.doc.core.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -54,16 +64,13 @@
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-core</artifactId>
|
||||
<version>${zyplayer.doc.core.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<!-- 打包跳过单元测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||
</properties>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.mg.swagger.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.mg.swagger.controller.param.HttpRequestParam;
|
||||
import com.mg.swagger.framework.json.MgUiResponseJson;
|
||||
import com.mg.swagger.framework.json.ResponseJson;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* 后台代理网络请求的控制器
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/swagger-mg-ui/http")
|
||||
public class MgHttpRequestController {
|
||||
|
||||
@PostMapping(value = "/request")
|
||||
public ResponseJson post(HttpRequestParam param) {
|
||||
HttpRequest request = param.createRequest();
|
||||
HttpResponse execute = request.execute();
|
||||
return MgUiResponseJson.ok(execute);
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.mg.swagger.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.mg.swagger.framework.constant.Toast;
|
||||
import com.mg.swagger.framework.json.MgUiResponseJson;
|
||||
import com.mg.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 后台存储服务控制器
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/swagger-mg-ui/storage")
|
||||
public class MgStorageController {
|
||||
|
||||
@Autowired(required = false)
|
||||
private MgStorageService storageService;
|
||||
|
||||
@PostMapping(value = "/checkConfig")
|
||||
public MgUiResponseJson checkConfig() {
|
||||
// 本接口能访问到而且实现了MgStorageService才算配置好了
|
||||
if (storageService == null) {
|
||||
return MgUiResponseJson.error("服务不可用");
|
||||
}
|
||||
return MgUiResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/data")
|
||||
public MgUiResponseJson setData(String key, String value) {
|
||||
if (storageService == null) {
|
||||
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
|
||||
}
|
||||
if (key == null || value == null) {
|
||||
return MgUiResponseJson.warn("参数名或值不能为空");
|
||||
}
|
||||
storageService.put(key, value);
|
||||
return MgUiResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/delete")
|
||||
public MgUiResponseJson delete(String key) {
|
||||
if (storageService == null) {
|
||||
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
|
||||
}
|
||||
if (key == null) {
|
||||
return MgUiResponseJson.warn("参数名不能为空");
|
||||
}
|
||||
String value = storageService.get(key);
|
||||
value = (value == null) ? "" : value;
|
||||
return MgUiResponseJson.ok(value);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/data")
|
||||
public MgUiResponseJson getData(String key) {
|
||||
if (storageService == null) {
|
||||
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
|
||||
}
|
||||
if (key == null) {
|
||||
return MgUiResponseJson.warn("参数名不能为空");
|
||||
}
|
||||
String value = storageService.get(key);
|
||||
value = (value == null) ? "" : value;
|
||||
return MgUiResponseJson.ok(value);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.mg.swagger.framework.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
import com.mg.swagger.framework.filter.MgUiTestFilter;
|
||||
|
||||
//@EnableAutoConfiguration
|
||||
@ComponentScan(basePackages = {
|
||||
"com.mg.swagger.controller",
|
||||
"com.mg.swagger.framework.service",
|
||||
})
|
||||
public class SwaggerCommonConfiguration {
|
||||
|
||||
@Autowired
|
||||
private MgUiTestFilter mgUiTestFilter;
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean mockTestFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
registration.setFilter(mgUiTestFilter);
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("mgUiTestFilter");
|
||||
registration.setOrder(2);
|
||||
return registration;
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
package com.mg.swagger.framework.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpCookie;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
||||
import com.mg.swagger.controller.vo.HttpCookieVo;
|
||||
import com.mg.swagger.controller.vo.HttpHeaderVo;
|
||||
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* MgUi返回数据格式
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
public class MgUiResponseJson implements ResponseJson {
|
||||
private static SerializeConfig mapping = new SerializeConfig();
|
||||
static {
|
||||
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
@ApiModelProperty(value = "状态码")
|
||||
private Integer errCode;
|
||||
@ApiModelProperty(value = "返回值说明")
|
||||
private String errMsg;
|
||||
@ApiModelProperty(value = "返回数据")
|
||||
private Object data;
|
||||
@ApiModelProperty(value = "代理请求返回的cookie")
|
||||
private List<HttpCookieVo> cookie;
|
||||
@ApiModelProperty(value = "代理请求返回的header")
|
||||
private List<HttpHeaderVo> header;
|
||||
@ApiModelProperty(value = "代理请求返回的status")
|
||||
private Integer status;
|
||||
|
||||
public MgUiResponseJson() {
|
||||
this.errCode = 200;
|
||||
}
|
||||
|
||||
public MgUiResponseJson(Object data) {
|
||||
this.setData(data);
|
||||
this.errCode = 200;
|
||||
}
|
||||
|
||||
public MgUiResponseJson(int errCode, String errMsg) {
|
||||
super();
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public MgUiResponseJson(int errCode, String errMsg, Object data) {
|
||||
super();
|
||||
this.setData(data);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public MgUiResponseJson(Integer errCode) {
|
||||
super();
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public Integer getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
public void setErrCode(Integer errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
public void setErrMsg(String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示语
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static MgUiResponseJson warn(String errMsg) {
|
||||
return new MgUiResponseJson(300, errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static MgUiResponseJson error(String errMsg) {
|
||||
return new MgUiResponseJson(500, errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功的返回方法
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static MgUiResponseJson ok() {
|
||||
return new MgUiResponseJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功的返回方法
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月7日
|
||||
* @return
|
||||
*/
|
||||
public static MgUiResponseJson ok(Object data) {
|
||||
if (data == null) {
|
||||
return MgUiResponseJson.ok();
|
||||
}
|
||||
MgUiResponseJson responseJson = new MgUiResponseJson();
|
||||
if (data instanceof HttpResponse) {
|
||||
HttpResponse response = (HttpResponse) data;
|
||||
responseJson.setData(response.body());
|
||||
responseJson.setStatus(response.getStatus());
|
||||
List<HttpCookie> cookies = response.getCookies();
|
||||
if (cookies != null && cookies.size() > 0) {
|
||||
List<HttpCookieVo> cookie = new ArrayList<>(cookies.size());
|
||||
for (HttpCookie httpCookie : cookies) {
|
||||
HttpCookieVo vo = new HttpCookieVo();
|
||||
vo.setName(httpCookie.getName());
|
||||
vo.setValue(httpCookie.getValue());
|
||||
cookie.add(vo);
|
||||
}
|
||||
responseJson.setCookie(cookie);
|
||||
}
|
||||
Map<String, List<String>> headers = response.headers();
|
||||
if (headers != null && headers.size() > 0) {
|
||||
List<HttpHeaderVo> header = new ArrayList<>(headers.size());
|
||||
for (Entry<String, List<String>> httpHeader : headers.entrySet()) {
|
||||
HttpHeaderVo vo = new HttpHeaderVo();
|
||||
vo.setName(httpHeader.getKey());
|
||||
vo.setValue(String.join(";", httpHeader.getValue()));
|
||||
header.add(vo);
|
||||
}
|
||||
responseJson.setHeader(header);
|
||||
}
|
||||
} else {
|
||||
responseJson.setData(data);
|
||||
}
|
||||
return responseJson;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return JSON.toJSONString(this, mapping);
|
||||
}
|
||||
|
||||
public void send(HttpServletResponse response) {
|
||||
try {
|
||||
response.setStatus(200);
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Cache-Control", "no-cache, must-revalidate");
|
||||
response.getWriter().write(toJson());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultResponseJson [errCode=" + errCode + ", errMsg=" + errMsg + ", data=" + data + "]";
|
||||
}
|
||||
|
||||
public List<HttpCookieVo> getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
public void setCookie(List<HttpCookieVo> cookie) {
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
public List<HttpHeaderVo> getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(List<HttpHeaderVo> header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.controller;
|
||||
package com.zyplayer.doc.swagger.controller;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
@@ -24,13 +24,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
import com.mg.swagger.framework.configuration.SpringContextUtil;
|
||||
import com.mg.swagger.framework.constant.StorageKeys;
|
||||
import com.mg.swagger.framework.constant.Toast;
|
||||
import com.mg.swagger.framework.json.MgUiResponseJson;
|
||||
import com.mg.swagger.framework.json.ResponseJson;
|
||||
import com.mg.swagger.framework.service.MgStorageService;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
import com.zyplayer.doc.swagger.framework.configuration.SpringContextUtil;
|
||||
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import springfox.documentation.swagger.web.SwaggerResource;
|
||||
@@ -47,7 +46,7 @@ public class MgDocumentController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(MgDocumentController.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
@Autowired
|
||||
private MgStorageService storageService;
|
||||
|
||||
/**
|
||||
@@ -55,35 +54,30 @@ public class MgDocumentController {
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
* @return 文档内容
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/resourcesList")
|
||||
public ResponseJson resourcesList() {
|
||||
if (storageService == null) {
|
||||
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
|
||||
}
|
||||
public ResponseJson<Set<String>> resourcesList() {
|
||||
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
|
||||
Set<String> resourcesSet = new HashSet<>();
|
||||
if (StringUtils.isNotBlank(swaggerResourcesStr)) {
|
||||
List<String> resourcesList = JSON.parseArray(swaggerResourcesStr, String.class);
|
||||
resourcesSet.addAll(resourcesList);
|
||||
}
|
||||
return MgUiResponseJson.ok(resourcesSet);
|
||||
return DocResponseJson.ok(resourcesSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的文档
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
* @param request request
|
||||
* @param response response
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/docs")
|
||||
public void docs(HttpServletRequest request, HttpServletResponse response) {
|
||||
if (storageService == null) {
|
||||
MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR).send(response);
|
||||
return;
|
||||
}
|
||||
boolean needRestorage = true;
|
||||
String choiseDocList = request.getParameter("choiseDocList");
|
||||
// 转成set,防止重复
|
||||
@@ -123,15 +117,13 @@ public class MgDocumentController {
|
||||
if (swaggerMgUi == null) {
|
||||
resourcesSet.add(serverPath + "/swagger-resources");
|
||||
} else {
|
||||
boolean selfDoc = swaggerMgUi.selfDoc();
|
||||
if (selfDoc) {
|
||||
if (swaggerMgUi.selfDoc()) {
|
||||
resourcesSet.add(serverPath + "/swagger-resources");
|
||||
} else {
|
||||
// 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
|
||||
String[] defaultResources = swaggerMgUi.defaultResources();
|
||||
if (defaultResources != null && defaultResources.length > 0) {
|
||||
resourcesSet.addAll(Arrays.asList(defaultResources));
|
||||
}
|
||||
}
|
||||
// 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
|
||||
String[] defaultResources = swaggerMgUi.defaultResources();
|
||||
if (defaultResources != null && defaultResources.length > 0) {
|
||||
resourcesSet.addAll(Arrays.asList(defaultResources));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,7 +187,7 @@ public class MgDocumentController {
|
||||
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
|
||||
}
|
||||
// 用默认的json解析要内存溢出,解析不了JSONObject、、就只有这样写了~
|
||||
MgUiResponseJson.ok(swaggerResourceStrList).send(response);
|
||||
DocResponseJson.ok(swaggerResourceStrList).send(response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,14 +195,11 @@ public class MgDocumentController {
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
* @param resourcesUrl
|
||||
* @return
|
||||
* @param resourcesUrl swagger-resources地址
|
||||
* @return 添加结果
|
||||
*/
|
||||
@PostMapping(value = "/addSwaggerResources")
|
||||
public ResponseJson addSwaggerResources(String resourcesUrl) {
|
||||
if (storageService == null) {
|
||||
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
|
||||
}
|
||||
public ResponseJson<Object> addSwaggerResources(String resourcesUrl) {
|
||||
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
|
||||
String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST);
|
||||
Set<String> swaggerDocsDeleteSet = new HashSet<>();
|
||||
@@ -224,11 +213,12 @@ public class MgDocumentController {
|
||||
List<String> resourcesList = JSON.parseArray(swaggerResourcesStr, String.class);
|
||||
resourcesSet.addAll(resourcesList);
|
||||
}
|
||||
String resourcesStr = null;
|
||||
try {
|
||||
String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body();
|
||||
resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body();
|
||||
List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
|
||||
if (resourceList == null || resourceList.isEmpty()) {
|
||||
return MgUiResponseJson.warn("改地址未找到文档");
|
||||
return DocResponseJson.warn("该地址未找到文档");
|
||||
}
|
||||
// 重新加入的时候把之前的已删除的回恢复
|
||||
String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1);
|
||||
@@ -249,12 +239,28 @@ public class MgDocumentController {
|
||||
}
|
||||
resourcesSet.add(resourcesUrl);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取文档失败:{},{}", resourcesUrl, e.getMessage());
|
||||
return MgUiResponseJson.warn("改地址查找文档失败");
|
||||
// 暂不想支持直接添加地址
|
||||
// try {
|
||||
// SwaggerLocationVo swaggerLocationVo = JSON.parseObject(resourcesStr, SwaggerLocationVo.class);
|
||||
// if (StringUtils.isNotBlank(swaggerLocationVo.getSwagger())) {
|
||||
// Set<String> locationSet = new HashSet<>();
|
||||
// if (StringUtils.isNotBlank(swaggerLocationListStr)) {
|
||||
// String swaggerLocationListStr = storageService.get(StorageKeys.SWAGGER_LOCATION_LIST);
|
||||
// List<String> locationList = JSON.parseArray(swaggerLocationListStr, String.class);
|
||||
// locationSet.addAll(locationList);
|
||||
// storageService.put(StorageKeys.SWAGGER_LOCATION_LIST, JSON.toJSONString(locationSet));
|
||||
// }
|
||||
// } else {
|
||||
// return DocResponseJson.warn("该地址查找文档失败");
|
||||
// }
|
||||
// } catch (Exception e2) {
|
||||
logger.error("获取文档失败:{},{}", resourcesUrl, e.getMessage());
|
||||
return DocResponseJson.warn("该地址查找文档失败");
|
||||
// }
|
||||
}
|
||||
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
|
||||
storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet));
|
||||
return MgUiResponseJson.ok();
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,14 +268,11 @@ public class MgDocumentController {
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
* @param docUrl
|
||||
* @return
|
||||
* @param docUrl 文档地址
|
||||
* @return 删除结果
|
||||
*/
|
||||
@PostMapping(value = "/deleteSwaggerDoc")
|
||||
public ResponseJson deleteSwaggerDoc(String docUrl) {
|
||||
if (storageService == null) {
|
||||
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
|
||||
}
|
||||
public ResponseJson<Object> deleteSwaggerDoc(String docUrl) {
|
||||
String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST);
|
||||
Set<String> swaggerDocsDeleteSet = new HashSet<>();
|
||||
if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) {
|
||||
@@ -278,6 +281,6 @@ public class MgDocumentController {
|
||||
}
|
||||
swaggerDocsDeleteSet.add(docUrl);
|
||||
storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet));
|
||||
return MgUiResponseJson.ok();
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.zyplayer.doc.swagger.controller;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.swagger.controller.param.HttpRequestParam;
|
||||
import com.zyplayer.doc.swagger.controller.vo.HttpCookieVo;
|
||||
import com.zyplayer.doc.swagger.controller.vo.HttpHeaderVo;
|
||||
import com.zyplayer.doc.swagger.controller.vo.HttpRequestVo;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* 后台代理网络请求的控制器
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/swagger-mg-ui/http")
|
||||
public class MgHttpRequestController {
|
||||
|
||||
@PostMapping(value = "/request")
|
||||
public DocResponseJson<HttpRequestVo> post(HttpRequestParam param) {
|
||||
HttpRequest request = param.createRequest();
|
||||
HttpResponse response = request.execute();
|
||||
HttpRequestVo httpRequestVo = new HttpRequestVo();
|
||||
httpRequestVo.setData(response.body());
|
||||
httpRequestVo.setStatus(response.getStatus());
|
||||
List<HttpCookie> cookies = response.getCookies();
|
||||
if (cookies != null && cookies.size() > 0) {
|
||||
List<HttpCookieVo> cookie = cookies.stream().map(val -> {
|
||||
return new HttpCookieVo(val.getName(), val.getValue());
|
||||
}).collect(Collectors.toList());
|
||||
httpRequestVo.setCookie(cookie);
|
||||
}
|
||||
Map<String, List<String>> headers = response.headers();
|
||||
if (headers != null && headers.size() > 0) {
|
||||
List<HttpHeaderVo> header = new ArrayList<>(headers.size());
|
||||
for (Entry<String, List<String>> httpHeader : headers.entrySet()) {
|
||||
HttpHeaderVo vo = new HttpHeaderVo();
|
||||
vo.setName(httpHeader.getKey());
|
||||
vo.setValue(String.join(";", httpHeader.getValue()));
|
||||
header.add(vo);
|
||||
}
|
||||
httpRequestVo.setHeader(header);
|
||||
}
|
||||
return DocResponseJson.ok(httpRequestVo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.zyplayer.doc.swagger.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorage;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 后台存储服务控制器
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/swagger-mg-ui/storage")
|
||||
public class MgStorageController {
|
||||
|
||||
@Autowired
|
||||
private MgStorageService storageService;
|
||||
|
||||
@PostMapping(value = "/checkConfig")
|
||||
public DocResponseJson<Object> checkConfig() {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/data")
|
||||
public DocResponseJson<Object> setData(String key, String value) {
|
||||
if (key == null || value == null) {
|
||||
return DocResponseJson.warn("参数名或值不能为空");
|
||||
}
|
||||
storageService.put(key, value);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/data")
|
||||
public DocResponseJson<String> getData(String key) {
|
||||
if (key == null) {
|
||||
return DocResponseJson.warn("参数名不能为空");
|
||||
}
|
||||
String value = storageService.get(key);
|
||||
value = (value == null) ? "" : value;
|
||||
return DocResponseJson.ok(value);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/delete")
|
||||
public DocResponseJson<Object> delete(String key) {
|
||||
if (key == null) {
|
||||
return DocResponseJson.warn("参数名不能为空");
|
||||
}
|
||||
storageService.remove(key);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/like")
|
||||
public DocResponseJson<Object> like(String key, String value) {
|
||||
List<MgStorage> likeList = storageService.like(key, value);
|
||||
return DocResponseJson.ok(likeList);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.controller.param;
|
||||
package com.zyplayer.doc.swagger.controller.param;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -92,6 +92,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* 组装请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest createRequest() {
|
||||
if("get".equalsIgnoreCase(this.method)) return get();
|
||||
@@ -107,6 +108,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* POST请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest post() {
|
||||
HttpRequest request = HttpRequest.post(this.getUrl());
|
||||
@@ -116,6 +118,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* GET请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest get() {
|
||||
HttpRequest request = HttpRequest.get(this.getUrl());
|
||||
@@ -125,6 +128,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* HEAD请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest head() {
|
||||
HttpRequest request = HttpRequest.head(this.getUrl());
|
||||
@@ -134,6 +138,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* OPTIONS请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest options() {
|
||||
HttpRequest request = HttpRequest.options(this.getUrl());
|
||||
@@ -143,6 +148,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* PUT请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest put() {
|
||||
HttpRequest request = HttpRequest.put(this.getUrl());
|
||||
@@ -152,6 +158,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* PATCH请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest patch() {
|
||||
HttpRequest request = HttpRequest.patch(this.getUrl());
|
||||
@@ -161,6 +168,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* DELETE请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest delete() {
|
||||
HttpRequest request = HttpRequest.delete(this.getUrl());
|
||||
@@ -170,6 +178,7 @@ public class HttpRequestParam {
|
||||
|
||||
/**
|
||||
* TRACE请求
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest trace() {
|
||||
HttpRequest request = HttpRequest.trace(this.getUrl());
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.mg.swagger.controller.vo;
|
||||
package com.zyplayer.doc.swagger.controller.vo;
|
||||
|
||||
/**
|
||||
* cookie返回值对象
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
@@ -9,6 +10,15 @@ public class HttpCookieVo {
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public HttpCookieVo() {
|
||||
|
||||
}
|
||||
|
||||
public HttpCookieVo(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.controller.vo;
|
||||
package com.zyplayer.doc.swagger.controller.vo;
|
||||
|
||||
/**
|
||||
* header返回值对象
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.zyplayer.doc.swagger.controller.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* request返回值对象
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月21日
|
||||
*/
|
||||
public class HttpRequestVo {
|
||||
@ApiModelProperty(value = "代理请求返回的cookie")
|
||||
private List<HttpCookieVo> cookie;
|
||||
@ApiModelProperty(value = "代理请求返回的header")
|
||||
private List<HttpHeaderVo> header;
|
||||
@ApiModelProperty(value = "代理请求返回的status")
|
||||
private Integer status;
|
||||
@ApiModelProperty(value = "返回数据")
|
||||
private Object data;
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public List<HttpCookieVo> getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
public void setCookie(List<HttpCookieVo> cookie) {
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
public List<HttpHeaderVo> getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(List<HttpHeaderVo> header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.zyplayer.doc.swagger.controller.vo;
|
||||
|
||||
public class SwaggerLocationVo {
|
||||
private String swagger;
|
||||
private String info;
|
||||
private String host;
|
||||
private String paths;
|
||||
private String definitions;
|
||||
|
||||
private String tags;
|
||||
private String basePath;
|
||||
|
||||
public String getSwagger() {
|
||||
return swagger;
|
||||
}
|
||||
|
||||
public void setSwagger(String swagger) {
|
||||
this.swagger = swagger;
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
public void setInfo(String info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getPaths() {
|
||||
return paths;
|
||||
}
|
||||
|
||||
public void setPaths(String paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
public String getDefinitions() {
|
||||
return definitions;
|
||||
}
|
||||
|
||||
public void setDefinitions(String definitions) {
|
||||
this.definitions = definitions;
|
||||
}
|
||||
|
||||
public String getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(String tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.framework.configuration;
|
||||
package com.zyplayer.doc.swagger.framework.configuration;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -6,23 +6,21 @@ import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.mg.swagger.framework.filter.MgUiTestFilter;
|
||||
|
||||
@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||
@Target(value = { java.lang.annotation.ElementType.TYPE })
|
||||
@Documented
|
||||
@Import({ SwaggerCommonConfiguration.class, MgUiTestFilter.class, SpringContextUtil.class })
|
||||
@Import({ SwaggerCommonConfiguration.class, SpringContextUtil.class })
|
||||
public @interface EnableSwaggerMgUi {
|
||||
|
||||
/**
|
||||
* 是否自动把自身的swagger-resources加进来
|
||||
* @return
|
||||
* @return 配置
|
||||
*/
|
||||
boolean selfDoc() default true;
|
||||
|
||||
/**
|
||||
* 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
|
||||
* @return
|
||||
* @return swagger-resources地址
|
||||
*/
|
||||
String[] defaultResources() default {};
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.framework.configuration;
|
||||
package com.zyplayer.doc.swagger.framework.configuration;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
@@ -35,8 +35,8 @@ public class SpringContextUtil implements ApplicationContextAware {
|
||||
|
||||
/**
|
||||
* 获取类
|
||||
* @param cacheName
|
||||
* @return
|
||||
* @param annotationType annotation
|
||||
* @return 类对象
|
||||
*/
|
||||
public static Object getBeanWithAnnotation(Class<? extends Annotation> annotationType) {
|
||||
if (context == null) {
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.zyplayer.doc.swagger.framework.configuration;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
//@EnableAutoConfiguration
|
||||
@ComponentScan(basePackages = {
|
||||
"com.zyplayer.doc.swagger.controller",
|
||||
"com.zyplayer.doc.swagger.framework.service",
|
||||
})
|
||||
public class SwaggerCommonConfiguration {
|
||||
|
||||
// 不再默认开启拦截
|
||||
// @Autowired
|
||||
// private MgUiTestFilter mgUiTestFilter;
|
||||
//
|
||||
// @Bean
|
||||
// public FilterRegistrationBean mockTestFilter() {
|
||||
// FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
// registration.setFilter(mgUiTestFilter);
|
||||
// registration.addUrlPatterns("/*");
|
||||
// registration.setName("mgUiTestFilter");
|
||||
// registration.setOrder(2);
|
||||
// return registration;
|
||||
// }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.framework.constant;
|
||||
package com.zyplayer.doc.swagger.framework.constant;
|
||||
|
||||
/**
|
||||
* 存储数据的KEY常量类
|
||||
@@ -11,4 +11,6 @@ public class StorageKeys {
|
||||
public static final String SWAGGER_RESOURCES_LIST = "swagger-resources-list";
|
||||
// 已删除的文档
|
||||
public static final String SWAGGER_DOCS_DELETE_LIST = "swagger-docs-delete-list";
|
||||
// 所有详细文档地址
|
||||
public static final String SWAGGER_LOCATION_LIST = "swagger-location-list";
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.framework.constant;
|
||||
package com.zyplayer.doc.swagger.framework.constant;
|
||||
|
||||
/**
|
||||
* 提示语常量类
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mg.swagger.framework.filter;
|
||||
package com.zyplayer.doc.swagger.framework.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -12,11 +12,11 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mg.swagger.framework.service.MgStorageService;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 有需要此拦截器的请自行拷贝至自身项目,不再开启@Component<br>
|
||||
* 判断是否是模拟请求,功能需求:<br>
|
||||
* 很多时候后端定义好了接口,但还未实现,这时前端已经需要数据调试了,这时就需要用到这个过滤器了!<br>
|
||||
* 在页面上先配置好模拟返回的数据,然后在url上加入参数:mgUiTestFlag=1<br>
|
||||
@@ -27,7 +27,7 @@ import com.mg.swagger.framework.service.MgStorageService;
|
||||
* 也许需要10天才能写完,但前端两天就写好了,急需数据看效果,这时就让他们自己去设置模拟值,加上参数自己测试好。
|
||||
* 而不是一味的催后台,把各种锅丢给后端,然后玩自己的去了,浪费各环节等待时间。
|
||||
*/
|
||||
@Component
|
||||
//@Component
|
||||
public class MgUiTestFilter implements Filter {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.zyplayer.doc.swagger.framework.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
public class MgStorage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
public MgStorage() {
|
||||
|
||||
}
|
||||
|
||||
public MgStorage(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static long getSerialversionuid() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
package com.mg.swagger.framework.service;
|
||||
package com.zyplayer.doc.swagger.framework.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 实现此类才能使用服务器端的存贮功能
|
||||
@@ -11,17 +13,27 @@ public interface MgStorageService {
|
||||
* 获取存储的值
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月19日
|
||||
* @param key
|
||||
* @return
|
||||
* @param key 参数
|
||||
* @return 值
|
||||
*/
|
||||
String get(String key);
|
||||
|
||||
/**
|
||||
* 模糊获取存储的值
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月19日
|
||||
* @param key 参数
|
||||
* @param value 值
|
||||
* @return 值
|
||||
*/
|
||||
List<MgStorage> like(String key, String value);
|
||||
|
||||
/**
|
||||
* 存储数据
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月19日
|
||||
* @param key
|
||||
* @param value
|
||||
* @param key 参数
|
||||
* @param value 值
|
||||
*/
|
||||
void put(String key, String value);
|
||||
|
||||
@@ -29,7 +41,7 @@ public interface MgStorageService {
|
||||
* 删除数据
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月19日
|
||||
* @param key
|
||||
* @param key 参数
|
||||
*/
|
||||
void remove(String key);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<title>swagger-mg-ui</title>
|
||||
<title>接口文档管理系统 - zyplayer</title>
|
||||
<link rel="shortcut icon" href="webjars/mg-ui/img/api.ico"/>
|
||||
<link rel="stylesheet" href="webjars/zui/css/zui.min.css" />
|
||||
<link rel="stylesheet" href="webjars/zui/lib/dashboard/zui.dashboard.min.css" />
|
||||
@@ -12,12 +12,12 @@
|
||||
<body>
|
||||
<div class="left-body" id="leftContent">
|
||||
<div class="left-header">
|
||||
<span class="logo" id="logoText">swagger-mg-ui</span>
|
||||
<span class="logo" id="logoText">zyplayer-doc-swagger</span>
|
||||
<i class="icon icon-bars" id="changeContentWidth"></i>
|
||||
</div>
|
||||
<div class="scrollbar-hover left-container">
|
||||
<!-- 样式类可选:tree-menu tree-folders tree-chevrons tree-angles -->
|
||||
<ul class="tree tree-lines tree-menu projects">
|
||||
<ul class="tree tree-lines tree-menu projects" data-ride="tree">
|
||||
<li>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="searchDocInput">
|
||||
@@ -27,7 +27,16 @@
|
||||
</div>
|
||||
</li>
|
||||
<li id="homePageLi"><a href="javascript:void(0)" path=""><i class="icon-home"></i> 控制台</a></li>
|
||||
<li id="onlineDebugLi" class="local-storage"><a href="javascript:void(0)" path=""><i class="icon-bug"></i> 在线调试管理</a></li>
|
||||
<li>
|
||||
<a href="#"><i class="icon icon-cogs"></i> 文档管理</a>
|
||||
<ul>
|
||||
<li id="onlineDebugLi" class="local-storage"><a href="javascript:void(0)" path=""><i class="icon-bug"></i> 在线调试管理</a></li>
|
||||
<li><a href="#" path=""><i class="icon-cog"></i> 文档展示配置</a></li>
|
||||
<li><a href="#" path=""><i class="icon-globe"></i> 全局参数管理</a></li>
|
||||
<li><a href="#" path=""><i class="icon-bug"></i> 调试数据管理</a></li>
|
||||
<li><a href="#" path=""><i class="icon-list-ul"></i> 文档地址管理</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<div id="apiPathTree">
|
||||
<ul class="tree tree-lines projects"></ul>
|
||||
@@ -104,11 +113,11 @@
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<div align="center">简介</div>
|
||||
swagger-mg-ui是swagger-ui的一个前端实现,使用简单、解析速度快、走心的设计,
|
||||
zyplayer-doc-swagger是swagger-ui的一个前端实现,使用简单、解析速度快、走心的设计,
|
||||
支持多项目同时展示,多种文档目录的展示方案,多种自定义配置,满足各种使用习惯。
|
||||
本项目是完全从头写的,所以有任何属性未解析到、UI上有何建议都能及时处理得到。
|
||||
使用中您有任何的意见和建议都可到源码地址处反馈哦!<br/>
|
||||
源码地址:<a target="_blank" href="https://gitee.com/zyplayer/swagger-mg-ui">swagger-mg-ui</a>,
|
||||
源码地址:<a target="_blank" href="https://gitee.com/zyplayer/zyplayer-doc">zyplayer-doc-swagger</a>,
|
||||
前端框架:<a target="_blank" href="http://zui.sexy">zui</a>,
|
||||
我的网站:<a target="_blank" href="http://kongjianzhou.com">空间轴</a>
|
||||
</td>
|
||||
@@ -369,7 +378,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="info">测试地址</td>
|
||||
<td><a id="simulationResultUrlTest" href="" target="_blank"></a> <i class="icon icon-info-sign" title='需要被访问项目导入swagger-mg-ui包才能使用'></i></td>
|
||||
<td><a id="simulationResultUrlTest" href="" target="_blank"></a> <i class="icon icon-info-sign" title='需要被访问项目导入zyplayer-doc包才能使用'></i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="info">返回内容</td>
|
||||
@@ -417,7 +426,7 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="alert alert-danger hidden">
|
||||
1、请到 <a target="_blank" href="https://gitee.com/zyplayer/swagger-mg-ui">源码处下载</a>《对外文档模板.zip》解压<br/>
|
||||
1、请到 <a target="_blank" href="https://gitee.com/zyplayer/zyplayer-doc">源码处下载</a>《对外文档模板.zip》解压<br/>
|
||||
2、复制以下文本内容覆盖至 /js/mg-ui-data.js 文件内<br/>
|
||||
3、然后双击打开目录下的:document.html 即可看到导出的文档
|
||||
</div>
|
||||
|
||||
@@ -97,7 +97,7 @@ label{font-weight: normal;}
|
||||
.param-box .param-table tbody td:nth-child(3){border-left: 0;padding: 0 10px 0 0;width: 10px;}
|
||||
.param-box .param-table tbody td:nth-child(3) i{cursor: pointer;color: #ccc;}
|
||||
.param-box .param-table tbody td:nth-child(3) i:hover{color: #888;}
|
||||
.param-box .param-table tbody tr.base td:last-child{display: none;}
|
||||
.param-box .param-table tbody tr.base td:last-child i{display: none;}
|
||||
#bulkEditHeaderCheck{margin-left: 10px;}
|
||||
#bulkEditHeader,#bulkEditForm{display: none;}
|
||||
|
||||
|
||||
@@ -100,22 +100,23 @@ $(document).ready(function(){
|
||||
paramSendToServer.method = options;
|
||||
ajaxTemp("swagger-mg-ui/http/request", "post", "json", paramSendToServer, function(result){
|
||||
//console.log(result);
|
||||
var requestObj = result.data;
|
||||
setStorage('p-request-obj-' + docUrl, storeRequestParam);
|
||||
var afterSendTime = new Date().getTime();
|
||||
$("#httpRequestStatus").text(result.status);
|
||||
$("#httpRequestStatus").text(requestObj.status);
|
||||
$("#httpRequestTime").text((afterSendTime - beforSendTime) + "ms");
|
||||
try {
|
||||
var htmlStr = Formatjson.processObjectToHtmlPre(JSON.parse(result.data), 0, false, false, false, false);
|
||||
var htmlStr = Formatjson.processObjectToHtmlPre(JSON.parse(requestObj.data), 0, false, false, false, false);
|
||||
$("#responseBodyJsonDiv").html(htmlStr);
|
||||
} catch (e) {
|
||||
$("#responseBodyJsonDiv").html("<iframe id='responseBodyJsonIframe'></iframe>");
|
||||
setTimeout(function(){
|
||||
$("#responseBodyJsonIframe").contents().find("body").html(result.data);
|
||||
$("#responseBodyJsonIframe").contents().find("body").html(requestObj.data);
|
||||
}, 300);
|
||||
}
|
||||
$("#tabResponseHeader table tbody").empty();
|
||||
$("#tabResponseCookie table tbody").empty();
|
||||
var headers = result.header||[];
|
||||
var headers = requestObj.header||[];
|
||||
for (var i = 0; i < headers.length; i++) {
|
||||
var name = getNotEmptyStr(headers[i].name);
|
||||
var value = getNotEmptyStr(headers[i].value);
|
||||
@@ -123,7 +124,7 @@ $(document).ready(function(){
|
||||
'<tr>'+'<td>'+name+'</td>' + '<td>'+value+'</td>'+'</tr>'
|
||||
);
|
||||
}
|
||||
var cookies = result.cookie||[];
|
||||
var cookies = requestObj.cookie||[];
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var name = getNotEmptyStr(cookies[i].name);
|
||||
var value = getNotEmptyStr(cookies[i].value);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* swagger-mg-ui是swagger-ui的一个前端实现,使用简单、解析速度快、走心的设计
|
||||
* zyplayer-doc-swagger是swagger-ui的一个前端实现,使用简单、解析速度快、走心的设计
|
||||
* 支持多项目同时展示,多种文档目录的展示方案,多种自定义配置,满足各种使用习惯。
|
||||
* 使用中您有任何的意见和建议都可到源码地址处反馈哦!
|
||||
* git地址:https://gitee.com/zyplayer/swagger-mg-ui
|
||||
* git地址:https://gitee.com/zyplayer/zyplayer-doc-swagger
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年5月20日
|
||||
*/
|
||||
@@ -873,11 +873,11 @@ function changeContentWidth(width) {
|
||||
$("#leftContent").css("width", width + 'px');
|
||||
$("#resizebleLeftRight").css("left", width + 'px');
|
||||
$("#rightContent").css("left", width + 'px');
|
||||
var logoText = "swagger-mg-ui";
|
||||
if(width < 270 && width > 140){
|
||||
logoText = "mg-ui";
|
||||
} else if(width < 140){
|
||||
logoText = "mui";
|
||||
var logoText = "zyplayer-doc-swagger";
|
||||
if(width < 370 && width > 290){
|
||||
logoText = "zyplayer-doc";
|
||||
} else if(width < 290){
|
||||
logoText = "doc";
|
||||
}
|
||||
$("#logoText").text(logoText);
|
||||
userSettings.prevWNow = width;
|
||||
|
||||
Reference in New Issue
Block a user