Examples of OAuth2Authentication


Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

  public void removeAccessToken(String tokenValue) {
    OAuth2AccessToken removed = this.accessTokenStore.remove(tokenValue);
    this.accessTokenToRefreshTokenStore.remove(tokenValue);
    // Don't remove the refresh token - it's up to the caller to do that
    OAuth2Authentication authentication = this.authenticationStore.remove(tokenValue);
    if (authentication != null) {
      this.authenticationToAccessTokenStore.remove(authenticationKeyGenerator.extractKey(authentication));
      Collection<OAuth2AccessToken> tokens;
      tokens = this.userNameToAccessTokenStore.get(authentication.getName());
      if (tokens != null) {
        tokens.remove(removed);
      }
      String clientId = authentication.getOAuth2Request().getClientId();
      tokens = this.clientIdToAccessTokenStore.get(clientId);
      if (tokens != null) {
        tokens.remove(removed);
      }
      this.authenticationToAccessTokenStore.remove(authenticationKeyGenerator.extractKey(authentication));
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

        }

        OAuth2Request storedOAuth2Request = oAuth2RequestFactory.createOAuth2Request(authorizationRequest);
       
        SecurityContextHolder.getContext().setAuthentication(
            new OAuth2Authentication(storedOAuth2Request, authResult));

        onSuccessfulAuthentication(request, response, authResult);

      }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

    if (token.isExpired()) {
      throw new InvalidTokenException("Token has expired");
    }

    OAuth2Authentication authentication = resourceServerTokenServices.loadAuthentication(token.getValue());

    Map<String, ?> response = accessTokenConverter.convertAccessToken(token, authentication);

    return response;
  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

  public boolean revokeApprovals(Collection<Approval> approvals) {
    boolean success = true;
    for (Approval approval : approvals) {
      Collection<OAuth2AccessToken> tokens = store.findTokensByClientIdAndUserName(approval.getClientId(), approval.getUserId());
      for (OAuth2AccessToken token : tokens) {
        OAuth2Authentication authentication = store.readAuthentication(token);
        if (authentication != null
            && approval.getClientId().equals(authentication.getOAuth2Request().getClientId())) {
          store.removeAccessToken(token);
        }
      }
    }
    return success;
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

  @Override
  public Collection<Approval> getApprovals(String userId, String clientId) {
    Collection<Approval> result = new HashSet<Approval>();
    Collection<OAuth2AccessToken> tokens = store.findTokensByClientIdAndUserName(clientId, userId);
    for (OAuth2AccessToken token : tokens) {
      OAuth2Authentication authentication = store.readAuthentication(token);
      if (authentication != null) {
        Date expiresAt = token.getExpiration();
        for (String scope : token.getScope()) {
          result.add(new Approval(userId, clientId, scope, expiresAt, ApprovalStatus.APPROVED));
        }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

    if (userAuth == null || !userAuth.isAuthenticated()) {
      throw new InvalidGrantException("Could not authenticate user: " + username);
    }
   
    OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest);   
    return new OAuth2Authentication(storedOAuth2Request, userAuth);
  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

    }
    Assert.state(clientToken instanceof ImplicitTokenRequest, "An ImplicitTokenRequest is required here. Caller needs to wrap the TokenRequest.");
   
    OAuth2Request requestForStorage = ((ImplicitTokenRequest)clientToken).getOAuth2Request();
   
    return new OAuth2Authentication(requestForStorage, userAuth);

  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

    @SuppressWarnings("unchecked")
    Set<String> resourceIds = new LinkedHashSet<String>(map.containsKey(AUD) ? (Collection<String>) map.get(AUD)
        : Collections.<String>emptySet());
    OAuth2Request request = new OAuth2Request(parameters, clientId, null, true, scope, resourceIds, null, null,
        null);
    return new OAuth2Authentication(request, user);
  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

    return tokenServices.createAccessToken(getOAuth2Authentication(client, tokenRequest));
  }

  protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
    OAuth2Request storedOAuth2Request = requestFactory.createOAuth2Request(client, tokenRequest);
    return new OAuth2Authentication(storedOAuth2Request, null);
  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication

    OAuth2RefreshToken refreshToken = tokenStore.readRefreshToken(refreshTokenValue);
    if (refreshToken == null) {
      throw new InvalidGrantException("Invalid refresh token: " + refreshTokenValue);
    }

    OAuth2Authentication authentication = tokenStore.readAuthenticationForRefreshToken(refreshToken);
    String clientId = authentication.getOAuth2Request().getClientId();
    if (clientId == null || !clientId.equals(tokenRequest.getClientId())) {
      throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue);
    }

    // clear out any access tokens already associated with the refresh
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.