| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 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 | |
|
| 37 | |
|
| 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 | |
} |