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