// Path: pie-core/src/main/java/com/coverity/security/pie/core/PolicyEnforcer.java
// public interface PolicyEnforcer {
//     
//     public Policy getPolicy();
//     public PolicyConfig getPolicyConfig();
//     
//     public void init(PieConfig pieConfig);
//     
//     /**
//      * Apply the policy to the servlet context being initialized. This enforcer should configure
//      * itself to both apply its policy to permission requests and keep an internal record of any
//      * policy violations. 
//      * 
//      * @param cx The servlet context currently being initialized.
//      */
//     public void applyPolicy(ServletContext cx);
//     
//     /**
//      * The ServletContext to which this policy is applied is shutting down. The enforcer
//      * should do any cleanup it needs.
//      */
//     public void shutdown();
//     
// }


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import com.coverity.security.pie.core.PolicyEnforcer;
package com.coverity.security.pie.web;




/**
 * A servlet filter which provides an endpoint to retrieve policy violations. At this point its intended use is to
 * facilitate the Maven plugin.
 */
public class PieAdminFilter implements Filter {

    public static final String ADMIN_FILTER_URI = "/c0bd580ddcb4666b1PIEec61812f3cdf305";

    private final PieInitializer pieInitializer;
    
    public PieAdminFilter(PieInitializer pieInitializer) {
        this.pieInitializer = pieInitializer;
    }
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        if (request instanceof HttpServletRequest) {
            HttpServletRequest httpServletRequest = (HttpServletRequest)request;
            String path = null;
            if (httpServletRequest.getRequestURI().length() >= httpServletRequest.getContextPath().length()) {
                path = httpServletRequest.getRequestURI().substring(httpServletRequest.getContextPath().length());
            }
            if (ADMIN_FILTER_URI.equals(path)) {
                
// Path: pie-core/src/main/java/com/coverity/security/pie/core/PolicyEnforcer.java
// public interface PolicyEnforcer {
//     
//     public Policy getPolicy();
//     public PolicyConfig getPolicyConfig();
//     
//     public void init(PieConfig pieConfig);
//     
//     /**
//      * Apply the policy to the servlet context being initialized. This enforcer should configure
//      * itself to both apply its policy to permission requests and keep an internal record of any
//      * policy violations. 
//      * 
//      * @param cx The servlet context currently being initialized.
//      */
//     public void applyPolicy(ServletContext cx);
//     
//     /**
//      * The ServletContext to which this policy is applied is shutting down. The enforcer
//      * should do any cleanup it needs.
//      */
//     public void shutdown();
//     
// }


// Path: pie-core/src/main/java/com/coverity/security/pie/web/PieAdminFilter.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import com.coverity.security.pie.core.PolicyEnforcer;

package com.coverity.security.pie.web;




/**
 * A servlet filter which provides an endpoint to retrieve policy violations. At this point its intended use is to
 * facilitate the Maven plugin.
 */
public class PieAdminFilter implements Filter {

    public static final String ADMIN_FILTER_URI = "/c0bd580ddcb4666b1PIEec61812f3cdf305";

    private final PieInitializer pieInitializer;
    
    public PieAdminFilter(PieInitializer pieInitializer) {
        this.pieInitializer = pieInitializer;
    }
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        if (request instanceof HttpServletRequest) {
            HttpServletRequest httpServletRequest = (HttpServletRequest)request;
            String path = null;
            if (httpServletRequest.getRequestURI().length() >= httpServletRequest.getContextPath().length()) {
                path = httpServletRequest.getRequestURI().substring(httpServletRequest.getContextPath().length());
            }
            if (ADMIN_FILTER_URI.equals(path)) {
                
                PolicyEnforcer policyEnforcer = pieInitializer.getPolicyEnforcer(httpServletRequest.getParameter("policyEnforcer"));