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

Examples of org.springframework.security.oauth2.client.token.AccessTokenRequest


    return null;
  }

  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);
    }
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

  }

  private AccessTokenRequest createAccessTokenRequest(String username, String password) {
    Map<String, String> parameters = new LinkedHashMap<String, String>();
    parameters.put("credentials", String.format("{\"username\":\"%s\",\"password\":\"%s\"}", username, password));
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAll(parameters);

    return request;
  }
View Full Code Here

  @Override
  public void starting(FrameworkMethod method) {
    if (resource != null) {
      logger.info("Starting OAuth2 context for: " + resource);
      AccessTokenRequest request = new DefaultAccessTokenRequest();
      request.setAll(parameters);
      client = createRestTemplate(resource, request);
      if (initializeAccessToken) {
        this.accessToken = null;
        this.accessToken = getAccessToken();
      }
View Full Code Here

        OAuth2ContextConfiguration beforeConfiguration = findOAuthContextConfiguration(before, testClass);
        if (beforeConfiguration != null) {

          OAuth2ProtectedResourceDetails resource = creatResource(target, beforeConfiguration);
          AccessTokenRequest beforeRequest = new DefaultAccessTokenRequest();
          beforeRequest.setAll(parameters);
          OAuth2RestTemplate client = createRestTemplate(resource, beforeRequest);
          clientHolder.setRestTemplate(client);

        }

        AccessTokenRequest request = new DefaultAccessTokenRequest();
        request.setAll(parameters);
        this.client = createRestTemplate(this.resource, request);

        List<FrameworkMethod> list = Arrays.asList(before);
        try {
          new RunBefores(new Statement() {
View Full Code Here

  }

  protected OAuth2AccessToken acquireAccessToken(OAuth2ClientContext oauth2Context)
      throws UserRedirectRequiredException {

    AccessTokenRequest accessTokenRequest = oauth2Context.getAccessTokenRequest();
    if (accessTokenRequest == null) {
      throw new AccessTokenRequiredException(
          "No OAuth 2 security context has been established. Unable to access resource '"
              + this.resource.getId() + "'.", resource);
    }

    // Transfer the preserved state from the (longer lived) context to the current request.
    String stateKey = accessTokenRequest.getStateKey();
    if (stateKey != null) {
      accessTokenRequest.setPreservedState(oauth2Context.removePreservedState(stateKey));
    }

    OAuth2AccessToken existingToken = oauth2Context.getAccessToken();
    if (existingToken != null) {
      accessTokenRequest.setExistingToken(existingToken);
    }

    OAuth2AccessToken accessToken = null;
    accessToken = accessTokenProvider.obtainAccessToken(resource, accessTokenRequest);
    if (accessToken == null || accessToken.getValue() == null) {
View Full Code Here

    }
    else {
      form.putAll(getParametersForAuthorizeRequest(resource, request));
    }
    authorizationRequestEnhancer.enhance(request, resource, form, headers);
    final AccessTokenRequest copy = request;

    final ResponseExtractor<ResponseEntity<Void>> delegate = getAuthorizationResponseExtractor();
    ResponseExtractor<ResponseEntity<Void>> extractor = new ResponseExtractor<ResponseEntity<Void>>() {
      @Override
      public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
        if (response.getHeaders().containsKey("Set-Cookie")) {
          copy.setCookie(response.getHeaders().getFirst("Set-Cookie"));
        }
        return delegate.extractData(response);
      }
    };
    // Instead of using restTemplate.exchange we use an explicit response extractor here so it can be overridden by
View Full Code Here

  @Test
  @OAuth2ContextConfiguration(resource = MyLessTrustedClient.class, initialize = false)
  public void testUnauthenticatedAuthorizationRequestRedirectsToLogin() throws Exception {

    AccessTokenRequest request = context.getAccessTokenRequest();
    request.setCurrentUri("http://anywhere");
    request.add(OAuth2Utils.USER_OAUTH_APPROVAL, "true");

    String location = null;

    try {
      String code = accessTokenProvider.obtainAuthorizationCode(context.getResource(), request);
View Full Code Here

    approveAccessTokenGrant("http://anywhere", true);

    // Finally everything is in place for the grant to happen...
    assertNotNull(context.getAccessToken());

    AccessTokenRequest request = context.getAccessTokenRequest();
    assertNotNull(request.getAuthorizationCode());
    assertEquals(HttpStatus.OK, serverRunning.getStatusCode("/sparklr2/photos?format=json"));

  }
View Full Code Here

  @Test
  @OAuth2ContextConfiguration(resource = MyLessTrustedClient.class, initialize = false)
  public void testWrongRedirectUri() throws Exception {
    approveAccessTokenGrant("http://anywhere", true);
    AccessTokenRequest request = context.getAccessTokenRequest();
    // The redirect is stored in the preserved state...
    context.getOAuth2ClientContext().setPreservedState(request.getStateKey(), "http://nowhere");
    // Finally everything is in place for the grant to happen...
    try {
      assertNotNull(context.getAccessToken());
      fail("Expected RedirectMismatchException");
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.client.token.AccessTokenRequest

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.