本文整理汇总了Java中org.xdi.oxauth.client.UserInfoClient类的典型用法代码示例。如果您正苦于以下问题:Java UserInfoClient类的具体用法?Java UserInfoClient怎么用?Java UserInfoClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserInfoClient类属于org.xdi.oxauth.client包,在下文中一共展示了UserInfoClient类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import org.xdi.oxauth.client.UserInfoClient; //导入依赖的package包/类
public void exec() {
try {
UserInfoRequest request = new UserInfoRequest(accessToken);
request.setAuthorizationMethod(authorizationMethod);
UserInfoClient client = new UserInfoClient(userInfoEndpoint);
client.setRequest(request);
client.exec();
showResults = true;
requestString = client.getRequestAsString();
responseString = client.getResponseAsString();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
示例2: getUserInfo
import org.xdi.oxauth.client.UserInfoClient; //导入依赖的package包/类
private UserInfoResponse getUserInfo(final String accessToken) {
logger.debug("Session validation successful. Getting user information");
final UserInfoClient userInfoClient = new UserInfoClient(this.openIdConfiguration.getUserInfoEndpoint());
final UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);
logger.trace("userInfoResponse.getStatus(): '{}'", userInfoResponse.getStatus());
logger.trace("userInfoResponse.getErrorType(): '{}'", userInfoResponse.getErrorType());
logger.debug("userInfoResponse.getClaims(): '{}'", userInfoResponse.getClaims());
return userInfoResponse;
}
示例3: doGet
import org.xdi.oxauth.client.UserInfoClient; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
resp.setContentType("text/html;charset=utf-8");
PrintWriter pw = resp.getWriter();
pw.println("<h1>RP Demo</h1>");
pw.println("<br/><br/>");
String accessToken = (String) req.getSession().getAttribute("access_token");
String userInfoEndpoint = (String) req.getSession().getAttribute("userinfo_endpoint");
LOG.trace("access_token: " + accessToken + ", userinfo_endpoint: " + userInfoEndpoint);
UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint);
userInfoClient.setExecutor(Utils.createTrustAllExecutor());
UserInfoResponse response = userInfoClient.execUserInfo(accessToken);
LOG.trace("UserInfo response: " + response);
if (response.getStatus() != 200) {
pw.print("Failed to fetch user info claims");
return;
}
pw.println("<h2>User Info Claims:</h2>");
pw.println("<br/>");
for (Map.Entry<String, List<String>> entry : response.getClaims().entrySet()) {
pw.print("Name: " + entry.getKey() + " Value: " + entry.getValue());
pw.println("<br/>");
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
示例4: requestAccessToken
import org.xdi.oxauth.client.UserInfoClient; //导入依赖的package包/类
private String requestAccessToken(String oxAuthHost, String authorizationCode, String sessionState, String idToken, String scopes,
String clientID, String clientPassword, String tokenURL) {
TokenClient tokenClient1 = new TokenClient(tokenURL);
log.info("Sending request to token endpoint");
String redirectURL = applicationConfiguration.getLoginRedirectUrl();
log.info("redirectURI : " + applicationConfiguration.getLoginRedirectUrl());
TokenResponse tokenResponse = tokenClient1.execAuthorizationCode(authorizationCode, redirectURL, clientID, clientPassword);
log.debug(" tokenResponse : " + tokenResponse);
if (tokenResponse == null) {
log.error("Get empty token response. User rcan't log into application");
return OxTrustConstants.RESULT_NO_PERMISSIONS;
}
log.debug(" tokenResponse.getErrorType() : " + tokenResponse.getErrorType());
String accessToken = tokenResponse.getAccessToken();
log.debug(" accessToken : " + accessToken);
// 2. Validate the access token
// ValidateTokenClient validateTokenClient = new
// ValidateTokenClient(applicationConfiguration.getOxAuthValidateTokenUrl());
// ValidateTokenResponse response3 = validateTokenClient
// .execValidateToken(accessToken);
log.debug(" validating AccessToken ");
String validateUrl = applicationConfiguration.getOxAuthTokenValidationUrl();
ValidateTokenClient validateTokenClient = new ValidateTokenClient(validateUrl);
ValidateTokenResponse response3 = validateTokenClient.execValidateToken(accessToken);
log.debug(" response3.getStatus() : " + response3.getStatus());
log.debug("validate check session status:" + response3.getStatus());
if (response3.getErrorDescription() != null) {
log.debug("validate token status message:" + response3.getErrorDescription());
}
if (response3.getStatus() == 200) {
log.info("Session validation successful. User is logged in");
String userInfoEndPoint = applicationConfiguration.getOxAuthUserInfo();
UserInfoClient userInfoClient = new UserInfoClient(userInfoEndPoint);
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);
this.oauthData.setHost(oxAuthHost);
// Determine uid
List<String> uidValues = userInfoResponse.getClaims().get(JwtClaimName.USER_NAME);
if ((uidValues == null) || (uidValues.size() == 0)) {
log.error("User info response doesn't contains uid claim");
return OxTrustConstants.RESULT_NO_PERMISSIONS;
}
this.oauthData.setUserUid(uidValues.get(0));
this.oauthData.setAccessToken(accessToken);
this.oauthData.setAccessTokenExpirationInSeconds(response3.getExpiresIn());
this.oauthData.setScopes(scopes);
this.oauthData.setIdToken(idToken);
this.oauthData.setSessionState(sessionState);
log.info("user uid:" + oauthData.getUserUid());
// Create session scope authentication service
Component.getInstance(AuthenticationSessionService.class);
return OxTrustConstants.RESULT_SUCCESS;
}
log.info("Token validation failed. User is NOT logged in");
return OxTrustConstants.RESULT_NO_PERMISSIONS;
}