Search in sources :

Example 1 with CertificateProfileInfoProvider

use of ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider in project X-Road by nordic-institute.

the class FiVRKCertificateProfileInfoProviderTest method providerReturnsCorrectImplementations.

/**
 * Tests whether provider returns correct implementation as expected.
 */
@Test
public void providerReturnsCorrectImplementations() {
    CertificateProfileInfoProvider provider = provider();
    assertTrue("Must return instance of DefaultAuthCertificateProfileInfo", provider.getAuthCertProfile(new AuthCertificateProfileInfoParameters(SecurityServerId.create("XX", "foo", "bar", "server"), "foo")) instanceof FiVRKAuthCertificateProfileInfo);
    assertTrue("Must return instance of DefaultSignCertificateProfileInfo", provider.getSignCertProfile(new SignCertificateProfileInfoParameters(SecurityServerId.create("XX", "foo", "bar", "server"), ClientId.create("XX", "foo", "bar"), "foo")) instanceof FiVRKSignCertificateProfileInfo);
}
Also used : CertificateProfileInfoProvider(ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider) Test(org.junit.Test)

Example 2 with CertificateProfileInfoProvider

use of ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider in project X-Road by nordic-institute.

the class FoCertificateProfileInfoProviderTest method providerReturnsCorrectImplementations.

/**
 * Tests whether provider returns correct implementation as expected.
 */
@Test
public void providerReturnsCorrectImplementations() {
    CertificateProfileInfoProvider provider = newProvider();
    assertTrue("Must return instance of FoAuthCertificateProfileInfo", provider.getAuthCertProfile(new AuthCertificateProfileInfoParameters(SecurityServerId.create("XX", "foo", "bar", "server"), "foo")) instanceof FoAuthCertificateProfileInfo);
    assertTrue("Must return instance of FoSignCertificateProfileInfo", provider.getSignCertProfile(new SignCertificateProfileInfoParameters(SecurityServerId.create("XX", "CLASS", "OWNER", "server"), ClientId.create("XX", "CLASS", "CLIENT"), "client")) instanceof FoSignCertificateProfileInfo);
}
Also used : CertificateProfileInfoProvider(ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider) Test(org.junit.Test)

Example 3 with CertificateProfileInfoProvider

use of ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider in project X-Road by nordic-institute.

the class EjbcaCertificateProfileInfoProviderTest method providerReturnsCorrectImplementations.

/**
 * Tests whether provider returns correct implementation as expected.
 */
@Test
public void providerReturnsCorrectImplementations() {
    CertificateProfileInfoProvider provider = provider();
    assertTrue("Must return instance of DefaultAuthCertificateProfileInfo", provider.getAuthCertProfile(new AuthCertificateProfileInfoParameters(SecurityServerId.create("XX", "foo", "bar", "server"), "foo")) instanceof EjbcaAuthCertificateProfileInfo);
    assertTrue("Must return instance of DefaultSignCertificateProfileInfo", provider.getSignCertProfile(new SignCertificateProfileInfoParameters(ClientId.create("XX", "foo", "bar"), "foo")) instanceof EjbcaSignCertificateProfileInfo);
}
Also used : CertificateProfileInfoProvider(ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider) Test(org.junit.Test)

Example 4 with CertificateProfileInfoProvider

use of ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider in project X-Road by nordic-institute.

the class CertificateAuthorityService method getCertificateProfile.

/**
 * Return correct CertificateProfileInfo for given parameters
 * @param caName name of the CA
 * @param keyUsageInfo key usage
 * @param memberId member when key usage = signing, ignored otherwise
 * @return CertificateProfileInfo
 * @throws CertificateAuthorityNotFoundException if matching CA was not found
 * @throws CertificateProfileInstantiationException if instantiation of certificate profile failed
 * @throws WrongKeyUsageException if attempted to read signing profile from authenticationOnly ca
 * @throws ClientNotFoundException if client with memberId was not found
 */
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) {
        // validate that the member exists or has a subsystem on this server - except when adding a new client
        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();
    }
}
Also used : GetCertificateProfile(ee.ria.xroad.common.certificateprofile.GetCertificateProfile) ApprovedCAInfo(ee.ria.xroad.common.conf.globalconf.ApprovedCAInfo) CertificateProfileInfoProvider(ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider) CurrentSecurityServerId(org.niis.xroad.securityserver.restapi.cache.CurrentSecurityServerId) SecurityServerId(ee.ria.xroad.common.identifier.SecurityServerId) AuthCertificateProfileInfoParameters(ee.ria.xroad.common.certificateprofile.impl.AuthCertificateProfileInfoParameters) ServiceException(org.niis.xroad.restapi.service.ServiceException) SignCertificateProfileInfoParameters(ee.ria.xroad.common.certificateprofile.impl.SignCertificateProfileInfoParameters)

Aggregations

CertificateProfileInfoProvider (ee.ria.xroad.common.certificateprofile.CertificateProfileInfoProvider)4 Test (org.junit.Test)3 GetCertificateProfile (ee.ria.xroad.common.certificateprofile.GetCertificateProfile)1 AuthCertificateProfileInfoParameters (ee.ria.xroad.common.certificateprofile.impl.AuthCertificateProfileInfoParameters)1 SignCertificateProfileInfoParameters (ee.ria.xroad.common.certificateprofile.impl.SignCertificateProfileInfoParameters)1 ApprovedCAInfo (ee.ria.xroad.common.conf.globalconf.ApprovedCAInfo)1 SecurityServerId (ee.ria.xroad.common.identifier.SecurityServerId)1 ServiceException (org.niis.xroad.restapi.service.ServiceException)1 CurrentSecurityServerId (org.niis.xroad.securityserver.restapi.cache.CurrentSecurityServerId)1