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.security.Signature;
19 import java.security.cert.Certificate;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.http.HttpRequest;
23 import org.kuali.rice.ksb.util.KSBConstants;
24
25
26
27
28
29
30
31 public class HttpClientHeaderDigitalSigner extends AbstractDigitalSigner {
32
33 private HttpRequest method;
34 private String alias;
35 private Certificate certificate;
36
37 public HttpClientHeaderDigitalSigner(Signature signature, HttpRequest method, String alias) {
38 super(signature);
39 this.method = method;
40 this.alias = alias;
41 }
42
43 public HttpClientHeaderDigitalSigner(Signature signature, HttpRequest method, String alias, Certificate certificate) {
44 this(signature, method, alias);
45 this.certificate = certificate;
46 }
47
48 public HttpClientHeaderDigitalSigner(Signature signature, HttpRequest method, Certificate certificate) {
49 super(signature);
50 this.method = method;
51 this.certificate = certificate;
52 }
53
54 public void sign() throws Exception {
55 if (StringUtils.isNotBlank(this.alias) ) {
56 this.method.addHeader(KSBConstants.KEYSTORE_ALIAS_HEADER, this.alias);
57 }
58 if (this.certificate != null) {
59 this.method.addHeader(KSBConstants.KEYSTORE_CERTIFICATE_HEADER, getEncodedCertificate(this.certificate));
60 }
61 this.method.addHeader(KSBConstants.DIGITAL_SIGNATURE_HEADER, getEncodedSignature());
62 }
63
64 }