Uses Log4j instead of SLF4J

This commit is contained in:
Lukasz Lenart
2022-01-01 14:25:32 +01:00
parent 767f40b509
commit bab276e29d
2 changed files with 24 additions and 24 deletions
@@ -22,28 +22,26 @@ import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.PreResultListener;
import com.opensymphony.xwork2.util.TextParseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Interceptor that implements Cross-Origin Embedder Policy on incoming requests used to protect a
* document from loading any non-same-origin resources which don't explicitly grant the document
* permission to be loaded.
*
*
* @see <a href="https://web.dev/why-coop-coep/#coep">https://web.dev/why-coop-coep/#coep</a>
* @see <a href="https://wicg.github.io/cross-origin-embedder-policy/">https://wicg.github.io/cross-origin-embedder-policy/</a>
**/
public class CoepInterceptor extends AbstractInterceptor implements PreResultListener {
private static final Logger LOG = LoggerFactory.getLogger(CoepInterceptor.class);
private static final Logger LOG = LogManager.getLogger(CoepInterceptor.class);
private static final String REQUIRE_COEP_HEADER = "require-corp";
private static final String COEP_ENFORCING_HEADER = "Cross-Origin-Embedder-Policy";
private static final String COEP_REPORT_HEADER = "Cross-Origin-Embedder-Policy-Report-Only";
@@ -64,28 +62,29 @@ public class CoepInterceptor extends AbstractInterceptor implements PreResultLis
HttpServletResponse res = invocation.getInvocationContext().getServletResponse();
final String path = req.getContextPath();
if (exemptedPaths.contains(path)){
if (exemptedPaths.contains(path)) {
// no need to add headers
LOG.debug(String.format("Skipping COEP header for exempted path %s", path));
} else if (!disabled){
LOG.debug("Skipping COEP header for exempted path {}", path);
} else if (!disabled) {
res.setHeader(header, REQUIRE_COEP_HEADER);
}
}
public void setExemptedPaths(String paths){
public void setExemptedPaths(String paths) {
this.exemptedPaths.addAll(TextParseUtil.commaDelimitedStringToSet(paths));
}
public void setEnforcingMode(String mode){
public void setEnforcingMode(String mode) {
boolean enforcingMode = Boolean.parseBoolean(mode);
if (enforcingMode){
if (enforcingMode) {
header = COEP_ENFORCING_HEADER;
} else {
header = COEP_REPORT_HEADER;
}
}
public void setDisabled(String value){
public void setDisabled(String value) {
disabled = Boolean.parseBoolean(value);
}
}
@@ -22,15 +22,14 @@ import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.PreResultListener;
import com.opensymphony.xwork2.util.TextParseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.Set;
/**
* Interceptor that implements Cross-Origin Opener Policy on incoming requests. COOP is a mitigation against
* cross-origin information leaks and is used to make websites, cross-origin isolated. Setting the COOP header allows you to ensure that a top-level window is
@@ -42,7 +41,8 @@ import java.util.Set;
**/
public class CoopInterceptor extends AbstractInterceptor implements PreResultListener {
private static final Logger LOG = LoggerFactory.getLogger(CoopInterceptor.class);
private static final Logger LOG = LogManager.getLogger(CoopInterceptor.class);
private static final String SAME_ORIGIN = "same-origin";
private static final String SAME_ORIGIN_ALLOW_POPUPS = "same-origin-allow-popups";
private static final String UNSAFE_NONE = "unsafe-none";
@@ -63,30 +63,31 @@ public class CoopInterceptor extends AbstractInterceptor implements PreResultLis
HttpServletResponse response = invocation.getInvocationContext().getServletResponse();
String path = request.getContextPath();
if (isExempted(path)){
if (isExempted(path)) {
// no need to add headers
LOG.debug(String.format("Skipping COOP header for exempted path %s", path));
LOG.debug("Skipping COOP header for exempted path {}", path);
} else {
response.setHeader(COOP_HEADER, getMode());
}
}
public boolean isExempted(String path){
public boolean isExempted(String path) {
return exemptedPaths.contains(path);
}
public void setExemptedPaths(String paths){
public void setExemptedPaths(String paths) {
exemptedPaths.addAll(TextParseUtil.commaDelimitedStringToSet(paths));
}
private String getMode(){
private String getMode() {
return mode;
}
public void setMode(String mode) {
if (!(mode.equals(SAME_ORIGIN) || mode.equals(SAME_ORIGIN_ALLOW_POPUPS) || mode.equals(UNSAFE_NONE))){
if (!(mode.equals(SAME_ORIGIN) || mode.equals(SAME_ORIGIN_ALLOW_POPUPS) || mode.equals(UNSAFE_NONE))) {
throw new IllegalArgumentException(String.format("Mode '%s' not recognized!", mode));
}
this.mode = mode;
}
}
}