Search in sources :

Example 1 with OAuthAccessResourceRequest

use of org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest in project tesla by linking12.

the class Oauth2HttpRequestFilter method doFilter.

@Override
public HttpResponse doFilter(HttpRequest originalRequest, HttpObject httpObject, ChannelHandlerContext channelHandlerContext) {
    if (httpObject instanceof HttpRequest) {
        try {
            HttpRequest httpRequest = (HttpRequest) httpObject;
            NettyHttpServletRequest servletRequest = new NettyHttpServletRequest(httpRequest, "/", channelHandlerContext);
            OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(servletRequest, ParameterStyle.QUERY);
            String accessToken = oauthRequest.getAccessToken();
            if (!oauth2TokenCache.checkAccessToken(accessToken)) {
                return super.createResponse(HttpResponseStatus.FORBIDDEN, originalRequest);
            }
        } catch (Throwable e) {
            return super.createResponse(HttpResponseStatus.FORBIDDEN, originalRequest);
        }
    }
    return null;
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) OAuthAccessResourceRequest(org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest) NettyHttpServletRequest(io.github.tesla.gateway.netty.servlet.NettyHttpServletRequest)

Aggregations

NettyHttpServletRequest (io.github.tesla.gateway.netty.servlet.NettyHttpServletRequest)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 OAuthAccessResourceRequest (org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest)1