當前位置: 首頁>>代碼示例>>Java>>正文


Java User類代碼示例

本文整理匯總了Java中org.eclipse.che.security.oauth.shared.User的典型用法代碼示例。如果您正苦於以下問題:Java User類的具體用法?Java User怎麽用?Java User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


User類屬於org.eclipse.che.security.oauth.shared包,在下文中一共展示了User類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
  URL getUserUrL;
  Map<String, String> params = new HashMap<>();
  params.put("Authorization", "Bearer " + accessToken.getToken());
  try {
    getUserUrL = new URL(String.format("%s?schema=%s", userUri, SCOPE));
    JsonValue userValue = doRequest(getUserUrL, params);
    User user = new Wso2User();
    user.setEmail(userValue.getElement("email").getStringValue());
    user.setName(userValue.getElement("name").getStringValue());
    return user;
  } catch (JsonParseException | IOException e) {
    throw new OAuthAuthenticationException(e.getMessage(), e);
  }
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:18,代碼來源:WSO2OAuthAuthenticator.java

示例2: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
  Map<String, String> params = new HashMap<>();
  params.put("Authorization", "Bearer " + accessToken.getToken());
  try {
    BitbucketUser user = doRequest(new URL(userUri), BitbucketUser.class, params);

    BitbucketEmail[] emails =
        doRequest(
            new URL("https://bitbucket.org/api/1.0/emails"), BitbucketEmail[].class, params);

    for (final BitbucketEmail oneEmail : emails) {
      if (oneEmail.isPrimary()) {
        user.setEmail(oneEmail.getEmail());
        break;
      }
    }
    return user;
  } catch (JsonParseException | IOException e) {
    throw new OAuthAuthenticationException(e.getMessage(), e);
  }
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:23,代碼來源:BitbucketOAuthAuthenticator.java

示例3: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
  Map<String, String> params = new HashMap<>();
  params.put("Authorization", "Bearer " + accessToken.getToken());
  try {
    JsonValue userValue = doRequest(new URL(userUri), params);
    if (userValue.getElement("email") == null) {
      throw new OAuthAuthenticationException(
          "Cannot retrieve user email, authentication impossible.");
    }
    final String email = userValue.getElement("email").getStringValue();
    User user = new RedHatUser();
    user.setEmail(email);
    String username = "";
    if (userValue.getElement("preferred_username") != null) {
      username = userValue.getElement("preferred_username").getStringValue().toLowerCase();
    } else if (userValue.getElement("given_name") != null
        && userValue.getElement("family_name") != null) {
      username =
          userValue
              .getElement("given_name")
              .getStringValue()
              .toLowerCase()
              .concat("_")
              .concat(userValue.getElement("family_name").getStringValue().toLowerCase());

    } else {
      username = email.substring(0, email.indexOf("@")); //
    }
    user.setName(username);
    return user;
  } catch (JsonParseException | IOException e) {
    throw new OAuthAuthenticationException(e.getMessage(), e);
  }
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:36,代碼來源:RedHatOAuthAuthenticator.java

示例4: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
  Map<String, String> params = new HashMap<>();
  params.put("Authorization", "Bearer " + accessToken.getToken());
  try {
    // LinkedIn specific trick (default user URL does not returns email)
    final String values = "(email-address,first-name,last-name)";
    final String query = String.format("format=json");
    JsonValue userValue = doRequest(new URL(userUri + ":" + values + "?" + query), params);
    if (userValue.getElement("emailAddress") == null) {
      throw new OAuthAuthenticationException(
          "Cannot retrieve user email, authentication impossible.");
    }
    final String email = userValue.getElement("emailAddress").getStringValue();
    String username = "";
    User user = new LinkedInUser();
    user.setEmail(email);
    if (userValue.getElement("firstName") == null || userValue.getElement("lastName") == null) {
      username = email.substring(0, email.indexOf("@"));
    } else {
      username =
          userValue
              .getElement("firstName")
              .getStringValue()
              .toLowerCase()
              .concat("_")
              .concat(userValue.getElement("lastName").getStringValue().toLowerCase());
    }
    user.setName(username);
    return user;
  } catch (JsonParseException | IOException e) {
    throw new OAuthAuthenticationException(e.getMessage(), e);
  }
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:35,代碼來源:LinkedInOAuthAuthenticator.java

示例5: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
  Map<String, String> params = new HashMap<>();
  params.put("Authorization", "Bearer " + accessToken.getToken());
  try {
    JsonValue userValue = doRequest(new URL(userUri), params);
    User user = new MicrosoftUser();
    user.setEmail(userValue.getElement("emailAddress").getStringValue());
    user.setName(userValue.getElement("displayName").getStringValue());
    return user;
  } catch (JsonParseException | IOException e) {
    throw new OAuthAuthenticationException(e.getMessage(), e);
  }
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:15,代碼來源:MicrosoftOauthAuthenticator.java

示例6: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
  return getJson(
      "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessToken.getToken(),
      GoogleUser.class);
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:7,代碼來源:GoogleOAuthAuthenticator.java

示例7: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
  return null;
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:5,代碼來源:ProjectLockerOAuthAuthenticator.java

示例8: getUser

import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
/**
 * Get user info.
 *
 * @param accessToken oauth access token
 * @return user info
 * @throws OAuthAuthenticationException if fail to get user info
 */
public abstract User getUser(OAuthToken accessToken) throws OAuthAuthenticationException;
 
開發者ID:eclipse,項目名稱:che,代碼行數:9,代碼來源:OAuthAuthenticator.java


注:本文中的org.eclipse.che.security.oauth.shared.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。