KeyStore ks = generateToken(username, password, keylength, false);
KeyStore ks = generateToken(administrator, username, password, keylength, false);
    public void doPost(HttpServletRequest request, HttpServletResponse response)        throws IOException, ServletException {        ServletDebug debug = new ServletDebug(request,response);        try {            String username        = request.getParameter("user");            String password        = request.getParameter("password");            String keylengthstring = request.getParameter("keylength");            int keylength = 1024;            if(keylengthstring != null)              keylength = Integer.parseInt(keylengthstring);            administrator = new Admin(Admin.TYPE_PUBLIC_WEB_USER, request.getRemoteAddr());            IUserAdminSessionRemote adminsession = userdatahome.create();            ISignSessionRemote signsession = signsessionhome.create();            RequestHelper helper = new RequestHelper(administrator, debug);            cat.debug("Got request for " + username + "/" + password);            debug.print("<h3>username: "+username+"</h3>");            // Check user            int tokentype = SecConst.TOKEN_SOFT_BROWSERGEN;            UserAdminData data = adminsession.findUser(administrator, username);            if(data == null)              throw new ObjectNotFoundException();                // get users Token Type.            tokentype = data.getTokenType();            if(tokentype == SecConst.TOKEN_SOFT_P12){              KeyStore ks = generateToken(username, password, keylength, false);              sendP12Token(ks, username, password, response);            }            if(tokentype == SecConst.TOKEN_SOFT_JKS){              KeyStore ks = generateToken(username, password, keylength, true);              sendJKSToken(ks, username, password, response);            }            if(tokentype == SecConst.TOKEN_SOFT_PEM){              KeyStore ks = generateToken(username, password, keylength, false);              sendPEMTokens(ks, username, password, response);            }            if(tokentype == SecConst.TOKEN_SOFT_BROWSERGEN){              // first check if it is a netcsape request,              if (request.getParameter("keygen") != null) {                  byte[] reqBytes=request.getParameter("keygen").getBytes();                  cat.debug("Received NS request:"+new String(reqBytes));                  if (reqBytes != null) {                      byte[] certs = helper.nsCertRequest(signsession, reqBytes, username, password);                      RequestHelper.sendNewCertToNSClient(certs, response);                  }              } else if ( (request.getParameter("pkcs10") != null) || (request.getParameter("PKCS10") != null) ) {                  // if not netscape, check if it's IE                  byte[] reqBytes=request.getParameter("pkcs10").getBytes();                  if (reqBytes == null)                      reqBytes=request.getParameter("PKCS10").getBytes();                  cat.debug("Received IE request:"+new String(reqBytes));                  if (reqBytes != null) {                      byte[] b64cert=helper.pkcs10CertRequest(signsession, reqBytes, username, password);                      debug.ieCertFix(b64cert);                      RequestHelper.sendNewCertToIEClient(b64cert, response.getOutputStream(), getServletContext(), getInitParameter("responseTemplate"));                  }              } else if (request.getParameter("pkcs10req") != null) {                  // if not IE, check if it's manual request                  byte[] reqBytes=request.getParameter("pkcs10req").getBytes();                  if (reqBytes != null) {                      byte[] b64cert=helper.pkcs10CertRequest(signsession, reqBytes, username, password);                    RequestHelper.sendNewB64Cert(b64cert, response);                  }              }            }        } catch (ObjectNotFoundException oe) {            cat.debug("Non existens username!");            debug.printMessage("Non existent username!");            debug.printMessage("To generate a certificate a valid username and password must be entered.");            debug.printDebugInfo();            return;        } catch (AuthStatusException ase) {            cat.debug("Wrong user status!");            debug.printMessage("Wrong user status!");            debug.printMessage("To generate a certificate for a user the user must have status new, failed or inprocess.");            debug.printDebugInfo();            return;        } catch (AuthLoginException ale) {            cat.debug("Wrong password for user!");            debug.printMessage("Wrong username or password!");            debug.printMessage("To generate a certificate a valid username and password must be entered.");            debug.printDebugInfo();            return;        } catch (SignRequestException re) {            cat.debug("Invalid request!");            debug.printMessage("Invalid request!");            debug.printMessage("Please supply a correct request.");            debug.printDebugInfo();            return;        } catch (SignRequestSignatureException se) {            cat.debug("Invalid signature on certificate request!");            debug.printMessage("Invalid signature on certificate request!");            debug.printMessage("Please supply a correctly signed request.");            debug.printDebugInfo();            return;        } catch (java.lang.ArrayIndexOutOfBoundsException ae) {            cat.debug("Empty or invalid request received.");            debug.printMessage("Empty or invalid request!");            debug.printMessage("Please supply a correct request.");            debug.printDebugInfo();            return;        } catch (Exception e) {            cat.debug(e);            debug.print("<h3>parameter name and values: </h3>");            Enumeration paramNames=request.getParameterNames();            while (paramNames.hasMoreElements()) {                String name=paramNames.nextElement().toString();                String parameter=request.getParameter(name);                debug.print("<h4>"+name+":</h4>"+parameter+"<br>");            }            debug.takeCareOfException(e);            debug.printDebugInfo();        }    } //doPost