@Test void givenZosmfIsntPresentBecauseOfError_whenTokenIsRequested_shouldReturnTokenCreatedByApiMl() { when(providers.isZosmfAvailable()).thenThrow(new AuthenticationServiceException("zOSMF id invalid")); when(authenticationService.createJwtToken(eq(VALID_USER_ID), any(), any())).thenReturn(VALID_APIML_TOKEN); when(authenticationService.createTokenAuthentication(VALID_USER_ID, VALID_APIML_TOKEN)).thenReturn(new TokenAuthentication(VALID_USER_ID, VALID_APIML_TOKEN)); String jwtToken = underTest.createJwtTokenWithoutCredentials(VALID_USER_ID); assertThat(jwtToken, is(VALID_APIML_TOKEN)); }
public String createJwtTokenWithoutCredentials(String user) { boolean isZosmfUsedAndAvailable = false; try { isZosmfUsedAndAvailable = providers.isZosfmUsed() && providers.isZosmfAvailable(); } catch (AuthenticationServiceException ex) { } if (isZosmfUsedAndAvailable) { try { String passTicket = passTicketService.generate(user, zosmfApplId); return ((TokenAuthentication) zosmfAuthenticationProvider.authenticate(new UsernamePasswordAuthenticationToken(user, passTicket))) .getCredentials(); } catch (IRRPassTicketGenerationException e) { throw new AuthenticationTokenException("Problem with generating PassTicket"); } } else { final String domain = "security-domain"; final String jwtTokenString = authenticationService.createJwtToken(user, domain, null); return authenticationService.createTokenAuthentication(user, jwtTokenString).getCredentials(); } }
TokenCreationService { public String createJwtTokenWithoutCredentials(String user) { boolean isZosmfUsedAndAvailable = false; try { isZosmfUsedAndAvailable = providers.isZosfmUsed() && providers.isZosmfAvailable(); } catch (AuthenticationServiceException ex) { } if (isZosmfUsedAndAvailable) { try { String passTicket = passTicketService.generate(user, zosmfApplId); return ((TokenAuthentication) zosmfAuthenticationProvider.authenticate(new UsernamePasswordAuthenticationToken(user, passTicket))) .getCredentials(); } catch (IRRPassTicketGenerationException e) { throw new AuthenticationTokenException("Problem with generating PassTicket"); } } else { final String domain = "security-domain"; final String jwtTokenString = authenticationService.createJwtToken(user, domain, null); return authenticationService.createTokenAuthentication(user, jwtTokenString).getCredentials(); } } }
TokenCreationService { public String createJwtTokenWithoutCredentials(String user) { boolean isZosmfUsedAndAvailable = false; try { isZosmfUsedAndAvailable = providers.isZosfmUsed() && providers.isZosmfAvailable(); } catch (AuthenticationServiceException ex) { } if (isZosmfUsedAndAvailable) { try { String passTicket = passTicketService.generate(user, zosmfApplId); return ((TokenAuthentication) zosmfAuthenticationProvider.authenticate(new UsernamePasswordAuthenticationToken(user, passTicket))) .getCredentials(); } catch (IRRPassTicketGenerationException e) { throw new AuthenticationTokenException("Problem with generating PassTicket"); } } else { final String domain = "security-domain"; final String jwtTokenString = authenticationService.createJwtToken(user, domain, null); return authenticationService.createTokenAuthentication(user, jwtTokenString).getCredentials(); } }  }
TokenCreationService { public String createJwtTokenWithoutCredentials(String user) { boolean isZosmfUsedAndAvailable = false; try { isZosmfUsedAndAvailable = providers.isZosfmUsed() && providers.isZosmfAvailable(); } catch (AuthenticationServiceException ex) { } if (isZosmfUsedAndAvailable) { try { String passTicket = passTicketService.generate(user, zosmfApplId); return ((TokenAuthentication) zosmfAuthenticationProvider.authenticate(new UsernamePasswordAuthenticationToken(user, passTicket))) .getCredentials(); } catch (IRRPassTicketGenerationException e) { throw new AuthenticationTokenException("Problem with generating PassTicket"); } } else { final String domain = "security-domain"; final String jwtTokenString = authenticationService.createJwtToken(user, domain, null); return authenticationService.createTokenAuthentication(user, jwtTokenString).getCredentials(); } }  String createJwtTokenWithoutCredentials(String user); }
TokenCreationService { public String createJwtTokenWithoutCredentials(String user) { boolean isZosmfUsedAndAvailable = false; try { isZosmfUsedAndAvailable = providers.isZosfmUsed() && providers.isZosmfAvailable(); } catch (AuthenticationServiceException ex) { } if (isZosmfUsedAndAvailable) { try { String passTicket = passTicketService.generate(user, zosmfApplId); return ((TokenAuthentication) zosmfAuthenticationProvider.authenticate(new UsernamePasswordAuthenticationToken(user, passTicket))) .getCredentials(); } catch (IRRPassTicketGenerationException e) { throw new AuthenticationTokenException("Problem with generating PassTicket"); } } else { final String domain = "security-domain"; final String jwtTokenString = authenticationService.createJwtToken(user, domain, null); return authenticationService.createTokenAuthentication(user, jwtTokenString).getCredentials(); } }  String createJwtTokenWithoutCredentials(String user);  }