org.springframework.security.oauth2.provider.NoSuchClientException Java Examples
The following examples show how to use
org.springframework.security.oauth2.provider.NoSuchClientException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AAAGuestServiceImpl.java From spring4-rest-oauth2 with GNU General Public License v2.0 | 6 votes |
@Override public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException { if (clientId.equals(id)) { List<String> authorizedGrantTypes = new ArrayList<String>(); authorizedGrantTypes.add("password"); authorizedGrantTypes.add("refresh_token"); authorizedGrantTypes.add("client_credentials"); BaseClientDetails clientDetails = new BaseClientDetails(); clientDetails.setClientId(id); clientDetails.setClientSecret(secretKey); clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes); return clientDetails; } else { throw new NoSuchClientException("No client recognized with id: " + clientId); } }
Example #2
Source File: MongoClientDetailsServiceTest.java From spring-security-mongo with MIT License | 6 votes |
@Test(expected = NoSuchClientException.class) public void shouldNotUpdateClientSecretWhenClientIdIsInvalid() throws NoSuchClientException { //Given final String clientId = string().next(); final String secret = string().next(); //And final String expectedNewSecret = string().next(); given(passwordEncoder.encode(secret)).willReturn(expectedNewSecret); //And given(mongoClientDetailsRepository.updateClientSecret(clientId, expectedNewSecret)).willReturn(false); //When mongoClientDetailsService.updateClientSecret(clientId, secret); }
Example #3
Source File: MongoClientDetailsServiceTest.java From spring-security-mongo with MIT License | 6 votes |
@Test public void shouldUpdateClientSecret() throws NoSuchClientException { //Given final String clientId = string().next(); final String secret = string().next(); //And final String expectedNewSecret = string().next(); given(passwordEncoder.encode(secret)).willReturn(expectedNewSecret); //And given(mongoClientDetailsRepository.updateClientSecret(clientId, expectedNewSecret)).willReturn(true); //When mongoClientDetailsService.updateClientSecret(clientId, secret); }
Example #4
Source File: ApplicationEndpoint.java From watchdog-spring-boot-starter with MIT License | 6 votes |
@PutMapping(value = {"${watchdog.application.prefix:}/applications/{clientId}"}) public ClientDetails update(@PathVariable String clientId, @RequestBody ApplicationParam param){ Optional<Application> application = applicationService.findByClientId(clientId); if(!application.isPresent()){ throw new NoSuchClientException("Not Found The Client."); } application.ifPresent(app -> { param.populateDefault(); if(!StringUtils.isEmpty(param.getName())){ app.setName(param.getName()); } if(param.getRedirectUri() != null){ app.setRegisteredRedirectUri(param.getRedirectUri()); } if(param.getScope() != null){ app.setScope(param.getScope()); } }); applicationService.updateClientDetails(application.get()); return application.get(); }
Example #5
Source File: CustomClientDetailsService.java From oauth-server with Apache License 2.0 | 5 votes |
@Override public ClientDetails loadClientByClientId(String name) { ClientE clientE = this.selectByName(name); if (clientE == null) { throw new NoSuchClientException("No client found : " + name); } CustomClientDetails clientDetails = new CustomClientDetails(); clientDetails.setAuthorizedGrantTypes(StringUtils .commaDelimitedListToSet(clientE.getAuthorizedGrantTypes())); clientDetails.setClientId(clientE.getName()); clientDetails.setClientSecret(clientE.getSecret()); clientDetails.setResourceIds(StringUtils.commaDelimitedListToSet(clientE.getResourceIds())); clientDetails.setScope(StringUtils.commaDelimitedListToSet(clientE.getScope())); clientDetails.setRegisteredRedirectUri(StringUtils .commaDelimitedListToSet(clientE.getWebServerRedirectUri())); clientDetails.setAuthorities(Collections.emptyList()); int accessTokenValidity = clientE.getAccessTokenValidity() != null ? clientE.getAccessTokenValidity().intValue() : 3600; clientDetails.setAccessTokenValiditySeconds(accessTokenValidity); int refreshTokenValidity = clientE.getRefreshTokenValidity() != null ? clientE.getRefreshTokenValidity().intValue() : 3600; clientDetails.setRefreshTokenValiditySeconds(refreshTokenValidity); clientDetails.setOrganizationId(1L); String json = clientE.getAdditionalInformation(); if (json != null) { try { Map<String, Object> additionalInformation = mapper.readValue(json, Map.class); clientDetails.setAdditionalInformation(additionalInformation); } catch (Exception e) { LOGGER.warn("parser addition info error: {}", e); } } clientDetails.setAutoApproveScopes(StringUtils.commaDelimitedListToSet(clientE.getAutoApprove())); return clientDetails; }
Example #6
Source File: MongoClientDetailsServiceTest.java From spring-security-mongo with MIT License | 5 votes |
@Test public void shouldLoadClientByClientId() throws NoSuchClientException { //Given final String clientId = string().next(); final MongoClientDetails expectedClientDetails = MongoClientDetailsBuilder.mongoClientDetailsBuilder().build(); given(mongoClientDetailsRepository.findByClientId(clientId)).willReturn(expectedClientDetails); //When final ClientDetails clientDetails = mongoClientDetailsService.loadClientByClientId(clientId); //Then assertThat(clientDetails.getClientId()).isEqualTo(expectedClientDetails.getClientId()); }
Example #7
Source File: MongoClientDetailsServiceTest.java From spring-security-mongo with MIT License | 5 votes |
@Test(expected = NoSuchClientException.class) public void shouldNotUpdateClientDetailsWhenClientIdIsNotValid() throws NoSuchClientException { //Given final ClientDetails clientDetails = ClientDetailsBuilder.clientDetailsBuilder().build(); //And given(mongoClientDetailsRepository.update(any(MongoClientDetails.class))).willReturn(false); //When mongoClientDetailsService.updateClientDetails(clientDetails); }
Example #8
Source File: MongoClientDetailsServiceTest.java From spring-security-mongo with MIT License | 5 votes |
@Test public void shouldUpdateClientDetails() throws NoSuchClientException { //Given final ClientDetails clientDetails = ClientDetailsBuilder.clientDetailsBuilder().build(); //And given(mongoClientDetailsRepository.update(any(MongoClientDetails.class))).willReturn(true); //When mongoClientDetailsService.updateClientDetails(clientDetails); }
Example #9
Source File: MongoClientDetailsServiceTest.java From spring-security-mongo with MIT License | 5 votes |
@Test(expected = NoSuchClientException.class) public void shouldThrowsExceptionWhenTryToRemoveClientDetailsWithInvalidClientId() { //Given final String clientId = string().next(); //And given(mongoClientDetailsRepository.deleteByClientId(clientId)).willReturn(false); //When mongoClientDetailsService.removeClientDetails(clientId); }
Example #10
Source File: OsiamClientDetailsService.java From osiam with MIT License | 5 votes |
@Override public ClientDetails loadClientByClientId(final String clientId) { ClientEntity client = clientRepository.findById(clientId); if (client == null) { throw new NoSuchClientException(String.format( "OsiamClientDetailsService failed to load client with id %s: no client found", clientId )); } return client; }
Example #11
Source File: CustomClientInterceptor.java From oauth-server with Apache License 2.0 | 5 votes |
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (!(antPathMatcher.match(AUTHORIZE,request.getRequestURI()) && CODE.equals(request.getParameter(RESPONSE_TYPE)))) { return true; } Long userId; String clientId = request.getParameter(CLIENT_ID); ClientE client = clientService.getClientByName(clientId); LOGGER.info("start to handle client:, clientId:{}", clientId); if (client == null) { throw new NoSuchClientException("No client found : " + clientId); } // 不需要做普罗米修斯的客户端权限校验 if (!ClientTypeEnum.CLUSTER.value().equals(client.getSourceType())) { return true; } CustomUserDetails customUserDetails = DetailsHelper.getUserDetails(); if (customUserDetails == null || customUserDetails.getUserId() == null) { LOGGER.info("=========不能拿到userId"); throw new AccessDeniedException("未登录"); } userId = customUserDetails.getUserId(); LOGGER.info("start to check user's cluster permission: userId:{}", userId); // 调用devops接口校验用户是否有访问集群的权限 Boolean result = devopsFeignClient.checkUserClusterPermission(client.getSourceId(), userId).getBody(); if (Boolean.FALSE.equals(result)) { throw new AccessDeniedException("权限不足"); } return true; }
Example #12
Source File: DefaultApplicationRepositoryImpl.java From watchdog-spring-boot-starter with MIT License | 5 votes |
@Override public void delete(String clientId) { int count = jdbcTemplate.update(deleteApplicationSql, clientId); if (count != 1) { throw new NoSuchClientException("No client found with id = " + clientId); } }
Example #13
Source File: DefaultApplicationRepositoryImpl.java From watchdog-spring-boot-starter with MIT License | 5 votes |
@Override public Application update(ClientDetails application) { int count = jdbcTemplate.update(updateApplicationSql, getFieldsForUpdate(application)); if (count != 1) { throw new NoSuchClientException("No client found with id = " + application.getClientId()); } return findByClientId(application.getClientId()).get(); }
Example #14
Source File: ClientDetailsServiceImpl.java From springcloud-oauth2 with MIT License | 5 votes |
/** * Load a client by the client id. This method must not return null. * * @param clientId The client id. * @return The client details (never null). * @throws ClientRegistrationException If the client account is locked, expired, disabled, or invalid for any other reason. */ @Override public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException { log.info("客户端查询:" + clientId); BaseClientDetails baseClientDetails = clientDetailService.selectById(clientId); if (baseClientDetails == null) { throw new NoSuchClientException("not found clientId:" + clientId); } return baseClientDetails; }
Example #15
Source File: ClientController.java From cloud-service with MIT License | 5 votes |
/** * 根据id获取client信息 * * @param clientId * @param check 是否校验存在性 * @return */ private ClientDetails getAndCheckClient(String clientId, boolean check) { ClientDetails clientDetails = null; try { clientDetails = clientDetailsService.loadClientByClientId(clientId); isSystemClient(clientDetails); } catch (NoSuchClientException e) { if (check) { throw new IllegalArgumentException(clientId + "不存在"); } } return clientDetails; }
Example #16
Source File: RedisClientDetailsService.java From open-capacity-platform with Apache License 2.0 | 4 votes |
@Override public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException { super.updateClientDetails(clientDetails); cacheAndGetClient(clientDetails.getClientId()); }
Example #17
Source File: RedisClientDetailsService.java From cloud-service with MIT License | 4 votes |
@Override public void removeClientDetails(String clientId) throws NoSuchClientException { super.removeClientDetails(clientId); removeRedisCache(clientId); }
Example #18
Source File: RedisClientDetailsService.java From cloud-service with MIT License | 4 votes |
@Override public void updateClientSecret(String clientId, String secret) throws NoSuchClientException { super.updateClientSecret(clientId, secret); cacheAndGetClient(clientId); }
Example #19
Source File: RedisClientDetailsService.java From cloud-service with MIT License | 4 votes |
@Override public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException { super.updateClientDetails(clientDetails); cacheAndGetClient(clientDetails.getClientId()); }
Example #20
Source File: RedisClientDetailsService.java From open-capacity-platform with Apache License 2.0 | 4 votes |
@Override public void removeClientDetails(String clientId) throws NoSuchClientException { super.removeClientDetails(clientId); removeRedisCache(clientId); }
Example #21
Source File: RedisClientDetailsService.java From open-capacity-platform with Apache License 2.0 | 4 votes |
@Override public void updateClientSecret(String clientId, String secret) throws NoSuchClientException { super.updateClientSecret(clientId, secret); cacheAndGetClient(clientId); }
Example #22
Source File: SysClientDetailsService.java From spring-boot-demo with MIT License | 2 votes |
/** * 更新客户端信息,不包括 clientSecret. * * @param clientDetails 客户端信息 * @throws NoSuchClientException 找不到客户端异常 */ void updateClientDetails(SysClientDetails clientDetails) throws NoSuchClientException;
Example #23
Source File: SysClientDetailsService.java From spring-boot-demo with MIT License | 2 votes |
/** * 更新客户端密钥. * * @param clientId 客户端 id * @param clientSecret 客户端密钥 * @throws NoSuchClientException 找不到客户端异常 */ void updateClientSecret(String clientId, String clientSecret) throws NoSuchClientException;
Example #24
Source File: SysClientDetailsService.java From spring-boot-demo with MIT License | 2 votes |
/** * 删除客户端信息. * * @param clientId 客户端 id * @throws NoSuchClientException 找不到客户端异常 */ void removeClientDetails(String clientId) throws NoSuchClientException;