Coverage Report - org.kuali.rice.ksb.security.admin.ExportServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
ExportServlet
0%
0/20
0%
0/4
1.75
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ksb.security.admin;
 17  
 
 18  
 import java.io.IOException;
 19  
 
 20  
 import javax.servlet.ServletException;
 21  
 import javax.servlet.http.HttpServlet;
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 import javax.servlet.http.HttpServletResponse;
 24  
 
 25  
 /**
 26  
  * A servlet which returns a client {@link java.security.KeyStore} object to the user as a file.  It takes in
 27  
  * the KeyStore file as a session attribute byte array.
 28  
  * 
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class ExportServlet extends HttpServlet {
 32  
 
 33  
     private static final long serialVersionUID = 3234778044685975458L;
 34  
     
 35  
     private static final String MIME_TYPE = "application/octet-stream";
 36  
 //    application/pkix-cert
 37  
 //    application/pkix-crl
 38  
     public static final String CLIENT_KEYSTORE_DATA = "ClientKeyStoreData";
 39  
     
 40  
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 41  0
         byte[] clientKeyStoreData = (byte[])request.getSession().getAttribute(CLIENT_KEYSTORE_DATA);
 42  0
         request.getSession().removeAttribute(CLIENT_KEYSTORE_DATA);
 43  0
         if (clientKeyStoreData == null) {
 44  0
             throw new ServletException("No keystore file was specified.");
 45  
         }
 46  0
         response.setContentType(MIME_TYPE);
 47  0
         response.setContentLength(clientKeyStoreData.length);
 48  0
         response.setHeader("Content-disposition", "attachment; filename="+extractFileName(request));
 49  0
         response.getOutputStream().write(clientKeyStoreData);
 50  0
         response.getOutputStream().close();
 51  0
     }
 52  
 
 53  
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 54  0
         doPost(request, response);
 55  0
     }
 56  
 
 57  
     private String extractFileName(HttpServletRequest request) {
 58  0
         String path = request.getPathInfo();
 59  0
         int index = path.lastIndexOf('/');
 60  0
         if (index >= 0) {
 61  0
             path = path.substring(index+1);
 62  
         }
 63  0
         return path;
 64  
     }
 65  
 
 66  
     public static final String generateExportPath(String keystoreFileName, HttpServletRequest request) {
 67  0
         String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
 68  0
         return basePath + "/exportsecurity/"+keystoreFileName;
 69  
     }
 70  
 
 71  
 }