@Test @WithMockUser(authorities = { "INIT_CONFIG" }) public void initSecurityServerFail() throws Exception { InitialServerConf initialServerConf = createInitConfWithPin(SOFTWARE_TOKEN_PIN); doThrow(new AnchorNotFoundException("")) .when(initializationService).initialize(any(), any(), any(), any(), anyBoolean()); try { initializationApiController.initSecurityServer(initialServerConf); fail("should have thrown"); } catch (ConflictException expected) { } doThrow(new InitializationService.ServerAlreadyFullyInitializedException("")) .when(initializationService).initialize(any(), any(), any(), any(), anyBoolean()); try { initializationApiController.initSecurityServer(initialServerConf); fail("should have thrown"); } catch (ConflictException expected) { } doThrow(new InitializationService.InvalidInitParamsException("", Collections.emptyList())) .when(initializationService).initialize(any(), any(), any(), any(), anyBoolean()); try { initializationApiController.initSecurityServer(initialServerConf); fail("should have thrown"); } catch (BadRequestException expected) { } doThrow(new UnhandledWarningsException(Collections.emptyList())) .when(initializationService).initialize(any(), any(), any(), any(), anyBoolean()); try { initializationApiController.initSecurityServer(initialServerConf); fail("should have thrown"); } catch (BadRequestException expected) { } doThrow(new InitializationService.InvalidCharactersException("")) .when(initializationService).initialize(any(), any(), any(), any(), anyBoolean()); try { initializationApiController.initSecurityServer(initialServerConf); fail("should have thrown"); } catch (BadRequestException expected) { } doThrow(new InitializationService.WeakPinException("", Collections.emptyList())) .when(initializationService).initialize(any(), any(), any(), any(), anyBoolean()); try { initializationApiController.initSecurityServer(initialServerConf); fail("should have thrown"); } catch (BadRequestException expected) { } doThrow(new InitializationService.SoftwareTokenInitException("", new Exception())) .when(initializationService).initialize(any(), any(), any(), any(), anyBoolean()); try { initializationApiController.initSecurityServer(initialServerConf); fail("should have thrown"); } catch (InternalServerErrorException expected) { } }
@Override @PreAuthorize("hasAuthority('INIT_CONFIG')") @AuditEventMethod(event = INIT_SERVER_CONFIGURATION) public synchronized ResponseEntity<Void> initSecurityServer(InitialServerConf initialServerConf) { String securityServerCode = initialServerConf.getSecurityServerCode(); String ownerMemberClass = initialServerConf.getOwnerMemberClass(); String ownerMemberCode = initialServerConf.getOwnerMemberCode(); String softwareTokenPin = initialServerConf.getSoftwareTokenPin(); boolean ignoreWarnings = Boolean.TRUE.equals(initialServerConf.getIgnoreWarnings()); try { initializationService.initialize(securityServerCode, ownerMemberClass, ownerMemberCode, softwareTokenPin, ignoreWarnings); } catch (AnchorNotFoundException | InitializationService.ServerAlreadyFullyInitializedException e) { throw new ConflictException(e); } catch (UnhandledWarningsException | InitializationService.InvalidCharactersException | InitializationService.WeakPinException | InitializationService.InvalidInitParamsException e) { throw new BadRequestException(e); } catch (InitializationService.SoftwareTokenInitException e) { throw new InternalServerErrorException(e); } return new ResponseEntity<>(HttpStatus.CREATED); }
InitializationApiController implements InitializationApi { @Override @PreAuthorize("hasAuthority('INIT_CONFIG')") @AuditEventMethod(event = INIT_SERVER_CONFIGURATION) public synchronized ResponseEntity<Void> initSecurityServer(InitialServerConf initialServerConf) { String securityServerCode = initialServerConf.getSecurityServerCode(); String ownerMemberClass = initialServerConf.getOwnerMemberClass(); String ownerMemberCode = initialServerConf.getOwnerMemberCode(); String softwareTokenPin = initialServerConf.getSoftwareTokenPin(); boolean ignoreWarnings = Boolean.TRUE.equals(initialServerConf.getIgnoreWarnings()); try { initializationService.initialize(securityServerCode, ownerMemberClass, ownerMemberCode, softwareTokenPin, ignoreWarnings); } catch (AnchorNotFoundException | InitializationService.ServerAlreadyFullyInitializedException e) { throw new ConflictException(e); } catch (UnhandledWarningsException | InitializationService.InvalidCharactersException | InitializationService.WeakPinException | InitializationService.InvalidInitParamsException e) { throw new BadRequestException(e); } catch (InitializationService.SoftwareTokenInitException e) { throw new InternalServerErrorException(e); } return new ResponseEntity<>(HttpStatus.CREATED); } }
InitializationApiController implements InitializationApi { @Override @PreAuthorize("hasAuthority('INIT_CONFIG')") @AuditEventMethod(event = INIT_SERVER_CONFIGURATION) public synchronized ResponseEntity<Void> initSecurityServer(InitialServerConf initialServerConf) { String securityServerCode = initialServerConf.getSecurityServerCode(); String ownerMemberClass = initialServerConf.getOwnerMemberClass(); String ownerMemberCode = initialServerConf.getOwnerMemberCode(); String softwareTokenPin = initialServerConf.getSoftwareTokenPin(); boolean ignoreWarnings = Boolean.TRUE.equals(initialServerConf.getIgnoreWarnings()); try { initializationService.initialize(securityServerCode, ownerMemberClass, ownerMemberCode, softwareTokenPin, ignoreWarnings); } catch (AnchorNotFoundException | InitializationService.ServerAlreadyFullyInitializedException e) { throw new ConflictException(e); } catch (UnhandledWarningsException | InitializationService.InvalidCharactersException | InitializationService.WeakPinException | InitializationService.InvalidInitParamsException e) { throw new BadRequestException(e); } catch (InitializationService.SoftwareTokenInitException e) { throw new InternalServerErrorException(e); } return new ResponseEntity<>(HttpStatus.CREATED); } @Autowired  InitializationApiController(InitializationService initializationService); }
InitializationApiController implements InitializationApi { @Override @PreAuthorize("hasAuthority('INIT_CONFIG')") @AuditEventMethod(event = INIT_SERVER_CONFIGURATION) public synchronized ResponseEntity<Void> initSecurityServer(InitialServerConf initialServerConf) { String securityServerCode = initialServerConf.getSecurityServerCode(); String ownerMemberClass = initialServerConf.getOwnerMemberClass(); String ownerMemberCode = initialServerConf.getOwnerMemberCode(); String softwareTokenPin = initialServerConf.getSoftwareTokenPin(); boolean ignoreWarnings = Boolean.TRUE.equals(initialServerConf.getIgnoreWarnings()); try { initializationService.initialize(securityServerCode, ownerMemberClass, ownerMemberCode, softwareTokenPin, ignoreWarnings); } catch (AnchorNotFoundException | InitializationService.ServerAlreadyFullyInitializedException e) { throw new ConflictException(e); } catch (UnhandledWarningsException | InitializationService.InvalidCharactersException | InitializationService.WeakPinException | InitializationService.InvalidInitParamsException e) { throw new BadRequestException(e); } catch (InitializationService.SoftwareTokenInitException e) { throw new InternalServerErrorException(e); } return new ResponseEntity<>(HttpStatus.CREATED); } @Autowired  InitializationApiController(InitializationService initializationService); @Override @PreAuthorize("isAuthenticated()") ResponseEntity<InitializationStatus> getInitializationStatus(); @Override @PreAuthorize("hasAuthority('INIT_CONFIG')") @AuditEventMethod(event = INIT_SERVER_CONFIGURATION) synchronized ResponseEntity<Void> initSecurityServer(InitialServerConf initialServerConf); }
InitializationApiController implements InitializationApi { @Override @PreAuthorize("hasAuthority('INIT_CONFIG')") @AuditEventMethod(event = INIT_SERVER_CONFIGURATION) public synchronized ResponseEntity<Void> initSecurityServer(InitialServerConf initialServerConf) { String securityServerCode = initialServerConf.getSecurityServerCode(); String ownerMemberClass = initialServerConf.getOwnerMemberClass(); String ownerMemberCode = initialServerConf.getOwnerMemberCode(); String softwareTokenPin = initialServerConf.getSoftwareTokenPin(); boolean ignoreWarnings = Boolean.TRUE.equals(initialServerConf.getIgnoreWarnings()); try { initializationService.initialize(securityServerCode, ownerMemberClass, ownerMemberCode, softwareTokenPin, ignoreWarnings); } catch (AnchorNotFoundException | InitializationService.ServerAlreadyFullyInitializedException e) { throw new ConflictException(e); } catch (UnhandledWarningsException | InitializationService.InvalidCharactersException | InitializationService.WeakPinException | InitializationService.InvalidInitParamsException e) { throw new BadRequestException(e); } catch (InitializationService.SoftwareTokenInitException e) { throw new InternalServerErrorException(e); } return new ResponseEntity<>(HttpStatus.CREATED); } @Autowired  InitializationApiController(InitializationService initializationService); @Override @PreAuthorize("isAuthenticated()") ResponseEntity<InitializationStatus> getInitializationStatus(); @Override @PreAuthorize("hasAuthority('INIT_CONFIG')") @AuditEventMethod(event = INIT_SERVER_CONFIGURATION) synchronized ResponseEntity<Void> initSecurityServer(InitialServerConf initialServerConf);  }