@Test void testGetAuthenticationCommand_whenNoJwt() { AbstractAuthenticationScheme schemeBeanMock = mock(AbstractAuthenticationScheme.class); when(authenticationSchemeFactory.getSchema(AuthenticationScheme.HTTP_BASIC_PASSTICKET)) .thenReturn(schemeBeanMock); Authentication authentication = new Authentication(AuthenticationScheme.HTTP_BASIC_PASSTICKET, "applid"); serviceAuthenticationService.getAuthenticationCommand(authentication, null); verify(schemeBeanMock, times(1)).createCommand( eq(authentication), argThat(x -> x.get() == null) ); }
@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; }