@Test public void getCertificateProfile() throws Exception { ClientType client = new ClientType(); client.setIdentifier(COMMON_OWNER_ID); when(clientRepository.getAllLocalClients()).thenReturn(Collections.singletonList(client)); CertificateProfileInfo profile = certificateAuthorityService.getCertificateProfile("fi-not-auth-only", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false); assertTrue(profile instanceof FiVRKSignCertificateProfileInfo); assertEquals("FI/SS1/GOV", profile.getSubjectFields()[2].getDefaultValue()); assertEquals("M1", profile.getSubjectFields()[3].getDefaultValue()); assertTrue(profile.getSubjectFields()[3].isReadOnly()); profile = certificateAuthorityService.getCertificateProfile("fi-not-auth-only", KeyUsageInfo.AUTHENTICATION, COMMON_OWNER_ID, false); assertTrue(profile instanceof FiVRKAuthCertificateProfileInfo); assertEquals("FI/SS1/GOV", profile.getSubjectFields()[2].getDefaultValue()); assertEquals("", profile.getSubjectFields()[3].getDefaultValue()); assertFalse(profile.getSubjectFields()[3].isReadOnly()); profile = certificateAuthorityService.getCertificateProfile("est-auth-only", KeyUsageInfo.AUTHENTICATION, COMMON_OWNER_ID, false); assertTrue(profile instanceof AuthCertificateProfileInfo); assertEquals(0, profile.getSubjectFields().length); try { certificateAuthorityService.getCertificateProfile("est-auth-only", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false); fail("should have thrown exception"); } catch (WrongKeyUsageException expected) { } try { certificateAuthorityService.getCertificateProfile("this-does-not-exist", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false); fail("should have thrown exception"); } catch (CertificateAuthorityNotFoundException expected) { } List<ApprovedCAInfo> approvedCAInfos = new ArrayList<>(); approvedCAInfos.add(new ApprovedCAInfo("provider-class-does-not-exist", false, "ee.ria.xroad.common.certificateprofile.impl.NonExistentProvider")); when(globalConfFacade.getApprovedCAs(any())).thenReturn(approvedCAInfos); try { certificateAuthorityService.getCertificateProfile("provider-class-does-not-exist", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false); fail("should have thrown exception"); } catch (CertificateProfileInstantiationException expected) { } }
public CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId, boolean isNewMember) throws CertificateAuthorityNotFoundException, CertificateProfileInstantiationException, WrongKeyUsageException, ClientNotFoundException { ApprovedCAInfo caInfo = getCertificateAuthorityInfo(caName); if (Boolean.TRUE.equals(caInfo.getAuthenticationOnly()) && KeyUsageInfo.SIGNING == keyUsageInfo) { throw new WrongKeyUsageException(); } if (keyUsageInfo == KeyUsageInfo.SIGNING && !isNewMember) { if (!clientService.getLocalClientMemberIds().contains(memberId)) { throw new ClientNotFoundException("client with id " + memberId + ", or subsystem for it, not found"); } } CertificateProfileInfoProvider provider = null; try { provider = new GetCertificateProfile(caInfo.getCertificateProfileInfo()).instance(); } catch (Exception e) { throw new CertificateProfileInstantiationException(e); } SecurityServerId serverId = currentSecurityServerId.getServerId(); if (KeyUsageInfo.AUTHENTICATION == keyUsageInfo) { String ownerName = globalConfFacade.getMemberName(serverId.getOwner()); AuthCertificateProfileInfoParameters params = new AuthCertificateProfileInfoParameters( serverId, ownerName); return provider.getAuthCertProfile(params); } else if (KeyUsageInfo.SIGNING == keyUsageInfo) { String memberName = globalConfFacade.getMemberName(memberId); SignCertificateProfileInfoParameters params = new SignCertificateProfileInfoParameters( serverId, memberId, memberName); return provider.getSignCertProfile(params); } else { throw new IllegalArgumentException(); } }
CertificateAuthorityService { public CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId, boolean isNewMember) throws CertificateAuthorityNotFoundException, CertificateProfileInstantiationException, WrongKeyUsageException, ClientNotFoundException { ApprovedCAInfo caInfo = getCertificateAuthorityInfo(caName); if (Boolean.TRUE.equals(caInfo.getAuthenticationOnly()) && KeyUsageInfo.SIGNING == keyUsageInfo) { throw new WrongKeyUsageException(); } if (keyUsageInfo == KeyUsageInfo.SIGNING && !isNewMember) { if (!clientService.getLocalClientMemberIds().contains(memberId)) { throw new ClientNotFoundException("client with id " + memberId + ", or subsystem for it, not found"); } } CertificateProfileInfoProvider provider = null; try { provider = new GetCertificateProfile(caInfo.getCertificateProfileInfo()).instance(); } catch (Exception e) { throw new CertificateProfileInstantiationException(e); } SecurityServerId serverId = currentSecurityServerId.getServerId(); if (KeyUsageInfo.AUTHENTICATION == keyUsageInfo) { String ownerName = globalConfFacade.getMemberName(serverId.getOwner()); AuthCertificateProfileInfoParameters params = new AuthCertificateProfileInfoParameters( serverId, ownerName); return provider.getAuthCertProfile(params); } else if (KeyUsageInfo.SIGNING == keyUsageInfo) { String memberName = globalConfFacade.getMemberName(memberId); SignCertificateProfileInfoParameters params = new SignCertificateProfileInfoParameters( serverId, memberId, memberName); return provider.getSignCertProfile(params); } else { throw new IllegalArgumentException(); } } }
CertificateAuthorityService { public CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId, boolean isNewMember) throws CertificateAuthorityNotFoundException, CertificateProfileInstantiationException, WrongKeyUsageException, ClientNotFoundException { ApprovedCAInfo caInfo = getCertificateAuthorityInfo(caName); if (Boolean.TRUE.equals(caInfo.getAuthenticationOnly()) && KeyUsageInfo.SIGNING == keyUsageInfo) { throw new WrongKeyUsageException(); } if (keyUsageInfo == KeyUsageInfo.SIGNING && !isNewMember) { if (!clientService.getLocalClientMemberIds().contains(memberId)) { throw new ClientNotFoundException("client with id " + memberId + ", or subsystem for it, not found"); } } CertificateProfileInfoProvider provider = null; try { provider = new GetCertificateProfile(caInfo.getCertificateProfileInfo()).instance(); } catch (Exception e) { throw new CertificateProfileInstantiationException(e); } SecurityServerId serverId = currentSecurityServerId.getServerId(); if (KeyUsageInfo.AUTHENTICATION == keyUsageInfo) { String ownerName = globalConfFacade.getMemberName(serverId.getOwner()); AuthCertificateProfileInfoParameters params = new AuthCertificateProfileInfoParameters( serverId, ownerName); return provider.getAuthCertProfile(params); } else if (KeyUsageInfo.SIGNING == keyUsageInfo) { String memberName = globalConfFacade.getMemberName(memberId); SignCertificateProfileInfoParameters params = new SignCertificateProfileInfoParameters( serverId, memberId, memberName); return provider.getSignCertProfile(params); } else { throw new IllegalArgumentException(); } } @Autowired  CertificateAuthorityService(GlobalConfService globalConfService,
            GlobalConfFacade globalConfFacade,
            ClientService clientService,
            SignerProxyFacade signerProxyFacade,
            CurrentSecurityServerId currentSecurityServerId); }
CertificateAuthorityService { public CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId, boolean isNewMember) throws CertificateAuthorityNotFoundException, CertificateProfileInstantiationException, WrongKeyUsageException, ClientNotFoundException { ApprovedCAInfo caInfo = getCertificateAuthorityInfo(caName); if (Boolean.TRUE.equals(caInfo.getAuthenticationOnly()) && KeyUsageInfo.SIGNING == keyUsageInfo) { throw new WrongKeyUsageException(); } if (keyUsageInfo == KeyUsageInfo.SIGNING && !isNewMember) { if (!clientService.getLocalClientMemberIds().contains(memberId)) { throw new ClientNotFoundException("client with id " + memberId + ", or subsystem for it, not found"); } } CertificateProfileInfoProvider provider = null; try { provider = new GetCertificateProfile(caInfo.getCertificateProfileInfo()).instance(); } catch (Exception e) { throw new CertificateProfileInstantiationException(e); } SecurityServerId serverId = currentSecurityServerId.getServerId(); if (KeyUsageInfo.AUTHENTICATION == keyUsageInfo) { String ownerName = globalConfFacade.getMemberName(serverId.getOwner()); AuthCertificateProfileInfoParameters params = new AuthCertificateProfileInfoParameters( serverId, ownerName); return provider.getAuthCertProfile(params); } else if (KeyUsageInfo.SIGNING == keyUsageInfo) { String memberName = globalConfFacade.getMemberName(memberId); SignCertificateProfileInfoParameters params = new SignCertificateProfileInfoParameters( serverId, memberId, memberName); return provider.getSignCertProfile(params); } else { throw new IllegalArgumentException(); } } @Autowired  CertificateAuthorityService(GlobalConfService globalConfService,
            GlobalConfFacade globalConfFacade,
            ClientService clientService,
            SignerProxyFacade signerProxyFacade,
            CurrentSecurityServerId currentSecurityServerId); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo,
            boolean includeIntermediateCas); CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId,
            boolean isNewMember); ApprovedCAInfo getCertificateAuthorityInfo(String caName); }
CertificateAuthorityService { public CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId, boolean isNewMember) throws CertificateAuthorityNotFoundException, CertificateProfileInstantiationException, WrongKeyUsageException, ClientNotFoundException { ApprovedCAInfo caInfo = getCertificateAuthorityInfo(caName); if (Boolean.TRUE.equals(caInfo.getAuthenticationOnly()) && KeyUsageInfo.SIGNING == keyUsageInfo) { throw new WrongKeyUsageException(); } if (keyUsageInfo == KeyUsageInfo.SIGNING && !isNewMember) { if (!clientService.getLocalClientMemberIds().contains(memberId)) { throw new ClientNotFoundException("client with id " + memberId + ", or subsystem for it, not found"); } } CertificateProfileInfoProvider provider = null; try { provider = new GetCertificateProfile(caInfo.getCertificateProfileInfo()).instance(); } catch (Exception e) { throw new CertificateProfileInstantiationException(e); } SecurityServerId serverId = currentSecurityServerId.getServerId(); if (KeyUsageInfo.AUTHENTICATION == keyUsageInfo) { String ownerName = globalConfFacade.getMemberName(serverId.getOwner()); AuthCertificateProfileInfoParameters params = new AuthCertificateProfileInfoParameters( serverId, ownerName); return provider.getAuthCertProfile(params); } else if (KeyUsageInfo.SIGNING == keyUsageInfo) { String memberName = globalConfFacade.getMemberName(memberId); SignCertificateProfileInfoParameters params = new SignCertificateProfileInfoParameters( serverId, memberId, memberName); return provider.getSignCertProfile(params); } else { throw new IllegalArgumentException(); } } @Autowired  CertificateAuthorityService(GlobalConfService globalConfService,
            GlobalConfFacade globalConfFacade,
            ClientService clientService,
            SignerProxyFacade signerProxyFacade,
            CurrentSecurityServerId currentSecurityServerId); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo); @Cacheable(GET_CERTIFICATE_AUTHORITIES_CACHE) List<ApprovedCaDto> getCertificateAuthorities(KeyUsageInfo keyUsageInfo,
            boolean includeIntermediateCas); CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId,
            boolean isNewMember); ApprovedCAInfo getCertificateAuthorityInfo(String caName); static final String OCSP_RESPONSE_NOT_AVAILABLE; }