001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.geronimo.ca.helper; 019 020 import java.io.ByteArrayOutputStream; 021 import java.io.IOException; 022 import java.util.Properties; 023 024 import javax.servlet.ServletException; 025 import javax.servlet.http.HttpServletRequest; 026 import javax.servlet.http.HttpServletResponse; 027 028 import org.apache.geronimo.ca.helper.util.CAHelperUtils; 029 030 /** 031 * Servlet implementation class for Servlet: CertificateRequestServlet 032 * 033 * @version $Rev: 514091 $ $Date: 2007-03-03 01:26:39 -0500 (Sat, 03 Mar 2007) $ 034 */ 035 public class CertificateRequestServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { 036 /* (non-Java-doc) 037 * @see javax.servlet.http.HttpServlet#HttpServlet() 038 */ 039 public CertificateRequestServlet() { 040 super(); 041 } 042 043 /* (non-Java-doc) 044 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 045 */ 046 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 047 doPost(request, response); 048 } 049 050 /* (non-Java-doc) 051 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 052 */ 053 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 054 // Retrieve the values submitted by the user 055 String reqCN = request.getParameter("reqCN"); 056 String reqOU = request.getParameter("reqOU"); 057 String reqO = request.getParameter("reqO"); 058 String reqL = request.getParameter("reqL"); 059 String reqST = request.getParameter("reqST"); 060 String reqC = request.getParameter("reqC"); 061 String spkac = request.getParameter("spkac"); 062 063 if(spkac == null || spkac.equals("")) { 064 // browser did not generate SignedPublicKeyAndChallenge 065 throw new ServletException("Browser did not generate SignedPublicKeyAndChallenge. Resubmit your certificate request."); 066 } 067 // Create a Properties object with user supplied values 068 Properties csrProps = new Properties(); 069 csrProps.setProperty("CN", reqCN); 070 csrProps.setProperty("OU", reqOU); 071 csrProps.setProperty("O", reqO); 072 csrProps.setProperty("L", reqL); 073 csrProps.setProperty("ST", reqST); 074 csrProps.setProperty("C", reqC); 075 csrProps.setProperty("SPKAC", spkac); 076 077 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 078 csrProps.store(baos, "Request received through CA Helper Application"); 079 baos.close(); 080 081 // Store the CSR in the Certificate Request Store. 082 String csrId = CAHelperUtils.getCertificateRequestStore().storeRequest(null, baos.toString()); 083 084 // Display the CSR Id to the user and confirm the receipt of CSR 085 request.setAttribute("id", csrId); 086 getServletContext().getRequestDispatcher("/receivedCSR.jsp").forward(request, response); 087 } 088 }