1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.security;
17
18 import java.io.IOException;
19 import java.io.PrintWriter;
20 import java.security.Signature;
21
22 import javax.servlet.ServletOutputStream;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.servlet.http.HttpServletResponseWrapper;
25
26 import org.kuali.rice.ksb.service.KSBServiceLocator;
27
28
29
30
31
32
33
34 public class SignatureSigningResponseWrapper extends HttpServletResponseWrapper {
35
36 private DigitalSigner signer;
37 private ServletOutputStream outputStream;
38 private PrintWriter writer;
39
40 public SignatureSigningResponseWrapper(HttpServletResponse response) {
41 super(response);
42 try {
43 Signature signature = KSBServiceLocator.getDigitalSignatureService().getSignatureForSigning();
44 String alias = KSBServiceLocator.getJavaSecurityManagementService().getModuleKeyStoreAlias();
45 this.signer = new ResponseHeaderDigitalSigner(signature, alias, response);
46 } catch (Exception e) {
47 throw new RuntimeException("Failed to initialize digital signature verification.", e);
48 }
49 }
50
51 @Override
52 public ServletOutputStream getOutputStream() throws IOException {
53 if (this.outputStream == null) {
54 this.outputStream = new SignatureSigningOutputStream(this.signer, super.getOutputStream(), true);
55 }
56 return this.outputStream;
57 }
58
59 @Override
60 public PrintWriter getWriter() throws IOException {
61 if (this.writer == null) {
62 this.writer = new PrintWriter(getOutputStream());
63 }
64 return this.writer;
65 }
66
67 }