SpringBoot: HoldingAdintity.isPlayer
This commit is contained in:
parent
c7154864a2
commit
cff3c4a584
@ -8,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public record holdingIdentity(String x500Name, String shortHash) {
|
public record holdingIdentity(String x500Name, String shortHash) {
|
||||||
|
|
||||||
public String getName() throws InvalidNameException {
|
public String getName() throws InvalidNameException {
|
||||||
LdapName ln = new LdapName(x500Name);
|
LdapName ln = new LdapName(x500Name);
|
||||||
|
|
||||||
@ -19,4 +20,16 @@ public record holdingIdentity(String x500Name, String shortHash) {
|
|||||||
|
|
||||||
throw new IllegalArgumentException("CN was not found");
|
throw new IllegalArgumentException("CN was not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPlayer() throws InvalidNameException {
|
||||||
|
LdapName ln = new LdapName(x500Name);
|
||||||
|
|
||||||
|
for(Rdn rdn : ln.getRdns()) {
|
||||||
|
if(rdn.getType().equalsIgnoreCase("OU")) {
|
||||||
|
return rdn.getValue().toString().equalsIgnoreCase("Player");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package djmil.cordacheckers;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import djmil.cordacheckers.cordaclient.pojo.holdingIdentity;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import javax.naming.InvalidNameException;
|
||||||
|
|
||||||
|
|
||||||
|
public class HoldingIdentityTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isPlayerTest() throws InvalidNameException {
|
||||||
|
|
||||||
|
holdingIdentity alice = new holdingIdentity("CN=Alice, OU=Player, O=Checkers, L=Zug, C=CH", "HHHDDD");
|
||||||
|
holdingIdentity bob = new holdingIdentity("CN=Bob, OU=Other, O=Checkers, L=Zug, C=CH", "HHHDDD");
|
||||||
|
|
||||||
|
assertThat(alice.getName()).isEqualTo("Alice");
|
||||||
|
assertThat(alice.isPlayer()).isEqualTo(true);
|
||||||
|
|
||||||
|
assertThat(bob.getName()).isEqualTo("Bob");
|
||||||
|
assertThat(bob.isPlayer()).isEqualTo(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user