use of org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails in project spring-security-oauth by spring-projects.
the class RefreshTokenGrantTests method setup.
@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);
}
use of org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails in project spring-security-oauth by spring-projects.
the class ResourceOwnerPasswordGrantTests method testConnectDirectlyToResourceServer.
@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);
}
use of org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails in project spring-security-oauth by spring-projects.
the class AbstractResourceOwnerPasswordProviderTests method testTokenEndpointWrongPassword.
@Test
@OAuth2ContextConfiguration(value = ResourceOwner.class, initialize = false)
public void testTokenEndpointWrongPassword() throws Exception {
ResourceOwnerPasswordResourceDetails resource = (ResourceOwnerPasswordResourceDetails) context.getResource();
resource.setPassword("bogus");
try {
new OAuth2RestTemplate(resource).getAccessToken();
} catch (OAuth2AccessDeniedException e) {
String summary = ((OAuth2Exception) e.getCause()).getSummary();
assertTrue("Wrong summary: " + summary, summary.contains("Bad credentials"));
}
}
use of org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails in project spring-security-oauth by spring-projects.
the class AbstractIntegrationTests method fixPaths.
@BeforeOAuth2Context
public void fixPaths() {
String prefix = server.getServletPrefix();
http.setPort(port);
http.setPrefix(prefix);
BaseOAuth2ProtectedResourceDetails resource = (BaseOAuth2ProtectedResourceDetails) context.getResource();
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) {
((ResourceOwnerPasswordResourceDetails) resource).setUsername(security.getUser().getName());
((ResourceOwnerPasswordResourceDetails) resource).setPassword(security.getUser().getPassword());
}
}
Aggregations