1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.certificates;
12
13 import java.lang.reflect.InvocationTargetException;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.Set;
17
18 import org.apache.commons.beanutils.BeanUtils;
19 import org.apache.coyote.http11.AbstractHttp11JsseProtocol;
20 import org.apache.tomcat.util.net.SSLHostConfig;
21 import org.apache.tomcat.util.net.SSLHostConfigCertificate;
22
23 import psiprobe.model.certificates.CertificateInfo;
24 import psiprobe.model.certificates.ConnectorInfo;
25 import psiprobe.model.certificates.SslHostConfigInfo;
26
27
28
29
30 public class SslHostConfigHelper {
31
32
33
34
35
36
37
38
39
40
41 public SslHostConfigHelper(AbstractHttp11JsseProtocol<?> protocol, ConnectorInfo info)
42 throws IllegalAccessException, InvocationTargetException {
43 SSLHostConfig[] sslHostConfigs = protocol.findSslHostConfigs();
44 List<SslHostConfigInfo> sslHostConfigInfos = new ArrayList<>(sslHostConfigs.length);
45 for (SSLHostConfig sslHostConfig : sslHostConfigs) {
46 sslHostConfigInfos.add(toSslHostConfigInfo(sslHostConfig));
47 }
48 info.setSslHostConfigInfos(sslHostConfigInfos);
49 }
50
51
52
53
54
55
56
57
58
59
60
61 private SslHostConfigInfo toSslHostConfigInfo(SSLHostConfig sslHostConfig)
62 throws IllegalAccessException, InvocationTargetException {
63 SslHostConfigInfo sslHostConfigInfo = new SslHostConfigInfo();
64 BeanUtils.copyProperties(sslHostConfigInfo, sslHostConfig);
65
66 Set<SSLHostConfigCertificate> certificates = sslHostConfig.getCertificates();
67 List<CertificateInfo> certificateInfos = new ArrayList<>(certificates.size());
68 for (SSLHostConfigCertificate sslHostConfigCertificate : certificates) {
69 certificateInfos.add(toCertificateInfo(sslHostConfigCertificate));
70 }
71 sslHostConfigInfo.setCertificateInfos(certificateInfos);
72
73 return sslHostConfigInfo;
74 }
75
76
77
78
79
80
81
82
83
84
85
86 private CertificateInfo toCertificateInfo(SSLHostConfigCertificate sslHostConfigCertificate)
87 throws IllegalAccessException, InvocationTargetException {
88 CertificateInfo certificateInfo = new CertificateInfo();
89 BeanUtils.copyProperties(certificateInfo, sslHostConfigCertificate);
90 return certificateInfo;
91 }
92 }