KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > ca > helper > CertificateRequestServlet


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.ca.helper;
19
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.Properties JavaDoc;
23
24 import javax.servlet.ServletException JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.geronimo.ca.helper.util.CAHelperUtils;
29
30 /**
31  * Servlet implementation class for Servlet: CertificateRequestServlet
32  *
33  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
34  */

35  public class CertificateRequestServlet extends javax.servlet.http.HttpServlet JavaDoc implements javax.servlet.Servlet JavaDoc {
36     /* (non-Java-doc)
37      * @see javax.servlet.http.HttpServlet#HttpServlet()
38      */

39     public CertificateRequestServlet() {
40         super();
41     }
42
43     /* (non-Java-doc)
44      * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
45      */

46     protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
47         doPost(request, response);
48     }
49
50     /* (non-Java-doc)
51      * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
52      */

53     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
54         // Retrieve the values submitted by the user
55
String JavaDoc reqCN = request.getParameter("reqCN");
56         String JavaDoc reqOU = request.getParameter("reqOU");
57         String JavaDoc reqO = request.getParameter("reqO");
58         String JavaDoc reqL = request.getParameter("reqL");
59         String JavaDoc reqST = request.getParameter("reqST");
60         String JavaDoc reqC = request.getParameter("reqC");
61         String JavaDoc spkac = request.getParameter("spkac");
62
63         if(spkac == null || spkac.equals("")) {
64             // browser did not generate SignedPublicKeyAndChallenge
65
throw new ServletException JavaDoc("Browser did not generate SignedPublicKeyAndChallenge. Resubmit your certificate request.");
66         }
67         // Create a Properties object with user supplied values
68
Properties JavaDoc csrProps = new Properties JavaDoc();
69         csrProps.setProperty("CN", reqCN);
70         csrProps.setProperty("OU", reqOU);
71         csrProps.setProperty("O", reqO);
72         csrProps.setProperty("L", reqL);
73         csrProps.setProperty("ST", reqST);
74         csrProps.setProperty("C", reqC);
75         csrProps.setProperty("SPKAC", spkac);
76
77         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
78         csrProps.store(baos, "Request received through CA Helper Application");
79         baos.close();
80
81         // Store the CSR in the Certificate Request Store.
82
String JavaDoc csrId = CAHelperUtils.getCertificateRequestStore().storeRequest(null, baos.toString());
83
84         // Display the CSR Id to the user and confirm the receipt of CSR
85
request.setAttribute("id", csrId);
86         getServletContext().getRequestDispatcher("/receivedCSR.jsp").forward(request, response);
87     }
88 }
89
Popular Tags