Compare commits
2 Commits
2a026de472
...
ada353ce2f
Author | SHA1 | Date | |
---|---|---|---|
ada353ce2f | |||
d3f5499ad8 |
@ -40,7 +40,7 @@ public class CordaClient {
|
|||||||
this.jsonMapper = jsonMapper;
|
this.jsonMapper = jsonMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<VirtualNode> getVirtualNodeList() {
|
public List<VirtualNode> fetchVirtualNodeList() {
|
||||||
ResponseEntity<VirtualNodeList> resp = this.restTemplate.exchange(
|
ResponseEntity<VirtualNodeList> resp = this.restTemplate.exchange(
|
||||||
"/virtualnode",
|
"/virtualnode",
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
|
@ -34,4 +34,28 @@ public record HoldingIdentity(String x500Name, String shortHash) implements Seri
|
|||||||
|
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.naming.InvalidNameException;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.CordaClient;
|
import djmil.cordacheckers.cordaclient.CordaClient;
|
||||||
@ -22,45 +20,49 @@ public class HoldingIdentityResolver {
|
|||||||
* Ideally, we want to be able to force update cache, had the corda
|
* Ideally, we want to be able to force update cache, had the corda
|
||||||
* cluster configuration changed (aka in case of a cache miss)
|
* cluster configuration changed (aka in case of a cache miss)
|
||||||
*/
|
*/
|
||||||
final Map<String, HoldingIdentity> cache; // PlayerName to ShortHash
|
Map<String, HoldingIdentity> player; // PlayerName to ShortHash
|
||||||
|
HoldingIdentity custodian;
|
||||||
|
|
||||||
HoldingIdentityResolver(CordaClient cordaClient) {
|
HoldingIdentityResolver(CordaClient cordaClient) {
|
||||||
this.cache = setCache(cordaClient);
|
this.player = new HashMap<>();
|
||||||
|
|
||||||
|
fetchVNodeList(cordaClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, HoldingIdentity> setCache(CordaClient cordaClient) {
|
private void fetchVNodeList(CordaClient cordaClient) {
|
||||||
Map<String, HoldingIdentity> map = new HashMap<>();
|
final List<VirtualNode> vnodeList = cordaClient.fetchVirtualNodeList();
|
||||||
|
|
||||||
try {
|
for (VirtualNode vNode : vnodeList) {
|
||||||
List<VirtualNode> vNodeList = cordaClient.getVirtualNodeList();
|
final var identity = vNode.holdingIdentity();
|
||||||
|
try {
|
||||||
|
if (!identity.isCordaCheckers())
|
||||||
|
continue;
|
||||||
|
|
||||||
for (VirtualNode vNode : vNodeList) {
|
if (identity.isPlayer())
|
||||||
var identity = vNode.holdingIdentity();
|
player.put(identity.getName().toLowerCase(locale), identity);
|
||||||
|
|
||||||
if (identity.isPlayer()) {
|
if (identity.isCustodian())
|
||||||
map.put(
|
custodian = identity; // <<-- there shall be only one custodian
|
||||||
identity.getName().toLowerCase(locale),
|
|
||||||
identity
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (InvalidNameException e) {
|
catch (Exception e) {
|
||||||
// TODO: logs
|
System.err.println("Incomprehensible VirtualNode identity " +identity);
|
||||||
System.out.println("Unable to get ShorHash list of Corda VirtualNodes: "+e.getMessage());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param playerName
|
* @param playerName
|
||||||
* HoldingIdentity x500 name typically looks like
|
* HoldingIdentity x500 name typically looks like
|
||||||
* "CN=Bob, OU=Player, O=Checkers, L=Kviv, C=UA"
|
* "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA"
|
||||||
* CN - is a common name, expected to be unique for CordaCheckers setup.
|
* CN - is a common name, expected to be unique for CordaCheckers setup.
|
||||||
*
|
*
|
||||||
* @return HoldingIdentity
|
* @return HoldingIdentity
|
||||||
*/
|
*/
|
||||||
public HoldingIdentity getByUsername(String userName) {
|
public HoldingIdentity getByUsername(String userName) {
|
||||||
return this.cache.get(userName.toLowerCase(locale));
|
return this.player.get(userName.toLowerCase(locale));
|
||||||
|
}
|
||||||
|
|
||||||
|
public HoldingIdentity getCustodian() {
|
||||||
|
return this.custodian;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ allprojects {
|
|||||||
cordaClusterURL = "https://localhost:8888"
|
cordaClusterURL = "https://localhost:8888"
|
||||||
networkConfigFile = "config/static-network-config.json"
|
networkConfigFile = "config/static-network-config.json"
|
||||||
r3RootCertFile = "config/r3-ca-key.pem"
|
r3RootCertFile = "config/r3-ca-key.pem"
|
||||||
corDappCpiName = "MyCorDapp"
|
corDappCpiName = "CordaCheckers"
|
||||||
notaryCpiName = "NotaryServer"
|
notaryCpiName = "NotaryServer"
|
||||||
cordaRpcUser = "admin"
|
cordaRpcUser = "admin"
|
||||||
cordaRpcPasswd ="admin"
|
cordaRpcPasswd ="admin"
|
||||||
@ -60,8 +60,7 @@ publishing {
|
|||||||
artifactId "corda-CSDE-java-sample"
|
artifactId "corda-CSDE-java-sample"
|
||||||
groupId project.group
|
groupId project.group
|
||||||
artifact jar
|
artifact jar
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"x500Name" : "CN=Alice, OU=Player, O=Checkers, L=Zug, C=CH",
|
"x500Name" : "CN=Alice, OU=Player, O=Checkers, L=Zug, C=CH",
|
||||||
"cpi" : "MyCorDapp"
|
"cpi" : "CordaCheckers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kviv, C=UA",
|
"x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA",
|
||||||
"cpi" : "MyCorDapp"
|
"cpi" : "CordaCheckers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"x500Name" : "CN=Charlie, OU=Player, O=Checkers, L=London, C=GB",
|
"x500Name" : "CN=Charlie, OU=Player, O=Checkers, L=London, C=GB",
|
||||||
"cpi" : "MyCorDapp"
|
"cpi" : "CordaCheckers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"x500Name" : "CN=Kumar, OU=Player, O=Checkers, L=Mumbai, C=IN",
|
"x500Name" : "CN=Kumar, OU=Custodian, O=Checkers, L=Mumbai, C=IN",
|
||||||
"cpi" : "MyCorDapp"
|
"cpi" : "CordaCheckers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB",
|
"x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB",
|
||||||
|
Loading…
Reference in New Issue
Block a user