mirror of
https://gitee.com/jamen/slife.git
synced 2026-11-18 22:53:38 +00:00
2.0 first build
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.4.RELEASE</version>
|
||||
<version>2.0.5.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
|
||||
<!--版本说明-->
|
||||
<properties>
|
||||
<ehcache.core.version>2.6.11</ehcache.core.version>
|
||||
@@ -26,7 +27,7 @@
|
||||
<commons-lang3.version>3.4</commons-lang3.version>
|
||||
<slife.version>1.0-SNAPSHOT</slife.version>
|
||||
<swagger.version>2.7.0</swagger.version>
|
||||
<druid.version>1.1.1</druid.version>
|
||||
<!--<druid.version>1.1.1</druid.version>-->
|
||||
<mybatis-plus.version>2.1.0</mybatis-plus.version>
|
||||
<activiti.version>5.22.0</activiti.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
@@ -57,6 +58,21 @@
|
||||
<!--全局依赖-->
|
||||
<dependencies>
|
||||
|
||||
<!-- 新依赖start -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.14</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring-boot-starter</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 新依赖end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@@ -90,17 +106,17 @@
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.apache.shiro</groupId>-->
|
||||
<!--<artifactId>shiro-core</artifactId>-->
|
||||
<!--<version>${shiro.version}</version>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.apache.shiro</groupId>-->
|
||||
<!--<artifactId>shiro-spring</artifactId>-->
|
||||
<!--<version>${shiro.version}</version>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<!--缓存-->
|
||||
<dependency>
|
||||
@@ -134,10 +150,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.session</groupId>
|
||||
<artifactId>spring-session-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.session</groupId>-->
|
||||
<!--<artifactId>spring-session-data-redis</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -161,10 +177,10 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.alibaba</groupId>-->
|
||||
<!--<artifactId>druid</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -221,11 +237,11 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.alibaba</groupId>-->
|
||||
<!--<artifactId>druid</artifactId>-->
|
||||
<!--<version>${druid.version}</version>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
@@ -340,7 +356,4 @@
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -8,6 +8,7 @@ import com.slife.service.ISysRoleService;
|
||||
import com.slife.service.ISysUserService;
|
||||
import com.slife.util.ApplicationContextRegister;
|
||||
import com.slife.util.Encodes;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
@@ -15,29 +16,15 @@ import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.util.ByteSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/7/14.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
* @author felixu
|
||||
* @date 2019.03.14
|
||||
*/
|
||||
|
||||
@Component(value = "authRealm")
|
||||
@Slf4j
|
||||
public class AuthRealm extends AuthorizingRealm {
|
||||
|
||||
|
||||
|
||||
private Logger logger= LoggerFactory.getLogger(getClass());
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设定密码校验的Hash算法与迭代次数
|
||||
*/
|
||||
@@ -46,7 +33,7 @@ public class AuthRealm extends AuthorizingRealm {
|
||||
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(Setting.HASH_ALGORITHM);
|
||||
matcher.setHashIterations(Setting.HASH_INTERATIONS);
|
||||
setCredentialsMatcher(matcher);
|
||||
logger.info("---------密码校验器 -matcher----------------");
|
||||
log.info("---------密码校验器 -matcher----------------");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +45,7 @@ public class AuthRealm extends AuthorizingRealm {
|
||||
ISysUserService sysUserService = ApplicationContextRegister.getBean(ISysUserService.class);
|
||||
SysUser sysUser = sysUserService.getByLoginName(loginName);
|
||||
if (sysUser != null) {
|
||||
logger.info(sysUser.getName()+"登录");
|
||||
log.info(sysUser.getName() + "登录");
|
||||
if (Global.NO.equals(sysUser.getLoginFlag())) {
|
||||
throw new DisabledAccountException();
|
||||
}
|
||||
@@ -67,7 +54,7 @@ public class AuthRealm extends AuthorizingRealm {
|
||||
sysUser.getPassword().substring(16), ByteSource.Util.bytes(salt),
|
||||
getName());
|
||||
} else {
|
||||
logger.info(sysUser.getName()+"登录失败");
|
||||
log.info(sysUser.getName()+"登录失败");
|
||||
throw new UnknownAccountException();
|
||||
}
|
||||
}
|
||||
@@ -77,7 +64,7 @@ public class AuthRealm extends AuthorizingRealm {
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
logger.info("登录授权");
|
||||
log.info("登录授权");
|
||||
ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
|
||||
|
||||
+17
-19
@@ -25,11 +25,11 @@
|
||||
<dependencies>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.drtrang</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.github.drtrang</groupId>-->
|
||||
<!--<artifactId>druid-spring-boot-starter</artifactId>-->
|
||||
<!--<version>1.0.2</version>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
|
||||
<dependency>
|
||||
@@ -38,15 +38,15 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-code</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.slife</groupId>-->
|
||||
<!--<artifactId>slife-code</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-drools</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.slife</groupId>-->
|
||||
<!--<artifactId>slife-drools</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
@@ -64,10 +64,10 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
<artifactId>slife-activiti</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.slife</groupId>-->
|
||||
<!--<artifactId>slife-activiti</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -79,6 +79,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(scanBasePackages = "com.slife")
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.slife.dao")//@Mapper 在mapper 接口上加入也行
|
||||
public class WebApplication {
|
||||
|
||||
+28
-28
@@ -37,44 +37,44 @@ public class CacheConfig {
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Bean(name = "slifeRedisCacheManager")
|
||||
@Primary
|
||||
public SlifeRedisCacheManager slifeRedisCacheManager() {
|
||||
logger.info("--------------redis cache init---------------");
|
||||
SlifeRedisCacheManager slifeRedisCacheManager = new SlifeRedisCacheManager();
|
||||
slifeRedisCacheManager.setRedisTemplate(redisTemplate);
|
||||
logger.info("--------------redis cache ---------------" + slifeRedisCacheManager);
|
||||
return slifeRedisCacheManager;
|
||||
}
|
||||
// @Bean(name = "slifeRedisCacheManager")
|
||||
// @Primary
|
||||
// public SlifeRedisCacheManager slifeRedisCacheManager() {
|
||||
// logger.info("--------------redis cache init---------------");
|
||||
// SlifeRedisCacheManager slifeRedisCacheManager = new SlifeRedisCacheManager();
|
||||
// slifeRedisCacheManager.setRedisTemplate(redisTemplate);
|
||||
// logger.info("--------------redis cache ---------------" + slifeRedisCacheManager);
|
||||
// return slifeRedisCacheManager;
|
||||
// }
|
||||
|
||||
|
||||
@Bean(name = "redisCacheManager")
|
||||
@Primary
|
||||
public RedisCacheManager redisCacheManager() {
|
||||
logger.info("--------------redis cache init---------------");
|
||||
RedisCacheManager redisCacheManager = new RedisCacheManager();
|
||||
redisCacheManager.setRedisManager(redisManager());
|
||||
logger.info("--------------redis cache ---------------" + redisCacheManager);
|
||||
return redisCacheManager;
|
||||
}
|
||||
// @Bean(name = "redisCacheManager")
|
||||
// @Primary
|
||||
// public RedisCacheManager redisCacheManager() {
|
||||
// logger.info("--------------redis cache init---------------");
|
||||
// RedisCacheManager redisCacheManager = new RedisCacheManager();
|
||||
// redisCacheManager.setRedisManager(redisManager());
|
||||
// logger.info("--------------redis cache ---------------" + redisCacheManager);
|
||||
// return redisCacheManager;
|
||||
// }
|
||||
|
||||
|
||||
@Value("${spring.redis.host}")
|
||||
private String host;
|
||||
@Value("${spring.redis.password}")
|
||||
private String password;
|
||||
// @Value("${spring.redis.password}")
|
||||
// private String password;
|
||||
@Value("${spring.redis.port}")
|
||||
private int port;
|
||||
@Value("${spring.redis.database}")
|
||||
private int database;
|
||||
|
||||
public RedisManager redisManager() {
|
||||
RedisManager redisManager = new RedisManager();
|
||||
redisManager.setHost(host);
|
||||
redisManager.setPassword(password);
|
||||
redisManager.setPort(port);
|
||||
redisManager.setDatabase(database);
|
||||
return redisManager;
|
||||
}
|
||||
// public RedisManager redisManager() {
|
||||
// RedisManager redisManager = new RedisManager();
|
||||
// redisManager.setHost(host);
|
||||
//// redisManager.setPassword(password);
|
||||
// redisManager.setPort(port);
|
||||
// redisManager.setDatabase(database);
|
||||
// return redisManager;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,83 +1,77 @@
|
||||
package com.slife.config.mvc;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.serializer.ToStringSerializer;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.slife.config.sitemesh.WebSiteMeshFilter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
|
||||
import org.springframework.boot.web.servlet.ErrorPage;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/7/17.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
//@EnableWebMvc
|
||||
public class MvcConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Value("${attach_path}")
|
||||
private String attachPath;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/attach/**").addResourceLocations("file:"+attachPath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 装饰器
|
||||
*
|
||||
* @return 2016年8月27日下午12:37:20
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean siteMeshFilter() {
|
||||
FilterRegistrationBean fitler = new FilterRegistrationBean();
|
||||
WebSiteMeshFilter siteMeshFilter = new WebSiteMeshFilter();
|
||||
fitler.setFilter(siteMeshFilter);
|
||||
return fitler;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EmbeddedServletContainerCustomizer containerCustomizer() {
|
||||
return new EmbeddedServletContainerCustomizer() {
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
container.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400.html"));
|
||||
container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html"));
|
||||
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
|
||||
FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
|
||||
FastJsonConfig fjc = new FastJsonConfig();
|
||||
//1、序列化重点
|
||||
fjc.setSerializerFeatures(SerializerFeature.BrowserCompatible);
|
||||
fastJsonConverter.setFastJsonConfig(fjc);
|
||||
converters.add(fastJsonConverter);
|
||||
}
|
||||
|
||||
}
|
||||
//package com.slife.config.mvc;
|
||||
//import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
//
|
||||
//import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
//import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
//import com.slife.config.sitemesh.WebSiteMeshFilter;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.boot.web.server.ErrorPage;
|
||||
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.converter.HttpMessageConverter;
|
||||
//import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * Created by chen on 2017/7/17.
|
||||
// * <p>
|
||||
// * Email 122741482@qq.com
|
||||
// * <p>
|
||||
// * Describe:
|
||||
// */
|
||||
//
|
||||
////@Configuration
|
||||
////@EnableWebMvc
|
||||
//public class MvcConfiguration extends WebMvcConfigurerAdapter {
|
||||
//
|
||||
// @Value("${attach_path}")
|
||||
// private String attachPath;
|
||||
//
|
||||
// @Override
|
||||
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// registry.addResourceHandler("/attach/**").addResourceLocations("file:"+attachPath);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 装饰器
|
||||
// *
|
||||
// * @return 2016年8月27日下午12:37:20
|
||||
// */
|
||||
// @Bean
|
||||
// public FilterRegistrationBean siteMeshFilter() {
|
||||
// FilterRegistrationBean fitler = new FilterRegistrationBean();
|
||||
// WebSiteMeshFilter siteMeshFilter = new WebSiteMeshFilter();
|
||||
// fitler.setFilter(siteMeshFilter);
|
||||
// return fitler;
|
||||
// }
|
||||
//
|
||||
//// @Bean
|
||||
//// public EmbeddedServletContainerCustomizer containerCustomizer() {
|
||||
//// return new EmbeddedServletContainerCustomizer() {
|
||||
//// @Override
|
||||
//// public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
//// container.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400.html"));
|
||||
//// container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html"));
|
||||
//// container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
|
||||
////
|
||||
//// }
|
||||
//// };
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
//
|
||||
// FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
|
||||
// FastJsonConfig fjc = new FastJsonConfig();
|
||||
// //1、序列化重点
|
||||
// fjc.setSerializerFeatures(SerializerFeature.BrowserCompatible);
|
||||
// fastJsonConverter.setFastJsonConfig(fjc);
|
||||
// converters.add(fastJsonConverter);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.slife.config.mvc;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.slife.config.sitemesh.WebSiteMeshFilter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.server.ErrorPage;
|
||||
import org.springframework.boot.web.server.ErrorPageRegistrar;
|
||||
import org.springframework.boot.web.server.ErrorPageRegistry;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.filter.DelegatingFilterProxy;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author felixu
|
||||
* @date 2019.03.14
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${attach_path}")
|
||||
private String attachPath;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/attach/**").
|
||||
addResourceLocations("file:" + attachPath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 装饰器
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean siteMeshFilter() {
|
||||
FilterRegistrationBean fitler = new FilterRegistrationBean();
|
||||
WebSiteMeshFilter siteMeshFilter = new WebSiteMeshFilter();
|
||||
fitler.setFilter(siteMeshFilter);
|
||||
return fitler;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ErrorPageRegistrar errorPageRegistrar(){
|
||||
return new MyErrorPageRegistrar();
|
||||
}
|
||||
|
||||
private static class MyErrorPageRegistrar implements ErrorPageRegistrar {
|
||||
@Override
|
||||
public void registerErrorPages(ErrorPageRegistry registry) {
|
||||
registry.addErrorPages(
|
||||
new ErrorPage(HttpStatus.BAD_REQUEST, "/400.html"),
|
||||
new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html"),
|
||||
new ErrorPage(HttpStatus.NOT_FOUND, "/404.html")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
|
||||
FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
|
||||
FastJsonConfig fjc = new FastJsonConfig();
|
||||
//1、序列化重点
|
||||
fjc.setSerializerFeatures(SerializerFeature.BrowserCompatible);
|
||||
fastJsonConverter.setFastJsonConfig(fjc);
|
||||
converters.add(fastJsonConverter);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.slife.config.session;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
||||
|
||||
/**
|
||||
* Created by chen on 2018/1/3.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@Configuration
|
||||
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 86400*30) //maxInactiveIntervalInSeconds: 设置Session失效时间,使用Redis Session之后,原Boot的server.session.timeout属性不再生效
|
||||
public class SessionConfig {
|
||||
}
|
||||
//package com.slife.config.session;
|
||||
//
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
||||
//
|
||||
///**
|
||||
// * Created by chen on 2018/1/3.
|
||||
// * <p>
|
||||
// * Email 122741482@qq.com
|
||||
// * <p>
|
||||
// * Describe:
|
||||
// */
|
||||
//@Configuration
|
||||
//@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 86400*30) //maxInactiveIntervalInSeconds: 设置Session失效时间,使用Redis Session之后,原Boot的server.session.timeout属性不再生效
|
||||
//public class SessionConfig {
|
||||
//}
|
||||
|
||||
@@ -11,6 +11,8 @@ package com.slife.config.shiro;
|
||||
import com.slife.shiro.AuthRealm;
|
||||
import org.apache.shiro.cache.CacheManager;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.mgt.SessionsSecurityManager;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
@@ -19,10 +21,13 @@ import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.apache.shiro.web.servlet.SimpleCookie;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.filter.DelegatingFilterProxy;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import java.util.EnumSet;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
@@ -34,11 +39,35 @@ import java.util.LinkedHashMap;
|
||||
@Configuration
|
||||
public class ShiroConfig {
|
||||
|
||||
private Logger logger = org.slf4j.LoggerFactory.getLogger(getClass());
|
||||
|
||||
private Logger logger = org.slf4j.LoggerFactory.getLogger(getClass());
|
||||
// @Bean
|
||||
// public FilterRegistrationBean delegatingFilterProxy(){
|
||||
// FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
|
||||
// DelegatingFilterProxy proxy = new DelegatingFilterProxy();
|
||||
// proxy.setTargetFilterLifecycle(true);
|
||||
// proxy.setTargetBeanName("shiroFilter");
|
||||
// filterRegistrationBean.setFilter(proxy);
|
||||
// return filterRegistrationBean;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
|
||||
public FilterRegistrationBean<DelegatingFilterProxy> delegatingFilterProxy(){
|
||||
FilterRegistrationBean<DelegatingFilterProxy> filterRegistrationBean = new FilterRegistrationBean<>();
|
||||
DelegatingFilterProxy proxy = new DelegatingFilterProxy();
|
||||
proxy.setTargetFilterLifecycle(true);
|
||||
proxy.setTargetBeanName("shiroFilter");
|
||||
filterRegistrationBean.setFilter(proxy);
|
||||
filterRegistrationBean.setEnabled(true);
|
||||
filterRegistrationBean.addUrlPatterns("/*");
|
||||
//filterRegistrationBean.setAsyncSupported(true);
|
||||
EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
|
||||
filterRegistrationBean.setDispatcherTypes(types);
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
|
||||
//SecurityManager manager= securityManager(authRealm);
|
||||
ShiroFilterFactoryBean bean=new ShiroFilterFactoryBean();
|
||||
bean.setSecurityManager(securityManager);
|
||||
@@ -83,13 +112,32 @@ public class ShiroConfig {
|
||||
filterChainDefinitionMap.put("/*.*", "authc");
|
||||
bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
||||
return bean;
|
||||
}
|
||||
|
||||
// TODO: 2019-03-14 可配置的cache
|
||||
// /**
|
||||
// * 创建自定义的AuthorizingRealm
|
||||
// * 关于缓存可以选择使用Ehcache或者Redis
|
||||
// * {@link org.apache.shiro.cache.ehcache.EhCacheManager}
|
||||
// * {@link RedisCacheManager}
|
||||
// * {@link CacheConfig}
|
||||
// *
|
||||
// * @param cacheManager 这里注入接口,在yaml文件中配置具体使用Ehcache还是Redis. {@link CacheConfig}
|
||||
// * @return AuthorizingRealm
|
||||
// */
|
||||
@Bean
|
||||
public AuthorizingRealm authorizingRealm(CacheManager cacheManager) {
|
||||
AuthRealm realm = new AuthRealm();
|
||||
realm.setCacheManager(cacheManager);
|
||||
return realm;
|
||||
}
|
||||
|
||||
|
||||
//配置核心安全事务管理器
|
||||
@Bean
|
||||
public SecurityManager securityManager(@Qualifier("authRealm")AuthRealm authRealm,@Qualifier("redisCacheManager")CacheManager
|
||||
cacheManager) {
|
||||
// public SecurityManager securityManager(@Qualifier("authRealm")AuthRealm authRealm,@Qualifier("redisCacheManager")CacheManager
|
||||
// cacheManager) {
|
||||
public SessionsSecurityManager securityManager(AuthorizingRealm authRealm) {
|
||||
|
||||
logger.info("--------------shiro已经加载----------------");
|
||||
DefaultWebSecurityManager manager=new DefaultWebSecurityManager();
|
||||
@@ -98,7 +146,7 @@ public class ShiroConfig {
|
||||
|
||||
//注入缓存管理器;
|
||||
//注意:开发时请先关闭,如不关闭热启动会报错
|
||||
manager.setCacheManager(cacheManager);//这个如果执行多次,也是同样的一个对象;
|
||||
// manager.setCacheManager(cacheManager);//这个如果执行多次,也是同样的一个对象;
|
||||
//注入记住我管理器;
|
||||
manager.setRememberMeManager(rememberMeManager());
|
||||
|
||||
|
||||
@@ -19,16 +19,15 @@ spring:
|
||||
|
||||
redis:
|
||||
database: 0
|
||||
host: 1.1.1.2
|
||||
host: localhost
|
||||
port: 6379
|
||||
timeout: 6000ms
|
||||
password: 123456
|
||||
pool:
|
||||
max-active: 8
|
||||
max-wait: -1
|
||||
max-idle: 18
|
||||
min-idle: 0
|
||||
timeout: 0
|
||||
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 1000
|
||||
max-idle: 100
|
||||
min-idle: 20
|
||||
|
||||
sitemesh:
|
||||
contentPath: /*
|
||||
@@ -60,7 +59,7 @@ mybatis-plus:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: false
|
||||
security:
|
||||
basic:
|
||||
enabled: false
|
||||
#security:
|
||||
# basic:
|
||||
# enabled: false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user