Skip to content

Commit cebc22e

Browse files
authored
[#2117] Feature: Add ability to specify keystore type in JAAS keystore (#2118)
1 parent ad267eb commit cebc22e

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public URL getSchemaLocation(String namespace) {
5353
return getClass().getResource("/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd");
5454
case "http://karaf.apache.org/xmlns/jaas/v1.1.0":
5555
return getClass().getResource("/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd");
56+
case "http://karaf.apache.org/xmlns/jaas/v1.2.0":
57+
return getClass().getResource("/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.2.0.xsd");
5658
default:
5759
return null;
5860
}
@@ -131,6 +133,13 @@ public ComponentMetadata parseKeystore(Element element, ParserContext context) {
131133
if (rank != null && rank.length() > 0) {
132134
bean.addProperty("rank", createValue(context, rank));
133135
}
136+
137+
// Parse type
138+
String type = element.getAttribute("type");
139+
if (type != null && type.length() > 0) {
140+
bean.addProperty("type", createValue(context, type));
141+
}
142+
134143
// Parse path
135144
String path = element.getAttribute("path");
136145
if (path != null && path.length() > 0) {

jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@
3333
</service-properties>
3434
</service>
3535

36+
<service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
37+
<service-properties>
38+
<entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jaas/v1.2.0" />
39+
</service-properties>
40+
</service>
41+
3642
</blueprint>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. 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+
19+
-->
20+
<xs:schema elementFormDefault='qualified'
21+
targetNamespace='http://karaf.apache.org/xmlns/jaas/v1.2.0'
22+
xmlns:xs='http://www.w3.org/2001/XMLSchema'
23+
xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
24+
xmlns:tns='http://karaf.apache.org/xmlns/jaas/v1.1.0'>
25+
26+
<xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
27+
28+
<xs:element name="config">
29+
<xs:complexType>
30+
<xs:sequence>
31+
<xs:element name="module" minOccurs="0" maxOccurs="unbounded">
32+
<xs:complexType mixed="true">
33+
<xs:attribute name="name" use="optional" type="xs:string"/>
34+
<xs:attribute name="className" use="required" type="xs:string"/>
35+
<xs:attribute name="flags" default="required">
36+
<xs:simpleType>
37+
<xs:restriction base="xs:NMTOKEN">
38+
<xs:enumeration value="required"/>
39+
<xs:enumeration value="requisite"/>
40+
<xs:enumeration value="sufficient"/>
41+
<xs:enumeration value="optional"/>
42+
</xs:restriction>
43+
</xs:simpleType>
44+
</xs:attribute>
45+
</xs:complexType>
46+
</xs:element>
47+
</xs:sequence>
48+
<xs:attribute name="name" use="required" type="xs:string"/>
49+
<xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
50+
</xs:complexType>
51+
</xs:element>
52+
53+
<xs:element name="keystore">
54+
<xs:complexType>
55+
<xs:attribute name="name" use="required" type="xs:string"/>
56+
<xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
57+
<xs:attribute name="path" use="required" type="xs:string"/>
58+
<xs:attribute name="keystorePassword" use="optional" type="xs:string"/>
59+
<xs:attribute name="keyPasswords" use="optional" type="xs:string"/>
60+
<xs:attribute name="type" use="optional" type="xs:string"/>
61+
</xs:complexType>
62+
</xs:element>
63+
64+
</xs:schema>

jaas/config/src/main/java/org/apache/karaf/jaas/config/KeystoreInstance.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public interface KeystoreInstance {
3535

3636
int getRank();
3737

38+
String getType();
39+
3840
String[] listTrustCertificates();
3941

4042
Certificate getCertificate(String alias);

jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/ResourceKeystoreInstance.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class ResourceKeystoreInstance implements KeystoreInstance {
5353
private static final String JKS = "JKS";
5454

5555
private String name;
56+
private String type = JKS;
5657
private int rank;
5758
private URL path;
5859
private String keystorePassword;
@@ -77,6 +78,20 @@ public void setName(String keystoreName) {
7778
this.name = keystoreName;
7879
}
7980

81+
/**
82+
* @return the keystoreName
83+
*/
84+
public String getType() {
85+
return type;
86+
}
87+
88+
/**
89+
* @param type the keystore type to set
90+
*/
91+
public void setType(String type) {
92+
this.type = type;
93+
}
94+
8095
/**
8196
* @return the rank
8297
*/
@@ -213,7 +228,8 @@ public TrustManager[] getTrustManager(String algorithm) throws KeyStoreException
213228
}
214229

215230
public boolean isKeyLocked(String keyAlias) {
216-
return keyPasswords.get(keyAlias) == null;
231+
// [KARAF-2117] JKS requires a password, PKCS12 does not permit a password
232+
return (JKS.equals(type) && keyPasswords.get(keyAlias) == null);
217233
}
218234

219235
public boolean isKeystoreLocked() {
@@ -247,7 +263,7 @@ private boolean loadKeystoreData() {
247263
keystoreReadDate = System.currentTimeMillis();
248264
trustCerts.clear();
249265
if (keystore == null) {
250-
keystore = KeyStore.getInstance(JKS);
266+
keystore = KeyStore.getInstance(getType());
251267
}
252268
InputStream in = new BufferedInputStream(path.openStream());
253269
keystore.load(in, keystorePassword == null ? new char[0] : keystorePassword.toCharArray());

0 commit comments

Comments
 (0)