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

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


  @Bean
  @Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
  public OAuth2RestOperations restTemplate() {
    OAuth2RestTemplate template = new OAuth2RestTemplate(resource(), new DefaultOAuth2ClientContext(accessTokenRequest));
    AccessTokenProviderChain provider = new AccessTokenProviderChain(Arrays.asList(new AuthorizationCodeAccessTokenProvider()));
    provider.setClientTokenServices(clientTokenServices());
    return template;
  }
View Full Code Here


  private ClientHttpResponse tokenEndpointResponse;

  @BeforeOAuth2Context
  public void setupAccessTokenProvider() {
    accessTokenProvider = new AuthorizationCodeAccessTokenProvider() {

      private ResponseExtractor<OAuth2AccessToken> extractor = super.getResponseExtractor();

      private ResponseExtractor<ResponseEntity<Void>> authExtractor = super.getAuthorizationResponseExtractor();
View Full Code Here

  }

  private void verifyAuthorizationPage(OAuth2RestTemplate restTemplate, String location) {
    final AtomicReference<String> confirmationPage = new AtomicReference<String>();
    AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider() {
      @Override
      protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() {
        return new ResponseExtractor<ResponseEntity<Void>>() {
          public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
            confirmationPage.set(StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8")));
            return new ResponseEntity<Void>(response.getHeaders(), response.getStatusCode());
          }
        };
      }
    };
    try {
      provider.obtainAuthorizationCode(restTemplate.getResource(), restTemplate.getOAuth2ClientContext().getAccessTokenRequest());
    } catch (UserApprovalRequiredException e) {
      // ignore
    }
    String page = confirmationPage.get();
    verifyAuthorizationPage(page);
View Full Code Here

  private ClientHttpResponse tokenEndpointResponse;

  @BeforeOAuth2Context
  public void setupAccessTokenProvider() {
    accessTokenProvider = new AuthorizationCodeAccessTokenProvider() {

      private ResponseExtractor<OAuth2AccessToken> extractor = super.getResponseExtractor();

      private ResponseExtractor<ResponseEntity<Void>> authExtractor = super.getAuthorizationResponseExtractor();
View Full Code Here

  }

  private void verifyAuthorizationPage(OAuth2RestTemplate restTemplate, String location) {
    final AtomicReference<String> confirmationPage = new AtomicReference<String>();
    AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider() {
      @Override
      protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() {
        return new ResponseExtractor<ResponseEntity<Void>>() {
          public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
            confirmationPage.set(StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8")));
            return new ResponseEntity<Void>(response.getHeaders(), response.getStatusCode());
          }
        };
      }
    };
    try {
      provider.obtainAuthorizationCode(restTemplate.getResource(), restTemplate.getOAuth2ClientContext().getAccessTokenRequest());
    } catch (UserApprovalRequiredException e) {
      // ignore
    }
    String page = confirmationPage.get();
    verifyAuthorizationPage(page);
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

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

    ResourceOwnerPasswordAccessTokenProvider provider = createResourceOwnerPasswordAccessTokenProvider();

    return provider.refreshAccessToken(resource, currentToken.getRefreshToken(), request);
  }
View Full Code Here

    HttpEntity<Map> httpEntity = new HttpEntity<Map>(body, headers);
    restTemplate.put(authorizationUrl + "/User/{id}/password", httpEntity, userId);
  }

  protected ResourceOwnerPasswordAccessTokenProvider createResourceOwnerPasswordAccessTokenProvider() {
    ResourceOwnerPasswordAccessTokenProvider resourceOwnerPasswordAccessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider();
    resourceOwnerPasswordAccessTokenProvider.setRequestFactory(restTemplate.getRequestFactory()); //copy the http proxy along
    return resourceOwnerPasswordAccessTokenProvider;
  }
View Full Code Here

    return request;
  }

  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;
  }
View Full Code Here

  }

  @Test
  public void tokenSavedOnLogin() throws MojoExecutionException, IOException, URISyntaxException {
    DefaultOAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken("refreshtoken");
    DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("accesstoken");
    accessToken.setRefreshToken(refreshToken);
    when(client.login()).thenReturn(accessToken);

    HashMap<String, Object> info = new HashMap<String, Object>(1);
    info.put("version", "2");
    when(client.getCloudInfo()).thenReturn(new CloudInfo(info));
View Full Code Here

TOP

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

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.