jihoonson commented on a change in pull request #8992: druid extension for OpenID Connect auth using pac4j lib URL: https://github.com/apache/druid/pull/8992#discussion_r396667554
########## File path: extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/Pac4jFilter.java ########## @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.security.pac4j; + +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.server.security.AuthConfig; +import org.apache.druid.server.security.AuthenticationResult; +import org.pac4j.core.config.Config; +import org.pac4j.core.context.J2EContext; +import org.pac4j.core.context.session.SessionStore; +import org.pac4j.core.engine.CallbackLogic; +import org.pac4j.core.engine.DefaultCallbackLogic; +import org.pac4j.core.engine.DefaultSecurityLogic; +import org.pac4j.core.engine.SecurityLogic; +import org.pac4j.core.profile.CommonProfile; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Collection; + +public class Pac4jFilter implements Filter +{ + private static final Logger LOGGER = new Logger(Pac4jFilter.class); + + private final Config pac4jConfig; + private final SecurityLogic<String, J2EContext> securityLogic; + private final CallbackLogic<String, J2EContext> callbackLogic; + private final SessionStore<J2EContext> sessionStore; + + private final String name; + private final String authorizerName; + + public Pac4jFilter(String name, String authorizerName, Config pac4jConfig, String cookiePassphrase) + { + this.pac4jConfig = pac4jConfig; + this.securityLogic = new DefaultSecurityLogic<>(); + this.callbackLogic = new DefaultCallbackLogic<>(); + + this.name = name; + this.authorizerName = authorizerName; + + this.sessionStore = new Pac4jSessionStore(cookiePassphrase); + } + + @Override + public void init(FilterConfig filterConfig) + { + } + + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) + throws IOException, ServletException + { + HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; + HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; + J2EContext context = new J2EContext(httpServletRequest, httpServletResponse, sessionStore); + + if (Pac4jCallbackResource.SELF_URL.equals(httpServletRequest.getRequestURI())) { + callbackLogic.perform( + context, + pac4jConfig, + (int code, J2EContext ctx) -> null, Review comment: Oh, I just thought it would be nice to use an existing implementation. It sounds still good 👍. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
