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; }
assertEquals(response2.getStatus(), 200, "Unexpected response code: " + response2.getStatus()); assertNotNull(response2.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(response2.getClaim(JwtClaimName.NAME)); assertNotNull(response2.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(response2.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(response2.getClaim(JwtClaimName.EMAIL)); assertNotNull(response2.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(response2.getClaim(JwtClaimName.LOCALE)); assertNotNull(response2.getClaim(JwtClaimName.ADDRESS)); assertNull(response2.getClaim("org_name")); assertNull(response2.getClaim("work_phone"));
assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.BIRTHDATE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GENDER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.MIDDLE_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NICKNAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PREFERRED_USERNAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PROFILE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.WEBSITE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL_VERIFIED)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PHONE_NUMBER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PHONE_NUMBER_VERIFIED)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.USER_NAME)); assertNull(userInfoResponse.getClaim("org_name")); assertNull(userInfoResponse.getClaim("work_phone")); assertEquals(userInfoResponse.getStatus(), 400, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(userInfoResponse.getErrorDescription(), "Unexpected result: errorDescription not found");
@Test public void requestUserInfoInvalidRequest() throws Exception { showTitle("requestUserInfoInvalidRequest"); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); UserInfoResponse response = userInfoClient.execUserInfo(null); showClient(userInfoClient); assertEquals(response.getStatus(), 400, "Unexpected response code: " + response.getStatus()); assertNotNull(response.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(response.getErrorDescription(), "Unexpected result: errorDescription not found"); }
setResponse(new UserInfoResponse(status)); getResponse().setEntity(entity); getResponse().setHeaders(clientResponse.getMetadata()); if (StringUtils.isNotBlank(entity)) { List<Object> contentType = clientResponse.getHeaders().get("Content-Type"); byte[] sharedSymmetricKey = sharedKey != null ? sharedKey.getBytes(Util.UTF8_STRING_ENCODING) : null; Jwe jwe = Jwe.parse(entity, privateKey, sharedSymmetricKey); getResponse().setClaims(jwe.getClaims().toMap()); } else { Jwt jwt = Jwt.parse(entity); getResponse().setClaims(jwt.getClaims().toMap()); getResponse().setErrorType(UserInfoErrorResponseType.fromString(jsonObj.getString("error"))); jsonObj.remove("error"); getResponse().setErrorDescription(jsonObj.getString("error_description")); jsonObj.remove("error_description"); getResponse().setErrorUri(jsonObj.getString("error_uri")); jsonObj.remove("error_uri"); getResponse().getClaims().put(key, values);
assertEquals(userInfoResponse.getStatus(), 403); assertEquals(userInfoResponse.getErrorType(), UserInfoErrorResponseType.INSUFFICIENT_SCOPE);
oAuthData.setHost(oAuthHost); List<String> uidValues = userInfoResponse.getClaims().get(JwtClaimName.USER_NAME); if ((uidValues == null) || (uidValues.size() == 0)) { log.error("User infor response doesn't contains uid claim");
protected String getFirstClaim(final UserInfoResponse userInfoResponse, final String claimName) { final List<String> claims = userInfoResponse.getClaim(claimName); if ((claims == null) || claims.isEmpty()) { return null; } return claims.get(0); }
@Test public void requestUserInfoInvalidToken() throws Exception { showTitle("requestUserInfoInvalidToken"); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); UserInfoResponse response = userInfoClient.execUserInfo("INVALID_ACCESS_TOKEN"); showClient(userInfoClient); assertEquals(response.getStatus(), 400, "Unexpected response code: " + response.getStatus()); assertNotNull(response.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(response.getErrorDescription(), "Unexpected result: errorDescription not found"); }
private UserInfoResponse requestUserInfo(String accessToken) throws Exception { UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); userInfoClient.setExecutor(clientExecutor(true)); UserInfoResponse response2 = userInfoClient.execUserInfo(accessToken); assertNotNull(response2.getClaim(JwtClaimName.EMAIL)); return response2; }
assertEquals(response2.getStatus(), 200, "Unexpected response code: " + response2.getStatus()); assertNotNull(response2.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(response2.getClaim(JwtClaimName.NAME)); assertNotNull(response2.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(response2.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(response2.getClaim(JwtClaimName.EMAIL)); assertNotNull(response2.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(response2.getClaim(JwtClaimName.LOCALE)); assertNotNull(response2.getClaim(JwtClaimName.ADDRESS)); assertNull(response2.getClaim("phone_mobile_number"));
assertEquals(userInfoResponse1.getStatus(), 200, "Unexpected response code: " + userInfoResponse1.getStatus()); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.BIRTHDATE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.GENDER)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.MIDDLE_NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.NICKNAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PREFERRED_USERNAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PROFILE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.WEBSITE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.EMAIL_VERIFIED)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PHONE_NUMBER)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PHONE_NUMBER_VERIFIED)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.ADDRESS)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.LOCALE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.USER_NAME)); assertNull(userInfoResponse1.getClaim("org_name")); assertNull(userInfoResponse1.getClaim("work_phone")); assertEquals(userInfoResponse2.getStatus(), 400, "Unexpected response code: " + userInfoResponse2.getStatus()); assertNotNull(userInfoResponse2.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(userInfoResponse2.getErrorDescription(), "Unexpected result: errorDescription not found");
assertEquals(userInfoResponse.getStatus(), 403, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(userInfoResponse.getErrorDescription(), "Unexpected result: errorDescription not found");
assertEquals(response2.getStatus(), 200, "Unexpected response code: " + response2.getStatus()); assertNotNull(response2.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(response2.getClaim(JwtClaimName.NAME)); assertNotNull(response2.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(response2.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(response2.getClaim(JwtClaimName.EMAIL)); assertNotNull(response2.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(response2.getClaim(JwtClaimName.LOCALE)); assertNotNull(response2.getClaim(JwtClaimName.ADDRESS)); assertNotNull(response2.getClaim("org_name")); assertNotNull(response2.getClaim("work_phone"));
assertEquals(userInfoResponse1.getStatus(), 200, "Unexpected response code: " + userInfoResponse1.getStatus()); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.BIRTHDATE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.GENDER)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.MIDDLE_NAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.NICKNAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PREFERRED_USERNAME)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PROFILE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.WEBSITE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.EMAIL_VERIFIED)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PHONE_NUMBER)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.PHONE_NUMBER_VERIFIED)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.ADDRESS)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.LOCALE)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse1.getClaim(JwtClaimName.USER_NAME)); assertNull(userInfoResponse1.getClaim("org_name")); assertNull(userInfoResponse1.getClaim("work_phone")); assertEquals(userInfoResponse2.getStatus(), 400, "Unexpected response code: " + userInfoResponse2.getStatus()); assertNotNull(userInfoResponse2.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(userInfoResponse2.getErrorDescription(), "Unexpected result: errorDescription not found");
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken); showClient(userInfoClient); assertEquals(userInfoResponse.getStatus(), 403, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(userInfoResponse.getErrorDescription(), "Unexpected result: errorDescription not found");
assertEquals(response2.getStatus(), 200, "Unexpected response code: " + response2.getStatus()); assertNotNull(response2.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(response2.getClaim(JwtClaimName.NAME)); assertNotNull(response2.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(response2.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(response2.getClaim(JwtClaimName.EMAIL)); assertNotNull(response2.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(response2.getClaim(JwtClaimName.LOCALE)); assertNull(response2.getClaim("org_name")); assertNull(response2.getClaim("work_phone"));
assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); assertEquals(userInfoResponse.getStatus(), 400, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(userInfoResponse.getErrorDescription(), "Unexpected result: errorDescription not found");
assertEquals(response7.getStatus(), 400, "Unexpected response code: " + response7.getStatus()); assertNotNull(response7.getErrorType(), "Unexpected result: errorType not found"); assertNotNull(response7.getErrorDescription(), "Unexpected result: errorDescription not found");
assertEquals(response2.getStatus(), 200, "Unexpected response code: " + response2.getStatus()); assertNotNull(response2.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(response2.getClaim(JwtClaimName.NAME)); assertNotNull(response2.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(response2.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(response2.getClaim(JwtClaimName.EMAIL)); assertNotNull(response2.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(response2.getClaim(JwtClaimName.LOCALE)); assertNotNull(response2.getClaim("org_name")); assertNotNull(response2.getClaim("work_phone"));