Package org.springframework.security.oauth2.client.token.grant.code

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


  @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

    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

  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

  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

    @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

      return details;
    }

    @Bean
    public OAuth2ProtectedResourceDetails facebook() {
      AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
      details.setId("facebook");
      details.setClientId("233668646673605");
      details.setClientSecret("33b17e044ee6a4fa383f46ec6e28ea1d");
      details.setAccessTokenUri("https://graph.facebook.com/oauth/access_token");
      details.setUserAuthorizationUri("https://www.facebook.com/dialog/oauth");
      details.setTokenName("oauth_token");
      details.setAuthenticationScheme(AuthenticationScheme.query);
      details.setClientAuthenticationScheme(AuthenticationScheme.form);
      return details;
    }
View Full Code Here

    @Qualifier("accessTokenRequest")
    private AccessTokenRequest accessTokenRequest;

    @Bean
    public OAuth2ProtectedResourceDetails sparklr() {
      AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
      details.setId("sparklr/tonr");
      details.setClientId("tonr");
      details.setClientSecret("secret");
      details.setAccessTokenUri(accessTokenUri);
      details.setUserAuthorizationUri(userAuthorizationUri);
      details.setScope(Arrays.asList("read", "write"));
      return details;
    }
View Full Code Here

      return details;
    }

    @Bean
    public OAuth2ProtectedResourceDetails sparklrRedirect() {
      AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
      details.setId("sparklr/tonr-redirect");
      details.setClientId("tonr-with-redirect");
      details.setClientSecret("secret");
      details.setAccessTokenUri(accessTokenUri);
      details.setUserAuthorizationUri(userAuthorizationUri);
      details.setScope(Arrays.asList("read", "write"));
      details.setUseCurrentUri(false);
      return details;
    }
View Full Code Here

  private OAuth2AccessToken createToken(String username, String password, String clientId, String clientSecret) {
    OAuth2ProtectedResourceDetails resource = getResourceDetails(username, password, clientId, clientSecret);
    AccessTokenRequest request = createAccessTokenRequest(username, password);

    ResourceOwnerPasswordAccessTokenProvider provider = createResourceOwnerPasswordAccessTokenProvider();
    try {
      return provider.obtainAccessToken(resource, request);
    }
    catch (OAuth2AccessDeniedException oauthEx) {
      HttpStatus status = HttpStatus.valueOf(oauthEx.getHttpErrorCode());
      CloudFoundryException cfEx = new CloudFoundryException(status, oauthEx.getMessage());
      cfEx.setDescription(oauthEx.getSummary());
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails

Copyright © 2018 www.massapicom. 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.