fix:修复项目异常

This commit is contained in:
haoxr 2020-11-18 17:14:47 +08:00
parent c616af407f
commit 664b03e2c9
8 changed files with 92 additions and 57 deletions

View File

@ -37,7 +37,7 @@
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-database</artifactId>
<artifactId>common-mybatis</artifactId>
<version>${youlai.version}</version>
</dependency>

View File

@ -30,7 +30,7 @@
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-database</artifactId>
<artifactId>common-mybatis</artifactId>
<version>${youlai.version}</version>
</dependency>

View File

@ -31,33 +31,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
// 登录失败处理handler返回一段json
http
.formLogin().failureHandler(
(req, resp, e) -> {
resp.setContentType("application/json;charset=utf-8");
PrintWriter out = resp.getWriter();
Map<String, Object> map = new HashMap<>();
map.put("status", 401);
if (e instanceof LockedException) {
map.put("msg", "账户被锁定,登录失败!");
} else if (e instanceof BadCredentialsException) {
map.put("msg", "用户名或密码输入错误,登录失败!");
} else if (e instanceof DisabledException) {
map.put("msg", "账户被禁用,登录失败!");
} else if (e instanceof AccountExpiredException) {
map.put("msg", "账户过期,登录失败!");
} else if (e instanceof CredentialsContainer) {
map.put("msg", "密码过期,登录失败");
} else {
map.put("msg", "登录失败!");
}
out.write(new ObjectMapper().writeValueAsString(map));
out.flush();
out.close();
}
)
.and()
.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()
.and()
.authorizeRequests().antMatchers("/oauth/public_key", "/oauth/logout").permitAll().anyRequest().authenticated()
@ -74,32 +47,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
return super.authenticationManagerBean();
}
@Bean
AuthenticationFailureHandler authenticationFailureHandler() {
return (request, response, e) -> {
/*
if (!user.isEnabled()) {
throw new DisabledException("该账户已被禁用!");
} else if (!user.isAccountNonLocked()) {
throw new LockedException("该账号已被锁定!");
} else if (!user.isAccountNonExpired()) {
throw new AccountExpiredException("该账号已过期!");
} else if (!user.isCredentialsNonExpired()) {
throw new CredentialsExpiredException("该账户的登录凭证已过期,请重新登录!");
}
*/
if (e instanceof DisabledException) {
log.info(e.getMessage());
} else if (e instanceof LockedException) {
log.info(e.getMessage());
} else if (e instanceof AccountExpiredException) {
log.info(e.getMessage());
}
};
}
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>youlai-common</artifactId>
<groupId>com.youlai</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>common-mybatis</artifactId>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,33 @@
package com.youlai.common.mybatis.config;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.youlai.common.mybatis.handler.MetaHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
public class MybatisPlusConfig {
/**
* 分页插件自动识别数据库类型 多租户请参考官网插件扩展
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
/**
* 自动填充数据库创建人创建时间更新人更新时间
*/
@Bean
public GlobalConfig globalConfig() {
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setMetaObjectHandler(new MetaHandler());
return globalConfig;
}
}

View File

@ -0,0 +1,23 @@
package com.youlai.common.mybatis.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class MetaHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("gmtCreate", new Date(), metaObject);
this.setFieldValByName("gmtModified", new Date(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("gmtCreate", new Date(), metaObject);
}
}

View File

@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.youlai.common.mybatis.config.MybatisPlusConfig

View File

@ -18,7 +18,7 @@
<module>common-knife4j</module>
<module>common-redis</module>
<module>common-web</module>
<module>common-database</module>
<module>common-mybatis</module>
</modules>
<properties>
@ -118,7 +118,7 @@
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-database</artifactId>
<artifactId>common-mybatis</artifactId>
<version>${youlai.version}</version>
</dependency>