Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
92b0a0cc
Commit
92b0a0cc
authored
May 12, 2019
by
macro
Browse files
登录相关返回结果修改
parent
d5a1803a
Changes
5
Hide whitespace changes
Inline
Side-by-side
mall-portal/src/main/java/com/macro/mall/portal/component/GoAccessDeniedHandler.java
View file @
92b0a0cc
package
com.macro.mall.portal.component
;
import
cn.hutool.json.JSONUtil
;
import
com.macro.mall.common.api.CommonResult
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.web.access.AccessDeniedHandler
;
...
...
@@ -15,7 +17,7 @@ public class GoAccessDeniedHandler implements AccessDeniedHandler{
@Override
public
void
handle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AccessDeniedException
accessDeniedException
)
throws
IOException
,
ServletException
{
response
.
setHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
response
.
getWriter
().
print
(
"{\"code\":401,\"message\":\""
+
"未认证:"
+
accessDeniedException
.
getMessage
()
+
"\"}"
);
response
.
getWriter
().
print
(
JSONUtil
.
parse
(
CommonResult
.
unauthorized
(
accessDeniedException
.
getMessage
()
))
);
response
.
getWriter
().
flush
();
}
}
mall-portal/src/main/java/com/macro/mall/portal/component/GoAuthenticationEntryPoint.java
View file @
92b0a0cc
package
com.macro.mall.portal.component
;
import
cn.hutool.json.JSONUtil
;
import
com.macro.mall.common.api.CommonResult
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.AuthenticationEntryPoint
;
...
...
@@ -15,7 +17,7 @@ public class GoAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public
void
commence
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
authException
)
throws
IOException
,
ServletException
{
response
.
setHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
response
.
getWriter
().
print
(
"{\"code\":403,\"message\":\""
+
"未授权:"
+
authException
.
getMessage
()
+
"\"}"
);
response
.
getWriter
().
print
(
JSONUtil
.
parse
(
CommonResult
.
forbidden
(
authException
.
getMessage
()
))
);
response
.
getWriter
().
flush
();
}
}
mall-portal/src/main/java/com/macro/mall/portal/component/GoAuthenticationFailureHandler.java
View file @
92b0a0cc
package
com.macro.mall.portal.component
;
import
cn.hutool.json.JSONUtil
;
import
com.macro.mall.common.api.CommonResult
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.authentication.AuthenticationFailureHandler
;
...
...
@@ -15,7 +17,7 @@ public class GoAuthenticationFailureHandler implements AuthenticationFailureHand
@Override
public
void
onAuthenticationFailure
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
exception
)
throws
IOException
,
ServletException
{
response
.
setHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
response
.
getWriter
().
print
(
"{\"code\":500,\"message\":\""
+
"登录失败:"
+
exception
.
getMessage
()
+
"\"}"
);
response
.
getWriter
().
print
(
JSONUtil
.
parse
(
CommonResult
.
failed
(
"登录失败:"
+
exception
.
getMessage
()
))
);
response
.
getWriter
().
flush
();
}
}
mall-portal/src/main/java/com/macro/mall/portal/component/GoAuthenticationSuccessHandler.java
View file @
92b0a0cc
package
com.macro.mall.portal.component
;
import
cn.hutool.json.JSONUtil
;
import
com.macro.mall.common.api.CommonResult
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.web.authentication.AuthenticationSuccessHandler
;
...
...
@@ -15,7 +17,7 @@ public class GoAuthenticationSuccessHandler implements AuthenticationSuccessHand
@Override
public
void
onAuthenticationSuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Authentication
authentication
)
throws
IOException
,
ServletException
{
response
.
setHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
response
.
getWriter
().
print
(
"{\"code\":200,\"message\":\
"登录成功
\"}"
);
response
.
getWriter
().
print
(
JSONUtil
.
parse
(
CommonResult
.
success
(
null
,
"登录成功
"
))
);
response
.
getWriter
().
flush
();
}
}
mall-portal/src/main/java/com/macro/mall/portal/component/GoLogoutSuccessHandler.java
View file @
92b0a0cc
package
com.macro.mall.portal.component
;
import
cn.hutool.json.JSONUtil
;
import
com.macro.mall.common.api.CommonResult
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.web.authentication.logout.LogoutSuccessHandler
;
...
...
@@ -15,7 +17,7 @@ public class GoLogoutSuccessHandler implements LogoutSuccessHandler {
@Override
public
void
onLogoutSuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Authentication
authentication
)
throws
IOException
,
ServletException
{
response
.
setHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
response
.
getWriter
().
print
(
"{\"code\":200,\"message\":\"已注销\"}"
);
response
.
getWriter
().
print
(
JSONUtil
.
parse
(
CommonResult
.
success
(
null
,
"已注销"
))
);
response
.
getWriter
().
flush
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment