@Test @WithMockUser(authorities = { "GENERATE_KEY" }) public void addKey() { ResponseEntity<Key> response = tokensApiController.addKey(GOOD_TOKEN_ID, new KeyLabel().label(KEY_LABEL)); assertEquals(HttpStatus.CREATED, response.getStatusCode()); Key key = response.getBody(); assertEquals(KEY_LABEL, key.getLabel()); try { tokensApiController.addKey(TOKEN_NOT_FOUND_TOKEN_ID, new KeyLabel().label(KEY_LABEL)); fail("should have thrown exception"); } catch (ResourceNotFoundException expected) { } try { tokensApiController.addKey(NOT_ACTIVE_TOKEN_ID, new KeyLabel().label(KEY_LABEL)); fail("should have thrown exception"); } catch (ConflictException expected) { } }
@PreAuthorize("hasAuthority('GENERATE_KEY')") @Override @AuditEventMethod(event = GENERATE_KEY) public ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel) { try { KeyInfo keyInfo = keyService.addKey(tokenId, keyLabel.getLabel()); Key key = keyConverter.convert(keyInfo); return ApiUtil.createCreatedResponse("/api/keys/{keyId}", key, key.getId()); } catch (TokenNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ActionNotPossibleException e) { throw new ConflictException(e); } }
TokensApiController implements TokensApi { @PreAuthorize("hasAuthority('GENERATE_KEY')") @Override @AuditEventMethod(event = GENERATE_KEY) public ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel) { try { KeyInfo keyInfo = keyService.addKey(tokenId, keyLabel.getLabel()); Key key = keyConverter.convert(keyInfo); return ApiUtil.createCreatedResponse("/api/keys/{keyId}", key, key.getId()); } catch (TokenNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ActionNotPossibleException e) { throw new ConflictException(e); } } }
TokensApiController implements TokensApi { @PreAuthorize("hasAuthority('GENERATE_KEY')") @Override @AuditEventMethod(event = GENERATE_KEY) public ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel) { try { KeyInfo keyInfo = keyService.addKey(tokenId, keyLabel.getLabel()); Key key = keyConverter.convert(keyInfo); return ApiUtil.createCreatedResponse("/api/keys/{keyId}", key, key.getId()); } catch (TokenNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ActionNotPossibleException e) { throw new ConflictException(e); } } @Autowired  TokensApiController(KeyConverter keyConverter, KeyService keyService,
            TokenService tokenService,
            TokenConverter tokenConverter,
            ClientConverter clientConverter,
            KeyAndCertificateRequestService keyAndCertificateRequestService); }
TokensApiController implements TokensApi { @PreAuthorize("hasAuthority('GENERATE_KEY')") @Override @AuditEventMethod(event = GENERATE_KEY) public ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel) { try { KeyInfo keyInfo = keyService.addKey(tokenId, keyLabel.getLabel()); Key key = keyConverter.convert(keyInfo); return ApiUtil.createCreatedResponse("/api/keys/{keyId}", key, key.getId()); } catch (TokenNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ActionNotPossibleException e) { throw new ConflictException(e); } } @Autowired  TokensApiController(KeyConverter keyConverter, KeyService keyService,
            TokenService tokenService,
            TokenConverter tokenConverter,
            ClientConverter clientConverter,
            KeyAndCertificateRequestService keyAndCertificateRequestService); @PreAuthorize("hasAuthority('VIEW_KEYS')") @Override ResponseEntity<List<Token>> getTokens(); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<Token> getToken(String id); @PreAuthorize("hasAuthority('ACTIVATE_DEACTIVATE_TOKEN')") @Override @AuditEventMethod(event = LOGIN_TOKEN) ResponseEntity<Token> loginToken(String id, TokenPassword tokenPassword); @PreAuthorize("hasAuthority('ACTIVATE_DEACTIVATE_TOKEN')") @Override @AuditEventMethod(event = LOGOUT_TOKEN) ResponseEntity<Token> logoutToken(String id); @PreAuthorize("hasAuthority('EDIT_TOKEN_FRIENDLY_NAME')") @Override @AuditEventMethod(event = UPDATE_TOKEN_NAME) ResponseEntity<Token> updateToken(String id, TokenName tokenName); @PreAuthorize("hasAuthority('GENERATE_KEY')") @Override @AuditEventMethod(event = GENERATE_KEY) ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel); @Override @PreAuthorize("hasAuthority('GENERATE_KEY') " + " and (hasAuthority('GENERATE_AUTH_CERT_REQ') or hasAuthority('GENERATE_SIGN_CERT_REQ'))") @AuditEventMethod(event = GENERATE_KEY_AND_CSR) ResponseEntity<KeyWithCertificateSigningRequestId> addKeyAndCsr(String tokenId,
            KeyLabelWithCsrGenerate keyLabelWithCsrGenerate); }
TokensApiController implements TokensApi { @PreAuthorize("hasAuthority('GENERATE_KEY')") @Override @AuditEventMethod(event = GENERATE_KEY) public ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel) { try { KeyInfo keyInfo = keyService.addKey(tokenId, keyLabel.getLabel()); Key key = keyConverter.convert(keyInfo); return ApiUtil.createCreatedResponse("/api/keys/{keyId}", key, key.getId()); } catch (TokenNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ActionNotPossibleException e) { throw new ConflictException(e); } } @Autowired  TokensApiController(KeyConverter keyConverter, KeyService keyService,
            TokenService tokenService,
            TokenConverter tokenConverter,
            ClientConverter clientConverter,
            KeyAndCertificateRequestService keyAndCertificateRequestService); @PreAuthorize("hasAuthority('VIEW_KEYS')") @Override ResponseEntity<List<Token>> getTokens(); @Override @PreAuthorize("hasAuthority('VIEW_KEYS')") ResponseEntity<Token> getToken(String id); @PreAuthorize("hasAuthority('ACTIVATE_DEACTIVATE_TOKEN')") @Override @AuditEventMethod(event = LOGIN_TOKEN) ResponseEntity<Token> loginToken(String id, TokenPassword tokenPassword); @PreAuthorize("hasAuthority('ACTIVATE_DEACTIVATE_TOKEN')") @Override @AuditEventMethod(event = LOGOUT_TOKEN) ResponseEntity<Token> logoutToken(String id); @PreAuthorize("hasAuthority('EDIT_TOKEN_FRIENDLY_NAME')") @Override @AuditEventMethod(event = UPDATE_TOKEN_NAME) ResponseEntity<Token> updateToken(String id, TokenName tokenName); @PreAuthorize("hasAuthority('GENERATE_KEY')") @Override @AuditEventMethod(event = GENERATE_KEY) ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel); @Override @PreAuthorize("hasAuthority('GENERATE_KEY') " + " and (hasAuthority('GENERATE_AUTH_CERT_REQ') or hasAuthority('GENERATE_SIGN_CERT_REQ'))") @AuditEventMethod(event = GENERATE_KEY_AND_CSR) ResponseEntity<KeyWithCertificateSigningRequestId> addKeyAndCsr(String tokenId,
            KeyLabelWithCsrGenerate keyLabelWithCsrGenerate);  }