Compare commits
No commits in common. "ada353ce2f21e1dc99ce156b3c93335158f81e4f" and "2a026de47215e69a7b6cd3e7dc3a08f7a814af6b" have entirely different histories.
ada353ce2f
...
2a026de472
@ -40,7 +40,7 @@ public class CordaClient {
|
|||||||
this.jsonMapper = jsonMapper;
|
this.jsonMapper = jsonMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<VirtualNode> fetchVirtualNodeList() {
|
public List<VirtualNode> getVirtualNodeList() {
|
||||||
ResponseEntity<VirtualNodeList> resp = this.restTemplate.exchange(
|
ResponseEntity<VirtualNodeList> resp = this.restTemplate.exchange(
|
||||||
"/virtualnode",
|
"/virtualnode",
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
|
@ -34,28 +34,4 @@ 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,6 +5,8 @@ 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;
|
||||||
@ -20,49 +22,45 @@ 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)
|
||||||
*/
|
*/
|
||||||
Map<String, HoldingIdentity> player; // PlayerName to ShortHash
|
final Map<String, HoldingIdentity> cache; // PlayerName to ShortHash
|
||||||
HoldingIdentity custodian;
|
|
||||||
|
|
||||||
HoldingIdentityResolver(CordaClient cordaClient) {
|
HoldingIdentityResolver(CordaClient cordaClient) {
|
||||||
this.player = new HashMap<>();
|
this.cache = setCache(cordaClient);
|
||||||
|
|
||||||
fetchVNodeList(cordaClient);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchVNodeList(CordaClient cordaClient) {
|
private static Map<String, HoldingIdentity> setCache(CordaClient cordaClient) {
|
||||||
final List<VirtualNode> vnodeList = cordaClient.fetchVirtualNodeList();
|
Map<String, HoldingIdentity> map = new HashMap<>();
|
||||||
|
|
||||||
for (VirtualNode vNode : vnodeList) {
|
|
||||||
final var identity = vNode.holdingIdentity();
|
|
||||||
try {
|
try {
|
||||||
if (!identity.isCordaCheckers())
|
List<VirtualNode> vNodeList = cordaClient.getVirtualNodeList();
|
||||||
continue;
|
|
||||||
|
|
||||||
if (identity.isPlayer())
|
for (VirtualNode vNode : vNodeList) {
|
||||||
player.put(identity.getName().toLowerCase(locale), identity);
|
var identity = vNode.holdingIdentity();
|
||||||
|
|
||||||
if (identity.isCustodian())
|
if (identity.isPlayer()) {
|
||||||
custodian = identity; // <<-- there shall be only one custodian
|
map.put(
|
||||||
}
|
identity.getName().toLowerCase(locale),
|
||||||
catch (Exception e) {
|
identity
|
||||||
System.err.println("Incomprehensible VirtualNode identity " +identity);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (InvalidNameException e) {
|
||||||
|
// TODO: logs
|
||||||
|
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=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.
|
* 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.player.get(userName.toLowerCase(locale));
|
return this.cache.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 = "CordaCheckers"
|
corDappCpiName = "MyCorDapp"
|
||||||
notaryCpiName = "NotaryServer"
|
notaryCpiName = "NotaryServer"
|
||||||
cordaRpcUser = "admin"
|
cordaRpcUser = "admin"
|
||||||
cordaRpcPasswd ="admin"
|
cordaRpcPasswd ="admin"
|
||||||
@ -61,6 +61,7 @@ publishing {
|
|||||||
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" : "CordaCheckers"
|
"cpi" : "MyCorDapp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA",
|
"x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kviv, C=UA",
|
||||||
"cpi" : "CordaCheckers"
|
"cpi" : "MyCorDapp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"x500Name" : "CN=Charlie, OU=Player, O=Checkers, L=London, C=GB",
|
"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",
|
"x500Name" : "CN=Kumar, OU=Player, O=Checkers, L=Mumbai, C=IN",
|
||||||
"cpi" : "CordaCheckers"
|
"cpi" : "MyCorDapp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"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