@Test public void should_store_certificate() throws Exception { IdentityInsertModel identityInsertModel = new IdentityInsertModel(); identityInsertModel.setContextId("contextId"); InputStream stream = getClass().getResourceAsStream("/certificate.pem"); byte[] certificate = toByteArray(stream); identityInsertModel.setCertificate(certificate); identityService.createIdentity(identityInsertModel); ArgumentCaptor<IdentityModel> identityModelCaptor = ArgumentCaptor.forClass(IdentityModel.class); then(identityRepository).should().createIdentity(identityModelCaptor.capture()); IdentityModel identityModel = identityModelCaptor.getValue(); assertThat(identityModel.getSubjectDN()).isEqualTo( "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"); assertThat(identityModel.getSerialNumber()).isEqualTo(String.valueOf(BigInteger.ZERO)); assertThat(identityModel.getIssuerDN()).isEqualTo( "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"); assertThat(identityModel.getCertificate()).isEqualTo(certificate); }
public void createIdentity(IdentityInsertModel identityInsertModel) throws CertificateException, InvalidParseOperationException { IdentityModel identityModel = new IdentityModel(); identityModel.setId(GUIDFactory.newGUID().toString()); identityModel.setContextId(identityInsertModel.getContextId()); identityModel.setCertificate(identityInsertModel.getCertificate()); identityModel.setCertificateStatus(CertificateStatus.VALID); X509Certificate certificate = X509PKIUtil.parseX509Certificate(identityInsertModel.getCertificate()); identityModel.setSubjectDN(certificate.getSubjectDN().getName()); identityModel.setIssuerDN(certificate.getIssuerDN().getName()); identityModel.setSerialNumber(String.valueOf(certificate.getSerialNumber())); identityRepository.createIdentity(identityModel); }
IdentityService { public void createIdentity(IdentityInsertModel identityInsertModel) throws CertificateException, InvalidParseOperationException { IdentityModel identityModel = new IdentityModel(); identityModel.setId(GUIDFactory.newGUID().toString()); identityModel.setContextId(identityInsertModel.getContextId()); identityModel.setCertificate(identityInsertModel.getCertificate()); identityModel.setCertificateStatus(CertificateStatus.VALID); X509Certificate certificate = X509PKIUtil.parseX509Certificate(identityInsertModel.getCertificate()); identityModel.setSubjectDN(certificate.getSubjectDN().getName()); identityModel.setIssuerDN(certificate.getIssuerDN().getName()); identityModel.setSerialNumber(String.valueOf(certificate.getSerialNumber())); identityRepository.createIdentity(identityModel); } }
IdentityService { public void createIdentity(IdentityInsertModel identityInsertModel) throws CertificateException, InvalidParseOperationException { IdentityModel identityModel = new IdentityModel(); identityModel.setId(GUIDFactory.newGUID().toString()); identityModel.setContextId(identityInsertModel.getContextId()); identityModel.setCertificate(identityInsertModel.getCertificate()); identityModel.setCertificateStatus(CertificateStatus.VALID); X509Certificate certificate = X509PKIUtil.parseX509Certificate(identityInsertModel.getCertificate()); identityModel.setSubjectDN(certificate.getSubjectDN().getName()); identityModel.setIssuerDN(certificate.getIssuerDN().getName()); identityModel.setSerialNumber(String.valueOf(certificate.getSerialNumber())); identityRepository.createIdentity(identityModel); } IdentityService(IdentityRepository identityRepository); }
IdentityService { public void createIdentity(IdentityInsertModel identityInsertModel) throws CertificateException, InvalidParseOperationException { IdentityModel identityModel = new IdentityModel(); identityModel.setId(GUIDFactory.newGUID().toString()); identityModel.setContextId(identityInsertModel.getContextId()); identityModel.setCertificate(identityInsertModel.getCertificate()); identityModel.setCertificateStatus(CertificateStatus.VALID); X509Certificate certificate = X509PKIUtil.parseX509Certificate(identityInsertModel.getCertificate()); identityModel.setSubjectDN(certificate.getSubjectDN().getName()); identityModel.setIssuerDN(certificate.getIssuerDN().getName()); identityModel.setSerialNumber(String.valueOf(certificate.getSerialNumber())); identityRepository.createIdentity(identityModel); } IdentityService(IdentityRepository identityRepository); void createIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> linkContextToIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> findIdentity(byte[] certificate); boolean contextIsUsed(String contextId); }
IdentityService { public void createIdentity(IdentityInsertModel identityInsertModel) throws CertificateException, InvalidParseOperationException { IdentityModel identityModel = new IdentityModel(); identityModel.setId(GUIDFactory.newGUID().toString()); identityModel.setContextId(identityInsertModel.getContextId()); identityModel.setCertificate(identityInsertModel.getCertificate()); identityModel.setCertificateStatus(CertificateStatus.VALID); X509Certificate certificate = X509PKIUtil.parseX509Certificate(identityInsertModel.getCertificate()); identityModel.setSubjectDN(certificate.getSubjectDN().getName()); identityModel.setIssuerDN(certificate.getIssuerDN().getName()); identityModel.setSerialNumber(String.valueOf(certificate.getSerialNumber())); identityRepository.createIdentity(identityModel); } IdentityService(IdentityRepository identityRepository); void createIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> linkContextToIdentity(IdentityInsertModel identityInsertModel); Optional<IdentityModel> findIdentity(byte[] certificate); boolean contextIsUsed(String contextId);  }