当前位置: 首页>>代码示例>>Java>>正文


Java ClientCredentialsResourceDetails.setClientSecret方法代码示例

本文整理汇总了Java中org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails.setClientSecret方法的典型用法代码示例。如果您正苦于以下问题:Java ClientCredentialsResourceDetails.setClientSecret方法的具体用法?Java ClientCredentialsResourceDetails.setClientSecret怎么用?Java ClientCredentialsResourceDetails.setClientSecret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails的用法示例。


在下文中一共展示了ClientCredentialsResourceDetails.setClientSecret方法的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());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:19,代码来源:LocalServerSecurityWithOAuth2Tests.java

示例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()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:22,代码来源:LocalServerSecurityWithOAuth2Tests.java

示例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;
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:18,代码来源:ClientConfiguration.java

示例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);
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:25,代码来源:Oauth2ClientRestTemplate.java

示例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 方法

}
 
开发者ID:h819,项目名称:spring-boot,代码行数:25,代码来源:Oauth2ClientRestTemplateTest.java

示例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);
}
 
开发者ID:cloudfoundry-community,项目名称:oauth-register-broker,代码行数:21,代码来源:UaaDriver.java

示例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());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dataflow,代码行数:19,代码来源:LocalServerSecurityWithOAuth2Tests.java

示例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)));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dataflow,代码行数:23,代码来源:LocalServerSecurityWithOAuth2Tests.java

示例9: 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;
}
 
开发者ID:eclipse,项目名称:keti,代码行数:14,代码来源:UAAACSClientsUtil.java

示例10: 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;
}
 
开发者ID:sdcuike,项目名称:spring-boot-oauth2-demo,代码行数:11,代码来源:Oauth2ClientConfig.java

示例11: 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,代码行数:15,代码来源:UserApplication.java

示例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;
}
 
开发者ID:kbastani,项目名称:cloud-native-microservice-strangler-example,代码行数:16,代码来源:LegacyEdgeApplication.java

示例13: 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

示例14: 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;
}
 
开发者ID:fdlessard,项目名称:YaasRestClientProject,代码行数:14,代码来源:SpringOAuth2ConfigurationProfile.java

示例15: ConfigClientCredentialsResourceDetails

import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入方法依赖的package包/类
@Bean
public ClientCredentialsResourceDetails ConfigClientCredentialsResourceDetails() {
	
	ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
	resource.setAccessTokenUri("http://localhost:8080/uaa/oauth/token");
	resource.setClientId("fortressdemo2");
	resource.setClientSecret("hard2guess!");
	resource.setId("fortressdemo2");
	resource.setGrantType("client_credentials");
	resource.setScope(Arrays.asList("fortressdemo2.read", "fortressdemo2.write"));

	return resource;
	
}
 
开发者ID:johnpfield,项目名称:oauth2-cli,代码行数:15,代码来源:ConfigRestResources.java


注:本文中的org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails.setClientSecret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。