@Test public void updateClient_noOfflineAccess() { ClientDetailsEntity oldClient = Mockito.mock(ClientDetailsEntity.class); ClientDetailsEntity newClient = Mockito.mock(ClientDetailsEntity.class); Mockito.when(newClient.isAllowRefresh()).thenReturn(false); @SuppressWarnings("unchecked") Set<String> scopes = Mockito.mock(Set.class); Mockito.when(newClient.getScope()).thenReturn(scopes); service.updateClient(oldClient, newClient); Mockito.verify(scopes).remove(SystemScopeService.OFFLINE_ACCESS); }
@Override public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException { if (oldClient != null && newClient != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } if (newClient.isAllowRefresh()) { newClient.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } if (!Strings.isNullOrEmpty(newClient.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(newClient.getSectorIdentifierUri()); if (newClient.getRegisteredRedirectUri() != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (UncheckedExecutionException ue) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } } newClient.setScope(scopeService.removeRestrictedScopes(newClient.getScope())); return clientRepository.updateClient(oldClient.getId(), newClient); } throw new IllegalArgumentException("Neither old client or new client can be null!"); }
DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEntityService { @Override public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException { if (oldClient != null && newClient != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } if (newClient.isAllowRefresh()) { newClient.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } if (!Strings.isNullOrEmpty(newClient.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(newClient.getSectorIdentifierUri()); if (newClient.getRegisteredRedirectUri() != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (UncheckedExecutionException ue) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } } newClient.setScope(scopeService.removeRestrictedScopes(newClient.getScope())); return clientRepository.updateClient(oldClient.getId(), newClient); } throw new IllegalArgumentException("Neither old client or new client can be null!"); } }
DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEntityService { @Override public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException { if (oldClient != null && newClient != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } if (newClient.isAllowRefresh()) { newClient.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } if (!Strings.isNullOrEmpty(newClient.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(newClient.getSectorIdentifierUri()); if (newClient.getRegisteredRedirectUri() != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (UncheckedExecutionException ue) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } } newClient.setScope(scopeService.removeRestrictedScopes(newClient.getScope())); return clientRepository.updateClient(oldClient.getId(), newClient); } throw new IllegalArgumentException("Neither old client or new client can be null!"); }  }
DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEntityService { @Override public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException { if (oldClient != null && newClient != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } if (newClient.isAllowRefresh()) { newClient.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } if (!Strings.isNullOrEmpty(newClient.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(newClient.getSectorIdentifierUri()); if (newClient.getRegisteredRedirectUri() != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (UncheckedExecutionException ue) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } } newClient.setScope(scopeService.removeRestrictedScopes(newClient.getScope())); return clientRepository.updateClient(oldClient.getId(), newClient); } throw new IllegalArgumentException("Neither old client or new client can be null!"); }  @Override ClientDetailsEntity saveNewClient(ClientDetailsEntity client); @Override ClientDetailsEntity getClientById(Long id); @Override ClientDetailsEntity loadClientByClientId(String clientId); @Override void deleteClient(ClientDetailsEntity client); @Override ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient); @Override Collection<ClientDetailsEntity> getAllClients(); @Override ClientDetailsEntity generateClientId(ClientDetailsEntity client); @Override ClientDetailsEntity generateClientSecret(ClientDetailsEntity client); }
DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEntityService { @Override public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException { if (oldClient != null && newClient != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } if (newClient.isAllowRefresh()) { newClient.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } if (!Strings.isNullOrEmpty(newClient.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(newClient.getSectorIdentifierUri()); if (newClient.getRegisteredRedirectUri() != null) { for (String uri : newClient.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (UncheckedExecutionException ue) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri()); } } newClient.setScope(scopeService.removeRestrictedScopes(newClient.getScope())); return clientRepository.updateClient(oldClient.getId(), newClient); } throw new IllegalArgumentException("Neither old client or new client can be null!"); }  @Override ClientDetailsEntity saveNewClient(ClientDetailsEntity client); @Override ClientDetailsEntity getClientById(Long id); @Override ClientDetailsEntity loadClientByClientId(String clientId); @Override void deleteClient(ClientDetailsEntity client); @Override ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient); @Override Collection<ClientDetailsEntity> getAllClients(); @Override ClientDetailsEntity generateClientId(ClientDetailsEntity client); @Override ClientDetailsEntity generateClientSecret(ClientDetailsEntity client);  }