Search in sources :

Example 1 with Stapler

use of org.kohsuke.stapler.Stapler in project hudson-2.x by hudson.

the class AccessDeniedHandlerImpl method handle.

public void handle(ServletRequest request, ServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse rsp = (HttpServletResponse) response;
    rsp.setStatus(HttpServletResponse.SC_FORBIDDEN);
    req.setAttribute("exception", accessDeniedException);
    Stapler stapler = new Stapler();
    stapler.init(new ServletConfig() {

        public String getServletName() {
            return "Stapler";
        }

        public ServletContext getServletContext() {
            return Hudson.getInstance().servletContext;
        }

        public String getInitParameter(String name) {
            return null;
        }

        public Enumeration getInitParameterNames() {
            return new Vector().elements();
        }
    });
    stapler.invoke(req, rsp, Hudson.getInstance(), "/accessDenied");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Enumeration(java.util.Enumeration) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) Stapler(org.kohsuke.stapler.Stapler) Vector(java.util.Vector)

Aggregations

Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1 ServletConfig (javax.servlet.ServletConfig)1 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Stapler (org.kohsuke.stapler.Stapler)1