This repository has been archived by the owner on Apr 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/apache/falcon
- Loading branch information
Showing
16 changed files
with
569 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
prism/src/main/java/org/apache/falcon/security/FalconCSRFFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* 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.falcon.security; | ||
|
||
import org.apache.falcon.util.StartupProperties; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* CSRF filter before processing the request. | ||
*/ | ||
public class FalconCSRFFilter extends RestCsrfPreventionFilter { | ||
private static final Logger LOG = LoggerFactory.getLogger(FalconCSRFFilter.class); | ||
|
||
public static final String CSRF_PROP_KEY_PREFIX = "falcon.security.csrf."; | ||
public static final String CSRF_PROP_KEY_CUSTOMER_HEADER = "header"; | ||
public static final String CSRF_PROP_KEY_BROWSER_USER_AGENT = "browser"; | ||
|
||
private boolean isCSRFFilterEnabled; | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
isCSRFFilterEnabled = SecurityUtil.isCSRFFilterEnabled(); | ||
if (isCSRFFilterEnabled) { | ||
super.init(filterConfig); | ||
|
||
// add additional property: custom header | ||
Properties configProperties = StartupProperties.get(); | ||
String customHeader = configProperties.getProperty(CSRF_PROP_KEY_PREFIX + CSRF_PROP_KEY_CUSTOMER_HEADER); | ||
if (customHeader != null) { | ||
super.headerName = customHeader; | ||
} | ||
|
||
// add additional property: browser user agent | ||
String browerAgents = configProperties.getProperty(CSRF_PROP_KEY_PREFIX + CSRF_PROP_KEY_BROWSER_USER_AGENT); | ||
if (browerAgents != null) { | ||
super.parseBrowserUserAgents(browerAgents); | ||
} | ||
|
||
LOG.info("Adding cross-site request forgery (CSRF) protection, headerName = {}," | ||
+ "methodsToIgnore = {}, " + "browserUserAgents = {}", | ||
new Object[]{super.headerName, super.methodsToIgnore, super.browserUserAgents}); | ||
} else { | ||
LOG.info("CSRF filter is not enabled."); | ||
} | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, | ||
final FilterChain filterChain) throws IOException, ServletException { | ||
if (isCSRFFilterEnabled) { | ||
super.doFilter(request, response, filterChain); | ||
} else { | ||
filterChain.doFilter(request, response); | ||
} | ||
} | ||
} |
Oops, something went wrong.