if (res.containsHeader("Pragma")) { log.debug("Removing Pragma header to avoid caching issues in IE"); res.setHeader("Pragma",null); } if (res.containsHeader("Cache-Control")) { log.debug("Removing Cache-Control header to avoid caching issues in IE"); res.setHeader("Cache-Control",null); }
ServletUtils.removeCacheHeaders(res);
    public void doGet(HttpServletRequest req,  HttpServletResponse res) throws java.io.IOException, ServletException {        log.debug(">doGet()");        // Check if authorized        EjbcaWebBean ejbcawebbean= (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean)                                   req.getSession().getAttribute("ejbcawebbean");                RAInterfaceBean rabean =  (se.anatom.ejbca.webdist.rainterface.RAInterfaceBean)                                   req.getSession().getAttribute("rabean");        if ( ejbcawebbean == null ){          try {            ejbcawebbean = (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean");           } catch (ClassNotFoundException exc) {               throw new ServletException(exc.getMessage());           }catch (Exception exc) {               throw new ServletException (" Cannot create bean of class "+"se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean", exc);           }           req.getSession().setAttribute("ejbcawebbean", ejbcawebbean);        }                if ( rabean == null ){            try {              rabean = (se.anatom.ejbca.webdist.rainterface.RAInterfaceBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "se.anatom.ejbca.webdist.rainterface.RAInterfaceBean");             } catch (ClassNotFoundException exc) {                 throw new ServletException(exc.getMessage());             }catch (Exception exc) {                 throw new ServletException (" Cannot create bean of class "+"se.anatom.ejbca.webdist.rainterface.RAInterfaceBean", exc);             }             req.getSession().setAttribute("rabean", ejbcawebbean);          }        try{          ejbcawebbean.initialize(req,AvailableAccessRules.REGULAR_VIEWCERTIFICATE);          rabean.initialize(req,ejbcawebbean);                            } catch(Exception e){           throw new java.io.IOException("Authorization Denied");        }                String issuerdn = req.getParameter(ISSUER_PROPERTY);                String certificatesn = req.getParameter(CERTIFICATEDN_PROPERTY);        String command;        // Keep this for logging.        log.debug("Got request from "+req.getRemoteAddr());        command = req.getParameter(COMMAND_PROPERTY_NAME);        if (command == null)            command = "";        if ((command.equalsIgnoreCase(COMMAND_NSCERT) || command.equalsIgnoreCase(COMMAND_IECERT) || command.equalsIgnoreCase(COMMAND_CERT))         	 && issuerdn != null && certificatesn != null) {        	        	BigInteger certsn = new BigInteger(certificatesn,16);        	        	                	// Fetch the certificate and at the samt time check that the user is authorized to it.        	        	try {				rabean.loadCertificates(certsn, issuerdn);				CertificateView certview = rabean.getCertificate(0);								X509Certificate cert = certview.getCertificate();				byte[] enccert = cert.getEncoded();				if (res.containsHeader("Pragma")) {					log.debug("Removing Pragma header to avoid caching issues in IE");					res.setHeader("Pragma",null);				}				if (res.containsHeader("Cache-Control")) {					log.debug("Removing Cache-Control header to avoid caching issues in IE");					res.setHeader("Cache-Control",null);				}				if (command.equalsIgnoreCase(COMMAND_NSCERT)) {					res.setContentType("application/x-x509-ca-cert");					res.setContentLength(enccert.length);					res.getOutputStream().write(enccert);					log.debug("Sent CA cert to NS client, len="+enccert.length+".");				} else if (command.equalsIgnoreCase(COMMAND_IECERT)) {					res.setHeader("Content-disposition", "attachment; filename=" + certview.getUsername() + ".crt");					res.setContentType("application/octet-stream");					res.setContentLength(enccert.length);					res.getOutputStream().write(enccert);					log.debug("Sent CA cert to IE client, len="+enccert.length+".");				} else if (command.equalsIgnoreCase(COMMAND_CERT)) {					byte[] b64cert = Base64.encode(enccert);					String out = RequestHelper.BEGIN_CERTIFICATE_WITH_NL;                   					out += new String(b64cert);					out += RequestHelper.END_CERTIFICATE_WITH_NL;					res.setHeader("Content-disposition", "attachment; filename=" + certview.getUsername() + ".pem");					res.setContentType("application/octet-stream");					res.setContentLength(out.length());					res.getOutputStream().write(out.getBytes());					log.debug("Sent CA cert to client, len="+out.length()+".");				} else {					res.setContentType("text/plain");					res.getOutputStream().println("Commands="+COMMAND_NSCERT+" || "+COMMAND_IECERT+" || "+COMMAND_CERT);					return;				}            } catch (Exception e) {                log.error("Error getting certificates: ", e);                PrintStream ps = new PrintStream(res.getOutputStream());                e.printStackTrace(ps);                res.sendError(HttpServletResponse.SC_NOT_FOUND, "Error getting certificates.");                return;            }        }        else {            res.setContentType("text/plain");            res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad Request format");            return;        }    } // doGet