gresockj commented on a change in pull request #4988:
URL: https://github.com/apache/nifi/pull/4988#discussion_r620241802



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiCsrfTokenRepository.java
##########
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2012-2016 the original author or authors.
+ *
+ * Licensed 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
+ *
+ *      https://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.nifi.web;
+
+
+import org.springframework.security.web.csrf.CsrfToken;
+import org.springframework.security.web.csrf.CsrfTokenRepository;
+import org.springframework.security.web.csrf.DefaultCsrfToken;
+import org.springframework.util.Assert;
+import org.springframework.util.ReflectionUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.util.WebUtils;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Method;
+
+/**
+ * A {@link CsrfTokenRepository} implementation for NiFi that matches the NiFi 
Cookie JWT against the
+ * Authorization header JWT to protect against CSRF. If the request is an 
idempotent method type, then only the Cookie
+ * is required to be present - this allows authenticating access to static 
resources using a Cookie. If the request is a non-idempotent
+ * method, NiFi requires the Authorization header (eg. for POST requests).
+ *
+ * @author Rob Winch
+ * @since 4.1
+ */
+public final class NiFiCsrfTokenRepository implements CsrfTokenRepository {

Review comment:
       Though I understand you got this implementation from something like 
[CookieCsrfTokenRepository](https://github.com/spring-projects/spring-security/blob/master/web/src/main/java/org/springframework/security/web/csrf/CookieCsrfTokenRepository.java),
 I wonder if it would be preferable to use a [Delegation pattern 
](https://refactoring.guru/replace-inheritance-with-delegation)here instead of 
reimplementing CookieCsrfTokenRepository.

##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/JwtAuthenticationFilter.java
##########
@@ -33,43 +32,25 @@
     private static final Logger logger = 
LoggerFactory.getLogger(JwtAuthenticationFilter.class);
 
     // The Authorization header contains authentication credentials
-    public static final String AUTHORIZATION = "Authorization";
-    private static final Pattern tokenPattern = Pattern.compile("^Bearer 
(\\S*\\.\\S*\\.\\S*)$");
+    public static final String JWT_COOKIE_NAME = "__Host-jwt-auth-cookie";

Review comment:
       Does this need to be public?

##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas.js
##########
@@ -907,7 +907,7 @@
                             
$('#current-user').text(currentUser.identity).show();
 
                             // render the logout button if there is a token 
locally

Review comment:
       Change the comment?

##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiCsrfTokenRepository.java
##########
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2012-2016 the original author or authors.
+ *
+ * Licensed 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
+ *
+ *      https://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.nifi.web;
+
+
+import org.springframework.security.web.csrf.CsrfToken;
+import org.springframework.security.web.csrf.CsrfTokenRepository;
+import org.springframework.security.web.csrf.DefaultCsrfToken;
+import org.springframework.util.Assert;
+import org.springframework.util.ReflectionUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.util.WebUtils;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Method;
+
+/**
+ * A {@link CsrfTokenRepository} implementation for NiFi that matches the NiFi 
Cookie JWT against the
+ * Authorization header JWT to protect against CSRF. If the request is an 
idempotent method type, then only the Cookie
+ * is required to be present - this allows authenticating access to static 
resources using a Cookie. If the request is a non-idempotent
+ * method, NiFi requires the Authorization header (eg. for POST requests).
+ *
+ * @author Rob Winch
+ * @since 4.1

Review comment:
       We should probably get rid of the author and since annotations.

##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/NiFiBearerTokenResolver.java
##########
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012-2016 the original author or authors.
+ *
+ * Licensed 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
+ *
+ *      https://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.nifi.web.security.jwt;
+
+import org.apache.nifi.web.security.InvalidAuthenticationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class NiFiBearerTokenResolver implements BearerTokenResolver {
+    private static final Logger logger = 
LoggerFactory.getLogger(NiFiBearerTokenResolver.class);
+    private static final Pattern BEARER_HEADER_PATTERN = 
Pattern.compile("^Bearer (\\S*\\.\\S*\\.\\S*)$");
+    private static final Pattern JWT_PATTERN = 
Pattern.compile("^(\\S*\\.\\S*\\.\\S*)$");
+    public static final String AUTHORIZATION = "Authorization";

Review comment:
       Does this need to be public?




-- 
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:
us...@infra.apache.org


Reply via email to