/** * A role has exactly same set of keys as in the supplied role. It does not check the logic, * only that list of all keys is exactly same. * <p> * To check that the role can be performed by some other role, use {@link #isAllowedForKeys(Set)}. * * @param otherRole is {@link Role} for checking by keys * @return true if equals * @deprecated the only usable check allowance method is isAllowedForKeys */ @Deprecated public boolean equalKeys(@NonNull Role otherRole) { return otherRole.getKeys().equals(getKeys()); } @Deprecated
private boolean processQuorumMode(Set<? extends AbstractKey> keys) { int counter = this.quorumSize; boolean result = counter == 0; Set<Role> roles = this.roles; for (Role role : roles) { if (result) break; if (role != null && role.isAllowedForKeys(keys) && --counter == 0) { result = true; break; } } return result; }
/** * Get all addresses, used by this role. For public keys returns addresses too. * @deprecated the only usable check allowance method is isAllowedForKeys * @return list of strings with addresses */ @Deprecated public List<String> getAllAddresses() { List<String> res = new ArrayList<>(); getKeyAddresses().forEach(ka -> res.add(ka.toString())); getKeys().forEach(publicKey -> res.add(publicKey.getShortAddress().toString())); return res; }
/** * Register new role. Name must be unique otherwise existing role will be overwritten * @param role * @return registered role */ public Role registerRole(Role role) { String name = role.getName(); roles.put(name, role); role.setContract(this); return role; }
private boolean isSignedBy(Role role) throws Quantiser.QuantiserException { if (role == null) return false; role = role.resolve(); if (role == null) return false; return role.isAllowedForKeys(getEffectiveKeys()); }
registerAndCheckApproved(anonOwnerContract); assertTrue(anonOwnerContract.getOwner().getKeyAddresses().iterator().next().equals(stepaAddress)); assertEquals(0, anonOwnerContract.getOwner().getKeys().size()); assertEquals(0, afterSend.getOwner().getKeyAddresses().size()); assertTrue(afterSend.getOwner().isAllowedForKeys(martyPublicKeys));
registerAndCheckApproved(anonOwnerContract); assertTrue(anonOwnerContract.getOwner().getAnonymousIds().iterator().next().equals(stepaAnonId)); assertEquals(0, anonOwnerContract.getOwner().getKeys().size()); assertEquals(0, afterSend.getOwner().getAnonymousIds().size()); assertTrue(afterSend.getOwner().isAllowedForKeys(martyPublicKeys));
if (owner.isAllowedForKeys(getSealedByKeys())) return true; return false; if ((!(role instanceof Role)) || ((role instanceof RoleLink) && (role.getContract() == null))) return false; return role.isAllowedForKeys(getSealedByKeys()); }))) return true;
try (FileReader r = new FileReader(fileName)) { Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r))); Role role = Role.fromDslBinder("role",binder); assertTrue(role instanceof SimpleRole); assertTrue(role.getKeyRecords().size() == 1); try (FileReader r = new FileReader(fileName)) { Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r))); Role role = Role.fromDslBinder("role",binder); assertTrue(role instanceof SimpleRole); assertTrue(role.getKeyRecords().size() == 2); try (FileReader r = new FileReader(fileName)) { Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r))); Role role = Role.fromDslBinder("role",binder); assertTrue(role instanceof SimpleRole); assertTrue(role.getKeyRecords().size() == 1); try (FileReader r = new FileReader(fileName)) { Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r))); Role role = Role.fromDslBinder("role",binder); assertTrue(role instanceof SimpleRole); assertTrue(role.getKeyAddresses().size() == 1); try (FileReader r = new FileReader(fileName)) { Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r))); Role role = Role.fromDslBinder("role",binder); assertTrue(role instanceof SimpleRole); assertTrue(role.getKeyAddresses().size() == 2);
if (((left != null) && (left.getClass().getName().endsWith("Role") || left.getClass().getName().endsWith("RoleLink"))) && ((right != null) && (right.getClass().getName().endsWith("Role") || right.getClass().getName().endsWith("RoleLink")))) { if (((indxOperator == NOT_EQUAL) && !((Role)left).equalsIgnoreName((Role) right)) || ((indxOperator == EQUAL) && ((Role)left).equalsIgnoreName((Role) right))) ret = true; role = role.resolve(); SimpleRole simpleRole = new SimpleRole(role.getName(), Do.listOf(publicKey)); ret = role.equalsIgnoreName(simpleRole); } else { SimpleRole simpleRole = new SimpleRole(role.getName(), Do.listOf(ka)); ret = role.equalsIgnoreName(simpleRole); keys = leftOperandContract.getSealedByKeys(); ret = ((Role) right).isAllowedForKeys(keys);
/** * Adds required reference to role. The reference is added to the set corresponding * to the specified mode of combining references ({@link RequiredMode}). * * @param reference is added reference * @param requiredMode is mode of combining references */ public void addRequiredReference(Reference reference,RequiredMode requiredMode) { addRequiredReference(reference.getName(), requiredMode); }
/** * Create new root contract to be created. It may have parent, but does not have origin, as it is an origin itself. */ private void checkRootContract() throws Quantiser.QuantiserException { // root contract must be issued ny the issuer Role issuer = getRole("issuer"); if (issuer == null || !issuer.isValid()) { addError(BAD_VALUE, "definition.issuer", "missing issuer"); return; } // the bad case - no issuer - should be processed normally without exceptions: Role createdBy = getRole("creator"); if (createdBy == null || !createdBy.isValid()) { addError(BAD_VALUE, "state.created_by", "invalid creator"); return; } if (!issuer.isAllowedForKeys(getEffectiveKeys())) { addError(ISSUER_MUST_CREATE, "issuer.keys"); } if (state.revision != 1) addError(BAD_VALUE, "state.revision", "must be 1 in a root contract"); if (state.createdAt == null) state.createdAt = definition.createdAt; else if (!state.createdAt.equals(definition.createdAt)) addError(BAD_VALUE, "state.created_at", "invalid"); if (state.origin != null) addError(BAD_VALUE, "state.origin", "must be empty in a root contract"); checkRevokePermissions(revokingItems); }
report("\nWhich can play roles:\n"); contract.getRoles().forEach((name, role) -> { String canPlay = role.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + role.getName()); });
/** * Resolve object describing role and create either: - new role object - symlink to named role instance, ensure it * is register and return it, if it is a Map, tries to construct and register {@link Role} then return it. * * @param roleName is name of the role * @param roleObject is object for role creating * * @return created {@link Role} */ @NonNull public Role createRole(String roleName, Object roleObject) { if (roleObject instanceof CharSequence) { return registerRole(new RoleLink(roleName, roleObject.toString())); } if (roleObject instanceof Role) if(((Role)roleObject).getName() != null && ((Role)roleObject).getName().equals(roleName)) return registerRole(((Role) roleObject)); else return registerRole(((Role) roleObject).linkAs(roleName)); if (roleObject instanceof Map) { Role r = Role.fromDslBinder(roleName, Binder.from(roleObject)); return registerRole(r); } throw new IllegalArgumentException("cant make role from " + roleObject); }
@Deprecated public boolean equalAddresses(Role otherRole) { return otherRole.getKeyAddresses().equals(getKeyAddresses()); } @Deprecated
/** * Testing only. For lne-key roles, return the keyrecord. * @deprecated the only usable check allowance method is isAllowedForKeys * @return found {@link KeyRecord} */ @Deprecated public KeyRecord getKeyRecord() { Set<KeyRecord> kr = getKeyRecords(); if (kr.size() > 1) throw new IllegalStateException("can't get key record as there are many of them"); return kr.iterator().next(); }
KeyRecord issuer = c.getIssuer().getKeyRecords().iterator().next(); assertNotNull(issuer); assertThat(issuer.getPublicKey(), is(instanceOf(PublicKey.class))); assertEquals(owner, roles.get("owner").getKeyRecord()); assertEquals(issuer, roles.get("issuer").getKeyRecord()); assertEquals(issuer, roles.get("creator").getKeyRecord());
/** * Get all addresses, used by registered role from the contract. For public keys returns addresses too. * @return list of strings with addresses */ @Deprecated public List<String> getRoleAddresses(String roleName) { return getRole(roleName).getAllAddresses(); }
@Deprecated public boolean equalAnonIds(Role otherRole) { return otherRole.getAnonymousIds().equals(getAnonymousIds()); }
public void deserealizeWith(Binder data, BiDeserializer d) { createdAt = data.getZonedDateTimeOrThrow("created_at"); expiresAt = data.getZonedDateTime("expires_at", null); revision = data.getIntOrThrow("revision"); this.references = d.deserialize(data.getList("references", null)); if (revision <= 0) throw new IllegalArgumentException("illegal revision number: " + revision); Role r = registerRole(d.deserialize(data.getBinderOrThrow("owner"))); if (!r.getName().equals("owner")) throw new IllegalArgumentException("bad owner role name"); r = registerRole(d.deserialize(data.getBinderOrThrow("created_by"))); if (!r.getName().equals("creator")) throw new IllegalArgumentException("bad creator role name"); this.data = data.getBinder("data", Binder.EMPTY); branchId = data.getString("branch_id", null); parent = d.deserialize(data.get("parent")); origin = d.deserialize(data.get("origin")); }