取消main模块git关联
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
package com.adc.da;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@EnableEurekaClient
|
||||
@EnableFeignClients
|
||||
@ServletComponentScan
|
||||
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
|
||||
@MapperScan(value = {"com.adc.da.file.store"})
|
||||
public class AdcDaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdcDaApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.adc.da;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
/**
|
||||
* Springboot打war包的启动口
|
||||
*/
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||
// 注意这里要指向原先用main方法执行的Application启动类
|
||||
return builder.sources(AdcDaApplication.class);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.adc.da.main.advice;
|
||||
|
||||
import com.adc.da.exception.AdcDaBaseException;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.ResponseMessageCodeEnum;
|
||||
import com.adc.da.http.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
@Order(value=4)
|
||||
public class AdcDaBaseExceptionAdvice {
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ExceptionHandler(AdcDaBaseException.class)
|
||||
@ResponseBody
|
||||
public ResponseMessage handlerAdcDaBaseException(AdcDaBaseException exception) {
|
||||
log.warn(exception.getMessage(), exception);
|
||||
return Result.error(exception.getErrorCode(), exception.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public ResponseMessage handlerAdcDaBaseException(Exception exception) {
|
||||
log.error(exception.getMessage(), exception);
|
||||
// TODO 在数据库中记录程序异常,这个地方的异常是未处理的异常,需要管理员查看并进行处理以防重复出现
|
||||
return Result.error(ResponseMessageCodeEnum.ERROR.getCode(), "程序异常,请重试。如果重复出现请联系管理员处理!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.adc.da.main.advice;
|
||||
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authz.UnauthenticatedException;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
@Order(value=2)
|
||||
public class ShiroExceptionAdvice {
|
||||
|
||||
|
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||
@ExceptionHandler({AuthenticationException.class, UnknownAccountException.class,
|
||||
UnauthenticatedException.class, IncorrectCredentialsException.class})
|
||||
@ResponseBody
|
||||
public ResponseMessage unauthorized(Exception exception) {
|
||||
log.warn(exception.getMessage(), exception);
|
||||
log.info("catch UnknownAccountException");
|
||||
return Result.error("A404", "无权访问");
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||
@ExceptionHandler(UnauthorizedException.class)
|
||||
@ResponseBody
|
||||
public ResponseMessage unauthorized1(UnauthorizedException exception) {
|
||||
log.warn(exception.getMessage(), exception);
|
||||
return Result.error("A404","无权访问");
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.adc.da.main.config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* shiro 自定义URL规则设置
|
||||
*/
|
||||
public class DefinitionUrlConfig {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 匿名用户,无需登录
|
||||
*/
|
||||
private static final String ANON = "anon";
|
||||
|
||||
|
||||
|
||||
// 拦截器
|
||||
//rest:比如/admins/user/**=rest[user],根据请求的方法,相当于/admins/user/**=perms[user:method] ,其中method为post,get,delete等。
|
||||
//port:比如/admins/user/**=port[8081],当请求的url的端口不是8081是跳转到schemal://serverName:8081?queryString,其中schmal是协议http或https等,serverName是你访问的host,8081是url配置里port的端口,queryString是你访问的url里的?后面的参数。
|
||||
//perms:比如/admins/user/**=perms[user:add:*],perms参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,比如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。
|
||||
//roles:比如/admins/user/**=roles[admin],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,当有多个参数时,比如/admins/user/**=roles["admin,guest"],每个参数通过才算通过,相当于hasAllRoles()方法。//要实现or的效果看http://zgzty.blog.163.com/blog/static/83831226201302983358670/
|
||||
//anon:比如/admins/**=anon 没有参数,表示可以匿名使用。
|
||||
//authc:比如/admins/user/**=authc表示需要认证才能使用,没有参数
|
||||
//authcBasic:比如/admins/user/**=authcBasic没有参数表示httpBasic认证
|
||||
//ssl:比如/admins/user/**=ssl没有参数,表示安全的url请求,协议为https
|
||||
//user:比如/admins/user/**=user没有参数表示必须存在用户,当登入操作时不做检查
|
||||
public static Map<String,String> definitionUrlOptions(){
|
||||
Map<String, String> filterRuleMap = new LinkedHashMap<>();
|
||||
//TODO 此处设置URL过滤规则 默认是全部请求进行拦截,此处设置为不拦截的URL地址
|
||||
filterRuleMap.put("/api/login",ANON);//登录接口
|
||||
// swagger接口文档
|
||||
filterRuleMap.put("/v2/api-docs", "anon");
|
||||
filterRuleMap.put("/webjars/**", "anon");
|
||||
filterRuleMap.put("/swagger-resources/**", "anon");
|
||||
filterRuleMap.put("/swagger-ui.html", "anon");
|
||||
filterRuleMap.put("/doc.html", "anon");
|
||||
return filterRuleMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.adc.da.main.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* Mybatis Plus 配置
|
||||
*/
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
@MapperScan("com.adc.da.**.dao")
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.adc.da.main.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* restTemplate设置
|
||||
*/
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RestTemplateConfig.class);
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
|
||||
RestTemplate restTemplate = new RestTemplate(factory);
|
||||
// 使用 utf-8 编码集的 conver 替换默认的 conver(默认的 string conver 的编码集为"ISO-8859-1")
|
||||
List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
|
||||
Iterator<HttpMessageConverter<?>> iterator = messageConverters.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
HttpMessageConverter<?> converter = iterator.next();
|
||||
if (converter instanceof StringHttpMessageConverter) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
messageConverters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
|
||||
|
||||
return restTemplate;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setReadTimeout(50000);//单位为ms
|
||||
factory.setConnectTimeout(50000);//单位为ms
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package com.adc.da.main.config;
|
||||
|
||||
import com.adc.da.login.security.JWTFilter;
|
||||
import com.adc.da.login.security.JWTRealm;
|
||||
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
||||
import org.apache.shiro.mgt.DefaultSecurityManager;
|
||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
||||
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@Order(value=1)
|
||||
public class ShiroConfig {
|
||||
|
||||
private static final String JWT_FILTER_NAME = "jwt";
|
||||
|
||||
private static final String URL_SUFFIX="/api";
|
||||
|
||||
/**
|
||||
* 自定义realm,实现登录授权流程
|
||||
* @return
|
||||
*/
|
||||
@Bean(name="jwtRealm")
|
||||
public JWTRealm jwtRealm() {
|
||||
return new JWTRealm();
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置securityManager 管理subject(默认),并把自定义realm交由manager
|
||||
*/
|
||||
@Bean
|
||||
public DefaultSecurityManager securityManager() {
|
||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||
// 设置realm.
|
||||
securityManager.setRealm(jwtRealm());
|
||||
//注入缓存管理器
|
||||
securityManager.setCacheManager(ehCacheManager());
|
||||
/*
|
||||
* 关闭shiro自带的session,详情见文档
|
||||
* http://shiro.apache.org/session-management.html#SessionManagement-StatelessApplications%28Sessionless%29
|
||||
*/
|
||||
DefaultSubjectDAO defaultSubjectDAO = new DefaultSubjectDAO();
|
||||
DefaultSessionStorageEvaluator storageEvaluator = new DefaultSessionStorageEvaluator();
|
||||
storageEvaluator.setSessionStorageEnabled(false);
|
||||
defaultSubjectDAO.setSessionStorageEvaluator(storageEvaluator);
|
||||
securityManager.setSubjectDAO(defaultSubjectDAO);
|
||||
|
||||
return securityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截链
|
||||
*/
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultSecurityManager securityManager) {
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||
shiroFilterFactoryBean.setFilters(filterMap());
|
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(definitionMap());
|
||||
|
||||
return shiroFilterFactoryBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义拦截器,处理所有请求
|
||||
*/
|
||||
private Map<String, Filter> filterMap() {
|
||||
Map<String, Filter> filterMap = new HashMap<>();
|
||||
filterMap.put(JWT_FILTER_NAME, new JWTFilter());
|
||||
return filterMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* url拦截规则
|
||||
*/
|
||||
private Map<String, String> definitionMap() {
|
||||
// 拦截器
|
||||
//rest:比如/admins/user/**=rest[user],根据请求的方法,相当于/admins/user/**=perms[user:method] ,其中method为post,get,delete等。
|
||||
//port:比如/admins/user/**=port[8081],当请求的url的端口不是8081是跳转到schemal://serverName:8081?queryString,其中schmal是协议http或https等,serverName是你访问的host,8081是url配置里port的端口,queryString是你访问的url里的?后面的参数。
|
||||
//perms:比如/admins/user/**=perms[user:add:*],perms参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,比如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。
|
||||
//roles:比如/admins/user/**=roles[admin],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,当有多个参数时,比如/admins/user/**=roles["admin,guest"],每个参数通过才算通过,相当于hasAllRoles()方法。//要实现or的效果看http://zgzty.blog.163.com/blog/static/83831226201302983358670/
|
||||
//anon:比如/admins/**=anon 没有参数,表示可以匿名使用。
|
||||
//authc:比如/admins/user/**=authc表示需要认证才能使用,没有参数
|
||||
//authcBasic:比如/admins/user/**=authcBasic没有参数表示httpBasic认证
|
||||
//ssl:比如/admins/user/**=ssl没有参数,表示安全的url请求,协议为https
|
||||
//user:比如/admins/user/**=user没有参数表示必须存在用户,当登入操作时不做检查
|
||||
Map<String, String> definitionMap = DefinitionUrlConfig.definitionUrlOptions();
|
||||
// definitionMap.put(URL_SUFFIX+"/**", JWT_FILTER_NAME);
|
||||
return definitionMap;
|
||||
}
|
||||
|
||||
/* *//**
|
||||
* 开启注解
|
||||
*//*
|
||||
@Bean
|
||||
@DependsOn("lifecycleBeanPostProcessor")
|
||||
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
|
||||
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
// 强制使用cglib代理,防止和aop冲突
|
||||
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
|
||||
return defaultAdvisorAutoProxyCreator;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 开启shiro aop注解支持. 使用代理方式; 所以需要开启代码支持;
|
||||
*
|
||||
* @param securityManager 安全管理器
|
||||
* @return 授权Advisor
|
||||
*/
|
||||
@Bean("authorizationAttributeSourceAdvisor")
|
||||
public AuthorizationAttributeSourceAdvisor advisor(DefaultSecurityManager securityManager) {
|
||||
AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
|
||||
advisor.setSecurityManager(securityManager);
|
||||
return advisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* shiro缓存管理器;
|
||||
* 需要注入对应的其它的实体类中:
|
||||
* 1、安全管理器:securityManager
|
||||
* 可见securityManager是整个shiro的核心;
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public EhCacheManager ehCacheManager() {
|
||||
EhCacheManager cacheManager = new EhCacheManager();
|
||||
cacheManager.setCacheManagerConfigFile("classpath:cache/ehcache.xml");
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.adc.da.main.config;
|
||||
|
||||
import com.adc.da.login.security.JWTRealm;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
||||
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
||||
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
|
||||
//@Configuration
|
||||
public class ShiroConfiguration {
|
||||
|
||||
@Bean(name = "ehCacheManagerFactoryBean")
|
||||
public EhCacheManagerFactoryBean ehCacheManagerFactoryBean() {
|
||||
EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
|
||||
ClassPathResource classPathResource = new ClassPathResource("cache/ehcache-local.xml");
|
||||
ehCacheManagerFactoryBean.setConfigLocation(classPathResource);
|
||||
return ehCacheManagerFactoryBean;
|
||||
}
|
||||
|
||||
@Bean(name = "shiroCacheManager")
|
||||
@DependsOn({ "ehCacheManagerFactoryBean" })
|
||||
public EhCacheManager shiroCacheManager() {
|
||||
EhCacheManager ehCacheManager = new EhCacheManager();
|
||||
ehCacheManager.setCacheManager(ehCacheManagerFactoryBean().getObject());
|
||||
return ehCacheManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn({ "lifecycleBeanPostProcessor" })
|
||||
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
|
||||
DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
proxyCreator.setProxyTargetClass(true);
|
||||
return proxyCreator;
|
||||
}
|
||||
|
||||
@Bean(name = "lifecycleBeanPostProcessor")
|
||||
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Bean(name = "securityManager")
|
||||
public SecurityManager securityManager() {
|
||||
DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager();
|
||||
defaultWebSecurityManager.setRealm(jwtRealm());
|
||||
|
||||
// 关闭shiro自带的session
|
||||
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
||||
DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
||||
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
||||
subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
|
||||
defaultWebSecurityManager.setSubjectDAO(subjectDAO);
|
||||
|
||||
// 自定义缓存管理器
|
||||
defaultWebSecurityManager.setCacheManager(shiroCacheManager());
|
||||
SecurityUtils.setSecurityManager(defaultWebSecurityManager);
|
||||
return defaultWebSecurityManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HashedCredentialsMatcher hashedCredentialsMatcher() {
|
||||
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
|
||||
hashedCredentialsMatcher.setHashAlgorithmName("md5");// 散列算法:这里使用MD5算法;
|
||||
hashedCredentialsMatcher.setHashIterations(2);// 散列的次数,比如散列两次,相当于
|
||||
// md5(md5(""));
|
||||
return hashedCredentialsMatcher;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JWTRealm jwtRealm() {
|
||||
JWTRealm jwtRealm = new JWTRealm();
|
||||
return jwtRealm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor() {
|
||||
AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
|
||||
advisor.setSecurityManager(securityManager());
|
||||
return advisor;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.adc.da.main.config;
|
||||
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.ParameterBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Parameter;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* swagger UI 配置we年
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableKnife4j
|
||||
@Import(BeanValidatorPluginsConfiguration.class)
|
||||
public class SwaggerConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public Docket createRestApiByDefault() {
|
||||
|
||||
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
tokenPar.name("Authorization")
|
||||
.description("令牌")
|
||||
.modelRef(new ModelRef("string"))
|
||||
.parameterType("header")
|
||||
.required(true)
|
||||
.build();
|
||||
pars.add(tokenPar.build());
|
||||
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.adc.da"))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.globalOperationParameters(pars).groupName("默认");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("FOTON-SLRS-SYSTEM-REST APIs")
|
||||
.description("标准法规1.0")
|
||||
.termsOfServiceUrl("http://localhost:8888/")
|
||||
.contact("developer@mail.com")
|
||||
.version("1.0.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.adc.da.main.config;
|
||||
|
||||
import com.adc.da.filter.*;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* Web配置,用于注入过滤器,拦截器等
|
||||
*/
|
||||
@Configuration
|
||||
@Order(value =3)
|
||||
public class WebConfig {
|
||||
|
||||
/**
|
||||
* xss过滤器(高标准)
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean xssFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
// registration.setFilter(new XssFilter());
|
||||
registration.setFilter(new WebFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("xssFilter");
|
||||
registration.setOrder(10);
|
||||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* xss过滤器(低标准)
|
||||
*/
|
||||
// @Bean
|
||||
// public FilterRegistrationBean xssShieldFilter() {
|
||||
// FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
// registration.setFilter(new XssShieldFilter());
|
||||
// registration.addUrlPatterns("/*");
|
||||
// registration.setName("xssShieldFilter");
|
||||
// registration.setOrder(10);
|
||||
// return registration;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean csrfFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
registration.setFilter(new CsrfFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("csrfFilter");
|
||||
registration.setOrder(9);
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean requestInfoFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
registration.setFilter(new RequestInfoFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("RequestInfoFilter");
|
||||
registration.setOrder(8);
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", buildConfig()); // 4
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
|
||||
private CorsConfiguration buildConfig() {
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.addAllowedOrigin("*"); // 1允许任何域名使用
|
||||
corsConfiguration.addAllowedHeader("*"); // 2允许任何头
|
||||
corsConfiguration.addAllowedMethod("*"); // 3允许任何方法(post、get等)
|
||||
return corsConfiguration;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean httpCacheFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
registration.setFilter(new HttpCacheFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("httpCacheFilter");
|
||||
registration.addInitParameter("maxAge", String.valueOf(60 * 60 * 24 * 7));
|
||||
registration.setOrder(6);
|
||||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 防伪造jsessionid
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean fakeJSessionIdFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
registration.setFilter(new FakeJSessionIdFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("fakeJSessionIdFilter");
|
||||
registration.setOrder(5);
|
||||
return registration;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.adc.da.main.filter;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class AuthFormAuthenticationFilter extends FormAuthenticationFilter {
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
httpServletResponse.setStatus(200);
|
||||
httpServletResponse.setContentType("application/json;charset=utf-8");
|
||||
PrintWriter out = httpServletResponse.getWriter();
|
||||
ResponseMessage responseMessage = Result.error("A404", "无权访问");
|
||||
out.print(JSONUtil.toJsonStr(responseMessage));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
package com.adc.da.main.generate;
|
||||
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CodeGen {
|
||||
|
||||
private static final String PACKAGE_PATH="/adc-da-slrs/src/main";
|
||||
|
||||
private static final String AUTHOR="super_liu";
|
||||
|
||||
// x.x.x.x:3306/xxxx --MYSQL
|
||||
// 192.168.10.140:1521:foton_slrs_test
|
||||
private static final String DB_IP="127.0.0.1:3306/foton_slrs_test";
|
||||
|
||||
private static final String DB_USER="root";
|
||||
|
||||
private static final String DB_PWD="Zxy20010202";
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 读取控制台内容
|
||||
* </p>
|
||||
*/
|
||||
public static String scanner(String tip) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
StringBuilder help = new StringBuilder();
|
||||
help.append("请输入" + tip + ":");
|
||||
System.out.println(help.toString());
|
||||
if (scanner.hasNext()) {
|
||||
String ipt = scanner.next();
|
||||
if (StringUtils.isNotEmpty(ipt)) {
|
||||
return ipt;
|
||||
}
|
||||
}
|
||||
throw new MybatisPlusException("请输入正确的" + tip + "!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + PACKAGE_PATH+"/java");
|
||||
gc.setAuthor(AUTHOR);
|
||||
gc.setOpen(false);
|
||||
gc.setSwagger2(true); //实体属性 Swagger2 注解
|
||||
gc.setMapperName("%sDao");
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置 ORACLE
|
||||
// DataSourceConfig dsc = new DataSourceConfig();
|
||||
// dsc.setUrl("jdbc:oracle:thin:@"+DB_IP);
|
||||
// // dsc.setSchemaName("public");
|
||||
// dsc.setDriverName("oracle.jdbc.OracleDriver");
|
||||
// dsc.setUsername(DB_USER);
|
||||
// dsc.setPassword(DB_PWD);
|
||||
// mpg.setDataSource(dsc);
|
||||
|
||||
// 数据源配置 MYSQL
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl("jdbc:mysql://"+DB_IP+"?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&useSSL=false");
|
||||
//dsc.setSchemaName("public");//PostgreSQL schemaName
|
||||
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
dsc.setUsername(DB_USER);
|
||||
dsc.setPassword(DB_PWD);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(scanner("模块名"));
|
||||
pc.setMapper("dao");
|
||||
pc.setParent("com.adc.da.slrs");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
// to do nothing
|
||||
}
|
||||
};
|
||||
|
||||
// 如果模板引擎是 freemarker
|
||||
String templatePath = "/templates/mapper.xml.ftl";
|
||||
// 如果模板引擎是 velocity
|
||||
// String templatePath = "/templates/mapper.xml.vm";
|
||||
|
||||
// 自定义输出配置
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
// 自定义配置会被优先输出
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
|
||||
return projectPath +PACKAGE_PATH+ "/resources/mybatis/mapper/" + pc.getModuleName()
|
||||
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
/*
|
||||
cfg.setFileCreate(new IFileCreate() {
|
||||
@Override
|
||||
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
|
||||
// 判断自定义文件夹是否需要创建
|
||||
checkDir("调用默认方法创建的目录");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
*/
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
// 配置模板
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
|
||||
// 配置自定义输出模板
|
||||
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
|
||||
templateConfig.setController("templates/controller.java");
|
||||
templateConfig.setMapper("templates/mapper.java");
|
||||
templateConfig.setEntity("templates/entity.java");
|
||||
templateConfig.setService("templates/service.java");
|
||||
templateConfig.setServiceImpl("templates/serviceImpl.java");
|
||||
templateConfig.setXml(null);
|
||||
mpg.setTemplate(templateConfig);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setSuperEntityClass("com.adc.da.base.entity.BaseEntity");
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
// 公共父类
|
||||
strategy.setSuperControllerClass("com.adc.da.base.web.BaseController");
|
||||
// 写于父类中的公共字段
|
||||
strategy.setSuperEntityColumns("id");
|
||||
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setTablePrefix(pc.getModuleName() + "_");
|
||||
mpg.setStrategy(strategy);
|
||||
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
||||
mpg.execute();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.adc.da.main.generate;
|
||||
|
||||
//import com.codemagic.DbCodeGenerateFactory;
|
||||
|
||||
public class CodeUtil {
|
||||
|
||||
public CodeUtil() {}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String entityPackage="sys";
|
||||
// DbCodeGenerateFactory.codeGenerate("ECP_CHANGE_HIS_PLAN", entityPackage);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user