Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.cxf.rs.security.jose.common;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -156,12 +157,15 @@ public static boolean checkBooleanProperty(JoseHeaders headers, Properties props
// <Start> Copied from JAX-RS RT FRONTEND ResourceUtils
//

public static InputStream getResourceStream(String loc, Bus bus) throws Exception {
public static InputStream getResourceStream(String loc, Bus bus) throws IOException {
URL url = getResourceURL(loc, bus);
return url == null ? null : url.openStream();
}

public static URL getResourceURL(String loc, Bus bus) throws Exception {
public static URL getResourceURL(String loc, Bus bus) throws IOException {
if (loc == null) {
return null;
}
URL url = null;
if (loc.startsWith(CLASSPATH_PREFIX)) {
String path = loc.substring(CLASSPATH_PREFIX.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,12 @@ public static JsonWebKeys loadJwkSet(Properties props, Bus bus, JweDecryptionPro
String keyContent = null;
String keyStoreLoc = props.getProperty(JoseConstants.RSSEC_KEY_STORE_FILE);
if (keyStoreLoc != null) {
try {
InputStream is = JoseUtils.getResourceStream(keyStoreLoc, bus);
if (is == null) {
try (InputStream isResource = JoseUtils.getResourceStream(keyStoreLoc, bus)) {
if (isResource == null) {
throw new JwkException("Error in loading keystore location: " + keyStoreLoc);
}
try (InputStream isResource = is) {
keyContent = IOUtils.readStringFromStream(isResource);
}
} catch (Exception ex) {
keyContent = IOUtils.readStringFromStream(isResource);
} catch (IOException ex) {
throw new JwkException(ex);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.math.BigInteger;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Properties;

import org.apache.cxf.rs.security.jose.common.JoseConstants;
import org.apache.cxf.rs.security.jose.common.JoseException;
import org.apache.cxf.rs.security.jose.common.JoseUtils;
import org.apache.cxf.rs.security.jose.common.KeyManagementUtils;
Expand Down Expand Up @@ -189,5 +191,16 @@ public void testEc521KeyThumbprint() throws Exception {
String thumbprint = JwkUtils.getThumbprint(EC_521_KEY);
assertEquals("rz4Ohmpxg-UOWIWqWKHlOe0bHSjNUFlHW5vwG_M7qYg", thumbprint);
}
@Test
public void testLoadPublicJwkSet() throws Exception {
final Properties props = new Properties();
props.setProperty(JoseConstants.RSSEC_KEY_STORE_FILE, "unavailable");
try {
JwkUtils.loadPublicJwkSet(null, props);
fail();
} catch (JwkException e) {
assertNull(e.getCause());
}
}

}