Search in sources :

Example 1 with ResourceOwnerPasswordResourceDetails

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);
}
Also used : ResourceOwnerPasswordResourceDetails(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Date(java.util.Date) Before(org.junit.Before)

Example 2 with ResourceOwnerPasswordResourceDetails

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);
}
Also used : ResourceOwnerPasswordResourceDetails(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) Test(org.junit.Test)

Example 3 with ResourceOwnerPasswordResourceDetails

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"));
    }
}
Also used : ResourceOwnerPasswordResourceDetails(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails) OAuth2AccessDeniedException(org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) OAuth2ContextConfiguration(org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration) Test(org.junit.Test)

Example 4 with ResourceOwnerPasswordResourceDetails

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());
    }
}
Also used : AbstractRedirectResourceDetails(org.springframework.security.oauth2.client.token.grant.redirect.AbstractRedirectResourceDetails) ResourceOwnerPasswordResourceDetails(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails) ImplicitResourceDetails(org.springframework.security.oauth2.client.token.grant.implicit.ImplicitResourceDetails) BaseOAuth2ProtectedResourceDetails(org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails) BeforeOAuth2Context(org.springframework.security.oauth2.client.test.BeforeOAuth2Context)

Aggregations

ResourceOwnerPasswordResourceDetails (org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails)4 OAuth2RestTemplate (org.springframework.security.oauth2.client.OAuth2RestTemplate)3 Test (org.junit.Test)2 Date (java.util.Date)1 Before (org.junit.Before)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)1 BaseOAuth2ProtectedResourceDetails (org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails)1 OAuth2AccessDeniedException (org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException)1 BeforeOAuth2Context (org.springframework.security.oauth2.client.test.BeforeOAuth2Context)1 OAuth2ContextConfiguration (org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration)1 ImplicitResourceDetails (org.springframework.security.oauth2.client.token.grant.implicit.ImplicitResourceDetails)1 AbstractRedirectResourceDetails (org.springframework.security.oauth2.client.token.grant.redirect.AbstractRedirectResourceDetails)1 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)1