use of org.wso2.carbon.identity.oauth.user.UserInfoRequestValidator in project identity-inbound-auth-oauth by wso2-extensions.
the class UserInfoEndpointConfigTest method testGetUserInfoRequestValidator.
@Test(dataProvider = "getUserInfoRequestValidator")
public void testGetUserInfoRequestValidator(String validatorClass, Class validatorClassType, boolean isClassExisting) throws Exception {
mockStatic(EndpointUtil.class);
when(EndpointUtil.getUserInfoRequestValidator()).thenReturn(validatorClass);
UserInfoRequestValidator userInfoRequestValidator = UserInfoEndpointConfig.getInstance().getUserInfoRequestValidator();
if (isClassExisting) {
assertNotNull(userInfoRequestValidator, "UserInfoRequest builder should not be null for class " + validatorClass);
assertEquals(validatorClassType, userInfoRequestValidator.getClass(), "Expected type of UserInfoValidator" + " was not found");
} else {
assertNull(userInfoRequestValidator, "Non-existing or invalid class passed. Hence validator should be " + "null");
}
}
use of org.wso2.carbon.identity.oauth.user.UserInfoRequestValidator in project identity-inbound-auth-oauth by wso2-extensions.
the class OpenIDConnectUserEndpoint method getUserClaims.
@GET
@Path("/")
@Consumes("application/x-www-form-urlencoded")
public Response getUserClaims(@Context HttpServletRequest request) throws OAuthSystemException {
String userInfoResponse;
String userInfoResponseContentType;
try {
// validate the request
UserInfoRequestValidator requestValidator = UserInfoEndpointConfig.getInstance().getUserInfoRequestValidator();
String accessToken = requestValidator.validateRequest(request);
// validate the access token
UserInfoAccessTokenValidator tokenValidator = UserInfoEndpointConfig.getInstance().getUserInfoAccessTokenValidator();
OAuth2TokenValidationResponseDTO tokenResponse = tokenValidator.validateToken(accessToken, request);
// build the claims
// ToDO - Validate the grant type to be implicit or authorization_code before retrieving claims
UserInfoResponseBuilder userInfoResponseBuilder = UserInfoEndpointConfig.getInstance().getUserInfoResponseBuilder();
userInfoResponse = userInfoResponseBuilder.getResponseString(tokenResponse);
userInfoResponseContentType = getUserInfoResponseMediaType(userInfoResponseBuilder);
} catch (UserInfoEndpointException e) {
return handleError(e);
} catch (OAuthSystemException e) {
log.error("UserInfoEndpoint Failed", e);
throw new OAuthSystemException("UserInfoEndpoint Failed");
}
ResponseBuilder respBuilder = getResponseBuilderWithCacheControlHeaders();
if (userInfoResponse != null) {
return respBuilder.type(userInfoResponseContentType).entity(userInfoResponse).build();
}
return respBuilder.build();
}
Aggregations