Coverage Report - org.kuali.rice.ksb.security.SignatureSigningResponseWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
SignatureSigningResponseWrapper
0%
0/14
0%
0/4
2.333
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 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  
  * An HttpServletResponseWrapper which wraps the underlying response's OutputStream in a 
 31  
  * SignatureSingingOutputStream which will generate a digital signature for the outgoing message.
 32  
  *  
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
 }