当前位置: 首页>>代码示例>>Java>>正文


Java OAuthToken.getSecret方法代码示例

本文整理汇总了Java中com.google.gerrit.extensions.auth.oauth.OAuthToken.getSecret方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthToken.getSecret方法的具体用法?Java OAuthToken.getSecret怎么用?Java OAuthToken.getSecret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gerrit.extensions.auth.oauth.OAuthToken的用法示例。


在下文中一共展示了OAuthToken.getSecret方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUserInfo

import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
  service.signRequest(t, request);
  Response response = request.send();
  if (response.getCode() != SC_OK) {
    throw new IOException(
        String.format(
            "Status %s (%s) for request %s",
            response.getCode(), response.getBody(), request.getUrl()));
  }
  JsonElement userJson = JSON.newGson().fromJson(response.getBody(), JsonElement.class);
  if (log.isDebugEnabled()) {
    log.debug("User info response: {}", response.getBody());
  }
  if (userJson.isJsonObject()) {
    JsonObject jsonObject = userJson.getAsJsonObject();
    JsonObject userObject = jsonObject.getAsJsonObject("user");
    if (userObject == null || userObject.isJsonNull()) {
      throw new IOException("Response doesn't contain 'user' field");
    }
    JsonElement usernameElement = userObject.get("username");
    String username = usernameElement.getAsString();

    JsonElement displayName = jsonObject.get("display_name");
    return new OAuthUserInfo(
        BITBUCKET_PROVIDER_PREFIX + username,
        username,
        null,
        displayName == null || displayName.isJsonNull() ? null : displayName.getAsString(),
        fixLegacyUserId ? username : null);
  }

  throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:37,代码来源:BitbucketOAuthService.java

示例2: getUserInfo

import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
  final String protectedResourceUrl = String.format(PROTECTED_RESOURCE_URL, rootUrl);
  OAuthRequest request = new OAuthRequest(Verb.GET, protectedResourceUrl);
  Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
  service.signRequest(t, request);

  Response response = request.send();
  if (response.getCode() != SC_OK) {
    throw new IOException(
        String.format(
            "Status %s (%s) for request %s",
            response.getCode(), response.getBody(), request.getUrl()));
  }
  JsonElement userJson = JSON.newGson().fromJson(response.getBody(), JsonElement.class);
  if (log.isDebugEnabled()) {
    log.debug("User info response: {}", response.getBody());
  }
  JsonObject jsonObject = userJson.getAsJsonObject();
  if (jsonObject == null || jsonObject.isJsonNull()) {
    throw new IOException("Response doesn't contain 'user' field" + jsonObject);
  }
  JsonElement id = jsonObject.get("id");
  JsonElement username = jsonObject.get("username");
  JsonElement email = jsonObject.get("email");
  JsonElement name = jsonObject.get("name");
  return new OAuthUserInfo(
      GITLAB_PROVIDER_PREFIX + id.getAsString(),
      username == null || username.isJsonNull() ? null : username.getAsString(),
      email == null || email.isJsonNull() ? null : email.getAsString(),
      name == null || name.isJsonNull() ? null : name.getAsString(),
      null);
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:34,代码来源:GitLabOAuthService.java

示例3: getUserInfo

import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
  service.signRequest(t, request);
  Response response = request.send();
  if (response.getCode() != HttpServletResponse.SC_OK) {
    throw new IOException(
        String.format(
            "Status %s (%s) for request %s",
            response.getCode(), response.getBody(), request.getUrl()));
  }
  JsonElement userJson =
      OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
  if (log.isDebugEnabled()) {
    log.debug("User info response: {}", response.getBody());
  }
  if (userJson.isJsonObject()) {
    JsonObject jsonObject = userJson.getAsJsonObject();
    JsonElement id = jsonObject.get("id");
    if (id == null || id.isJsonNull()) {
      throw new IOException(String.format("Response doesn't contain id field"));
    }
    JsonElement email = jsonObject.get("email");
    JsonElement name = jsonObject.get("name");
    JsonElement login = jsonObject.get("login");
    return new OAuthUserInfo(
        GITHUB_PROVIDER_PREFIX + id.getAsString(),
        login == null || login.isJsonNull() ? null : login.getAsString(),
        email == null || email.isJsonNull() ? null : email.getAsString(),
        name == null || name.isJsonNull() ? null : name.getAsString(),
        fixLegacyUserId ? id.getAsString() : null);
  }

  throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:37,代码来源:GitHubOAuthService.java

示例4: getUserInfo

import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
  final String protectedResourceUrl = String.format(PROTECTED_RESOURCE_URL, rootUrl);
  OAuthRequest request = new OAuthRequest(Verb.GET, protectedResourceUrl);
  Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
  service.signRequest(t, request);

  Response response = request.send();
  if (response.getCode() != HttpServletResponse.SC_OK) {
    throw new IOException(
        String.format(
            "Status %s (%s) for request %s",
            response.getCode(), response.getBody(), request.getUrl()));
  }

  if (log.isDebugEnabled()) {
    log.debug("User info response: {}", response.getBody());
  }

  JsonElement userJson =
      OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
  if (!userJson.isJsonObject()) {
    throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
  }
  JsonObject jsonObject = userJson.getAsJsonObject();

  JsonElement id = jsonObject.get("id");
  if (id == null || id.isJsonNull()) {
    throw new IOException(String.format("CAS response missing id: %s", response.getBody()));
  }

  JsonElement attrListJson = jsonObject.get("attributes");
  if (attrListJson == null) {
    throw new IOException(
        String.format("CAS response missing attributes: %s", response.getBody()));
  }

  String email = null, name = null, login = null;

  if (attrListJson != null && attrListJson.isJsonArray()) {
    // It is possible for CAS to be configured to not return any attributes (email, name, login), in which case,
    // CAS returns an empty JSON object "attributes":{}, rather than "null" or an empty JSON array "attributes": []

    JsonArray attrJson = attrListJson.getAsJsonArray();
    for (JsonElement elem : attrJson) {
      if (elem == null || !elem.isJsonObject()) {
        throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", elem));
      }
      JsonObject obj = elem.getAsJsonObject();

      String property = getStringElement(obj, "email");
      if (property != null) email = property;
      property = getStringElement(obj, "name");
      if (property != null) name = property;
      property = getStringElement(obj, "login");
      if (property != null) login = property;
    }
  }

  return new OAuthUserInfo(
      CAS_PROVIDER_PREFIX + id.getAsString(),
      login,
      email,
      name,
      fixLegacyUserId ? id.getAsString() : null);
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:67,代码来源:CasOAuthService.java

示例5: getUserInfo

import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
  service.signRequest(t, request);
  Response response = request.send();
  if (response.getCode() != HttpServletResponse.SC_OK) {
    throw new IOException(
        String.format(
            "Status %s (%s) for request %s",
            response.getCode(), response.getBody(), request.getUrl()));
  }
  JsonElement userJson =
      OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
  if (log.isDebugEnabled()) {
    log.debug("User info response: {}", response.getBody());
  }
  if (userJson.isJsonObject()) {
    JsonObject jsonObject = userJson.getAsJsonObject();
    JsonElement id = jsonObject.get("id");
    if (id == null || id.isJsonNull()) {
      throw new IOException(String.format("Response doesn't contain id field"));
    }
    JsonElement email = jsonObject.get("email");
    JsonElement name = jsonObject.get("name");
    String login = null;

    if (domains.size() > 0) {
      boolean domainMatched = false;
      JsonObject jwtToken = retrieveJWTToken(token);
      String hdClaim = retrieveHostedDomain(jwtToken);
      for (String domain : domains) {
        if (domain.equalsIgnoreCase(hdClaim)) {
          domainMatched = true;
          break;
        }
      }
      if (!domainMatched) {
        // TODO(davido): improve error reporting in OAuth extension point
        log.error("Error: hosted domain validation failed: {}", Strings.nullToEmpty(hdClaim));
        return null;
      }
    }
    if (useEmailAsUsername && !email.isJsonNull()) {
      login = email.getAsString().split("@")[0];
    }
    return new OAuthUserInfo(
        GOOGLE_PROVIDER_PREFIX + id.getAsString() /*externalId*/,
        login /*username*/,
        email == null || email.isJsonNull() ? null : email.getAsString() /*email*/,
        name == null || name.isJsonNull() ? null : name.getAsString() /*displayName*/,
        fixLegacyUserId ? id.getAsString() : null /*claimedIdentity*/);
  }

  throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:57,代码来源:GoogleOAuthService.java

示例6: getUserInfo

import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
  request.addQuerystringParameter(FIELDS_QUERY, FIELDS);
  service.signRequest(t, request);
  Response response = request.send();

  if (response.getCode() != HttpServletResponse.SC_OK) {
    throw new IOException(
        String.format(
            "Status %s (%s) for request %s",
            response.getCode(), response.getBody(), request.getUrl()));
  }
  JsonElement userJson =
      OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);

  if (log.isDebugEnabled()) {
    log.debug("User info response: {}", response.getBody());
  }
  if (userJson.isJsonObject()) {
    JsonObject jsonObject = userJson.getAsJsonObject();
    JsonElement id = jsonObject.get("id");
    if (id == null || id.isJsonNull()) {
      throw new IOException(String.format("Response doesn't contain id field"));
    }
    JsonElement email = jsonObject.get("email");
    JsonElement name = jsonObject.get("name");
    // Heads up!
    // Lets keep `login` equal to `email`, since `username` field is
    // deprecated for Facebook API versions v2.0 and higher
    JsonElement login = jsonObject.get("email");

    return new OAuthUserInfo(
        FACEBOOK_PROVIDER_PREFIX + id.getAsString(),
        login == null || login.isJsonNull() ? null : login.getAsString(),
        email == null || email.isJsonNull() ? null : email.getAsString(),
        name == null || name.isJsonNull() ? null : name.getAsString(),
        null);
  }

  throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:44,代码来源:FacebookOAuthService.java


注:本文中的com.google.gerrit.extensions.auth.oauth.OAuthToken.getSecret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。