mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-04 01:52:21 +08:00
fix:修复项目异常
This commit is contained in:
parent
c616af407f
commit
664b03e2c9
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-database</artifactId>
|
<artifactId>common-mybatis</artifactId>
|
||||||
<version>${youlai.version}</version>
|
<version>${youlai.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-database</artifactId>
|
<artifactId>common-mybatis</artifactId>
|
||||||
<version>${youlai.version}</version>
|
<version>${youlai.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -31,33 +31,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
// 登录失败处理handler,返回一段json
|
// 登录失败处理handler,返回一段json
|
||||||
http
|
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()
|
.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()
|
||||||
.and()
|
.and()
|
||||||
.authorizeRequests().antMatchers("/oauth/public_key", "/oauth/logout").permitAll().anyRequest().authenticated()
|
.authorizeRequests().antMatchers("/oauth/public_key", "/oauth/logout").permitAll().anyRequest().authenticated()
|
||||||
@ -74,32 +47,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
return super.authenticationManagerBean();
|
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
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public PasswordEncoder passwordEncoder() {
|
||||||
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||||
|
30
youlai-common/common-mybatis/pom.xml
Normal file
30
youlai-common/common-mybatis/pom.xml
Normal 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>
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
com.youlai.common.mybatis.config.MybatisPlusConfig
|
@ -18,7 +18,7 @@
|
|||||||
<module>common-knife4j</module>
|
<module>common-knife4j</module>
|
||||||
<module>common-redis</module>
|
<module>common-redis</module>
|
||||||
<module>common-web</module>
|
<module>common-web</module>
|
||||||
<module>common-database</module>
|
<module>common-mybatis</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -118,7 +118,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-database</artifactId>
|
<artifactId>common-mybatis</artifactId>
|
||||||
<version>${youlai.version}</version>
|
<version>${youlai.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user