登录相关返回结果修改

This commit is contained in:
macro 2019-05-12 15:19:41 +08:00
parent d5a1803a7f
commit 92b0a0ccb4
5 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,7 @@
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();
}
}

View File

@ -1,5 +1,7 @@
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();
}
}

View File

@ -1,5 +1,7 @@
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();
}
}

View File

@ -1,5 +1,7 @@
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();
}
}

View File

@ -1,5 +1,7 @@
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();
}
}