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


Java ResourceOwnerPasswordResourceDetails类代码示例

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


ResourceOwnerPasswordResourceDetails类属于org.springframework.security.oauth2.client.token.grant.password包,在下文中一共展示了ResourceOwnerPasswordResourceDetails类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
@Before
public void setup() {
	resource = new ResourceOwnerPasswordResourceDetails();

	resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
	resource.setClientId("my-trusted-client");
	resource.setId("sparklr");
	resource.setScope(Arrays.asList("trust"));
	resource.setUsername("marissa");
	resource.setPassword("koala");

	OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
	existingToken = template.getAccessToken();
	((DefaultOAuth2AccessToken) existingToken).setExpiration(new Date(0L));

	SecurityContextImpl securityContext = new SecurityContextImpl();
	securityContext.setAuthentication(new TestingAuthenticationToken("marissa", "koala", "ROLE_USER"));
	SecurityContextHolder.setContext(securityContext);

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:21,代码来源:RefreshTokenGrantTests.java

示例2: passwordResourceDetails

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
@Bean
public OAuth2ProtectedResourceDetails passwordResourceDetails() {
    //@formatter:off
    ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails();

    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setScope(Arrays.asList("read_profile"));

    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);
    //@formatter:on

    return resourceDetails;
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:18,代码来源:ClientConfiguration.java

示例3: oAuth2RestOperations

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
@Bean
    public OAuth2RestOperations oAuth2RestOperations() {

        ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
        resource.setAccessTokenUri(tokenUri);

        resource.setId(resourceId);
        resource.setClientId(resourceClientId);
        resource.setClientSecret(resourceClientSecret);

        resource.setGrantType("password");
        resource.setScope(Arrays.asList("openid"));

        resource.setUsername(resourceUserId);
        resource.setPassword(resourceUserPassword);

        OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
//        template.setRequestFactory(requestFactory);
        return template;
    }
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:21,代码来源:JavaConfig.java

示例4: testConnectDirectlyToResourceServer

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
public void testConnectDirectlyToResourceServer() throws Exception {
    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setAccessTokenUri(tokenUrl);
    resource.setId("microservice-test");
    resource.setClientId("oauthClient1");
    resource.setClientSecret("oauthClient1Password");

    resource.setGrantType("password");

    resource.setScope(Arrays.asList("openid"));

    resource.setUsername("[email protected]");
    resource.setPassword("user1");
    OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
    logger.info(" CALLING: " + baseUrl+"/api");

    String result = template.getForObject(baseUrl+"/api", String.class);

    System.err.println(result);
    assertEquals("Hello, Trusted User marissa", result);
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:22,代码来源:OAuth2ClientTest.java

示例5: oAuth2RestOperations

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
@Bean
    public OAuth2RestOperations oAuth2RestOperations() {

        ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
        resource.setAccessTokenUri(tokenUrl);
        resource.setId(resourceId);
        resource.setClientId(resourceClientId);
        resource.setClientSecret(resourceClientSecret);

        resource.setGrantType("password");

        resource.setScope(Arrays.asList("openid"));

        resource.setUsername("[email protected]");
        resource.setPassword("user1");

        OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
//        template.setRequestFactory(requestFactory);
        return template;
    }
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:21,代码来源:JavaConfig.java

示例6: resourceOwnerPasswordRestTemplate

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
/**
 * 演示 grant_type=password 时,获取资源的方法
 * 用的场景还不知道,@Deprecated
 *
 * @param client_id
 * @param client_secret    取决于 AuthorizationServer 设置,如果 client 设置了secret,则此项参数为必需,否则可以没有
 * @param access_token_uri
 * @param username
 * @param password
 * @param scope
 * @return
 */
@Deprecated
public OAuth2RestOperations resourceOwnerPasswordRestTemplate(String client_id, String client_secret, String access_token_uri, String username, String password, String... scope) {

    // 防止 url 写错
    if (!access_token_uri.contains("token"))
        throw new RuntimeException("uri is wrong :  access_token_uri = " + access_token_uri);

    // 防止 client_secret 写错
    if (username == null || password == null || username.isEmpty() || password.isEmpty())
        throw new RuntimeException("username or password  is wrong :  username or password is a required parameter");

    ResourceOwnerPasswordResourceDetails details = new ResourceOwnerPasswordResourceDetails();
    details.setId("3");
    details.setClientId(client_id);
    if (client_secret != null && !client_secret.isEmpty())
        details.setClientSecret(client_secret);
    details.setAccessTokenUri(access_token_uri);
    details.setUsername(username);
    details.setPassword(password);
    details.setScope(Arrays.asList(scope));
    return new OAuth2RestTemplate(details, oAuth2ClientContext);


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

示例7: testOAuthService

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
@Test
public void testOAuthService() {	
       ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
       resource.setUsername("guest");
       resource.setPassword("guest123");
       resource.setAccessTokenUri("http://localhost:8080/oauth/token");
       resource.setClientId("trustedclient");
       resource.setClientSecret("trustedclient123");
       resource.setGrantType("password");
 
       DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
       OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource, clientContext);

       Greet greet = restTemplate.getForObject("http://localhost:8080", Greet.class);

       Assert.assertEquals("Hello World!", greet.getMessage());
}
 
开发者ID:PacktPublishing,项目名称:Microservices-Building-Scalable-Software,代码行数:18,代码来源:ApplicationTests.java

示例8: fixPaths

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
@BeforeOAuth2Context
public void fixPaths() {
	String prefix = server.getServletPrefix();
	http.setPort(port);
	http.setPrefix(prefix);
	BaseOAuth2ProtectedResourceDetails resource = (BaseOAuth2ProtectedResourceDetails) context.getResource();
	List<HttpMessageConverter<?>> converters = new ArrayList<>(context.getRestTemplate().getMessageConverters());
	converters.addAll(getAdditionalConverters());
	context.getRestTemplate().setMessageConverters(converters);
	context.getRestTemplate().setInterceptors(getInterceptors());
	resource.setAccessTokenUri(http.getUrl(tokenPath()));
	if (resource instanceof AbstractRedirectResourceDetails) {
		((AbstractRedirectResourceDetails) resource).setUserAuthorizationUri(http.getUrl(authorizePath()));
	}
	if (resource instanceof ImplicitResourceDetails) {
		resource.setAccessTokenUri(http.getUrl(authorizePath()));
	}
	if (resource instanceof ResourceOwnerPasswordResourceDetails && !(resource instanceof DoNotOverride)) {
		((ResourceOwnerPasswordResourceDetails) resource).setUsername(getUsername());
		((ResourceOwnerPasswordResourceDetails) resource).setPassword(getPassword());
	}
}
 
开发者ID:jfcorugedo,项目名称:spring-oauth2-samples,代码行数:23,代码来源:AbstractIntegrationTests.java

示例9: getBeanClass

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的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;
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:18,代码来源:ResourceBeanDefinitionParser.java

示例10: testConnectDirectlyToResourceServer

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
@Test
public void testConnectDirectlyToResourceServer() throws Exception {

	ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();

	resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
	resource.setClientId("my-trusted-client");
	resource.setId("sparklr");
	resource.setScope(Arrays.asList("trust"));
	resource.setUsername("marissa");
	resource.setPassword("koala");

	OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
	String result = template.getForObject(serverRunning.getUrl("/sparklr2/photos/user/message"), String.class);
	// System.err.println(result);
	assertEquals("Hello, Trusted User marissa", result);

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:19,代码来源:ResourceOwnerPasswordGrantTests.java

示例11: getResourceDetails

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
private OAuth2ProtectedResourceDetails getResourceDetails(String username, String password, String clientId, String clientSecret) {
    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setUsername(username);
    resource.setPassword(password);

    resource.setClientId(clientId);
    resource.setClientSecret(clientSecret);
    resource.setId(clientId);
    resource.setClientAuthenticationScheme(AuthenticationScheme.header);
    resource.setAccessTokenUri(authorizationUrl + "/oauth/token");

    return resource;
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:14,代码来源:OauthClient.java

示例12: resource

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
private OAuth2ProtectedResourceDetails resource() {
    ResourceOwnerPasswordResourceDetails details = new ResourceOwnerPasswordResourceDetails();
    details.setAccessTokenUri(accessTokenUri);
    details.setClientId(clientId);
    details.setScope(Arrays.asList(scope));
    details.setUsername("cliente");
    details.setPassword("cliente");
    return details;
}
 
开发者ID:rhawan,项目名称:microservices-tcc-alfa,代码行数:10,代码来源:FeignOAuthInterceptor.java

示例13: getOAuthTemplate

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
private OAuth2RestTemplate getOAuthTemplate() {
	ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
	resource.setUsername("user-name");
	resource.setPassword("user-password");
	resource.setAccessTokenUri(createURL("/oauth/token"));
	resource.setClientId("clientId");
	resource.setClientSecret("clientSecret");
	resource.setGrantType("password");
	OAuth2RestTemplate oauthTemplate = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext());
	return oauthTemplate;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Spring-5.0,代码行数:12,代码来源:BasicControllerIT.java

示例14: getOAuthTemplate

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
private OAuth2RestTemplate getOAuthTemplate() {
	ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
	resource.setUsername("user-name");
	resource.setPassword("user-password");
	resource.setAccessTokenUri(createUrl("/oauth/token"));
	resource.setClientId("clientId");
	resource.setClientSecret("clientSecret");
	resource.setGrantType("password");
	OAuth2RestTemplate oauthTemplate = new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext());
	return oauthTemplate;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Spring-5.0,代码行数:12,代码来源:TodoControllerIT.java

示例15: template

import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails; //导入依赖的package包/类
private OAuth2RestTemplate template(String user){
    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setAccessTokenUri(tokenUrl);
    resource.setId(resourceId);
    resource.setClientId(resourceClientId);
    resource.setClientSecret(resourceClientSecret);

    resource.setGrantType("password");

    resource.setScope(Arrays.asList("openid"));

    this.setResourceUser(resource, user);

    return new OAuth2RestTemplate(resource);
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:16,代码来源:OAuth2ClientTest.java


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