mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 20:54:26 +08:00
fix(AuthExceptionHandler.java): 用户名密码自定义异常抛出
This commit is contained in:
parent
877c4f0035
commit
3e6819cdf8
@ -37,7 +37,7 @@ public class AuthExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(InvalidGrantException.class)
|
||||
public Result handleInvalidGrantException(InvalidGrantException e) {
|
||||
return Result.failed(e.getMessage());
|
||||
return Result.failed(ResultCode.USERNAME_OR_PASSWORD_ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests().antMatchers("/oauth/**","/sms-code").permitAll()
|
||||
.authorizeRequests().antMatchers("/oauth/**", "/sms-code").permitAll()
|
||||
// @link https://gitee.com/xiaoym/knife4j/issues/I1Q5X6 (接口文档knife4j需要放行的规则)
|
||||
.antMatchers("/webjars/**", "/doc.html", "/swagger-resources/**", "/v2/api-docs").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
@ -56,9 +56,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(AuthenticationManagerBuilder auth) {
|
||||
auth.authenticationProvider(wechatAuthenticationProvider());
|
||||
auth.authenticationProvider(daoAuthenticationProvider());
|
||||
auth.authenticationProvider(smsCodeAuthenticationProvider());
|
||||
auth.authenticationProvider(wechatAuthenticationProvider()).
|
||||
authenticationProvider(daoAuthenticationProvider()).
|
||||
authenticationProvider(smsCodeAuthenticationProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,14 +97,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Bean
|
||||
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setHideUserNotFoundExceptions(false); // 是否隐藏用户不存在异常,默认:true-隐藏;false-抛出异常;
|
||||
provider.setUserDetailsService(sysUserDetailsService);
|
||||
provider.setPasswordEncoder(passwordEncoder());
|
||||
provider.setHideUserNotFoundExceptions(false); // 是否隐藏用户不存在异常,默认:true-隐藏;false-抛出异常;
|
||||
return provider;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 密码编码器
|
||||
* <p>
|
||||
|
@ -84,6 +84,7 @@ public class CaptchaTokenGranter extends AbstractTokenGranter {
|
||||
throw new InvalidGrantException(var9.getMessage());
|
||||
}
|
||||
|
||||
|
||||
if (userAuth != null && userAuth.isAuthenticated()) {
|
||||
OAuth2Request storedOAuth2Request = this.getRequestFactory().createOAuth2Request(client, tokenRequest);
|
||||
return new OAuth2Authentication(storedOAuth2Request, userAuth);
|
||||
|
Loading…
Reference in New Issue
Block a user