@@ -0,0 +1,3241 @@
+/*%0A * %0A * Copyright 2016-2017 Tom Misawa, riversun.org@gmail.com%0A * %0A * Permission is hereby granted, free of charge, to any person obtaining a copy of %0A * this software and associated documentation files (the %22Software%22), to deal in the %0A * Software without restriction, including without limitation the rights to use, %0A * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the %0A * Software, and to permit persons to whom the Software is furnished to do so, %0A * subject to the following conditions:%0A * %0A * The above copyright notice and this permission notice shall be included in all %0A * copies or substantial portions of the Software.%0A * %0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,%0A *  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A %0A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR %0A * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, %0A * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR %0A * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.%0A * %0A */%0Apackage org.riversun.oauth2.google;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0A%0Aimport com.google.api.client.googleapis.auth.oauth2.GoogleCredential;%0Aimport com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;%0A%0A/**%0A * Get OAuth 2 status and authentication result stored in http session%3Cbr%3E%0A * Thread-safe%0A * %0A * @author Tom Misawa (riversun.org@gmail.com)%0A */%0Apublic class OAuthSession %7B%0A%0A    private static final OAuthSession instance = new OAuthSession();%0A%0A    private OAuthSession() %7B%0A    %7D%0A%0A    public static OAuthSession getInstance() %7B%0A        return instance;%0A    %7D%0A%0A    /**%0A     * Clear OAuth2 state.Once cleared, execute OAuth flow again%0A     * %0A     * @param req%0A     */%0A    public void clearOAuth2State(HttpServletRequest req) %7B%0A        req.getSession().setAttribute(OAuthConst.SESSION_KEY_OAUTH2_DONE, null);%0A    %7D%0A%0A    /**%0A     * set URL to redirect after OAuth2 flow%0A     * %0A     * @param req%0A     * @param url%0A     */%0A    public void setRedirectUrlAfterOAuth(HttpServletRequest req, String url) %7B%0A        // URL to be redirected after OAuth2 flow is finished%0A        req.getSession().setAttribute(OAuthConst.SESSION_KEY_REDIRECT_URL_AFTER_OAUTH, url);%0A    %7D%0A%0A    /**%0A     * Returns credential%0A     * %0A     * @param req%0A     * @return%0A     */%0A    public GoogleCredential getCredential(HttpServletRequest req) %7B%0A        final GoogleCredential credential = (GoogleCredential) req.getSession().getAttribute(OAuthConst.SESSION_KEY_CREDENTIAL);%0A        return credential;%0A    %7D%0A%0A    /**%0A     * Returns idToken%0A     * %0A     * @param req%0A     * @return%0A     */%0A    public GoogleIdToken getIdToken(HttpServletRequest req) %7B%0A        final GoogleIdToken idToken = (GoogleIdToken) req.getSession().getAttribute(OAuthConst.SESSION_KEY_ID_TOKEN);%0A        return idToken;%0A    %7D%0A%0A    /**%0A     * Returns unique user id (subject)%0A     * %0A     * @param req%0A     * @return%0A     */%0A    public String getUserId(HttpServletRequest req) %7B%0A        final String userId = (String) req.getSession().getAttribute(OAuthConst.SESSION_KEY_UNIQUE_USER_ID);%0A        return userId;%0A    %7D%0A%0A%7D%0A

add session manager