mneethiraj commented on code in PR #873:
URL: https://github.com/apache/ranger/pull/873#discussion_r2927876799


##########
security-admin/src/main/java/org/apache/ranger/security/web/filter/RangerSecurityContextFormationFilter.java:
##########
@@ -165,11 +171,13 @@ private int getAuthType(HttpServletRequest request) {
         Object  ssoEnabledObj = request.getAttribute("ssoEnabled");
         boolean ssoEnabled    = ssoEnabledObj != null ? 
Boolean.parseBoolean(String.valueOf(ssoEnabledObj)) : 
PropertiesUtil.getBooleanProperty("ranger.sso.enabled", false);
 
-        if (ssoEnabled) {
+        if (isHeaderAuthenticated()) {
+            authType = XXAuthSession.AUTH_TYPE_TRUSTED_PROXY;

Review Comment:
   Having header-auth enabled doesn't mean the current session is authenticated 
by a header. It could have been by another configured authentication filter, 
right? Perhaps, RangerHeaderPreAuthFilter.doFilter() should replace 
instantiation of `UsernamePasswordAuthenticationToken` with an instance of a 
custom `Authentication` implementation (like `RangerAuthentication`) and use 
that to capture the authentication type. In fact other authentication filters 
must be updated to do the same:
   - RangerJwtAuthFilter
   - RangerKRBAuthenticationFilter 
   - RangerSSOAuthenticationFilter



##########
security-admin/src/main/java/org/apache/ranger/security/web/filter/RangerHeaderPreAuthFilter.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.ranger.security.web.filter;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ranger.biz.UserMgr;
+import org.apache.ranger.common.PropertiesUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import 
org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
+import 
org.springframework.security.web.authentication.WebAuthenticationDetails;
+import org.springframework.web.filter.GenericFilterBean;
+
+import javax.annotation.PostConstruct;
+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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class RangerHeaderPreAuthFilter extends GenericFilterBean {
+    private static final Logger LOG = 
LoggerFactory.getLogger(RangerHeaderPreAuthFilter.class);
+
+    public static final String PROP_HEADER_AUTH_ENABLED        = 
"ranger.authn.header.enabled";
+    public static final String PROP_USERNAME_HEADER_NAME       = 
"ranger.authn.header.username";
+    public static final String PROP_REQUEST_ID_HEADER_NAME     = 
"ranger.authn.header.requestid";
+
+    private static boolean headerAuthEnabled;

Review Comment:
   Fields `headerAuthEnabled` and `userNameHeader` don't need to be `static`.



##########
security-admin/src/main/java/org/apache/ranger/security/web/filter/RangerSecurityContextFormationFilter.java:
##########
@@ -181,4 +189,14 @@ private int getAuthType(HttpServletRequest request) {
 
         return authType;
     }
+
+    private boolean isHeaderAuthenticated() {
+        return 
PropertiesUtil.getBooleanProperty(RangerHeaderPreAuthFilter.PROP_HEADER_AUTH_ENABLED,
 false);

Review Comment:
   Consider caching result of `PropertiesUtil.getBooleanProperty()` (lines 194 
& 198), perhaps in the first call to `doFilter()`.



##########
security-admin/src/main/resources/conf.dist/ranger-admin-site.xml:
##########
@@ -271,6 +271,20 @@
                <value>Mozilla,chrome</value>
        </property>
        <!-- SSO Properties Ends-->
+       <!-- Trusted header auth properties start -->
+       <property>
+               <name>ranger.authn.header.enabled</name>

Review Comment:
   To be consistent with rest of properties here, use prefix `ranger.admin.`.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to