@Test void testCreateCommand() { Calendar calendar = Calendar.getInstance(); Authentication authentication = new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "APPLID"); QueryResponse queryResponse = new QueryResponse("domain", USERNAME, calendar.getTime(), calendar.getTime(), QueryResponse.Source.ZOWE); AuthenticationCommand ac = httpBasicPassTicketScheme.createCommand(authentication, () -> queryResponse); assertNotNull(ac); RequestContext requestContext = new RequestContext(); HttpServletRequest request = new MockHttpServletRequest(); requestContext.setRequest(request); RequestContext.testSetCurrentContext(requestContext); ac.apply(null); String authorizationValue = new String( Base64.getDecoder().decode( requestContext.getZuulRequestHeaders().get("authorization").split(" ")[1] ) ); assertTrue(authorizationValue.startsWith("USERNAME:ZOWE_DUMMY_PASS_TICKET_APPLID_USERNAME_")); calendar.add(Calendar.MINUTE, -1); QueryResponse queryResponse2 = new QueryResponse("domain", USERNAME, calendar.getTime(), calendar.getTime(), QueryResponse.Source.ZOWE); ac = httpBasicPassTicketScheme.createCommand(authentication, () -> queryResponse2); assertTrue(ac.isExpired()); calendar.add(Calendar.MINUTE, 2); QueryResponse queryResponse3 = new QueryResponse("domain", USERNAME, calendar.getTime(), calendar.getTime(), QueryResponse.Source.ZOWE); ac = httpBasicPassTicketScheme.createCommand(authentication, () -> queryResponse3); assertFalse(ac.isExpired()); calendar.add(Calendar.MINUTE, 100); QueryResponse queryResponse4 = new QueryResponse("domain", USERNAME, calendar.getTime(), calendar.getTime(), QueryResponse.Source.ZOWE); ac = httpBasicPassTicketScheme.createCommand(authentication, () -> queryResponse4); calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND, authConfigurationProperties.getPassTicket().getTimeout()); assertEquals(0.0, Math.abs(calendar.getTime().getTime() - (long) ReflectionTestUtils.getField(ac, "expireAt")), 10.0); }
@Override public AuthenticationCommand createCommand(Authentication authentication, Supplier<QueryResponse> tokenSupplier) { final long before = System.currentTimeMillis(); final QueryResponse token = tokenSupplier.get(); if (token == null) { return AuthenticationCommand.EMPTY; } final String applId = authentication.getApplid(); final String userId = token.getUserId(); String passTicket; try { passTicket = passTicketService.generate(userId, applId); } catch (IRRPassTicketGenerationException e) { throw new PassTicketException( String.format("Could not generate PassTicket for user ID %s and APPLID %s", userId, applId), e ); } final String encoded = Base64.getEncoder() .encodeToString((userId + ":" + passTicket).getBytes(StandardCharsets.UTF_8)); final String value = "Basic " + encoded; final long expiredAt = Math.min(before + authConfigurationProperties.getPassTicket().getTimeout() * 1000, token.getExpiration().getTime()); return new PassTicketCommand(value, cookieName, expiredAt); }
HttpBasicPassTicketScheme implements AbstractAuthenticationScheme { @Override public AuthenticationCommand createCommand(Authentication authentication, Supplier<QueryResponse> tokenSupplier) { final long before = System.currentTimeMillis(); final QueryResponse token = tokenSupplier.get(); if (token == null) { return AuthenticationCommand.EMPTY; } final String applId = authentication.getApplid(); final String userId = token.getUserId(); String passTicket; try { passTicket = passTicketService.generate(userId, applId); } catch (IRRPassTicketGenerationException e) { throw new PassTicketException( String.format("Could not generate PassTicket for user ID %s and APPLID %s", userId, applId), e ); } final String encoded = Base64.getEncoder() .encodeToString((userId + ":" + passTicket).getBytes(StandardCharsets.UTF_8)); final String value = "Basic " + encoded; final long expiredAt = Math.min(before + authConfigurationProperties.getPassTicket().getTimeout() * 1000, token.getExpiration().getTime()); return new PassTicketCommand(value, cookieName, expiredAt); } }
HttpBasicPassTicketScheme implements AbstractAuthenticationScheme { @Override public AuthenticationCommand createCommand(Authentication authentication, Supplier<QueryResponse> tokenSupplier) { final long before = System.currentTimeMillis(); final QueryResponse token = tokenSupplier.get(); if (token == null) { return AuthenticationCommand.EMPTY; } final String applId = authentication.getApplid(); final String userId = token.getUserId(); String passTicket; try { passTicket = passTicketService.generate(userId, applId); } catch (IRRPassTicketGenerationException e) { throw new PassTicketException( String.format("Could not generate PassTicket for user ID %s and APPLID %s", userId, applId), e ); } final String encoded = Base64.getEncoder() .encodeToString((userId + ":" + passTicket).getBytes(StandardCharsets.UTF_8)); final String value = "Basic " + encoded; final long expiredAt = Math.min(before + authConfigurationProperties.getPassTicket().getTimeout() * 1000, token.getExpiration().getTime()); return new PassTicketCommand(value, cookieName, expiredAt); } HttpBasicPassTicketScheme(
        PassTicketService passTicketService,
        AuthConfigurationProperties authConfigurationProperties
    ); }
HttpBasicPassTicketScheme implements AbstractAuthenticationScheme { @Override public AuthenticationCommand createCommand(Authentication authentication, Supplier<QueryResponse> tokenSupplier) { final long before = System.currentTimeMillis(); final QueryResponse token = tokenSupplier.get(); if (token == null) { return AuthenticationCommand.EMPTY; } final String applId = authentication.getApplid(); final String userId = token.getUserId(); String passTicket; try { passTicket = passTicketService.generate(userId, applId); } catch (IRRPassTicketGenerationException e) { throw new PassTicketException( String.format("Could not generate PassTicket for user ID %s and APPLID %s", userId, applId), e ); } final String encoded = Base64.getEncoder() .encodeToString((userId + ":" + passTicket).getBytes(StandardCharsets.UTF_8)); final String value = "Basic " + encoded; final long expiredAt = Math.min(before + authConfigurationProperties.getPassTicket().getTimeout() * 1000, token.getExpiration().getTime()); return new PassTicketCommand(value, cookieName, expiredAt); } HttpBasicPassTicketScheme(
        PassTicketService passTicketService,
        AuthConfigurationProperties authConfigurationProperties
    ); @Override AuthenticationScheme getScheme(); @Override AuthenticationCommand createCommand(Authentication authentication, Supplier<QueryResponse> tokenSupplier); }
HttpBasicPassTicketScheme implements AbstractAuthenticationScheme { @Override public AuthenticationCommand createCommand(Authentication authentication, Supplier<QueryResponse> tokenSupplier) { final long before = System.currentTimeMillis(); final QueryResponse token = tokenSupplier.get(); if (token == null) { return AuthenticationCommand.EMPTY; } final String applId = authentication.getApplid(); final String userId = token.getUserId(); String passTicket; try { passTicket = passTicketService.generate(userId, applId); } catch (IRRPassTicketGenerationException e) { throw new PassTicketException( String.format("Could not generate PassTicket for user ID %s and APPLID %s", userId, applId), e ); } final String encoded = Base64.getEncoder() .encodeToString((userId + ":" + passTicket).getBytes(StandardCharsets.UTF_8)); final String value = "Basic " + encoded; final long expiredAt = Math.min(before + authConfigurationProperties.getPassTicket().getTimeout() * 1000, token.getExpiration().getTime()); return new PassTicketCommand(value, cookieName, expiredAt); } HttpBasicPassTicketScheme(
        PassTicketService passTicketService,
        AuthConfigurationProperties authConfigurationProperties
    ); @Override AuthenticationScheme getScheme(); @Override AuthenticationCommand createCommand(Authentication authentication, Supplier<QueryResponse> tokenSupplier);  }