Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
microservices-platform
提交
9947000c
microservices-platform
项目概览
zhangjian1949
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9947000c
编写于
5月 27, 2020
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化授权码模式的登录错误响应
上级
b45f3c85
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
13 addition
and
36 deletion
+13
-36
zlt-uaa/src/main/java/com/central/oauth/config/SecurityConfig.java
...rc/main/java/com/central/oauth/config/SecurityConfig.java
+0
-4
zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java
.../java/com/central/oauth/config/SecurityHandlerConfig.java
+0
-25
zlt-uaa/src/main/java/com/central/oauth/filter/ValidateCodeFilter.java
...ain/java/com/central/oauth/filter/ValidateCodeFilter.java
+7
-7
zlt-uaa/src/main/resources/static/js/common.js
zlt-uaa/src/main/resources/static/js/common.js
+5
-0
zlt-uaa/src/main/resources/static/login.html
zlt-uaa/src/main/resources/static/login.html
+1
-0
未找到文件。
zlt-uaa/src/main/java/com/central/oauth/config/SecurityConfig.java
浏览文件 @
9947000c
...
...
@@ -18,7 +18,6 @@ import org.springframework.security.config.http.SessionCreationPolicy;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.security.web.AuthenticationEntryPoint
;
import
org.springframework.security.web.authentication.AuthenticationFailureHandler
;
import
org.springframework.security.web.authentication.AuthenticationSuccessHandler
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
import
org.springframework.security.web.authentication.logout.LogoutHandler
;
...
...
@@ -37,8 +36,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private
AuthenticationSuccessHandler
authenticationSuccessHandler
;
@Autowired
private
AuthenticationFailureHandler
authenticationFailureHandler
;
@Autowired
(
required
=
false
)
private
AuthenticationEntryPoint
authenticationEntryPoint
;
...
...
@@ -82,7 +79,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.
loginPage
(
SecurityConstants
.
LOGIN_PAGE
)
.
loginProcessingUrl
(
SecurityConstants
.
OAUTH_LOGIN_PRO_URL
)
.
successHandler
(
authenticationSuccessHandler
)
.
failureHandler
(
authenticationFailureHandler
)
.
and
()
.
logout
()
.
logoutUrl
(
SecurityConstants
.
LOGOUT_URL
)
...
...
zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java
浏览文件 @
9947000c
package
com.central.oauth.config
;
import
com.central.common.utils.ResponseUtil
;
import
com.central.oauth.handler.OauthLogoutHandler
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.authentication.BadCredentialsException
;
import
org.springframework.security.authentication.InternalAuthenticationServiceException
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.oauth2.common.exceptions.*
;
import
org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator
;
import
org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator
;
import
org.springframework.security.web.authentication.AuthenticationFailureHandler
;
import
org.springframework.security.web.authentication.AuthenticationSuccessHandler
;
import
org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler
;
import
javax.annotation.Resource
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -32,25 +26,6 @@ import java.io.IOException;
@Slf4j
@Configuration
public
class
SecurityHandlerConfig
{
@Resource
private
ObjectMapper
objectMapper
;
/**
* 登陆失败,返回401
*/
@Bean
public
AuthenticationFailureHandler
loginFailureHandler
()
{
return
(
request
,
response
,
exception
)
->
{
String
msg
;
if
(
exception
instanceof
BadCredentialsException
)
{
msg
=
"密码错误"
;
}
else
{
msg
=
exception
.
getMessage
();
}
ResponseUtil
.
responseWriter
(
objectMapper
,
response
,
msg
,
HttpStatus
.
UNAUTHORIZED
.
value
());
};
}
@Bean
public
OauthLogoutHandler
oauthLogoutHandler
()
{
return
new
OauthLogoutHandler
();
...
...
zlt-uaa/src/main/java/com/central/oauth/filter/ValidateCodeFilter.java
浏览文件 @
9947000c
package
com.central.oauth.filter
;
import
com.central.common.constant.SecurityConstants
;
import
com.central.common.utils.ResponseUtil
;
import
com.central.oauth.exception.ValidateCodeException
;
import
com.central.oauth.service.IValidateCodeService
;
import
com.central.oauth2.common.properties.SecurityProperties
;
import
com.central.oauth2.common.util.AuthUtils
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
security.web.authentication.AuthenticationFailureHandler
;
import
org.springframework.
http.HttpStatus
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.AntPathMatcher
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
javax.annotation.Resource
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -31,11 +34,8 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
@Autowired
private
SecurityProperties
securityProperties
;
/**
* 验证码校验失败处理器
*/
@Autowired
private
AuthenticationFailureHandler
authenticationFailureHandler
;
@Resource
private
ObjectMapper
objectMapper
;
/**
* 验证请求url与配置的url是否匹配的工具类
...
...
@@ -73,7 +73,7 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
try
{
validateCodeService
.
validate
(
request
);
}
catch
(
ValidateCodeException
e
)
{
authenticationFailureHandler
.
onAuthenticationFailure
(
request
,
response
,
e
);
ResponseUtil
.
responseWriter
(
objectMapper
,
response
,
e
.
getMessage
(),
HttpStatus
.
BAD_REQUEST
.
value
()
);
return
;
}
chain
.
doFilter
(
request
,
response
);
...
...
zlt-uaa/src/main/resources/static/js/common.js
浏览文件 @
9947000c
...
...
@@ -34,4 +34,9 @@ $(function(){
$
(
this
).
parent
().
next
().
hide
();
}
});
let
query
=
location
.
search
;
if
(
query
===
'
?error
'
)
{
$
(
'
#loginError
'
).
show
();
}
});
\ No newline at end of file
zlt-uaa/src/main/resources/static/login.html
浏览文件 @
9947000c
...
...
@@ -30,6 +30,7 @@
<div
class=
"form_btn"
>
<button
type=
"submit"
>
登录
</button>
</div>
<div
id=
"loginError"
class=
"ececk_warning"
style=
"text-align: center;"
><span>
用户名或密码错误
</span></div>
<div
class=
"form_reg_btn"
>
<!--span>还没有帐号?</span><a href="/register">马上注册</a-->
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录