Examples of AuthorizationCodeResourceDetails


Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

    return new OAuth2RestTemplate(resource(), oauth2ClientContext);
  }

  @Bean
  protected OAuth2ProtectedResourceDetails resource() {
    AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
    resource.setAccessTokenUri(tokenUrl);
    resource.setUserAuthorizationUri(authorizeUrl);
    resource.setClientId("my-trusted-client");
    return resource ;
  }
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

  }

  @Test
  @OAuth2ContextConfiguration(resource = MyClientWithRegisteredRedirect.class, initialize = false)
  public void testInsufficientScopeInResourceRequest() throws Exception {
    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) context.getResource();
    resource.setScope(Arrays.asList("trust"));
    approveAccessTokenGrant("http://anywhere?key=value", true);
    assertNotNull(context.getAccessToken());
    try {
      serverRunning.getForString("/sparklr2/photos?format=json");
      fail("Should have thrown exception");
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

  }

  private void approveAccessTokenGrant(String currentUri, boolean approved) {

    AccessTokenRequest request = context.getAccessTokenRequest();
    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) context.getResource();

    request.setCookie(cookie);
    if (currentUri != null) {
      request.setCurrentUri(currentUri);
    }

    String location = null;

    try {
      // First try to obtain the access token...
      assertNotNull(context.getAccessToken());
      fail("Expected UserRedirectRequiredException");
    }
    catch (UserRedirectRequiredException e) {
      // Expected and necessary, so that the correct state is set up in the request...
      location = e.getRedirectUri();
    }

    assertTrue(location.startsWith(resource.getUserAuthorizationUri()));
    assertNull(request.getAuthorizationCode());

    try {
      // Now try again and the token provider will redirect for user approval...
      assertNotNull(context.getAccessToken());
      fail("Expected UserRedirectRequiredException");
    }
    catch (UserApprovalRequiredException e) {
      // Expected and necessary, so that the user can approve the grant...
      location = e.getApprovalUri();
    }

    assertTrue(location.startsWith(resource.getUserAuthorizationUri()));
    assertNull(request.getAuthorizationCode());

    // The approval (will be processed on the next attempt to obtain an access token)...
    request.set(OAuth2Utils.USER_OAUTH_APPROVAL, "" + approved);
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

public class AuthorizationCodeProviderTests extends AbstractAuthorizationCodeProviderTests {

  @Test
  @OAuth2ContextConfiguration(resource = MyClientWithRegisteredRedirect.class, initialize = false)
  public void testInsufficientScopeInResourceRequest() throws Exception {
    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) context.getResource();
    resource.setScope(Arrays.asList("trust"));
    approveAccessTokenGrant("http://anywhere?key=value", true);
    assertNotNull(context.getAccessToken());
    try {
      http.getForString("/admin/beans");
      fail("Should have thrown exception");
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

  @Test
  public void testSaveAndRetrieveToken() throws Exception {
    OAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("FOO");
    Authentication authentication = new UsernamePasswordAuthenticationToken("marissa", "koala");
    AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
    resource.setClientId("client");
    resource.setScope(Arrays.asList("foo", "bar"));
    tokenStore.saveAccessToken(resource, authentication, accessToken);
    OAuth2AccessToken result = tokenStore.getAccessToken(resource, authentication);
    assertEquals(accessToken, result);
  }
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

  @Test
  public void testSaveAndRemoveToken() throws Exception {
    OAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("FOO");
    Authentication authentication = new UsernamePasswordAuthenticationToken("marissa", "koala");
    AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
    resource.setClientId("client");
    resource.setScope(Arrays.asList("foo", "bar"));
    tokenStore.saveAccessToken(resource, authentication, accessToken);
    tokenStore.removeAccessToken(resource, authentication);
    // System.err.println(new JdbcTemplate(db).queryForList("select * from oauth_client_token"));
    OAuth2AccessToken result = tokenStore.getAccessToken(resource, authentication);
    assertNull(result);
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

    return new JdbcClientTokenServices(dataSource);
  }

  @Bean
  protected OAuth2ProtectedResourceDetails resource() {
    AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
    resource.setAccessTokenUri(tokenUrl);
    resource.setUserAuthorizationUri(authorizeUrl);
    resource.setClientId("my-trusted-client");
    return resource;
  }
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

  protected void approveAccessTokenGrant(String currentUri, boolean approved) {

    AccessTokenRequest request = context.getAccessTokenRequest();
    request.setHeaders(getAuthenticatedHeaders());
    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) context.getResource();

    if (currentUri != null) {
      request.setCurrentUri(currentUri);
    }

    String location = null;

    try {
      // First try to obtain the access token...
      assertNotNull(context.getAccessToken());
      fail("Expected UserRedirectRequiredException");
    }
    catch (UserRedirectRequiredException e) {
      // Expected and necessary, so that the correct state is set up in the request...
      location = e.getRedirectUri();
    }

    assertTrue(location.startsWith(resource.getUserAuthorizationUri()));
    assertNull(request.getAuthorizationCode());
   
    verifyAuthorizationPage(context.getRestTemplate(), location);

    try {
      // Now try again and the token provider will redirect for user approval...
      assertNotNull(context.getAccessToken());
      fail("Expected UserRedirectRequiredException");
    }
    catch (UserApprovalRequiredException e) {
      // Expected and necessary, so that the user can approve the grant...
      location = e.getApprovalUri();
    }

    assertTrue(location.startsWith(resource.getUserAuthorizationUri()));
    assertNull(request.getAuthorizationCode());

    // The approval (will be processed on the next attempt to obtain an access token)...
    request.set(OAuth2Utils.USER_OAUTH_APPROVAL, "" + approved);
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

  protected void approveAccessTokenGrant(String currentUri, boolean approved) {

    AccessTokenRequest request = context.getAccessTokenRequest();
    request.setHeaders(getAuthenticatedHeaders());
    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) context.getResource();

    if (currentUri != null) {
      request.setCurrentUri(currentUri);
    }

    String location = null;

    try {
      // First try to obtain the access token...
      assertNotNull(context.getAccessToken());
      fail("Expected UserRedirectRequiredException");
    }
    catch (UserRedirectRequiredException e) {
      // Expected and necessary, so that the correct state is set up in the request...
      location = e.getRedirectUri();
    }

    assertTrue(location.startsWith(resource.getUserAuthorizationUri()));
    assertNull(request.getAuthorizationCode());
   
    verifyAuthorizationPage(context.getRestTemplate(), location);

    try {
      // Now try again and the token provider will redirect for user approval...
      assertNotNull(context.getAccessToken());
      fail("Expected UserRedirectRequiredException");
    }
    catch (UserApprovalRequiredException e) {
      // Expected and necessary, so that the user can approve the grant...
      location = e.getApprovalUri();
    }

    assertTrue(location.startsWith(resource.getUserAuthorizationUri()));
    assertNull(request.getAuthorizationCode());

    // The approval (will be processed on the next attempt to obtain an access token)...
    request.set(OAuth2Utils.USER_OAUTH_APPROVAL, "" + approved);
View Full Code Here

Examples of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

    @Bean
    @Lazy
    @Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
    public OAuth2RestOperations restTemplate() {
      AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails();
      resource.setClientId("client");
      resource.setAccessTokenUri("http://example.com/token");
      resource.setUserAuthorizationUri("http://example.com/authorize");
      return new OAuth2RestTemplate(resource, new DefaultOAuth2ClientContext(accessTokenRequest));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.