SpringBoot: get CN from HoldingIdentity.x500Name

This commit is contained in:
djmil 2023-08-23 13:41:15 +02:00
parent b0e2f0e25b
commit c7154864a2
2 changed files with 50 additions and 1 deletions

View File

@ -1,6 +1,22 @@
package djmil.cordacheckers.cordaclient.pojo;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public record holdingIdentity(String x500Name, String shortHash) { }
public record holdingIdentity(String x500Name, String shortHash) {
public String getName() throws InvalidNameException {
LdapName ln = new LdapName(x500Name);
for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("CN")) {
return rdn.getValue().toString();
}
}
throw new IllegalArgumentException("CN was not found");
}
}

View File

@ -0,0 +1,33 @@
package djmil.cordacheckers;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import djmil.cordacheckers.cordaclient.CordaClient;
import djmil.cordacheckers.cordaclient.pojo.holdingIdentity;
import djmil.cordacheckers.cordaclient.pojo.virtualNodes;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
import javax.naming.InvalidNameException;
@SpringBootTest
public class CordaClientTest {
@Autowired
CordaClient cordaclient;
@Test
void whenGetVirtualnode_thenListHoldingIdentity() throws GeneralSecurityException, IOException, InvalidNameException {
List<virtualNodes> vNodes = cordaclient.getVirtualnode();
holdingIdentity identity = vNodes.get(0).holdingIdentity();
assertThat(identity.getName()).isEqualTo("NotaryRep1");
}
}