Compare commits

..

No commits in common. "ada353ce2f21e1dc99ce156b3c93335158f81e4f" and "2a026de47215e69a7b6cd3e7dc3a08f7a814af6b" have entirely different histories.

5 changed files with 33 additions and 58 deletions

View File

@ -40,7 +40,7 @@ public class CordaClient {
this.jsonMapper = jsonMapper;
}
public List<VirtualNode> fetchVirtualNodeList() {
public List<VirtualNode> getVirtualNodeList() {
ResponseEntity<VirtualNodeList> resp = this.restTemplate.exchange(
"/virtualnode",
HttpMethod.GET,

View File

@ -34,28 +34,4 @@ public record HoldingIdentity(String x500Name, String shortHash) implements Seri
return false;
}
public boolean isCustodian() throws InvalidNameException {
LdapName ln = new LdapName(x500Name);
for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("OU")) {
return rdn.getValue().toString().equalsIgnoreCase("Custodian");
}
}
return false;
}
public boolean isCordaCheckers() throws InvalidNameException {
LdapName ln = new LdapName(x500Name);
for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("O")) {
return rdn.getValue().toString().equalsIgnoreCase("Checkers");
}
}
return false;
}
}

View File

@ -5,6 +5,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.naming.InvalidNameException;
import org.springframework.stereotype.Service;
import djmil.cordacheckers.cordaclient.CordaClient;
@ -20,49 +22,45 @@ public class HoldingIdentityResolver {
* Ideally, we want to be able to force update cache, had the corda
* cluster configuration changed (aka in case of a cache miss)
*/
Map<String, HoldingIdentity> player; // PlayerName to ShortHash
HoldingIdentity custodian;
final Map<String, HoldingIdentity> cache; // PlayerName to ShortHash
HoldingIdentityResolver(CordaClient cordaClient) {
this.player = new HashMap<>();
fetchVNodeList(cordaClient);
this.cache = setCache(cordaClient);
}
private void fetchVNodeList(CordaClient cordaClient) {
final List<VirtualNode> vnodeList = cordaClient.fetchVirtualNodeList();
private static Map<String, HoldingIdentity> setCache(CordaClient cordaClient) {
Map<String, HoldingIdentity> map = new HashMap<>();
for (VirtualNode vNode : vnodeList) {
final var identity = vNode.holdingIdentity();
try {
if (!identity.isCordaCheckers())
continue;
List<VirtualNode> vNodeList = cordaClient.getVirtualNodeList();
if (identity.isPlayer())
player.put(identity.getName().toLowerCase(locale), identity);
for (VirtualNode vNode : vNodeList) {
var identity = vNode.holdingIdentity();
if (identity.isCustodian())
custodian = identity; // <<-- there shall be only one custodian
}
catch (Exception e) {
System.err.println("Incomprehensible VirtualNode identity " +identity);
if (identity.isPlayer()) {
map.put(
identity.getName().toLowerCase(locale),
identity
);
}
}
} catch (InvalidNameException e) {
// TODO: logs
System.out.println("Unable to get ShorHash list of Corda VirtualNodes: "+e.getMessage());
}
return map;
}
/*
* @param playerName
* HoldingIdentity x500 name typically looks like
* "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA"
* "CN=Bob, OU=Player, O=Checkers, L=Kviv, C=UA"
* CN - is a common name, expected to be unique for CordaCheckers setup.
*
* @return HoldingIdentity
*/
public HoldingIdentity getByUsername(String userName) {
return this.player.get(userName.toLowerCase(locale));
}
public HoldingIdentity getCustodian() {
return this.custodian;
return this.cache.get(userName.toLowerCase(locale));
}
}

View File

@ -20,7 +20,7 @@ allprojects {
cordaClusterURL = "https://localhost:8888"
networkConfigFile = "config/static-network-config.json"
r3RootCertFile = "config/r3-ca-key.pem"
corDappCpiName = "CordaCheckers"
corDappCpiName = "MyCorDapp"
notaryCpiName = "NotaryServer"
cordaRpcUser = "admin"
cordaRpcPasswd ="admin"
@ -61,6 +61,7 @@ publishing {
groupId project.group
artifact jar
}
}
}

View File

@ -1,19 +1,19 @@
[
{
"x500Name" : "CN=Alice, OU=Player, O=Checkers, L=Zug, C=CH",
"cpi" : "CordaCheckers"
"cpi" : "MyCorDapp"
},
{
"x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA",
"cpi" : "CordaCheckers"
"x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kviv, C=UA",
"cpi" : "MyCorDapp"
},
{
"x500Name" : "CN=Charlie, OU=Player, O=Checkers, L=London, C=GB",
"cpi" : "CordaCheckers"
"cpi" : "MyCorDapp"
},
{
"x500Name" : "CN=Kumar, OU=Custodian, O=Checkers, L=Mumbai, C=IN",
"cpi" : "CordaCheckers"
"x500Name" : "CN=Kumar, OU=Player, O=Checkers, L=Mumbai, C=IN",
"cpi" : "MyCorDapp"
},
{
"x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB",