示例#1
0
 @Override
 public void setPermission(final Permission p) {
   LOG.debug("Permission requested : " + p.toString());
   this.scope = p;
   authenticationStrategy.setPermission(this.scope);
   authenticationStrategy.setScope(getScope());
 }
示例#2
0
  /**
   * Stores configuration for the provider
   *
   * @param providerConfig It contains the configuration of application like consumer key and
   *     consumer secret
   * @throws Exception
   */
  public GitHubImpl(final OAuthConfig providerConfig) throws Exception {
    config = providerConfig;
    if (config.getCustomPermissions() != null) {
      scope = Permission.CUSTOM;
    }

    if (config.getAuthenticationUrl() != null) {
      ENDPOINTS.put(Constants.OAUTH_AUTHORIZATION_URL, config.getAuthenticationUrl());
    } else {
      config.setAuthenticationUrl(ENDPOINTS.get(Constants.OAUTH_AUTHORIZATION_URL));
    }

    if (config.getAccessTokenUrl() != null) {
      ENDPOINTS.put(Constants.OAUTH_ACCESS_TOKEN_URL, config.getAccessTokenUrl());
    } else {
      config.setAccessTokenUrl(ENDPOINTS.get(Constants.OAUTH_ACCESS_TOKEN_URL));
    }

    authenticationStrategy = new OAuth2(config, ENDPOINTS);
    authenticationStrategy.setPermission(scope);
    authenticationStrategy.setScope(getScope());
  }
示例#3
0
  private Profile doVerifyResponse(final Map<String, String> requestParams) throws Exception {
    LOG.info("Retrieving Access Token in verify response function");
    if (requestParams.get("error_reason") != null
        && "user_denied".equals(requestParams.get("error_reason"))) {
      throw new UserDeniedPermissionException();
    }
    accessGrant = authenticationStrategy.verifyResponse(requestParams, MethodType.POST.toString());

    if (accessGrant != null) {
      LOG.debug("Obtaining user profile");
      return getProfile();
    } else {
      throw new SocialAuthException("Access token not found");
    }
  }
示例#4
0
 @Override
 public Response api(
     final String url,
     final String methodType,
     final Map<String, String> params,
     final Map<String, String> headerParams,
     final String body)
     throws Exception {
   LOG.info("Calling api function for url	:	" + url);
   Response response = null;
   try {
     response = authenticationStrategy.executeFeed(url, methodType, params, headerParams, body);
   } catch (Exception e) {
     throw new SocialAuthException("Error while making request to URL : " + url, e);
   }
   return response;
 }
示例#5
0
  private Profile getProfile() throws Exception {
    String presp;

    try {
      Response response = authenticationStrategy.executeFeed(PROFILE_URL);
      presp = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e);
    }
    try {
      LOG.debug("User Profile : " + presp);
      JSONObject resp = new JSONObject(presp);
      Profile p = new Profile();
      p.setValidatedId(resp.getString("id"));
      if (resp.has("name")) {
        p.setFullName(resp.getString("name"));
      }
      if (resp.has("email")) {
        String email = resp.getString("email");
        if (!"null".equals(email)) {
          p.setEmail(resp.getString("email"));
        }
      }
      if (resp.has("location")) {
        p.setLocation(resp.getString("location"));
      }
      if (resp.has("avatar_url")) {
        p.setProfileImageURL(resp.getString("avatar_url"));
      }
      p.setProviderId(getProviderId());
      userProfile = p;
      return p;
    } catch (Exception ex) {
      throw new ServerDataException("Failed to parse the user profile json : " + presp, ex);
    }
  }
示例#6
0
 @Override
 public void setAccessGrant(final AccessGrant accessGrant)
     throws AccessTokenExpireException, SocialAuthException {
   this.accessGrant = accessGrant;
   authenticationStrategy.setAccessGrant(accessGrant);
 }
示例#7
0
 @Override
 public void logout() {
   accessGrant = null;
   authenticationStrategy.logout();
 }
示例#8
0
 @Override
 public String getLoginRedirectURL(final String successUrl) throws Exception {
   return authenticationStrategy.getLoginRedirectURL(successUrl);
 }