pareshddevalia commented on code in PR #397:
URL: https://github.com/apache/atlas/pull/397#discussion_r2192884767


##########
webapp/src/main/java/org/apache/atlas/web/security/CustomLogoutSuccessHandler.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.atlas.web.security;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.core.Authentication;
+import 
org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
+import 
org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler 
implements LogoutSuccessHandler {
+    private final ObjectMapper mapper;
+    private static final Logger LOG = 
LoggerFactory.getLogger(CustomLogoutSuccessHandler.class);
+
+    @Inject
+    public CustomLogoutSuccessHandler(ObjectMapper mapper) {
+        this.mapper = mapper;
+    }
+
+    @Override
+    public void onLogoutSuccess(HttpServletRequest request, 
HttpServletResponse response, Authentication authentication) {
+        
request.getServletContext().removeAttribute(request.getRequestedSessionId());
+        response.setContentType("application/json;charset=UTF-8");

Review Comment:
   Try to get the header from HeadersUtil.class



##########
webapp/src/main/java/org/apache/atlas/web/security/CustomLogoutSuccessHandler.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.atlas.web.security;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.core.Authentication;
+import 
org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
+import 
org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler 
implements LogoutSuccessHandler {
+    private final ObjectMapper mapper;
+    private static final Logger LOG = 
LoggerFactory.getLogger(CustomLogoutSuccessHandler.class);
+
+    @Inject
+    public CustomLogoutSuccessHandler(ObjectMapper mapper) {
+        this.mapper = mapper;
+    }
+
+    @Override
+    public void onLogoutSuccess(HttpServletRequest request, 
HttpServletResponse response, Authentication authentication) {
+        
request.getServletContext().removeAttribute(request.getRequestedSessionId());
+        response.setContentType("application/json;charset=UTF-8");
+        response.setHeader("Cache-Control", "no-cache");
+        response.setHeader("X-Frame-Options", "DENY");
+
+        try {
+            Map<String, Object> responseMap = new HashMap<>();
+            responseMap.put("statusCode", HttpServletResponse.SC_OK);
+            responseMap.put("msgDesc", "Logout Successful");
+            String jsonStr = mapper.writeValueAsString(responseMap);
+
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.getWriter().write(jsonStr);
+            LOG.info("Log-out Successfully done. Returning Json : " + jsonStr);

Review Comment:
   Avoid logging at INFO for regular logout, use DEBUG



##########
webapp/src/main/java/org/apache/atlas/web/filters/RestUtil.java:
##########
@@ -30,7 +30,7 @@ public class RestUtil {
     private static final Logger LOG = LoggerFactory.getLogger(RestUtil.class);
 
     public static final  String TIMEOUT_ACTION = "timeout";
-    public static final  String LOGOUT_URL     = "/logout.html";
+    public static final String LOGOUT_URL = "/logout";

Review Comment:
   Check the inconsistent spacing and alignment 



##########
webapp/src/test/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilterTest.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.atlas.web.filters;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.mock.web.MockHttpSession;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+public class AtlasKnoxSSOAuthenticationFilterTest {
+    @Mock
+    private FilterChain filterChain;
+
+    @InjectMocks
+    private AtlasKnoxSSOAuthenticationFilter filter;
+
+    private MockHttpServletRequest request;
+    private MockHttpServletResponse response;
+    private MockHttpSession session;
+
+    @BeforeMethod
+    public void testSetup() {
+        MockitoAnnotations.openMocks(this);  // Required for @Mock
+
+        request = new MockHttpServletRequest();
+        response = new MockHttpServletResponse();
+        session = new MockHttpSession();
+        request.setSession(session);
+
+        request.setRequestURI("/api/atlas/admin/checksso");
+        request.addHeader("User-Agent", "Chrome");
+    }
+

Review Comment:
   Add Test for /admin/checksso API



##########
webapp/src/main/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java:
##########
@@ -163,17 +171,12 @@ public void init(FilterConfig filterConfig) throws 
ServletException {
      */
     @Override
     public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain filterChain) throws IOException, ServletException {
+        setSsoEnabled(false);

Review Comment:
   private boolean ssoEnabled in a singleton filter is not thread-safe.
   Consider storing ssoEnabled as a request attribute instead, to ensure thread 
safety across concurrent requests.



-- 
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: dev-unsubscr...@atlas.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to