huanghongfa
2020-12-20 def38240262b4403377d4c16beac3ea048f1e658
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.panzhihua.auth.handel;
 
import com.panzhihua.common.utlis.JWTTokenUtil;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.utlis.ResultUtil;
import com.panzhihua.common.constants.TokenConstant;
import com.panzhihua.common.model.vos.R;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
 
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 登录成功
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-11-24 15:23
 **/
public class UserLoginSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {
 
    }
 
    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        // 组装JWT
        LoginUserInfoVO loginUserInfoVO =  (LoginUserInfoVO) authentication.getPrincipal();
        String token = JWTTokenUtil.generateToken(loginUserInfoVO);
        token = TokenConstant.TOKEN_PRE + token;
        // 封装返回参数
        R<String> ok = R.ok(token);
        ResultUtil.responseJson(httpServletResponse,ok);
    }
}