本文整理汇总了Java中org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails.setClientId方法的典型用法代码示例。如果您正苦于以下问题:Java ClientCredentialsResourceDetails.setClientId方法的具体用法?Java ClientCredentialsResourceDetails.setClientId怎么用?Java ClientCredentialsResourceDetails.setClientId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails
的用法示例。
在下文中一共展示了ClientCredentialsResourceDetails.setClientId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAccessRootUrlWithOAuth2AccessToken
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Test
public void testAccessRootUrlWithOAuth2AccessToken() throws Exception {
final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId("myclient");
resourceDetails.setClientSecret("mysecret");
resourceDetails.setGrantType("client_credentials");
resourceDetails
.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");
final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();
final String accessTokenAsString = accessToken.getValue();
localSkipperResource.getMockMvc().perform(get("/api").header("Authorization", "bearer " + accessTokenAsString))
.andDo(print()).andExpect(status().isOk());
}
示例2: testAccessAboutUrlWithOAuth2AccessToken
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Test
public void testAccessAboutUrlWithOAuth2AccessToken() throws Exception {
final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId("myclient");
resourceDetails.setClientSecret("mysecret");
resourceDetails.setGrantType("client_credentials");
resourceDetails
.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");
final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();
final String accessTokenAsString = accessToken.getValue();
localSkipperResource.getMockMvc()
.perform(get("/api/about").header("Authorization", "bearer " + accessTokenAsString)).andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.versionInfo.server.name", is("Spring Cloud Skipper Server")))
.andExpect(jsonPath("$.versionInfo.server.version", notNullValue()));
}
示例3: passwordResourceDetails
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Bean
public OAuth2ProtectedResourceDetails passwordResourceDetails() {
//@formatter:off
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setId("oauth2server");
details.setTokenName("oauth_token");
details.setClientId("clientadmin");
details.setClientSecret("123");
details.setAccessTokenUri("http://localhost:8080/oauth/token");
details.setScope(Arrays.asList("admin"));
details.setClientAuthenticationScheme(AuthenticationScheme.header);
//@formatter:on
return details;
}
示例4: clientCredentialsRestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
/**
* 演示 grant_type=client_credentials 时,获取资源的方法
*
* @param client_id
* @param client_secret 取决于 AuthorizationServer 设置,如果 client 设置了secret,则此项参数为必需,否则可以没有
* @param access_token_uri
* @param scope
* @return
*/
public OAuth2RestOperations clientCredentialsRestTemplate(String client_id, String client_secret, String access_token_uri, String... scope) {
// 防止 url 写错
if (!access_token_uri.contains("token"))
throw new RuntimeException("uri is wrong : access_token_uri = " + access_token_uri);
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setId("4");
details.setClientId(client_id);
if (client_secret != null && !client_secret.isEmpty())
details.setClientSecret(client_secret);
details.setAccessTokenUri(access_token_uri);
details.setScope(Arrays.asList(scope));
return new OAuth2RestTemplate(details, oAuth2ClientContext);
}
示例5: testClientCredentialsRestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Test
public void testClientCredentialsRestTemplate() throws Exception {
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setId("4");
details.setClientId(client_id);
details.setClientSecret(client_secret);
details.setAccessTokenUri(access_token_uri);
// details.setScope(Arrays.asList("read write"));
OAuth2RestTemplate operations = new OAuth2RestTemplate(details,new DefaultOAuth2ClientContext());
// OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
operations.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());
// OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails(),oAuth2ClientContext());
DefaultOAuth2AccessToken token=(DefaultOAuth2AccessToken)operations.getAccessToken();
token.setTokenType("Bearer");
System.out.println("client_id : " + client_id);
System.out.println("source_url : " + source_url);
// OAuth2RestOperations operations = restTemplate.clientCredentialsRestTemplate(client_id, client_secret, access_token_uri, scopes); // getForObject 发送 get 方法
System.out.println(JSON.toJSONString(operations.getForObject(source_url, JsonNode.class))); // getForObject 发送 get 方法
}
示例6: connect
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
private UaaConnection connect(String providerUser, String providerPassword) throws DriverConnectionException {
if (uaaUrl == null) {
throw new DriverConnectionException(this, "Uaa is not registered in the broker, this driver can't be used");
}
ClientCredentialsResourceDetails credentials = new ClientCredentialsResourceDetails();
credentials.setAccessTokenUri(uaaUrl + "/oauth/token");
credentials.setClientAuthenticationScheme(AuthenticationScheme.header);
credentials.setClientId(providerUser);
credentials.setClientSecret(providerPassword);
URL uaaHost = null;
try {
uaaHost = new URL(uaaUrl);
} catch (MalformedURLException e) {
throw new DriverConnectionException(this, e.getMessage(), e);
}
return UaaConnectionFactory.getConnection(uaaHost, credentials);
}
示例7: testAccessRootUrlWithOAuth2AccessToken
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Test
public void testAccessRootUrlWithOAuth2AccessToken() throws Exception {
final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId("myclient");
resourceDetails.setClientSecret("mysecret");
resourceDetails.setGrantType("client_credentials");
resourceDetails
.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");
final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();
final String accessTokenAsString = accessToken.getValue();
localDataflowResource.getMockMvc().perform(get("/").header("Authorization", "bearer " + accessTokenAsString))
.andDo(print()).andExpect(status().isOk());
}
示例8: testAccessSecurityInfoUrlWithOAuth2AccessToken
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Test
public void testAccessSecurityInfoUrlWithOAuth2AccessToken() throws Exception {
final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId("myclient");
resourceDetails.setClientSecret("mysecret");
resourceDetails.setGrantType("client_credentials");
resourceDetails
.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");
final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();
final String accessTokenAsString = accessToken.getValue();
localDataflowResource.getMockMvc()
.perform(get("/security/info").header("Authorization", "bearer " + accessTokenAsString)).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath("$.authorizationEnabled", is(Boolean.TRUE)))
.andExpect(jsonPath("$.authenticated", is(Boolean.TRUE)))
.andExpect(jsonPath("$.authenticationEnabled", is(Boolean.TRUE)))
.andExpect(jsonPath("$.roles", hasSize(3)));
}
示例9: testConnectDirectlyToResourceServer
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Test
public void testConnectDirectlyToResourceServer() throws Exception {
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
resource.setClientId("my-client-with-registered-redirect");
resource.setId("sparklr");
resource.setScope(Arrays.asList("trust"));
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
OAuth2RestTemplate template = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(accessToken));
String result = template.getForObject(serverRunning.getUrl("/sparklr2/photos/trusted/message"), String.class);
assertEquals("Hello, Trusted Client", result);
}
示例10: getOAuth2RestTemplateForClient
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
private OAuth2RestTemplate getOAuth2RestTemplateForClient(final String tokenUrl, final String clientId,
final String clientSecret) {
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(tokenUrl);
resource.setClientId(clientId);
resource.setClientSecret(clientSecret);
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource);
CloseableHttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
restTemplate.setRequestFactory(requestFactory);
return restTemplate;
}
示例11: resourceDetails
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Bean("practiceClientCredentialsResourceDetails")
public ClientCredentialsResourceDetails resourceDetails() {
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setId(oauth2ClientProperties.getId());
details.setAccessTokenUri(oauth2ClientProperties.getAccessTokenUrl());
details.setClientId(oauth2ClientProperties.getClientId());
details.setClientSecret(oauth2ClientProperties.getClientSecret());
details.setAuthenticationScheme(AuthenticationScheme.valueOf(oauth2ClientProperties.getClientAuthenticationScheme()));
return details;
}
示例12: loadBalancedOauth2RestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@LoadBalanced
@Bean
public OAuth2RestTemplate loadBalancedOauth2RestTemplate(ClientCredentialsResourceDetails resource) {
ClientCredentialsResourceDetails clientCredentialsResourceDetails = new ClientCredentialsResourceDetails();
clientCredentialsResourceDetails.setAccessTokenUri(resource.getAccessTokenUri());
clientCredentialsResourceDetails.setClientId(resource.getClientId());
clientCredentialsResourceDetails.setClientSecret(resource.getClientSecret());
clientCredentialsResourceDetails.setClientAuthenticationScheme(resource.getClientAuthenticationScheme());
clientCredentialsResourceDetails.setScope(resource.getScope());
clientCredentialsResourceDetails.setGrantType(resource.getGrantType());
OAuth2RestTemplate auth2RestTemplate = new OAuth2RestTemplate(clientCredentialsResourceDetails);
auth2RestTemplate.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());
return auth2RestTemplate;
}
示例13: loadBalancedOauth2RestTemplate
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@LoadBalanced
@Bean
public OAuth2RestTemplate loadBalancedOauth2RestTemplate(
ClientCredentialsResourceDetails resource) {
ClientCredentialsResourceDetails clientCredentialsResourceDetails = new ClientCredentialsResourceDetails();
clientCredentialsResourceDetails.setAccessTokenUri(resource.getAccessTokenUri());
clientCredentialsResourceDetails.setClientId(resource.getClientId());
clientCredentialsResourceDetails.setClientSecret(resource.getClientSecret());
clientCredentialsResourceDetails.setClientAuthenticationScheme(resource.getClientAuthenticationScheme());
clientCredentialsResourceDetails.setScope(resource.getScope());
clientCredentialsResourceDetails.setGrantType(resource.getGrantType());
OAuth2RestTemplate auth2RestTemplate = new OAuth2RestTemplate(clientCredentialsResourceDetails);
auth2RestTemplate.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());
return auth2RestTemplate;
}
开发者ID:kbastani,项目名称:cloud-native-microservice-strangler-example,代码行数:16,代码来源:LegacyEdgeApplication.java
示例14: oAuth2ProtectedResourceDetails
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Bean
@Qualifier("timeseries-client")
public OAuth2ProtectedResourceDetails oAuth2ProtectedResourceDetails(DigitalTwinTimeSeriesClientProperties digitalTwinTimeSeriesClientProperties) {
final ClientCredentialsResourceDetails clientCredentialsResourceDetails = new ClientCredentialsResourceDetails();
clientCredentialsResourceDetails.setAccessTokenUri(digitalTwinTimeSeriesClientProperties.getTokenEndpoint().toString());
clientCredentialsResourceDetails.setClientId(digitalTwinTimeSeriesClientProperties.getClientId());
clientCredentialsResourceDetails.setClientSecret(digitalTwinTimeSeriesClientProperties.getClientSecret());
return clientCredentialsResourceDetails;
}
开发者ID:DigitalTwin,项目名称:digital-twin-time-series-client,代码行数:10,代码来源:DigitalTwinTimeSeriesClientConfiguration.java
示例15: getResourceDetails
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Bean
protected OAuth2ProtectedResourceDetails getResourceDetails() {
LOGGER.info("getResourceDetails()");
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(customerAccountGatewayProperties.getOauth2().getTokenUrl());
resource.setClientId(customerAccountGatewayProperties.getOauth2().getClient().getId());
resource.setClientSecret(customerAccountGatewayProperties.getOauth2().getClient().getSecret());
resource.setScope(customerAccountGatewayProperties.getScopes());
return resource;
}