Search in sources :

Example 1 with UserInfoRequestValidator

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");
    }
}
Also used : UserInfoRequestValidator(org.wso2.carbon.identity.oauth.user.UserInfoRequestValidator) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with UserInfoRequestValidator

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();
}
Also used : UserInfoEndpointException(org.wso2.carbon.identity.oauth.user.UserInfoEndpointException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) UserInfoRequestValidator(org.wso2.carbon.identity.oauth.user.UserInfoRequestValidator) UserInfoResponseBuilder(org.wso2.carbon.identity.oauth.user.UserInfoResponseBuilder) UserInfoResponseBuilder(org.wso2.carbon.identity.oauth.user.UserInfoResponseBuilder) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UserInfoAccessTokenValidator(org.wso2.carbon.identity.oauth.user.UserInfoAccessTokenValidator) OAuth2TokenValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Aggregations

UserInfoRequestValidator (org.wso2.carbon.identity.oauth.user.UserInfoRequestValidator)2 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 UserInfoAccessTokenValidator (org.wso2.carbon.identity.oauth.user.UserInfoAccessTokenValidator)1 UserInfoEndpointException (org.wso2.carbon.identity.oauth.user.UserInfoEndpointException)1 UserInfoResponseBuilder (org.wso2.carbon.identity.oauth.user.UserInfoResponseBuilder)1 OAuth2TokenValidationResponseDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO)1