Skip to content

Commit 1402cbd

Browse files
committed
Remove dependency on AEM's KeyStoreService
Introduce AEM agnostic service interface for which an impl is only registered when running inside AEM. Allows starting SCR component AuthorizableInstallerServiceImpl even outside AEM. This closes #878
1 parent a5bd940 commit 1402cbd

3 files changed

Lines changed: 95 additions & 2 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package biz.netcentric.cq.tools.actool.aem;
2+
3+
/*-
4+
* #%L
5+
* Access Control Tool Bundle
6+
* %%
7+
* Copyright (C) 2015 - 2026 Cognizant Netcentric
8+
* %%
9+
* This program and the accompanying materials are made
10+
* available under the terms of the Eclipse Public License 2.0
11+
* which is available at https://www.eclipse.org/legal/epl-2.0/
12+
*
13+
* SPDX-License-Identifier: EPL-2.0
14+
* #L%
15+
*/
16+
17+
import java.security.KeyPair;
18+
import java.security.PrivateKey;
19+
import java.security.cert.Certificate;
20+
21+
import org.apache.sling.api.resource.ResourceResolver;
22+
import org.osgi.service.component.annotations.Component;
23+
import org.osgi.service.component.annotations.Reference;
24+
import org.osgi.service.component.annotations.ReferencePolicyOption;
25+
26+
import com.adobe.granite.keystore.KeyStoreService;
27+
28+
import biz.netcentric.cq.tools.actool.crypto.UserKeyStoreService;
29+
30+
@Component
31+
public class AemUserKeyStoreService implements UserKeyStoreService {
32+
33+
@Reference(policyOption = ReferencePolicyOption.GREEDY)
34+
private KeyStoreService delegate;
35+
36+
@Override
37+
public boolean keyStoreExists(ResourceResolver resourceResolver, String userId) {
38+
return delegate.keyStoreExists(resourceResolver, userId);
39+
}
40+
41+
@Override
42+
public void addKeyStoreKeyEntry(ResourceResolver resourceResolver, String userId, String key, PrivateKey privateKey,
43+
Certificate[] certificates) {
44+
delegate.addKeyStoreKeyEntry(resourceResolver, userId, key, privateKey, certificates);
45+
}
46+
47+
@Override
48+
public void addKeyStoreKeyPair(ResourceResolver resourceResolver, String userId, KeyPair keyPair, String key) {
49+
delegate.addKeyStoreKeyPair(resourceResolver, userId, keyPair, key);
50+
}
51+
52+
@Override
53+
public void createKeyStore(ResourceResolver resourceResolver, String userId, char[] keyStorePasswordCharArray) {
54+
delegate.createKeyStore(resourceResolver, userId, keyStorePasswordCharArray);
55+
}
56+
57+
}

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/authorizableinstaller/impl/AuthorizableInstallerServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import org.slf4j.LoggerFactory;
6363

6464
import com.adobe.granite.keystore.KeyStoreNotInitialisedException;
65-
import com.adobe.granite.keystore.KeyStoreService;
6665

6766
import biz.netcentric.cq.tools.actool.api.InstallationOptions;
6867
import biz.netcentric.cq.tools.actool.authorizableinstaller.AuthorizableCreatorException;
@@ -73,6 +72,7 @@
7372
import biz.netcentric.cq.tools.actool.configmodel.pkcs.Key;
7473
import biz.netcentric.cq.tools.actool.configmodel.pkcs.RandomPassword;
7574
import biz.netcentric.cq.tools.actool.crypto.DecryptionService;
75+
import biz.netcentric.cq.tools.actool.crypto.UserKeyStoreService;
7676
import biz.netcentric.cq.tools.actool.externalusermanagement.ExternalGroupManagement;
7777
import biz.netcentric.cq.tools.actool.helper.AcHelper;
7878
import biz.netcentric.cq.tools.actool.helper.AccessControlUtils;
@@ -105,7 +105,7 @@ public class AuthorizableInstallerServiceImpl implements
105105
DecryptionService decryptionService;
106106

107107
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy=ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
108-
volatile KeyStoreService keyStoreService;
108+
volatile UserKeyStoreService keyStoreService;
109109

110110
@Reference(policyOption = ReferencePolicyOption.GREEDY)
111111
ResourceResolverFactory resourceResolverFactory;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package biz.netcentric.cq.tools.actool.crypto;
2+
3+
/*-
4+
* #%L
5+
* Access Control Tool Bundle
6+
* %%
7+
* Copyright (C) 2015 - 2026 Cognizant Netcentric
8+
* %%
9+
* This program and the accompanying materials are made
10+
* available under the terms of the Eclipse Public License 2.0
11+
* which is available at https://www.eclipse.org/legal/epl-2.0/
12+
*
13+
* SPDX-License-Identifier: EPL-2.0
14+
* #L%
15+
*/
16+
17+
import java.security.KeyPair;
18+
import java.security.PrivateKey;
19+
import java.security.cert.Certificate;
20+
21+
import org.apache.sling.api.resource.ResourceResolver;
22+
23+
/** Interface for managing user's key stores.
24+
* This allows to decouple from a concrete (AEM-specific) interface like {@link com.adobe.granite.keystore.KeyStoreService} */
25+
public interface UserKeyStoreService {
26+
27+
boolean keyStoreExists(ResourceResolver resourceResolver, String userId);
28+
29+
void addKeyStoreKeyEntry(ResourceResolver resourceResolver, String userId, String key, PrivateKey privateKey,
30+
Certificate[] certificates);
31+
32+
void addKeyStoreKeyPair(ResourceResolver resourceResolver, String userId, KeyPair keyPair, String key);
33+
34+
void createKeyStore(ResourceResolver resourceResolver, String userId, char[] keyStorePasswordCharArray);
35+
36+
}

0 commit comments

Comments
 (0)