Skip to content

Latest commit

 

History

History
executable file
·
55 lines (44 loc) · 2.5 KB

File metadata and controls

executable file
·
55 lines (44 loc) · 2.5 KB

AuthController

java.com.co.hm.base.web.AuthController

AuthController確認・ネクストエンジンへのログインを催促 機能を実施する操作を処理します。

callback

ユーザがネクストエンジンのログインページにリダイレクトされログインに成功してから、ネクストエンジンは https://localhost:8443/callback にリダイレクトします。 ここでは、確認してセッションにトークンを保存し、 (ユーザが利用していたページ) 参照パースにリダイレクトします。

@RequestMapping(value = "/callback", method = RequestMethod.GET)
    public String callback(HttpServletRequest request, HttpServletResponse response, RedirectAttributes messages) {
        logger.info("UID   ==============" + request.getParameter("uid"));
        logger.info("STATE ==============" + request.getParameter("state"));
        logger.info("PATH  ==============" + getReferrerPath(request));

        if (request.getParameter("uid") == null || request.getParameter("state") == null) {
            return "redirect:" + Constant.ROOT_PATH;
        }

        // Get accessToken and refreshToken
        HashMap<String, Object> apiResponse = neLogin(request, response, authClientProperty.getRedirectUrl());
        if (apiResponse != null) {
            try {
                saveToken(request, new NeToken(), apiResponse);
                messages.addFlashAttribute("data", getMessage("logged_in_success"));
            } catch (Exception e) {
                messages.addFlashAttribute("data", getMessage("st_error"));
                logger.error("error", e);
            }
        }

        return "redirect:" + getReferrerPath(request);
    }
login

ユーザがセッションにトークンの情報がまだないアプリの機能を利用する際、 フィルータは https://localhost:8443/auth/login にリダイレクトして、ネクストエンジンへのログインを催促するために NeApiClientService を利用します。

@RequestMapping(value = "/auth/login", method = RequestMethod.GET)
    public String login(HttpServletRequest request, HttpServletResponse response) {
        String path = request.getParameter("path");
        String query = "";
        if (path != null && !path.isEmpty()) {
            query = "?path=" + path;
        }
        neLogin(request, response, authClientProperty.getRedirectUrl() + query);
        return null;
    }