@Test @WithMockUser(authorities = { "VIEW_KEYS" }) public void getPossibleActionsForKey() { ResponseEntity<List<PossibleAction>> response = keysApiController .getPossibleActionsForKey(GOOD_SIGN_KEY_ID); assertEquals(HttpStatus.OK, response.getStatusCode()); Set<PossibleAction> allActions = new HashSet(Arrays.asList(PossibleAction.values())); assertEquals(allActions, new HashSet<>(response.getBody())); }
@Override @PreAuthorize("hasAuthority('VIEW_KEYS')") public ResponseEntity<List<PossibleAction>> getPossibleActionsForKey(String keyId) { try { EnumSet<PossibleActionEnum> actions = keyService.getPossibleActionsForKey(keyId); return new ResponseEntity<>(possibleActionConverter.convert(actions), HttpStatus.OK); } catch (KeyNotFoundException e) { throw new ResourceNotFoundException(e); } }
KeysApiController implements KeysApi { @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") public ResponseEntity<List<PossibleAction>> getPossibleActionsForKey(String keyId) { try { EnumSet<PossibleActionEnum> actions = keyService.getPossibleActionsForKey(keyId); return new ResponseEntity<>(possibleActionConverter.convert(actions), HttpStatus.OK); } catch (KeyNotFoundException e) { throw new ResourceNotFoundException(e); } } }
KeysApiController implements KeysApi { @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") public ResponseEntity<List<PossibleAction>> getPossibleActionsForKey(String keyId) { try { EnumSet<PossibleActionEnum> actions = keyService.getPossibleActionsForKey(keyId); return new ResponseEntity<>(possibleActionConverter.convert(actions), HttpStatus.OK); } catch (KeyNotFoundException e) { throw new ResourceNotFoundException(e); } } @Autowired  KeysApiController(KeyService keyService,
            KeyConverter keyConverter,
            ClientConverter clientConverter,
            TokenCertificateService tokenCertificateService,
            ServerConfService serverConfService,
            CsrFilenameCreator csrFilenameCreator,
            PossibleActionConverter possibleActionConverter); }
KeysApiController implements KeysApi { @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") public ResponseEntity<List<PossibleAction>> getPossibleActionsForKey(String keyId) { try { EnumSet<PossibleActionEnum> actions = keyService.getPossibleActionsForKey(keyId); return new ResponseEntity<>(possibleActionConverter.convert(actions), HttpStatus.OK); } catch (KeyNotFoundException e) { throw new ResourceNotFoundException(e); } } @Autowired  KeysApiController(KeyService keyService,
            KeyConverter keyConverter,
            ClientConverter clientConverter,
            TokenCertificateService tokenCertificateService,
            ServerConfService serverConfService,
            CsrFilenameCreator csrFilenameCreator,
            PossibleActionConverter possibleActionConverter); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<Key> getKey(String keyId); @Override @PreAuthorize("hasAuthority('EDIT_KEY_FRIENDLY_NAME')") @AuditEventMethod(event = UPDATE_KEY_NAME) ResponseEntity<Key> updateKey(String id, KeyName keyName); @SuppressWarnings("squid:S3655") // see reason below @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + "#csrGenerate.keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION)" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "#csrGenerate.keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING)") @AuditEventMethod(event = GENERATE_CSR) ResponseEntity<Resource> generateCsr(String keyId, CsrGenerate csrGenerate); @Override @PreAuthorize("hasAuthority('DELETE_AUTH_CERT') or hasAuthority('DELETE_SIGN_CERT')") @AuditEventMethod(event = DELETE_CSR) ResponseEntity<Void> deleteCsr(String keyId, String csrId); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<List<PossibleAction>> getPossibleActionsForCsr(String id, String csrId); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<List<PossibleAction>> getPossibleActionsForKey(String keyId); @Override @PreAuthorize("hasAnyAuthority('DELETE_KEY', 'DELETE_AUTH_KEY', 'DELETE_SIGN_KEY')") @AuditEventMethod(event = DELETE_KEY) ResponseEntity<Void> deleteKey(String keyId, Boolean ignoreWarnings); @Override @PreAuthorize("hasAnyAuthority('GENERATE_AUTH_CERT_REQ', 'GENERATE_SIGN_CERT_REQ')") ResponseEntity<Resource> downloadCsr(String keyId, String csrId, CsrFormat csrFormat); }
KeysApiController implements KeysApi { @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") public ResponseEntity<List<PossibleAction>> getPossibleActionsForKey(String keyId) { try { EnumSet<PossibleActionEnum> actions = keyService.getPossibleActionsForKey(keyId); return new ResponseEntity<>(possibleActionConverter.convert(actions), HttpStatus.OK); } catch (KeyNotFoundException e) { throw new ResourceNotFoundException(e); } } @Autowired  KeysApiController(KeyService keyService,
            KeyConverter keyConverter,
            ClientConverter clientConverter,
            TokenCertificateService tokenCertificateService,
            ServerConfService serverConfService,
            CsrFilenameCreator csrFilenameCreator,
            PossibleActionConverter possibleActionConverter); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<Key> getKey(String keyId); @Override @PreAuthorize("hasAuthority('EDIT_KEY_FRIENDLY_NAME')") @AuditEventMethod(event = UPDATE_KEY_NAME) ResponseEntity<Key> updateKey(String id, KeyName keyName); @SuppressWarnings("squid:S3655") // see reason below @Override @PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + "#csrGenerate.keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).AUTHENTICATION)" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "#csrGenerate.keyUsageType == T(org.niis.xroad.restapi.openapi.model.KeyUsageType).SIGNING)") @AuditEventMethod(event = GENERATE_CSR) ResponseEntity<Resource> generateCsr(String keyId, CsrGenerate csrGenerate); @Override @PreAuthorize("hasAuthority('DELETE_AUTH_CERT') or hasAuthority('DELETE_SIGN_CERT')") @AuditEventMethod(event = DELETE_CSR) ResponseEntity<Void> deleteCsr(String keyId, String csrId); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<List<PossibleAction>> getPossibleActionsForCsr(String id, String csrId); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<List<PossibleAction>> getPossibleActionsForKey(String keyId); @Override @PreAuthorize("hasAnyAuthority('DELETE_KEY', 'DELETE_AUTH_KEY', 'DELETE_SIGN_KEY')") @AuditEventMethod(event = DELETE_KEY) ResponseEntity<Void> deleteKey(String keyId, Boolean ignoreWarnings); @Override @PreAuthorize("hasAnyAuthority('GENERATE_AUTH_CERT_REQ', 'GENERATE_SIGN_CERT_REQ')") ResponseEntity<Resource> downloadCsr(String keyId, String csrId, CsrFormat csrFormat);  }