mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-23 13:03:42 +08:00
!285 ♻️ Refactoring code. 手机号登录手机号不存在异常细化
Merge pull request !285 from lbw/auto-441246-dev-1c49ca8b
This commit is contained in:
commit
6e1fe4b0fd
@ -19,6 +19,8 @@ package com.pig4cloud.pig.auth.support.handler;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.pig4cloud.pig.admin.api.entity.SysLog;
|
import com.pig4cloud.pig.admin.api.entity.SysLog;
|
||||||
import com.pig4cloud.pig.common.core.constant.CommonConstants;
|
import com.pig4cloud.pig.common.core.constant.CommonConstants;
|
||||||
|
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||||
|
import com.pig4cloud.pig.common.core.util.MsgUtils;
|
||||||
import com.pig4cloud.pig.common.core.util.R;
|
import com.pig4cloud.pig.common.core.util.R;
|
||||||
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
|
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
|
||||||
import com.pig4cloud.pig.common.log.event.SysLogEvent;
|
import com.pig4cloud.pig.common.log.event.SysLogEvent;
|
||||||
@ -76,14 +78,25 @@ public class PigAuthenticationFailureEventHandler implements AuthenticationFailu
|
|||||||
logVo.setUpdateBy(username);
|
logVo.setUpdateBy(username);
|
||||||
SpringContextHolder.publishEvent(new SysLogEvent(logVo));
|
SpringContextHolder.publishEvent(new SysLogEvent(logVo));
|
||||||
// 写出错误信息
|
// 写出错误信息
|
||||||
sendErrorResponse(response, exception);
|
sendErrorResponse(request, response, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendErrorResponse(HttpServletResponse response, AuthenticationException exception) throws IOException {
|
private void sendErrorResponse(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
AuthenticationException exception) throws IOException {
|
||||||
ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response);
|
ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response);
|
||||||
httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED);
|
httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED);
|
||||||
this.errorHttpResponseConverter.write(R.failed(exception.getLocalizedMessage()), MediaType.APPLICATION_JSON,
|
String errorMessage;
|
||||||
httpResponse);
|
|
||||||
|
// 手机号登录
|
||||||
|
String grantType = request.getParameter(OAuth2ParameterNames.GRANT_TYPE);
|
||||||
|
if (SecurityConstants.APP.equals(grantType)) {
|
||||||
|
errorMessage = MsgUtils.getSecurityMessage("AbstractUserDetailsAuthenticationProvider.smsBadCredentials");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
errorMessage = exception.getLocalizedMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.errorHttpResponseConverter.write(R.failed(errorMessage), MediaType.APPLICATION_JSON, httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,14 @@ public class MsgUtils {
|
|||||||
return messageSource.getMessage(code, objects, Locale.CHINA);
|
return messageSource.getMessage(code, objects, Locale.CHINA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* security 通过code 和参数获取中文错误信息
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getSecurityMessage(String code, Object... objects) {
|
||||||
|
MessageSource messageSource = SpringContextHolder.getBean("securityMessageSource");
|
||||||
|
return messageSource.getMessage(code, objects, Locale.CHINA);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ AbstractAccessDecisionManager.accessDenied=\u4E0D\u5141\u8BB8\u8BBF\u95EE
|
|||||||
AbstractLdapAuthenticationProvider.emptyPassword=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF
|
AbstractLdapAuthenticationProvider.emptyPassword=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF
|
||||||
AbstractSecurityInterceptor.authenticationNotFound=\u672A\u5728SecurityContext\u4E2D\u67E5\u627E\u5230\u8BA4\u8BC1\u5BF9\u8C61
|
AbstractSecurityInterceptor.authenticationNotFound=\u672A\u5728SecurityContext\u4E2D\u67E5\u627E\u5230\u8BA4\u8BC1\u5BF9\u8C61
|
||||||
OAuth2ResourceOwnerBaseAuthenticationProvider.tokenExpired=\u8BF7\u6C42\u4EE4\u724C\u5DF2\u8FC7\u671F
|
OAuth2ResourceOwnerBaseAuthenticationProvider.tokenExpired=\u8BF7\u6C42\u4EE4\u724C\u5DF2\u8FC7\u671F
|
||||||
|
AbstractUserDetailsAuthenticationProvider.smsBadCredentials=\u624B\u673A\u53F7\u4E0D\u5B58\u5728\u767B\u5F55\u5931\u8D25
|
||||||
AbstractUserDetailsAuthenticationProvider.badCredentials=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF
|
AbstractUserDetailsAuthenticationProvider.badCredentials=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF
|
||||||
AbstractUserDetailsAuthenticationProvider.credentialsExpired=\u7528\u6237\u51ED\u8BC1\u5DF2\u8FC7\u671F
|
AbstractUserDetailsAuthenticationProvider.credentialsExpired=\u7528\u6237\u51ED\u8BC1\u5DF2\u8FC7\u671F
|
||||||
AbstractUserDetailsAuthenticationProvider.disabled=\u7528\u6237\u5DF2\u5931\u6548
|
AbstractUserDetailsAuthenticationProvider.disabled=\u7528\u6237\u5DF2\u5931\u6548
|
||||||
|
Loading…
Reference in New Issue
Block a user