001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ksb.security;
017
018 import java.security.Signature;
019 import java.security.cert.Certificate;
020
021 import org.apache.commons.httpclient.HttpMethod;
022 import org.apache.commons.lang.StringUtils;
023 import org.kuali.rice.ksb.util.KSBConstants;
024
025 /**
026 * A DigitalSigner implementation which places the alias and digital signature into the request
027 * headers of the commons HttpClient's HttpMethod.
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031 public class HttpClientHeaderDigitalSigner extends AbstractDigitalSigner {
032
033 private HttpMethod method;
034 private String alias;
035 private Certificate certificate;
036
037 public HttpClientHeaderDigitalSigner(Signature signature, HttpMethod method, String alias) {
038 super(signature);
039 this.method = method;
040 this.alias = alias;
041 }
042
043 public HttpClientHeaderDigitalSigner(Signature signature, HttpMethod method, String alias, Certificate certificate) {
044 this(signature, method, alias);
045 this.certificate = certificate;
046 }
047
048 public HttpClientHeaderDigitalSigner(Signature signature, HttpMethod method, Certificate certificate) {
049 super(signature);
050 this.method = method;
051 this.certificate = certificate;
052 }
053
054 public void sign() throws Exception {
055 if (StringUtils.isNotBlank(this.alias) ) {
056 this.method.addRequestHeader(KSBConstants.KEYSTORE_ALIAS_HEADER, this.alias);
057 }
058 if (this.certificate != null) {
059 this.method.addRequestHeader(KSBConstants.KEYSTORE_CERTIFICATE_HEADER, getEncodedCertificate(this.certificate));
060 }
061 this.method.addRequestHeader(KSBConstants.DIGITAL_SIGNATURE_HEADER, getEncodedSignature());
062 }
063
064 }