Coverage Report - org.kuali.rice.ksb.security.HttpClientHeaderDigitalSigner
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpClientHeaderDigitalSigner
0%
0/17
0%
0/4
1.5
 
 1  
 /*
 2  
  * Copyright 2007 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;
 17  
 
 18  
 import java.security.Signature;
 19  
 import java.security.cert.Certificate;
 20  
 
 21  
 import org.apache.commons.httpclient.HttpMethod;
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.kuali.rice.ksb.util.KSBConstants;
 24  
 
 25  
 /**
 26  
  * A DigitalSigner implementation which places the alias and digital signature into the request
 27  
  * headers of the commons HttpClient's HttpMethod.
 28  
  * 
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  
 public class HttpClientHeaderDigitalSigner extends AbstractDigitalSigner {
 32  
 
 33  
         private HttpMethod method;
 34  
         private String alias;
 35  
         private Certificate certificate;
 36  
         
 37  
     public HttpClientHeaderDigitalSigner(Signature signature, HttpMethod method, String alias) {
 38  0
         super(signature);
 39  0
         this.method = method;
 40  0
         this.alias = alias;
 41  0
     }
 42  
     
 43  
     public HttpClientHeaderDigitalSigner(Signature signature, HttpMethod method, String alias, Certificate certificate) {
 44  0
         this(signature, method, alias);
 45  0
         this.certificate = certificate;
 46  0
     }
 47  
     
 48  
     public HttpClientHeaderDigitalSigner(Signature signature, HttpMethod method, Certificate certificate) {
 49  0
         super(signature);
 50  0
         this.method = method;
 51  0
         this.certificate = certificate;
 52  0
     }
 53  
     
 54  
         public void sign() throws Exception {
 55  0
         if (StringUtils.isNotBlank(this.alias) ) {
 56  0
             this.method.addRequestHeader(KSBConstants.KEYSTORE_ALIAS_HEADER, this.alias);
 57  
         }
 58  0
             if (this.certificate != null) {
 59  0
                 this.method.addRequestHeader(KSBConstants.KEYSTORE_CERTIFICATE_HEADER, getEncodedCertificate(this.certificate));
 60  
             }
 61  0
             this.method.addRequestHeader(KSBConstants.DIGITAL_SIGNATURE_HEADER, getEncodedSignature());
 62  0
         }
 63  
 
 64  
 }