本文整理汇总了Java中org.springframework.security.oauth2.provider.ClientRegistrationException类的典型用法代码示例。如果您正苦于以下问题:Java ClientRegistrationException类的具体用法?Java ClientRegistrationException怎么用?Java ClientRegistrationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientRegistrationException类属于org.springframework.security.oauth2.provider包,在下文中一共展示了ClientRegistrationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
public ClientDetails loadClientByClientId(String id) throws ClientRegistrationException {
if (CurrentAuthenticatedClientContext.hasAuthenticatedClient()) {
AuthenticatedClient client = CurrentAuthenticatedClientContext.getAuthenticatedClient();
if (client.getClientId().equals(id)) {
return CurrentAuthenticatedClientContext.getAuthenticatedClient();
}
CurrentAuthenticatedClientContext.clear();
}
Result<Client> result = clientService.findByClientId(id);
if (result.rejected()) {
CurrentAuthenticatedClientContext.clear();
throw new UsernameNotFoundException("Could not find client with client id " + id);
}
return CurrentAuthenticatedClientContext.setAuthenticatedClient(new AuthenticatedClient(result.getInstance()));
}
示例2: loadClientById
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
public ServiceResponse<OauthClientDetails> loadClientById(Tenant tenant, String clientId) throws ClientRegistrationException {
if (!Optional.ofNullable(clientId).isPresent()) {
throw new ClientRegistrationException(Validations.INVALID_ID.getCode());
}
OauthClientDetails details = oauthClientDetailRepository.findOne(clientId);
if (details != null) {
if (!details.getTenant().getId().equals(tenant.getId())) {
return ServiceResponseBuilder.<OauthClientDetails>error()
.withMessage(Messages.CLIENT_CREDENTIALS_INVALID.getCode())
.build();
}
return ServiceResponseBuilder.<OauthClientDetails>ok()
.withResult(details)
.build();
} else {
return ServiceResponseBuilder.<OauthClientDetails>error()
.withMessage(Messages.CLIENT_CREDENTIALS_INVALID.getCode())
.build();
}
}
示例3: loadClientByIdAsRoot
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
public ServiceResponse<OauthClientDetails> loadClientByIdAsRoot(String clientId) throws ClientRegistrationException {
if (!Optional.ofNullable(clientId).isPresent()) {
throw new ClientRegistrationException(Validations.INVALID_ID.getCode());
}
OauthClientDetails details = oauthClientDetailRepository.findOne(clientId);
if (details != null) {
return ServiceResponseBuilder.<OauthClientDetails>ok()
.withResult(details)
.build();
} else {
User user = userRepository.findByEmail(clientId);
if (user != null) {
return ServiceResponseBuilder.<OauthClientDetails>ok()
.withResult(OauthClientDetails.builder().build().setUserProperties(user))
.build();
}
return ServiceResponseBuilder.<OauthClientDetails>error()
.withMessage(Messages.CLIENT_CREDENTIALS_INVALID.getCode())
.build();
}
}
示例4: clientDetailsService
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Bean
ClientDetailsService clientDetailsService() {
return clientId -> clientRepository.findByClientId(clientId)
.map(client -> {
BaseClientDetails details = new BaseClientDetails(
client.getClientId(),
null,
client.getScopes(),
client.getAuthorizedGrantTypes(),
client.getAuthorities(),
client.getRegisteredRedirectUri()
);
details.setClientSecret(client.getSecret());
details.setAutoApproveScopes(Arrays.asList(client.getAutoApproveScopes().split(",")));
details.setAccessTokenValiditySeconds(1800); // 30mn Token < 1h RefreshToken!
details.setRefreshTokenValiditySeconds(3600);
return details;
})
.orElseThrow(() -> new ClientRegistrationException(String.format("no client %s registered", clientId)));
}
示例5: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
Client client = this.clientRepository.findByClientId(clientId);
if (client == null) {
throw new NoSuchClientException(String.format("No client with requested id: %s", clientId));
}
BaseClientDetails baseClientDetails = new BaseClientDetails();
baseClientDetails.setClientId(client.getClientId());
baseClientDetails.setClientSecret(client.getClientSecret());
baseClientDetails.setResourceIds(StringUtils.commaDelimitedListToSet(client.getResourceIds()));
baseClientDetails.setScope(StringUtils.commaDelimitedListToSet(client.getScopes()));
baseClientDetails.setAuthorizedGrantTypes(StringUtils.commaDelimitedListToSet(client.getGrantTypes()));
baseClientDetails.setRegisteredRedirectUri(StringUtils.commaDelimitedListToSet(client.getRedirectUris()));
baseClientDetails.setAutoApproveScopes(StringUtils.commaDelimitedListToSet(client.getAutoApproveScopes()));
return baseClientDetails;
}
示例6: getPluginSecret
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
/**
* GET /plugins/:id -> get the "id" plugin.
*/
@RequestMapping(value = "/plugins/{id}/secret",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<PluginSecret> getPluginSecret(@PathVariable Long id) {
log.debug("REST request to get Plugin : {}", id);
Plugin plugin = pluginRepository.findOne(id);
if (plugin == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} else {
try {
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(plugin.getIdentifier());
return new ResponseEntity<>(new PluginSecret(clientDetails.getClientSecret()),HttpStatus.OK);
} catch (ClientRegistrationException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
}
示例7: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
try {
final MongoClientDetails mongoClientDetails = mongoClientDetailsRepository.findByClientId(clientId);
BaseClientDetails client = new BaseClientDetails(mongoClientDetails.getClientId(),
Joiner.on(",").join(mongoClientDetails.getResourceIds()),
Joiner.on(",").join(mongoClientDetails.getScope()),
Joiner.on(",").join(mongoClientDetails.getAuthorizedGrantTypes()),
Joiner.on(",").join(mongoClientDetails.getAuthorities()),
Joiner.on(",").join(mongoClientDetails.getRegisteredRedirectUri()));
client.setAccessTokenValiditySeconds(mongoClientDetails.getAccessTokenValiditySeconds());
client.setRefreshTokenValiditySeconds(mongoClientDetails.getRefreshTokenValiditySeconds());
client.setClientSecret(mongoClientDetails.getClientSecret());
return client;
} catch (IllegalArgumentException e) {
throw new ClientRegistrationException("No Client Details for client id", e);
}
}
示例8: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId)
throws ClientRegistrationException {
if(clientId.equals("353b302c44574f565045687e534e7d6a")){
List<String> authorizedGrantTypes = new ArrayList<String>();
authorizedGrantTypes.add("password");
authorizedGrantTypes.add("refresh_token");
BaseClientDetails clientDetails = new BaseClientDetails();
clientDetails.setClientId("353b302c44574f565045687e534e7d6a");
clientDetails.setClientSecret("286924697e615a672a646a493545646c");
clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes);
List<String> list = new ArrayList<String>();
list.add("read");
list.add("write");
clientDetails.setScope(list);
return clientDetails;
}else{
throw new NoSuchClientException("No client with requested id:");
}
}
示例9: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@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);
}
}
示例10: isAuthenticationError
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
public static boolean isAuthenticationError(Throwable t) {
if (t instanceof AccessDeniedException
|| t instanceof AuthenticationException
|| t instanceof ClientAuthenticationException
|| t instanceof ClientRegistrationException
|| t instanceof AuthenticationError
|| (t instanceof AsyncHttpException)
&& ((AsyncHttpException) t).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
return true;
}
Throwable cause = t.getCause();
if (cause != t && cause != null && isAuthenticationError(cause)) {
return true;
}
if (t instanceof InvocationTargetException) {
Throwable target = ((InvocationTargetException) t).getTargetException();
if (isAuthenticationError(target)) {
return true;
}
}
return false;
}
示例11: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
GetItemResult result = client.getItem(schema.getTableName(), Collections.singletonMap(schema.getColumnClientId(), new AttributeValue(clientId)));
Map<String, AttributeValue> item = result.getItem();
if (item == null) {
return null;
}
String resourceIds = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnResourceIds()));
String scopes = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnScopes()));
String grantTypes = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorizedGrantTypes()));
String authorities = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorities()));
String redirectUris = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnRegisteredRedirectUris()));
String clientSecret = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnClientSecret()));
ClientDetails clientDetails = createClientDetails(clientId, resourceIds, scopes, grantTypes, authorities, redirectUris, clientSecret, item);
return clientDetails;
}
开发者ID:Vivastream,项目名称:spring-security-oauth2-dynamodb,代码行数:21,代码来源:DynamoDBClientDetailsService.java
示例12: addClientDetails
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Transactional
@Override
public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException {
if (clientDetailsRepository.findOneByClientId(clientDetails.getClientId()).isPresent()) {
throw new ClientAlreadyExistsException("Client ID already exists");
}
ClientDetailsEntity clientDetailsEntity = ClientDetailsEntity.builder()//
.clientId(clientDetails.getClientId())//
.clientSecret(clientDetails.getClientSecret())//
.accessTokenValiditySeconds(clientDetails.getAccessTokenValiditySeconds())//
.refreshTokenValiditySeconds(clientDetails.getRefreshTokenValiditySeconds()).build();
clientDetailsEntity.setAuthorizedGrantTypeXrefs(clientDetails.getAuthorizedGrantTypes().stream().map(grantType -> grantTypeRepository.findOneByValue(grantType).map(grantTypeEntity -> ClientDetailsToAuthorizedGrantTypeXrefEntity.builder().clientDetails(clientDetailsEntity).grantType(grantTypeEntity).build()).<ClientRegistrationException> orElseThrow(() -> new ClientRegistrationException("Unsupported grant type: "
+ grantType))).collect(Collectors.toSet()));
clientDetailsEntity.setScopeXrefs(clientDetails.getScope().stream().map(scope -> scopeRepository.findOneByValue(scope).map(scopeEntity -> ClientDetailsToScopesXrefEntity.builder().clientDetails(clientDetailsEntity).scope(scopeEntity).autoApprove(clientDetails.isAutoApprove(scope)).build()).<ClientRegistrationException> orElseThrow(() -> new ClientRegistrationException("Unknown scope: "
+ scope))).collect(Collectors.toSet()));
clientDetailsEntity.setResourceIdXrefs(clientDetails.getResourceIds().stream().map(resourceId -> resourceIdRepository.findOneByValue(resourceId).map(resourceIdEntity -> ClientDetailsToResourceIdXrefEntity.builder().clientDetails(clientDetailsEntity).resourceId(resourceIdEntity).build()).<ClientRegistrationException> orElseThrow(() -> new ClientRegistrationException("Unknown resource id: "
+ resourceId))).collect(Collectors.toSet()));
clientDetailsEntity.setRedirectUris(clientDetails.getRegisteredRedirectUri().stream().map(redirectUri -> RedirectUriEntity.builder().clientDetails(clientDetailsEntity).value(redirectUri).build()).collect(Collectors.toSet()));
clientDetailsRepository.save(clientDetailsEntity);
}
示例13: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
ClientDetails details = clientDetails.get(clientId);
if (details == null) {
throw new NoSuchClientException("No client with requested id: " + clientId);
}
return details;
}
示例14: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
CustomClient customClient = customClientRepository.findByClientName(clientId);
if (customClient == null) {
throw new ClientRegistrationException("Could not find client with clientId: " + clientId);
}
return new CustomClientDetails(customClient);
}
示例15: loadClientByClientId_whenClientRepositoryReturnsNoClient_throwsException
import org.springframework.security.oauth2.provider.ClientRegistrationException; //导入依赖的package包/类
@Test
public void loadClientByClientId_whenClientRepositoryReturnsNoClient_throwsException() throws Exception {
when(customClientRepository.findByClientName("someClient")).thenReturn(null);
expectedException.expect(ClientRegistrationException.class);
expectedException.expectMessage("Could not find client with clientId: someClient");
subject.loadClientByClientId("someClient");
}