本文整理汇总了Java中org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails类的典型用法代码示例。如果您正苦于以下问题:Java ClientCredentialsResourceDetails类的具体用法?Java ClientCredentialsResourceDetails怎么用?Java ClientCredentialsResourceDetails使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientCredentialsResourceDetails类属于org.springframework.security.oauth2.client.token.grant.client包,在下文中一共展示了ClientCredentialsResourceDetails类的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: testCanUseClientCredentials
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入依赖的package包/类
@Test
public void testCanUseClientCredentials() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(TestSecurityConfiguration.class,
MinimalSecureWebApplication.class);
TestPropertyValues
.of("security.oauth2.client.clientId=client",
"security.oauth2.client.grantType=client_credentials")
.applyTo(this.context);
ConfigurationPropertySources.attach(this.context.getEnvironment());
this.context.refresh();
OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class);
assertThat(bean.getAccessTokenRequest()).isNotNull();
assertThat(countBeans(ClientCredentialsResourceDetails.class)).isEqualTo(1);
assertThat(countBeans(OAuth2ClientContext.class)).isEqualTo(1);
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:17,代码来源:OAuth2AutoConfigurationTests.java
示例4: testCanUseClientCredentialsWithEnableOAuth2Client
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入依赖的package包/类
@Test
public void testCanUseClientCredentialsWithEnableOAuth2Client() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(ClientConfiguration.class,
MinimalSecureWebApplication.class);
TestPropertyValues
.of("security.oauth2.client.clientId=client",
"security.oauth2.client.grantType=client_credentials")
.applyTo(this.context);
ConfigurationPropertySources.attach(this.context.getEnvironment());
this.context.refresh();
// The primary context is fine (not session scoped):
OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class);
assertThat(bean.getAccessTokenRequest()).isNotNull();
assertThat(countBeans(ClientCredentialsResourceDetails.class)).isEqualTo(1);
// Kind of a bug (should ideally be 1), but the cause is in Spring OAuth2 (there
// is no need for the extra session-scoped bean). What this test proves is that
// even if the user screws up and does @EnableOAuth2Client for client credentials,
// it will still just about work (because of the @Primary annotation on the
// Boot-created instance of OAuth2ClientContext).
assertThat(countBeans(OAuth2ClientContext.class)).isEqualTo(2);
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:23,代码来源:OAuth2AutoConfigurationTests.java
示例5: 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;
}
示例6: 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);
}
示例7: 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 方法
}
示例8: 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);
}
示例9: 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());
}
示例10: 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)));
}
示例11: getBeanClass
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入依赖的package包/类
@Override
protected Class<?> getBeanClass(Element element) {
String type = element.getAttribute("type");
if ("authorization_code".equals(type)) {
return AuthorizationCodeResourceDetails.class;
}
if ("implicit".equals(type)) {
return ImplicitResourceDetails.class;
}
if ("client_credentials".equals(type)) {
return ClientCredentialsResourceDetails.class;
}
if ("password".equals(type)) {
return ResourceOwnerPasswordResourceDetails.class;
}
return BaseOAuth2ProtectedResourceDetails.class;
}
示例12: 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);
}
示例13: oauth2RemoteResource
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入依赖的package包/类
@Bean
@ConfigurationProperties(prefix = "security.oauth2.client")
@Primary
public ClientCredentialsResourceDetails oauth2RemoteResource() {
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
return details;
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:8,代码来源:OAuth2RestOperationsConfiguration.java
示例14: testClientIsNotAuthCode
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入依赖的package包/类
@Test
public void testClientIsNotAuthCode() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(MinimalSecureNonWebApplication.class);
TestPropertyValues.of("security.oauth2.client.clientId=client").applyTo(context);
context.refresh();
assertThat(countBeans(context, ClientCredentialsResourceDetails.class))
.isEqualTo(1);
context.close();
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:11,代码来源:OAuth2AutoConfigurationTests.java
示例15: clientCredentialsWithClientId
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; //导入依赖的package包/类
@Test
public void clientCredentialsWithClientId() throws Exception {
TestPropertyValues.of("security.oauth2.client.client-id=acme")
.applyTo(this.environment);
initializeContext(OAuth2RestOperationsConfiguration.class, true);
assertThat(this.context.getBean(OAuth2RestOperationsConfiguration.class))
.isNotNull();
assertThat(this.context.getBean(ClientCredentialsResourceDetails.class))
.isNotNull();
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:11,代码来源:OAuth2RestOperationsConfigurationTests.java