我的 servlet 过滤器 JAR 用于 Tomcat 8 &吉拉? [英] Where does my servlet filter JAR go for Tomcat 8 & Jira?
问题描述
我正在运行 Jira 8.3.1.在 Jira 附带的 Tomcat 8 上.
I'm running Jira 8.3.1. on the Tomcat 8 that comes with Jira.
我需要确定我的 JAR 文件应该放在这个配置的哪里.
I need to be sure where my JAR file should go with this configuration.
我写了一个servlet过滤器并将它打包成一个jar.我将过滤器添加到 {jira-install}/conf/web.xml 并将它添加到 {{jira-install}/atlassian-jira/WEB-INF/web.xml 因为我不确定它是哪一个应该进去.
I wrote a servlet filter and packaged it into a jar. I added my filter to {jira-install}/conf/web.xml and I also added it to {{jira-install}/atlassian-jira/WEB-INF/web.xml since I'm not really sure which one it should go in.
我把我的 JAR 放在 {jira-install}/lib 和 {jira-install}/atlassian-jira/WEB-INF/lib 中,因为我不确定它应该放在哪一个.
I put my JAR in {jira-install}/lib and also in {jira-install}/atlassian-jira/WEB-INF/lib since I'm not really sure which one it should go it.
我什至添加了一个 println stmt 来在 catalina.out 中观看它.我没有看到,这意味着我的过滤器可能永远不会被调用或初始化:
I even added a println stmt to watch it in catalina.out. I don't see it, which means my filter may never get invoked or initialized:
==================================
=================================
public class mySetHeader implements Filter {
private String headerName;
private String headerValue;
public void init(FilterConfig filterConfig) throws ServletException {
this.headerName = filterConfig.getInitParameter("header-name");
this.headerValue = filterConfig.getInitParameter("header-value");
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = new EnsureHeaderPresent((HttpServletRequest) req, headerName, headerValue);
chain.doFilter(request, res);
System.out.println("=============> My Filter <=============");
}
public void destroy() {
this.headerName = null;
this.headerValue = null;
}
private class EnsureHeaderPresent extends HttpServletRequestWrapper {
private String headerName;
private String headerValue;
public EnsureHeaderPresent(HttpServletRequest request, String name, String value) {
super(request);
this.headerName = name;
this.headerValue = value;
}
@Override
public String getHeader(String name) {
if (this.headerName != null && this.headerName.equals(name)) {
return this.headerValue;
}
return super.getParameter(name);
}
@Override
public Enumeration<String> getHeaderNames() {
Enumeration<String> headerNames = super.getHeaderNames();
ArrayList<String> all;
if (headerNames == null) {
all = new ArrayList<String>();
} else {
all = Collections.list(headerNames);
}
all.add(this.headerName);
return Collections.enumeration(all);
}
}
}
================== web.xml ==================
================= web.xml =================
<filter>
<filter-name>RequestHeaderFilter</filter-name>
<filter-class>org.nwea.setheader.NweaSetHeader</filter-class>
<init-param>
<param-name>header-name</param-name>
<param-value>Referrer-Policy</param-value>
</init-param>
<init-param>
<param-name>header-value</param-name>
<param-value>no-referrer</param-value>
</init-param>
</filter>
希望通过 https://securityheaders.com/ 运行我的网站,并让我的过滤器添加Referrer-Policy" 每个请求的标头.
Expecting to run my website through https://securityheaders.com/ and have my filter add the "Referrer-Policy" header on each request.
推荐答案
我能够解决这个问题.(1) 首先,我缺少这个特定过滤器的 servlet.我将它添加到 {jira-install}/conf/web.xml 并且我的过滤器开始被调用.(2) 因此,我不再需要{{jira-install}/atlassian-jira/WEB-INF/web.xml 中的servlet 过滤器条目,因为它是多余的,因此我将其删除.(3) 我了解到 Jira 在 {jira-install}/lib 中找到了我的 JAR,因此我将其从 {jira-install}/atlassian-jira/WEB-INF/lib 中删除.现在我看到我的过滤器被调用,但未设置 Referrer-Policy.原来的问题解决了.
I was able to resolve this question. (1) First, I was missing the servlet for this particular filter. I added that to {jira-install}/conf/web.xml and my filter began getting invoked. (2) Therefore, I no longer needed my servlet filter entry in {{jira-install}/atlassian-jira/WEB-INF/web.xml, as it was redundant, so I removed it. (3) I learned that Jira found my JAR in {jira-install}/lib, so I removed it from {jira-install}/atlassian-jira/WEB-INF/lib. Now I see my filter being called, but the Referrer-Policy is not being set. The original issue is resolved.
这篇关于我的 servlet 过滤器 JAR 用于 Tomcat 8 &吉拉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!