@Test public void should_read_certificate() throws Exception { InputStream stream = getClass().getResourceAsStream("/certificate.pem"); byte[] certBinary = toByteArray(stream); IdentityModel identityModel = new IdentityModel(); identityModel.setCertificate(certBinary); doReturn(Optional.of(identityModel)).when(identityRepository).findIdentity(any(), any()); identityService.findIdentity(certBinary); then(identityRepository).should().findIdentity( "EMAILADDRESS=personal-basic@thawte.com, CN=Thawte Personal Basic CA, OU=Certification Services Division, O=Thawte Consulting, L=Cape Town, ST=Western Cape, C=ZA", String.valueOf(BigInteger.ZERO)); }
public Optional<IdentityModel> findIdentity(byte[] certificate) throws CertificateException, InvalidParseOperationException { X509Certificate x509Certificate = X509PKIUtil.parseX509Certificate(certificate); Optional<IdentityModel> identityModelOptional = identityRepository .findIdentity(x509Certificate.getSubjectDN().getName(), String.valueOf(x509Certificate.getSerialNumber())); if (identityModelOptional.isPresent()) { X509PKIUtil.parseX509Certificate(identityModelOptional.get().getCertificate()); } return identityModelOptional; }
IdentityService { public Optional<IdentityModel> findIdentity(byte[] certificate) throws CertificateException, InvalidParseOperationException { X509Certificate x509Certificate = X509PKIUtil.parseX509Certificate(certificate); Optional<IdentityModel> identityModelOptional = identityRepository .findIdentity(x509Certificate.getSubjectDN().getName(), String.valueOf(x509Certificate.getSerialNumber())); if (identityModelOptional.isPresent()) { X509PKIUtil.parseX509Certificate(identityModelOptional.get().getCertificate()); } return identityModelOptional; } }
IdentityService { public Optional<IdentityModel> findIdentity(byte[] certificate) throws CertificateException, InvalidParseOperationException { X509Certificate x509Certificate = X509PKIUtil.parseX509Certificate(certificate); Optional<IdentityModel> identityModelOptional = identityRepository .findIdentity(x509Certificate.getSubjectDN().getName(), String.valueOf(x509Certificate.getSerialNumber())); if (identityModelOptional.isPresent()) { X509PKIUtil.parseX509Certificate(identityModelOptional.get().getCertificate()); } return identityModelOptional; } IdentityService(IdentityRepository identityRepository); }
IdentityService { public Optional<IdentityModel> findIdentity(byte[] certificate) throws CertificateException, InvalidParseOperationException { X509Certificate x509Certificate = X509PKIUtil.parseX509Certificate(certificate); Optional<IdentityModel> identityModelOptional = identityRepository .findIdentity(x509Certificate.getSubjectDN().getName(), String.valueOf(x509Certificate.getSerialNumber())); if (identityModelOptional.isPresent()) { X509PKIUtil.parseX509Certificate(identityModelOptional.get().getCertificate()); } return identityModelOptional; } IdentityService(IdentityRepository identityRepository); void createIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> linkContextToIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> findIdentity(byte[] certificate); boolean contextIsUsed(String contextId); }
IdentityService { public Optional<IdentityModel> findIdentity(byte[] certificate) throws CertificateException, InvalidParseOperationException { X509Certificate x509Certificate = X509PKIUtil.parseX509Certificate(certificate); Optional<IdentityModel> identityModelOptional = identityRepository .findIdentity(x509Certificate.getSubjectDN().getName(), String.valueOf(x509Certificate.getSerialNumber())); if (identityModelOptional.isPresent()) { X509PKIUtil.parseX509Certificate(identityModelOptional.get().getCertificate()); } return identityModelOptional; } IdentityService(IdentityRepository identityRepository); void createIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> linkContextToIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> findIdentity(byte[] certificate); boolean contextIsUsed(String contextId);  }