@Override public boolean isAuthorized(String blockchainAddress) { final Optional<AuthorizationNode> result = tree.breadthFirstSearch(node -> node.getAddress().equals(blockchainAddress)); return result.isPresent(); }
@Override public Optional<String> getRealWorldIdentity(String blockchainAddress) { final Optional<AuthorizationNode> result = tree.breadthFirstSearch(node -> node.getAddress().equals(blockchainAddress)); return result.map(AuthorizationNode::getIdentity); }
@Override public Optional<List<AuthorizationNode>> getAuthorizationLineage(String blockchainAddress) { // Find a strand that contains a node with the given blockchain address as authorized (each strand is ordered from // root to leaf) Optional<List<AuthorizationNode>> strandAsList = tree.getStrands() .map(strand -> strand.collect(Collectors.toList())) .filter(strand -> strand.stream().anyMatch(node -> node.getAddress().equals(blockchainAddress))) .findFirst(); // If we find the strand, build a path from node to root if (strandAsList.isPresent()) { final List<AuthorizationNode> result = new ArrayList<>(); for (AuthorizationNode node : strandAsList.get()) { result.add(node); // add nodes up until the one we need if (node.getAddress().equals(blockchainAddress)) break; } return Optional.of(result); } else { return Optional.empty(); } }
@POST @Path("authorize") @Consumes(MediaType.APPLICATION_JSON) public String addParticipant(AuthorizationNode participant) { try { return getAccountabilityManager() .authorize(Util.URLdecode(Util.URLdecode(provenanceId)), participant.getAddress(), participant.getIdentity()) .exceptionally(error -> null) .get(); } catch (InterruptedException | ExecutionException | AccountabilityException e) { LOGGER.error("Cannot authorize participant {}. Reason: {}", participant.getAddress(), e.getMessage()); throw createException(e); } }
final List<String> edges = new ArrayList<>(); nodesMap.put(serviceOwner.getAddress(), serviceOwner); elements.forEach(item -> { AuthorizationNode currentTarget = new AuthorizationNode(item, item.getAuthorizedBlockchainAddress(), item.getAuthorizedIdentity()); nodesMap.put(currentTarget.getAddress(), currentTarget); edges.add(currentSource.getAddress() + currentTarget.getAddress()); } else { log.debug( (parent, child) -> edges.contains(parent.getData().getAddress() + child.getData().getAddress()) );