All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.oauth.token.handler.Oauth2RefreshTokenRefreshTokenGetHandler Maven / Gradle / Ivy

There is a newer version: 2.1.30
Show newest version
package com.networknt.oauth.token.handler;

import com.hazelcast.map.IMap;
import com.networknt.config.Config;
import com.networknt.handler.LightHttpHandler;
import com.networknt.oauth.cache.CacheStartupHookProvider;
import com.networknt.oauth.cache.model.RefreshToken;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Oauth2RefreshTokenRefreshTokenGetHandler extends RefreshTokenAuditHandler implements LightHttpHandler {
    private static final String REFRESH_TOKEN_NOT_FOUND = "ERR12029";

    private static Logger logger = LoggerFactory.getLogger(Oauth2RefreshTokenRefreshTokenGetHandler.class);
    @SuppressWarnings("unchecked")
    @Override
    public void handleRequest(HttpServerExchange exchange) throws Exception {
        String refreshToken = exchange.getQueryParameters().get("refreshToken").getFirst();
        if(logger.isDebugEnabled()) logger.debug("refreshToken = " + refreshToken);
        IMap tokens = CacheStartupHookProvider.hz.getMap("tokens");
        RefreshToken token = tokens.get(refreshToken);

        if(token == null) {
            setExchangeStatus(exchange, REFRESH_TOKEN_NOT_FOUND, refreshToken);
        } else {
            exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "application/json");
            exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(token));
        }
        processAudit(exchange);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy