Skip to content

Package: DeviceKeystoreKeypairCreateTargetProcessor

DeviceKeystoreKeypairCreateTargetProcessor

nameinstructionbranchcomplexitylinemethod
DeviceKeystoreKeypairCreateTargetProcessor()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
initProcessing(JobTargetWrapper)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
lambda$processTarget$0(JobTarget, DeviceKeystoreKeypair, Long)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
processTarget(JobTarget)
M: 76 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.device.management.keystore.job;
14:
15: import org.eclipse.kapua.KapuaException;
16: import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
17: import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
18: import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
19: import org.eclipse.kapua.model.id.KapuaId;
20: import org.eclipse.kapua.service.device.management.keystore.DeviceKeystoreManagementFactory;
21: import org.eclipse.kapua.service.device.management.keystore.DeviceKeystoreManagementService;
22: import org.eclipse.kapua.service.device.management.keystore.job.definition.DeviceKeypairCreatePropertyKeys;
23: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreCertificate;
24: import org.eclipse.kapua.service.device.management.keystore.model.DeviceKeystoreKeypair;
25: import org.eclipse.kapua.service.job.operation.TargetProcessor;
26: import org.eclipse.kapua.service.job.targets.JobTarget;
27:
28: import javax.batch.runtime.context.JobContext;
29: import javax.batch.runtime.context.StepContext;
30: import javax.inject.Inject;
31:
32: /**
33: * {@link TargetProcessor} for {@link DeviceKeystoreManagementService#createKeystoreCertificate(KapuaId, KapuaId, DeviceKeystoreCertificate, Long)}.
34: *
35: * @since 1.0.0
36: */
37: public class DeviceKeystoreKeypairCreateTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {
38: private static final DeviceKeystoreManagementService KEYSTORE_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceKeystoreManagementService.class);
39: private static final DeviceKeystoreManagementFactory KEYSTORE_MANAGEMENT_FACTORY = LOCATOR.getFactory(DeviceKeystoreManagementFactory.class);
40:
41: @Inject
42: JobContext jobContext;
43:
44: @Inject
45: StepContext stepContext;
46:
47: @Override
48: protected void initProcessing(JobTargetWrapper wrappedJobTarget) {
49: setContext(jobContext, stepContext);
50: }
51:
52: @Override
53: public void processTarget(JobTarget jobTarget) throws KapuaException {
54:
55: String keystoreId = stepContextWrapper.getStepProperty(DeviceKeypairCreatePropertyKeys.KEYSTORE_ID, String.class);
56: String alias = stepContextWrapper.getStepProperty(DeviceKeypairCreatePropertyKeys.ALIAS, String.class);
57: Integer size = stepContextWrapper.getStepProperty(DeviceKeypairCreatePropertyKeys.SIZE, Integer.class);
58: String algorithm = stepContextWrapper.getStepProperty(DeviceKeypairCreatePropertyKeys.ALGORITHM, String.class);
59: String signatureAlgorithm = stepContextWrapper.getStepProperty(DeviceKeypairCreatePropertyKeys.SIGNATURE_ALGORITHM, String.class);
60: String attributes = stepContextWrapper.getStepProperty(DeviceKeypairCreatePropertyKeys.ATTRIBUTES, String.class);
61: Long timeout = stepContextWrapper.getStepProperty(DeviceKeypairCreatePropertyKeys.TIMEOUT, Long.class);
62:
63: DeviceKeystoreKeypair deviceKeystoreKeypair = KEYSTORE_MANAGEMENT_FACTORY.newDeviceKeystoreKeypair();
64:
65: deviceKeystoreKeypair.setKeystoreId(keystoreId);
66: deviceKeystoreKeypair.setAlias(alias);
67: deviceKeystoreKeypair.setSize(size);
68: deviceKeystoreKeypair.setAlgorithm(algorithm);
69: deviceKeystoreKeypair.setSignatureAlgorithm(signatureAlgorithm);
70: deviceKeystoreKeypair.setAttributes(attributes);
71:
72: KapuaSecurityUtils.doPrivileged(() -> KEYSTORE_MANAGEMENT_SERVICE.createKeystoreKeypair(jobTarget.getScopeId(), jobTarget.getJobTargetId(), deviceKeystoreKeypair, timeout));
73: }
74: }