servlet的单点登录的server端

要求

http://localhost:8083/ssoLogin?source=http://127.0.0.1:8085
输入链接 输入用户名密码

跳转到
http://127.0.0.1:8085/main?ticket=877b97ba-ad6a-410d-bf6c-0ef536a25c84&domains=http://localhost:8084,http://localhost:8081

其中ticket为id号

package com.ming;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;
import java.util.UUID;

/**
 * @author ming
 */
public class Login extends HttpServlet {
    private String domains = null;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 请求为登录
        if(Objects.equals("/login", req.getServletPath())){
            String username = req.getParameter("username");
            String password = req.getParameter("password");
            String source = req.getParameter("source");

            // 得到浏览器路由栈的回退地址
          if(null == source || Objects.equals("", source)){
                source = req.getHeader("referer");
                source = source.substring(source.indexOf("source=") + 7);
            }

            if(Objects.equals(username, password)){
                // 生成uid
                String ticket = UUID.randomUUID().toString();
                System.out.println(ticket);
                // 登录成功跳转登录回页面
                resp.sendRedirect(source + "/main?ticket=" + ticket + "&domains=" + domains);

            }else {
                // 登录失败转发到login.jsp
                req.setAttribute("source", source);
                req.getRequestDispatcher("/WEB-INF/view/login.jsp").forward(req, resp);
            }
        }else if(Objects.equals("/ssoLogin", req.getServletPath())){
            req.getRequestDispatcher("/WEB-INF/view/login.jsp").forward(req, resp);
        }else if(Objects.equals("/ssoLogout", req.getServletPath())){
            // 退出
            String referer = req.getHeader("referer");
            String source = referer.substring(referer.indexOf("source=") + 7);

            resp.sendRedirect(source + "/logout?domains=" +
                    domains
                    );
        }
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        this.domains = config.getInitParameter("domains");
    }
}

<%--
  Created by IntelliJ IDEA.
  User: ming
  Date: 19-5-8
  Time: 下午10:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form method="post" action="./login">
    <input type="hidden" name="source" value="${source}"/>
    <label>
        <input type="text" name="username"/>
    </label>
    <label>
        <input type="password" name="password"/>
    </label>
    <input type="submit"/>
</form>
</body>
</html>