@Test void testGetAuthenticationCommand() { AbstractAuthenticationScheme schemeBeanMock = mock(AbstractAuthenticationScheme.class); QueryResponse qr1 = new QueryResponse("domain", "userId", Date.valueOf(LocalDate.of(1900, 1, 1)), Date.valueOf(LocalDate.of(2100, 1, 1)), QueryResponse.Source.ZOWE ); QueryResponse qr2 = new QueryResponse("domain", "userId", Date.valueOf(LocalDate.of(1900, 1, 1)), Date.valueOf(LocalDate.of(2000, 1, 1)), QueryResponse.Source.ZOWE ); AuthenticationCommand acValid = spy(new AuthenticationCommandTest(false)); AuthenticationCommand acExpired = spy(new AuthenticationCommandTest(true)); when(authenticationSchemeFactory.getSchema(AuthenticationScheme.HTTP_BASIC_PASSTICKET)) .thenReturn(schemeBeanMock); when(authenticationService.parseJwtToken("token1")).thenReturn(qr1); when(authenticationService.parseJwtToken("token2")).thenReturn(qr2); when(schemeBeanMock.createCommand(eq(new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid")), argThat(x -> Objects.equals(x.get(), qr1)))).thenReturn(acValid); when(schemeBeanMock.createCommand(eq(new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid")), argThat(x -> Objects.equals(x.get(), qr2)))).thenReturn(acExpired); assertSame(acValid, serviceAuthenticationService.getAuthenticationCommand(new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid"), "token1")); verify(schemeBeanMock, times(1)).createCommand(any(), any()); assertSame(acValid, serviceAuthenticationService.getAuthenticationCommand(new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid"), "token1")); verify(schemeBeanMock, times(1)).createCommand(any(), any()); assertSame(acExpired, serviceAuthenticationService.getAuthenticationCommand(new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid"), "token2")); verify(schemeBeanMock, times(2)).createCommand(any(), any()); when(schemeBeanMock.createCommand(eq(new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid")), argThat(x -> Objects.equals(x.get(), qr2)))).thenReturn(acValid); assertSame(acValid, serviceAuthenticationService.getAuthenticationCommand(new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid"), "token2")); verify(schemeBeanMock, times(3)).createCommand(any(), any()); }
@Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) public AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken) { final AbstractAuthenticationScheme scheme = authenticationSchemeFactory.getSchema(authentication.getScheme()); if (jwtToken == null) return scheme.createCommand(authentication, () -> null); return scheme.createCommand(authentication, () -> authenticationService.parseJwtToken(jwtToken)); }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) public AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken) { final AbstractAuthenticationScheme scheme = authenticationSchemeFactory.getSchema(authentication.getScheme()); if (jwtToken == null) return scheme.createCommand(authentication, () -> null); return scheme.createCommand(authentication, () -> authenticationService.parseJwtToken(jwtToken)); } }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) public AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken) { final AbstractAuthenticationScheme scheme = authenticationSchemeFactory.getSchema(authentication.getScheme()); if (jwtToken == null) return scheme.createCommand(authentication, () -> null); return scheme.createCommand(authentication, () -> authenticationService.parseJwtToken(jwtToken)); }  }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) public AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken) { final AbstractAuthenticationScheme scheme = authenticationSchemeFactory.getSchema(authentication.getScheme()); if (jwtToken == null) return scheme.createCommand(authentication, () -> null); return scheme.createCommand(authentication, () -> authenticationService.parseJwtToken(jwtToken)); }  Authentication getAuthentication(InstanceInfo instanceInfo); @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken); @Override @RetryIfExpired @CacheEvict( value = CACHE_BY_SERVICE_ID, condition = "#result != null && #result.isExpired()", keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR ) @Cacheable(value = CACHE_BY_SERVICE_ID, keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR) AuthenticationCommand getAuthenticationCommand(String serviceId, String jwtToken); @Override @CacheEvict(value = CACHE_BY_SERVICE_ID, allEntries = true) void evictCacheAllService(); @Override void evictCacheService(String serviceId); }
ServiceAuthenticationServiceImpl implements ServiceAuthenticationService { @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) public AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken) { final AbstractAuthenticationScheme scheme = authenticationSchemeFactory.getSchema(authentication.getScheme()); if (jwtToken == null) return scheme.createCommand(authentication, () -> null); return scheme.createCommand(authentication, () -> authenticationService.parseJwtToken(jwtToken)); }  Authentication getAuthentication(InstanceInfo instanceInfo); @Override @CacheEvict(value = CACHE_BY_AUTHENTICATION, condition = "#result != null && #result.isExpired()") @Cacheable(CACHE_BY_AUTHENTICATION) AuthenticationCommand getAuthenticationCommand(Authentication authentication, String jwtToken); @Override @RetryIfExpired @CacheEvict( value = CACHE_BY_SERVICE_ID, condition = "#result != null && #result.isExpired()", keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR ) @Cacheable(value = CACHE_BY_SERVICE_ID, keyGenerator = CacheConfig.COMPOSITE_KEY_GENERATOR) AuthenticationCommand getAuthenticationCommand(String serviceId, String jwtToken); @Override @CacheEvict(value = CACHE_BY_SERVICE_ID, allEntries = true) void evictCacheAllService(); @Override void evictCacheService(String serviceId); static final String AUTHENTICATION_COMMAND_KEY; }