|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2022 IBM Corporation and others. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | + * IBM Corporation - initial API and implementation |
| 10 | + *******************************************************************************/ |
| 11 | +/** |
| 12 | + * @version 1.0 |
| 13 | + */ |
| 14 | +package com.ibm.ws.microprofile.openapi.servlet.filter; |
| 15 | + |
| 16 | +import javax.servlet.Filter; |
| 17 | +import javax.servlet.FilterConfig; |
| 18 | +import javax.servlet.FilterChain; |
| 19 | +import javax.servlet.ServletException; |
| 20 | +import javax.servlet.ServletRequest; |
| 21 | +import javax.servlet.ServletResponse; |
| 22 | +import javax.servlet.http.HttpServletRequest; |
| 23 | +import javax.servlet.http.HttpServletResponse; |
| 24 | +import java.io.IOException; |
| 25 | + |
| 26 | +public class OpenAPIUIFilter implements Filter { |
| 27 | + /** |
| 28 | + * Filters out specific requests and takes the appropriate action for each |
| 29 | + * |
| 30 | + * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) |
| 31 | + */ |
| 32 | + @Override |
| 33 | + public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { |
| 34 | + |
| 35 | + if (resp instanceof HttpServletResponse) { |
| 36 | + HttpServletResponse httpServletResp = (HttpServletResponse) resp; |
| 37 | + httpServletResp.setHeader("X-Frame-Options", "DENY"); |
| 38 | + httpServletResp.setHeader("X-Content-Type-Options", "nosniff"); |
| 39 | + chain.doFilter(req, resp); |
| 40 | + } else { |
| 41 | + chain.doFilter(req, resp); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public void destroy() {} |
| 47 | + |
| 48 | + @Override |
| 49 | + public void init(FilterConfig arg0) throws ServletException {} |
| 50 | +} |
0 commit comments