Removing AAF references from Cert-Service in OOM repo.
[oom/platform/cert-service.git] / certService / src / main / java / org / onap / oom / certservice / certification / CertificationModelFactory.java
1 /*
2  * ============LICENSE_START=======================================================
3  * PROJECT
4  * ================================================================================
5  * Copyright (C) 2020 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.oom.certservice.certification;
22
23 import org.onap.oom.certservice.certification.configuration.Cmpv2ServerProvider;
24 import org.onap.oom.certservice.certification.configuration.model.Cmpv2Server;
25 import org.onap.oom.certservice.certification.exception.DecryptionException;
26 import org.onap.oom.certservice.certification.model.CertificationModel;
27 import org.onap.oom.certservice.certification.model.CsrModel;
28 import org.onap.oom.certservice.cmpv2client.exceptions.CmpClientException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Service;
33
34 @Service
35 public class CertificationModelFactory {
36
37     private static final Logger LOGGER = LoggerFactory.getLogger(CertificationModelFactory.class);
38
39     private final CsrModelFactory csrModelFactory;
40     private final Cmpv2ServerProvider cmpv2ServerProvider;
41     private final CertificationProvider certificationProvider;
42
43     @Autowired
44     CertificationModelFactory(
45             CsrModelFactory csrModelFactory,
46             Cmpv2ServerProvider cmpv2ServerProvider,
47             CertificationProvider certificationProvider
48     ) {
49         this.cmpv2ServerProvider = cmpv2ServerProvider;
50         this.csrModelFactory = csrModelFactory;
51         this.certificationProvider = certificationProvider;
52     }
53
54     public CertificationModel createCertificationModel(String encodedCsr, String encodedPrivateKey, String caName)
55             throws DecryptionException, CmpClientException {
56         CsrModel csrModel = csrModelFactory.createCsrModel(
57                 new CsrModelFactory.StringBase64(encodedCsr),
58                 new CsrModelFactory.StringBase64(encodedPrivateKey)
59         );
60         LOGGER.debug("Received CSR meta data: \n{}", csrModel);
61
62         Cmpv2Server cmpv2Server = cmpv2ServerProvider.getCmpv2Server(caName);
63         LOGGER.debug("Found server for given CA name: \n{}", cmpv2Server);
64
65         LOGGER.info("Sending sign request for certification model for CA named: {}, and certificate signing request:\n{}",
66                 caName, csrModel);
67         return certificationProvider.signCsr(csrModel, cmpv2Server);
68     }
69
70 }