/**
   * Initialize a grant type validator
   *
   * @return an instance of OAuthValidator
   * @throws OAuthProblemException
   * @throws OAuthSystemException
   */
  @Override
  protected OAuthValidator<HttpServletRequest> initValidator()
      throws OAuthProblemException, OAuthSystemException {

    String requestTypeValue = getParam(OAuth.OAUTH_GRANT_TYPE);
    if (OAuthUtils.isEmpty(requestTypeValue)) {
      throw OAuthUtils.handleOAuthProblemException("Missing grant_type parameter value");
    }

    Class<? extends OAuthValidator<HttpServletRequest>> clazz =
        OAuthServerConfiguration.getInstance()
            .getSupportedGrantTypeValidators()
            .get(requestTypeValue);

    if (clazz == null) {
      if (log.isDebugEnabled()) {
        // Do not change this log format as these logs use by external applications
        log.debug(
            "Unsupported Grant Type : " + requestTypeValue + " for client id : " + getClientId());
      }
      throw OAuthUtils.handleOAuthProblemException("Invalid grant_type parameter value");
    }

    return OAuthUtils.instantiateClass(clazz);
  }
Example #2
0
 private void setAuthorization(
     TokenGrantInfo tokenGrantInfo, HttpServletRequest request, HttpServletResponse response)
     throws OAuthProblemException {
   isAuthorized = false;
   checkTokenCurrentAndNotExpired(tokenGrantInfo);
   OAuth2RSEndpoint requestEndpoint = findEndpointForRequest(request);
   if (grantScopeMatchesRequest(tokenGrantInfo, requestEndpoint)) {
     log.info("Verified token " + tokenGrantInfo.getAccessToken());
     isAuthorized = true;
     // If client has no refresh token and token is within the threshold time of expiring, push out
     // expiry time
     if ((!tokenGrantInfo.getHasRefreshToken())
         && tokenCloseToExpiring(tokenGrantInfo)
         && response != null) {
       log.info("Requesting token expiry time be extended");
       Optional<AccessTokenExpiryInfo> newExpiryInfo =
           authService.extendAccessTokenExpirySeconds(tokenGrantInfo.getAccessToken());
       if (newExpiryInfo.isPresent()) {
         Map<String, Object> entries = Maps.newHashMap();
         String accessTimeRemaining = newExpiryInfo.get().getAccessTokenTimeRemaining();
         entries.put(OAuth.OAUTH_EXPIRES_IN, accessTimeRemaining);
         log.info("Token will now expire in " + accessTimeRemaining + " seconds");
         response.setHeader(OAuth.HeaderType.AUTHORIZATION, OAuthUtils.encodeOAuthHeader(entries));
       }
     }
     return;
   }
   log.info("Could not find grant scope matching request");
   throw OAuthProblemException.error(OAuthError.ResourceResponse.INSUFFICIENT_SCOPE);
 }
Example #3
0
 protected OAuthAuthzResponse(HttpServletRequest request, OAuthClientValidator validator) {
   this.request = request;
   Map<String, String[]> params = request.getParameterMap();
   for (Map.Entry<String, String[]> entry : params.entrySet()) {
     String key = entry.getKey();
     String[] values = entry.getValue();
     if (!OAuthUtils.hasEmptyValues(values)) {
       parameters.put(key, values[0]);
     }
   }
   this.validator = validator;
 }