本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}