@Test @WithMockUser(authorities = { "GENERATE_AUTH_CERT_REQ" }) public void getApprovedCertificateAuthoritiesAuthWithAuthPermission() throws Exception { caController.getApprovedCertificateAuthorities(KeyUsageType.AUTHENTICATION, false); caController.getApprovedCertificateAuthorities(null, false); try { caController.getApprovedCertificateAuthorities(KeyUsageType.SIGNING, false); fail("should have thrown exception"); } catch (AccessDeniedException expected) { } }
@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)") public ResponseEntity<List<CertificateAuthority>> getApprovedCertificateAuthorities(KeyUsageType keyUsageType, Boolean includeIntermediateCas) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).orElse(null); Collection<ApprovedCaDto> caDtos = null; try { caDtos = certificateAuthorityService.getCertificateAuthorities(keyUsageInfo, includeIntermediateCas); } catch (CertificateAuthorityService.InconsistentCaDataException e) { throw new InternalServerErrorException(e); } List<CertificateAuthority> cas = certificateAuthorityConverter.convert(caDtos); return new ResponseEntity<>(cas, HttpStatus.OK); }
CertificateAuthoritiesApiController implements CertificateAuthoritiesApi { @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)") public ResponseEntity<List<CertificateAuthority>> getApprovedCertificateAuthorities(KeyUsageType keyUsageType, Boolean includeIntermediateCas) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).orElse(null); Collection<ApprovedCaDto> caDtos = null; try { caDtos = certificateAuthorityService.getCertificateAuthorities(keyUsageInfo, includeIntermediateCas); } catch (CertificateAuthorityService.InconsistentCaDataException e) { throw new InternalServerErrorException(e); } List<CertificateAuthority> cas = certificateAuthorityConverter.convert(caDtos); return new ResponseEntity<>(cas, HttpStatus.OK); } }
CertificateAuthoritiesApiController implements CertificateAuthoritiesApi { @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)") public ResponseEntity<List<CertificateAuthority>> getApprovedCertificateAuthorities(KeyUsageType keyUsageType, Boolean includeIntermediateCas) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).orElse(null); Collection<ApprovedCaDto> caDtos = null; try { caDtos = certificateAuthorityService.getCertificateAuthorities(keyUsageInfo, includeIntermediateCas); } catch (CertificateAuthorityService.InconsistentCaDataException e) { throw new InternalServerErrorException(e); } List<CertificateAuthority> cas = certificateAuthorityConverter.convert(caDtos); return new ResponseEntity<>(cas, HttpStatus.OK); } CertificateAuthoritiesApiController(CertificateAuthorityService certificateAuthorityService,
            CertificateAuthorityConverter certificateAuthorityConverter,
            KeyService keyService,
            ClientConverter clientConverter,
            CsrSubjectFieldDescriptionConverter subjectConverter); }
CertificateAuthoritiesApiController implements CertificateAuthoritiesApi { @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)") public ResponseEntity<List<CertificateAuthority>> getApprovedCertificateAuthorities(KeyUsageType keyUsageType, Boolean includeIntermediateCas) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).orElse(null); Collection<ApprovedCaDto> caDtos = null; try { caDtos = certificateAuthorityService.getCertificateAuthorities(keyUsageInfo, includeIntermediateCas); } catch (CertificateAuthorityService.InconsistentCaDataException e) { throw new InternalServerErrorException(e); } List<CertificateAuthority> cas = certificateAuthorityConverter.convert(caDtos); return new ResponseEntity<>(cas, HttpStatus.OK); } 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 { @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)") public ResponseEntity<List<CertificateAuthority>> getApprovedCertificateAuthorities(KeyUsageType keyUsageType, Boolean includeIntermediateCas) { KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).orElse(null); Collection<ApprovedCaDto> caDtos = null; try { caDtos = certificateAuthorityService.getCertificateAuthorities(keyUsageInfo, includeIntermediateCas); } catch (CertificateAuthorityService.InconsistentCaDataException e) { throw new InternalServerErrorException(e); } List<CertificateAuthority> cas = certificateAuthorityConverter.convert(caDtos); return new ResponseEntity<>(cas, HttpStatus.OK); } 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);  }