@Test(expected = IllegalArgumentException.class) public void saveNewClient_blacklisted() { ClientDetailsEntity client = Mockito.mock(ClientDetailsEntity.class); Mockito.when(client.getId()).thenReturn(null); String badUri = "badplace.xxx"; Mockito.when(blacklistedSiteService.isBlacklisted(badUri)).thenReturn(true); Mockito.when(client.getRegisteredRedirectUri()).thenReturn(Sets.newHashSet(badUri)); service.saveNewClient(client); }
@Override public ClientDetailsEntity saveNewClient(ClientDetailsEntity client) { if (client.getId() != null) { throw new IllegalArgumentException("Tried to save a new client with an existing ID: " + client.getId()); } if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } } if (Strings.isNullOrEmpty(client.getClientId())) { client = generateClientId(client); } if (client.isAllowRefresh()) { client.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { client.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } client.setCreatedAt(new Date()); if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(client.getSectorIdentifierUri()); if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + client.getSectorIdentifierUri()); } } client.setScope(scopeService.removeRestrictedScopes(client.getScope())); ClientDetailsEntity c = clientRepository.saveClient(client); statsService.resetCache(); return c; }
DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEntityService { @Override public ClientDetailsEntity saveNewClient(ClientDetailsEntity client) { if (client.getId() != null) { throw new IllegalArgumentException("Tried to save a new client with an existing ID: " + client.getId()); } if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } } if (Strings.isNullOrEmpty(client.getClientId())) { client = generateClientId(client); } if (client.isAllowRefresh()) { client.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { client.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } client.setCreatedAt(new Date()); if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(client.getSectorIdentifierUri()); if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + client.getSectorIdentifierUri()); } } client.setScope(scopeService.removeRestrictedScopes(client.getScope())); ClientDetailsEntity c = clientRepository.saveClient(client); statsService.resetCache(); return c; } }
DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEntityService { @Override public ClientDetailsEntity saveNewClient(ClientDetailsEntity client) { if (client.getId() != null) { throw new IllegalArgumentException("Tried to save a new client with an existing ID: " + client.getId()); } if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } } if (Strings.isNullOrEmpty(client.getClientId())) { client = generateClientId(client); } if (client.isAllowRefresh()) { client.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { client.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } client.setCreatedAt(new Date()); if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(client.getSectorIdentifierUri()); if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + client.getSectorIdentifierUri()); } } client.setScope(scopeService.removeRestrictedScopes(client.getScope())); ClientDetailsEntity c = clientRepository.saveClient(client); statsService.resetCache(); return c; }  }
DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEntityService { @Override public ClientDetailsEntity saveNewClient(ClientDetailsEntity client) { if (client.getId() != null) { throw new IllegalArgumentException("Tried to save a new client with an existing ID: " + client.getId()); } if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } } if (Strings.isNullOrEmpty(client.getClientId())) { client = generateClientId(client); } if (client.isAllowRefresh()) { client.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { client.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } client.setCreatedAt(new Date()); if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(client.getSectorIdentifierUri()); if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + client.getSectorIdentifierUri()); } } client.setScope(scopeService.removeRestrictedScopes(client.getScope())); ClientDetailsEntity c = clientRepository.saveClient(client); statsService.resetCache(); return c; }  @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 saveNewClient(ClientDetailsEntity client) { if (client.getId() != null) { throw new IllegalArgumentException("Tried to save a new client with an existing ID: " + client.getId()); } if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (blacklistedSiteService.isBlacklisted(uri)) { throw new IllegalArgumentException("Client URI is blacklisted: " + uri); } } } if (Strings.isNullOrEmpty(client.getClientId())) { client = generateClientId(client); } if (client.isAllowRefresh()) { client.getScope().add(SystemScopeService.OFFLINE_ACCESS); } else { client.getScope().remove(SystemScopeService.OFFLINE_ACCESS); } client.setCreatedAt(new Date()); if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) { try { List<String> redirects = sectorRedirects.get(client.getSectorIdentifierUri()); if (client.getRegisteredRedirectUri() != null) { for (String uri : client.getRegisteredRedirectUri()) { if (!redirects.contains(uri)) { throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects); } } } } catch (ExecutionException e) { throw new IllegalArgumentException("Unable to load sector identifier URI: " + client.getSectorIdentifierUri()); } } client.setScope(scopeService.removeRestrictedScopes(client.getScope())); ClientDetailsEntity c = clientRepository.saveClient(client); statsService.resetCache(); return c; }  @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);  }