/** * Adds {@link KeyRecord} to role. * * @param keyRecord is {@link KeyRecord} */ public void addKeyRecord(KeyRecord keyRecord) { keyRecords.put(keyRecord.getPublicKey(), keyRecord); }
/** * Create new {@link SimpleRole} and add one {@link KeyRecord} associated with role. * * @param name is name of role * @param keyRecord is {@link KeyRecord} associated with role */ public SimpleRole(String name, @NonNull KeyRecord keyRecord) { super(name); keyRecords.put(keyRecord.getPublicKey(), keyRecord); }
/** * Checks if permission of given type exists and is allowed for given key record * @param permissionName type of permission to check for * @param keyRecord key record to check permission with * @return permission allowed for keyRecord is found * @throws Quantiser.QuantiserException if quantas limit was reached during check */ public boolean isPermitted(String permissionName, KeyRecord keyRecord) throws Quantiser.QuantiserException { return isPermitted(permissionName, keyRecord.getPublicKey()); }
/** * Check role is allowed to keys * * @param keys is set of keys * @return true if role is allowed to keys */ @Override public boolean isAllowedForKeys(Set<? extends AbstractKey> keys) { if(!super.isAllowedForKeys(keys)) { return false; } boolean allMatch1 = anonymousIds.stream().allMatch(anonId -> keys.stream().anyMatch(key -> { try { return key.matchAnonymousId(anonId.getBytes()); } catch (IOException e) { return false; } })); boolean allMatch2 = keyRecords.values().stream().allMatch( kr -> keys.stream().anyMatch(k -> k.getPublicKey().equals(kr.getPublicKey()))); boolean allMatch3 = keyAddresses.stream().allMatch(address -> keys.stream().anyMatch(key -> key.isMatchingKeyAddress(address))); return allMatch1 && allMatch2 && allMatch3; }
private void initWithRecords(@NonNull Collection records) { records.forEach(x -> { KeyRecord kr = null; AnonymousId anonId = null; if (x instanceof KeyRecord) kr = (KeyRecord) x; else if (x instanceof PublicKey) kr = new KeyRecord((PublicKey) x); else if (x instanceof AnonymousId) anonId = (AnonymousId) x; else if (x instanceof PrivateKey) kr = new KeyRecord(((PrivateKey) x).getPublicKey()); else if (x instanceof KeyAddress) keyAddresses.add((KeyAddress) x); else throw new IllegalArgumentException("Cant create KeyRecord from " + x + ": "+(x.getClass().getName())); if (anonId != null) anonymousIds.add(anonId); else if (kr != null) keyRecords.put(kr.getPublicKey(), kr); }); }
assertThat(issuer.getPublicKey(), is(instanceOf(PublicKey.class))); assertEquals(issuer.getStringOrThrow("name"), "Universa");
KeyRecord checkingIssuer = checkingContract.getIssuer().getKeyRecords().iterator().next(); assertNotNull(checkingIssuer); assertThat(checkingIssuer.getPublicKey(), is(instanceOf(PublicKey.class))); assertEquals(checkingIssuer, originIssuer); KeyRecord checkingCreator = checkingContract.getCreator().getKeyRecords().iterator().next(); assertNotNull(checkingCreator); assertThat(checkingCreator.getPublicKey(), is(instanceOf(PublicKey.class))); assertEquals(checkingCreator, originCreator); KeyRecord checkingOwner = checkingContract.getOwner().getKeyRecords().iterator().next(); assertNotNull(checkingOwner); assertThat(checkingOwner.getPublicKey(), is(instanceOf(PublicKey.class))); assertEquals(checkingOwner, originOwner);