thenatog commented on a change in pull request #4988: URL: https://github.com/apache/nifi/pull/4988#discussion_r621436447
########## 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,88 @@ +/* + * 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.CookieCsrfTokenRepository; +import org.springframework.security.web.csrf.CsrfToken; +import org.springframework.security.web.csrf.CsrfTokenRepository; +import org.springframework.security.web.csrf.DefaultCsrfToken; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * 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). + */ +public final class NiFiCsrfTokenRepository implements CsrfTokenRepository { + + private CookieCsrfTokenRepository cookieRepository; + + public NiFiCsrfTokenRepository() { + cookieRepository = new CookieCsrfTokenRepository(); + } + + @Override + public CsrfToken generateToken(HttpServletRequest request) { + return new DefaultCsrfToken("empty", "empty", "empty"); Review comment: This method will be called by CsrfFilter when loadToken is null, which will occur when the Cookie header is not present or does not contain a cookie named "__Host-jwt-auth-cookie". This will happen when using a command line client. -- 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]
