Fix reading legacy atoms key
@@ -46,14 +46,19 @@ public class WonKeysReaderWriter {
public static Set<PublicKey> readKeyFromAtom(URI atomUri, Dataset dataset, String keyUri)
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException {
URI keyGraphUri = WonRelativeUriHelper.createKeyGraphURIForAtomURI(atomUri);
- PublicKey key = readFromModel(dataset.getNamedModel(keyGraphUri.toString()), keyUri);
+ PublicKey key = null;
+ if (dataset.containsNamedModel(keyGraphUri.toString())) {
+ key = readFromModel(dataset.getNamedModel(keyGraphUri.toString()), keyUri);
+ }
Set<PublicKey> keys = new HashSet<>();
if (key != null) {
+ // key found in #key graph
keys.add(key);
- } else {
+ return keys;
+ }
+ // allow legacy atoms (keys in content graph)
String aclGraphUri = WonRelativeUriHelper.createAclGraphURIForAtomURI(atomUri).toString();
String sysinfoGraphUri = WonRelativeUriHelper.createSysInfoGraphURIForAtomURI(atomUri).toString();
- // allow legacy atoms (keys in content graph)
Iterator<String> names = dataset.listNames();
while (names.hasNext()) {
String graphUri = names.next();
@@ -65,10 +70,11 @@ public class WonKeysReaderWriter {
key = readFromModel(dataset.getNamedModel(graphUri), keyUri);
if (key != null) {
keys.add(key);
+ // found key in content graph
return keys;
}
}
- }
+ // no key found
return keys;
}
@@ -82,6 +88,9 @@ public class WonKeysReaderWriter {
public static PublicKey readFromModel(Model model, String keyUri)
throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException {
Map<String, PublicKey> keys = new HashMap<>();
+ if (model == null) {
+ return null;
+ }
Resource keyRes = model.createResource(keyUri);
readFromModel(model, keys, keyRes);
return keys.get(keyUri);
