本文整理匯總了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例7: getUser
import org.eclipse.che.security.oauth.shared.User; //導入依賴的package包/類
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
return null;
}
示例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;