@Test @WithMockUser(authorities = { "GENERATE_SIGN_CERT_REQ", "GENERATE_AUTH_CERT_REQ" }) public void getSubjectFieldsKeyIsOptional() throws Exception { caController.getSubjectFieldDescriptions(GENERAL_PURPOSE_CA_NAME, KeyUsageType.SIGNING, null, "FI:GOV:M1", false); caController.getSubjectFieldDescriptions(GENERAL_PURPOSE_CA_NAME, KeyUsageType.AUTHENTICATION, null, "FI:GOV:M1", false); assertTrue("should not have thrown exception", true); }
@SuppressWarnings("squid:S3655") @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING))") public ResponseEntity<List<CsrSubjectFieldDescription>> getSubjectFieldDescriptions( String caName, KeyUsageType keyUsageType, String keyId, String encodedMemberId, Boolean isNewMember) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).get(); if (keyUsageInfo == KeyUsageInfo.SIGNING) { if (StringUtils.isBlank(encodedMemberId)) { throw new BadRequestException("memberId is mandatory for sign csrs"); } } try { if (!StringUtils.isBlank(keyId)) { KeyInfo keyInfo = keyService.getKey(keyId); if (keyInfo.getUsage() != null) { if (keyInfo.getUsage() != keyUsageInfo) { throw new BadRequestException("key is for different usage", new ErrorDeviation("wrong_key_usage")); } } } ClientId memberId = null; if (!StringUtils.isBlank(encodedMemberId)) { memberId = clientConverter.convertId(encodedMemberId); } CertificateProfileInfo profileInfo; profileInfo = certificateAuthorityService.getCertificateProfile( caName, keyUsageInfo, memberId, isNewMember); List<CsrSubjectFieldDescription> converted = subjectConverter.convert( profileInfo.getSubjectFields()); return new ResponseEntity<>(converted, HttpStatus.OK); } catch (WrongKeyUsageException | KeyNotFoundException | ClientNotFoundException e) { throw new BadRequestException(e); } catch (CertificateAuthorityNotFoundException e) { throw new ResourceNotFoundException(e); } catch (CertificateProfileInstantiationException e) { throw new InternalServerErrorException(e); } }
CertificateAuthoritiesApiController implements CertificateAuthoritiesApi { @SuppressWarnings("squid:S3655") @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING))") public ResponseEntity<List<CsrSubjectFieldDescription>> getSubjectFieldDescriptions( String caName, KeyUsageType keyUsageType, String keyId, String encodedMemberId, Boolean isNewMember) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).get(); if (keyUsageInfo == KeyUsageInfo.SIGNING) { if (StringUtils.isBlank(encodedMemberId)) { throw new BadRequestException("memberId is mandatory for sign csrs"); } } try { if (!StringUtils.isBlank(keyId)) { KeyInfo keyInfo = keyService.getKey(keyId); if (keyInfo.getUsage() != null) { if (keyInfo.getUsage() != keyUsageInfo) { throw new BadRequestException("key is for different usage", new ErrorDeviation("wrong_key_usage")); } } } ClientId memberId = null; if (!StringUtils.isBlank(encodedMemberId)) { memberId = clientConverter.convertId(encodedMemberId); } CertificateProfileInfo profileInfo; profileInfo = certificateAuthorityService.getCertificateProfile( caName, keyUsageInfo, memberId, isNewMember); List<CsrSubjectFieldDescription> converted = subjectConverter.convert( profileInfo.getSubjectFields()); return new ResponseEntity<>(converted, HttpStatus.OK); } catch (WrongKeyUsageException | KeyNotFoundException | ClientNotFoundException e) { throw new BadRequestException(e); } catch (CertificateAuthorityNotFoundException e) { throw new ResourceNotFoundException(e); } catch (CertificateProfileInstantiationException e) { throw new InternalServerErrorException(e); } } }
CertificateAuthoritiesApiController implements CertificateAuthoritiesApi { @SuppressWarnings("squid:S3655") @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING))") public ResponseEntity<List<CsrSubjectFieldDescription>> getSubjectFieldDescriptions( String caName, KeyUsageType keyUsageType, String keyId, String encodedMemberId, Boolean isNewMember) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).get(); if (keyUsageInfo == KeyUsageInfo.SIGNING) { if (StringUtils.isBlank(encodedMemberId)) { throw new BadRequestException("memberId is mandatory for sign csrs"); } } try { if (!StringUtils.isBlank(keyId)) { KeyInfo keyInfo = keyService.getKey(keyId); if (keyInfo.getUsage() != null) { if (keyInfo.getUsage() != keyUsageInfo) { throw new BadRequestException("key is for different usage", new ErrorDeviation("wrong_key_usage")); } } } ClientId memberId = null; if (!StringUtils.isBlank(encodedMemberId)) { memberId = clientConverter.convertId(encodedMemberId); } CertificateProfileInfo profileInfo; profileInfo = certificateAuthorityService.getCertificateProfile( caName, keyUsageInfo, memberId, isNewMember); List<CsrSubjectFieldDescription> converted = subjectConverter.convert( profileInfo.getSubjectFields()); return new ResponseEntity<>(converted, HttpStatus.OK); } catch (WrongKeyUsageException | KeyNotFoundException | ClientNotFoundException e) { throw new BadRequestException(e); } catch (CertificateAuthorityNotFoundException e) { throw new ResourceNotFoundException(e); } catch (CertificateProfileInstantiationException e) { throw new InternalServerErrorException(e); } } CertificateAuthoritiesApiController(CertificateAuthorityService certificateAuthorityService,
            CertificateAuthorityConverter certificateAuthorityConverter,
            KeyService keyService,
            ClientConverter clientConverter,
            CsrSubjectFieldDescriptionConverter subjectConverter); }
CertificateAuthoritiesApiController implements CertificateAuthoritiesApi { @SuppressWarnings("squid:S3655") @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING))") public ResponseEntity<List<CsrSubjectFieldDescription>> getSubjectFieldDescriptions( String caName, KeyUsageType keyUsageType, String keyId, String encodedMemberId, Boolean isNewMember) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).get(); if (keyUsageInfo == KeyUsageInfo.SIGNING) { if (StringUtils.isBlank(encodedMemberId)) { throw new BadRequestException("memberId is mandatory for sign csrs"); } } try { if (!StringUtils.isBlank(keyId)) { KeyInfo keyInfo = keyService.getKey(keyId); if (keyInfo.getUsage() != null) { if (keyInfo.getUsage() != keyUsageInfo) { throw new BadRequestException("key is for different usage", new ErrorDeviation("wrong_key_usage")); } } } ClientId memberId = null; if (!StringUtils.isBlank(encodedMemberId)) { memberId = clientConverter.convertId(encodedMemberId); } CertificateProfileInfo profileInfo; profileInfo = certificateAuthorityService.getCertificateProfile( caName, keyUsageInfo, memberId, isNewMember); List<CsrSubjectFieldDescription> converted = subjectConverter.convert( profileInfo.getSubjectFields()); return new ResponseEntity<>(converted, HttpStatus.OK); } catch (WrongKeyUsageException | KeyNotFoundException | ClientNotFoundException e) { throw new BadRequestException(e); } catch (CertificateAuthorityNotFoundException e) { throw new ResourceNotFoundException(e); } catch (CertificateProfileInstantiationException e) { throw new InternalServerErrorException(e); } } CertificateAuthoritiesApiController(CertificateAuthorityService certificateAuthorityService,
            CertificateAuthorityConverter certificateAuthorityConverter,
            KeyService keyService,
            ClientConverter clientConverter,
            CsrSubjectFieldDescriptionConverter subjectConverter); @Override @PreAuthorize("hasAuthority('VIEW_APPROVED_CERTIFICATE_AUTHORITIES')" + " or (hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION" + " or #keyUsageType == null))" + "or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING)") ResponseEntity<List<CertificateAuthority>> getApprovedCertificateAuthorities(KeyUsageType keyUsageType,
            Boolean includeIntermediateCas); @SuppressWarnings("squid:S3655") // see reason below @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING))") ResponseEntity<List<CsrSubjectFieldDescription>> getSubjectFieldDescriptions(
            String caName,
            KeyUsageType keyUsageType,
            String keyId,
            String encodedMemberId,
            Boolean isNewMember); }
CertificateAuthoritiesApiController implements CertificateAuthoritiesApi { @SuppressWarnings("squid:S3655") @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING))") public ResponseEntity<List<CsrSubjectFieldDescription>> getSubjectFieldDescriptions( String caName, KeyUsageType keyUsageType, String keyId, String encodedMemberId, Boolean isNewMember) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).get(); if (keyUsageInfo == KeyUsageInfo.SIGNING) { if (StringUtils.isBlank(encodedMemberId)) { throw new BadRequestException("memberId is mandatory for sign csrs"); } } try { if (!StringUtils.isBlank(keyId)) { KeyInfo keyInfo = keyService.getKey(keyId); if (keyInfo.getUsage() != null) { if (keyInfo.getUsage() != keyUsageInfo) { throw new BadRequestException("key is for different usage", new ErrorDeviation("wrong_key_usage")); } } } ClientId memberId = null; if (!StringUtils.isBlank(encodedMemberId)) { memberId = clientConverter.convertId(encodedMemberId); } CertificateProfileInfo profileInfo; profileInfo = certificateAuthorityService.getCertificateProfile( caName, keyUsageInfo, memberId, isNewMember); List<CsrSubjectFieldDescription> converted = subjectConverter.convert( profileInfo.getSubjectFields()); return new ResponseEntity<>(converted, HttpStatus.OK); } catch (WrongKeyUsageException | KeyNotFoundException | ClientNotFoundException e) { throw new BadRequestException(e); } catch (CertificateAuthorityNotFoundException e) { throw new ResourceNotFoundException(e); } catch (CertificateProfileInstantiationException e) { throw new InternalServerErrorException(e); } } CertificateAuthoritiesApiController(CertificateAuthorityService certificateAuthorityService,
            CertificateAuthorityConverter certificateAuthorityConverter,
            KeyService keyService,
            ClientConverter clientConverter,
            CsrSubjectFieldDescriptionConverter subjectConverter); @Override @PreAuthorize("hasAuthority('VIEW_APPROVED_CERTIFICATE_AUTHORITIES')" + " or (hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION" + " or #keyUsageType == null))" + "or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING)") ResponseEntity<List<CertificateAuthority>> getApprovedCertificateAuthorities(KeyUsageType keyUsageType,
            Boolean includeIntermediateCas); @SuppressWarnings("squid:S3655") // see reason below @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING))") ResponseEntity<List<CsrSubjectFieldDescription>> getSubjectFieldDescriptions(
            String caName,
            KeyUsageType keyUsageType,
            String keyId,
            String encodedMemberId,
            Boolean isNewMember);  }