unify x500 names for all vnodes

This commit is contained in:
djmil 2023-11-28 20:55:17 +01:00
parent b6b1358131
commit 946721c40e
4 changed files with 21 additions and 26 deletions

View File

@ -27,8 +27,9 @@ public record HoldingIdentity(String x500Name, String shortHash) implements Seri
LdapName ln = new LdapName(x500Name); LdapName ln = new LdapName(x500Name);
for(Rdn rdn : ln.getRdns()) { for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("OU")) { if(rdn.getType().equalsIgnoreCase("CN")) {
return rdn.getValue().toString().equalsIgnoreCase("Player"); final String name = rdn.getValue().toString();
return !name.equalsIgnoreCase("Custodian") && !name.equalsIgnoreCase("NotaryService");
} }
} }
@ -39,7 +40,7 @@ public record HoldingIdentity(String x500Name, String shortHash) implements Seri
LdapName ln = new LdapName(x500Name); LdapName ln = new LdapName(x500Name);
for(Rdn rdn : ln.getRdns()) { for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("OU")) { if(rdn.getType().equalsIgnoreCase("CN")) {
return rdn.getValue().toString().equalsIgnoreCase("Custodian"); return rdn.getValue().toString().equalsIgnoreCase("Custodian");
} }
} }
@ -51,7 +52,7 @@ public record HoldingIdentity(String x500Name, String shortHash) implements Seri
LdapName ln = new LdapName(x500Name); LdapName ln = new LdapName(x500Name);
for(Rdn rdn : ln.getRdns()) { for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("O")) { if(rdn.getType().equalsIgnoreCase("OU")) {
return rdn.getValue().toString().equalsIgnoreCase("Checkers"); return rdn.getValue().toString().equalsIgnoreCase("Checkers");
} }
} }

View File

@ -1,23 +1,23 @@
[ [
{ {
"x500Name" : "CN=Alice, OU=Player, O=Checkers, L=Zug, C=CH", "x500Name" : "CN=Alice, OU=Checkers, O=Corda, L=Zug, C=CH",
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=Bobik, OU=Player, O=Checkers, L=Kyiv, C=UA", "x500Name" : "CN=Bobik, OU=Checkers, O=Corda, L=Zug, C=CH",
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=Kumar, OU=Player, O=Checkers, L=Mumbai, C=IN", "x500Name" : "CN=Kumar, OU=Checkers, O=Corda, L=Zug, C=CH",
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=Eva, OU=Custodian, O=Checkers, L=Rotkreuz, C=CH", "x500Name" : "CN=Custodian, OU=Checkers, O=Corda, L=Zug, C=CH",
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=NotaryRep1, OU=Notary, O=Checkers, L=Rotkreuz, C=CH", "x500Name" : "CN=NotaryRep1, OU=Checkers, O=Corda, L=Zug, C=CH",
"cpi" : "NotaryServer", "cpi" : "NotaryServer",
"serviceX500Name" : "CN=Djmil, OU=Notary, O=Checkers, L=Rotkreuz, C=CH" "serviceX500Name" : "CN=NotaryService, OU=Checkers, O=Corda, L=Zug, C=CH"
} }
] ]

View File

@ -7,33 +7,26 @@ import net.corda.v5.membership.MemberInfo;
import net.corda.v5.membership.NotaryInfo; import net.corda.v5.membership.NotaryInfo;
public class VNode { public class VNode {
static final String CHECKERS = "Checkers"; // O aka Organization static final String CUSTODIAN = "Custodian";
static final String PLAYER = "Player"; // OU aka OrganizationUnit static final String NOTARY = "NotaryService";
static final String CUSTODIAN = "Custodian"; // OU aka OrganizationUnit
static final String NOTARY = "Notary"; // OU aka OrganizationUnit
@CordaInject @CordaInject
MemberLookup memberLookup; MemberLookup memberLookup;
public static boolean isCordaCherckersPlayer(MemberInfo memberInfo) { public static boolean isCordaCherckersPlayer(MemberInfo memberInfo) {
final MemberX500Name memberName = memberInfo.getName(); return !isCordaCherckersCustodian(memberInfo);
return memberName.getOrganization().equals(CHECKERS) &&
memberName.getOrganizationUnit().equals(PLAYER);
} }
public static boolean isCordaCherckersCustodian(MemberInfo memberInfo) { public static boolean isCordaCherckersCustodian(MemberInfo memberInfo) {
final MemberX500Name memberName = memberInfo.getName(); final MemberX500Name memberName = memberInfo.getName();
return memberName.getOrganization().equals(CHECKERS) && return memberName.getCommonName().equals(CUSTODIAN);
memberName.getOrganizationUnit().equals(CUSTODIAN);
} }
public static boolean isCordaCherckersNotary(NotaryInfo notaryInfo) { public static boolean isCordaCherckersNotary(NotaryInfo notaryInfo) {
final MemberX500Name memberName = notaryInfo.getName(); final MemberX500Name memberName = notaryInfo.getName();
return memberName.getOrganization().equals(CHECKERS) && return memberName.getCommonName().equals(NOTARY);
memberName.getOrganizationUnit().equals(NOTARY);
} }
} }

View File

@ -3,6 +3,7 @@ package djmil.cordacheckers.gamestate;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import djmil.cordacheckers.VNode;
import djmil.cordacheckers.contracts.GameInfo; import djmil.cordacheckers.contracts.GameInfo;
import net.corda.v5.application.flows.CordaInject; import net.corda.v5.application.flows.CordaInject;
import net.corda.v5.application.flows.InitiatedBy; import net.corda.v5.application.flows.InitiatedBy;
@ -62,11 +63,11 @@ public class CommitTrxResponder implements ResponderFlow {
if (info.issuer.compareTo(conterpartyName) != 0) if (info.issuer.compareTo(conterpartyName) != 0)
throw new ParticipantException("Issuer", conterpartyName, info.issuer); throw new ParticipantException("Issuer", conterpartyName, info.issuer);
final var myName = memberLookup.myInfo().getName(); final var myInfo = memberLookup.myInfo();
if (myName.getOrganizationUnit().equals("Custodian")) if (VNode.isCordaCherckersCustodian(myInfo))
return; // Custodian shall not validate state's counterparty return; // Custodian shall not validate state's counterparty
final var opponentName = info.state.getOpponentName(myName); // throws NotInvolved final var opponentName = info.state.getOpponentName(myInfo.getName()); // throws NotInvolved
if (conterpartyName.compareTo(opponentName) != 0) if (conterpartyName.compareTo(opponentName) != 0)
throw new ParticipantException("Opponent", conterpartyName, opponentName); throw new ParticipantException("Opponent", conterpartyName, opponentName);
} }