Search in sources :

Example 6 with UserInfo

use of com.nimbusds.openid.connect.sdk.claims.UserInfo in project di-authentication-api by alphagov.

the class IPVCallbackHandlerTest method shouldNotInvokeSPOTAndThrowWhenVTMMismatch.

@Test
void shouldNotInvokeSPOTAndThrowWhenVTMMismatch() {
    usingValidSession();
    usingValidClientSession();
    var userIdentityUserInfo = new UserInfo(new JSONObject(Map.of("sub", "sub-val", "vot", "P2", "vtm", OIDC_BASE_URL + "/invalid-trustmark")));
    var runtimeException = assertThrows(RuntimeException.class, () -> makeHandlerRequest(getApiGatewayProxyRequestEvent(userIdentityUserInfo)), "Expected to throw exception");
    assertThat(runtimeException.getMessage(), equalTo("IPV trustmark is invalid"));
    verifyAuditEvent(IPVAuditableEvent.IPV_AUTHORISATION_RESPONSE_RECEIVED);
    verifyAuditEvent(IPVAuditableEvent.IPV_SUCCESSFUL_TOKEN_RESPONSE_RECEIVED);
    verifyAuditEvent(IPVAuditableEvent.IPV_SUCCESSFUL_IDENTITY_RESPONSE_RECEIVED);
    verifyNoMoreInteractions(auditService);
    verifyNoInteractions(awsSqsClient);
    verifyNoInteractions(dynamoIdentityService);
}
Also used : JSONObject(net.minidev.json.JSONObject) UserInfo(com.nimbusds.openid.connect.sdk.claims.UserInfo) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with UserInfo

use of com.nimbusds.openid.connect.sdk.claims.UserInfo in project timbuctoo by HuygensING.

the class OpenIdConnectUserValidator method getUserFromAccessToken.

@Override
public Optional<User> getUserFromAccessToken(String accessToken) throws UserValidationException {
    if (StringUtils.isBlank(accessToken)) {
        return Optional.empty();
    }
    final User local = users.getIfPresent(accessToken);
    if (local != null) {
        return Optional.of(local);
    }
    try {
        final Optional<UserInfo> userInfoOpt = openIdClient.getUserInfo(accessToken);
        if (userInfoOpt.isEmpty()) {
            return Optional.empty();
        }
        final UserInfo userInfo = userInfoOpt.get();
        final String subject = userInfo.getSubject().getValue();
        final Optional<User> user = userStore.userFor(subject);
        if (user.isPresent()) {
            user.ifPresent(value -> users.put(accessToken, value));
            return user;
        } else {
            final User newUser = userStore.saveNew(userInfo.getNickname(), subject);
            users.put(subject, newUser);
            return Optional.of(newUser);
        }
    } catch (AuthenticationUnavailableException | IOException | ParseException e) {
        throw new UserValidationException(e);
    }
}
Also used : UserValidationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException) AuthenticationUnavailableException(nl.knaw.huygens.timbuctoo.security.exceptions.AuthenticationUnavailableException) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) UserInfo(com.nimbusds.openid.connect.sdk.claims.UserInfo) IOException(java.io.IOException) ParseException(com.nimbusds.oauth2.sdk.ParseException)

Example 8 with UserInfo

use of com.nimbusds.openid.connect.sdk.claims.UserInfo in project product-is by wso2.

the class OIDCSubAttributeTestCase method testResourceOwnerGrantValidateUserInfo.

@Test(groups = "wso2.is", description = "Validate sub attribute in user info call", dependsOnMethods = "testResourceOwnerGrantSendAuthRequestPost")
public void testResourceOwnerGrantValidateUserInfo() throws Exception {
    UserInfoResponse userInfoResponse = getUserInfoResponse();
    if (!userInfoResponse.indicatesSuccess()) {
        Assert.fail("User info API call failed.");
    }
    // Extract the claims
    UserInfo userInfo = userInfoResponse.toSuccessResponse().getUserInfo();
    Assert.assertEquals(userInfo.getSubject().getValue(), userId, "Subject received in the user info response is different from user id");
}
Also used : UserInfo(com.nimbusds.openid.connect.sdk.claims.UserInfo) UserInfoResponse(com.nimbusds.openid.connect.sdk.UserInfoResponse) Test(org.testng.annotations.Test) OAuth2ServiceAbstractIntegrationTest(org.wso2.identity.integration.test.oauth2.OAuth2ServiceAbstractIntegrationTest)

Example 9 with UserInfo

use of com.nimbusds.openid.connect.sdk.claims.UserInfo in project product-is by wso2.

the class OIDCSubAttributeTestCase method testAuthCodeGrantValidateUserInfo.

@Test(groups = "wso2.is", description = "Validate sub attribute in user info call", dependsOnMethods = "testAuthCodeGrantValidateSub")
public void testAuthCodeGrantValidateUserInfo() throws Exception {
    UserInfoResponse userInfoResponse = getUserInfoResponse();
    if (!userInfoResponse.indicatesSuccess()) {
        Assert.fail("User info API call failed.");
    }
    // Extract the claims
    UserInfo userInfo = userInfoResponse.toSuccessResponse().getUserInfo();
    Assert.assertEquals(userInfo.getSubject().getValue(), userId, "Subject received in the user info response is different from user id");
}
Also used : UserInfo(com.nimbusds.openid.connect.sdk.claims.UserInfo) UserInfoResponse(com.nimbusds.openid.connect.sdk.UserInfoResponse) Test(org.testng.annotations.Test) OAuth2ServiceAbstractIntegrationTest(org.wso2.identity.integration.test.oauth2.OAuth2ServiceAbstractIntegrationTest)

Example 10 with UserInfo

use of com.nimbusds.openid.connect.sdk.claims.UserInfo in project product-is by wso2.

the class OIDCSubAttributeTestCase method testImplicitGrantValidateUserInfo.

@Test(groups = "wso2.is", description = "Validate sub attribute in user info call", dependsOnMethods = "testImplicitGrantValidateSub")
public void testImplicitGrantValidateUserInfo() throws Exception {
    UserInfoResponse userInfoResponse = getUserInfoResponse();
    if (!userInfoResponse.indicatesSuccess()) {
        Assert.fail("User info API call failed.");
    }
    // Extract the claims
    UserInfo userInfo = userInfoResponse.toSuccessResponse().getUserInfo();
    Assert.assertEquals(userInfo.getSubject().getValue(), userId, "Subject received in the user info response is different from user id");
}
Also used : UserInfo(com.nimbusds.openid.connect.sdk.claims.UserInfo) UserInfoResponse(com.nimbusds.openid.connect.sdk.UserInfoResponse) Test(org.testng.annotations.Test) OAuth2ServiceAbstractIntegrationTest(org.wso2.identity.integration.test.oauth2.OAuth2ServiceAbstractIntegrationTest)

Aggregations

UserInfo (com.nimbusds.openid.connect.sdk.claims.UserInfo)18 Test (org.junit.jupiter.api.Test)5 Subject (com.nimbusds.oauth2.sdk.id.Subject)3 AccessToken (com.nimbusds.oauth2.sdk.token.AccessToken)3 BearerAccessToken (com.nimbusds.oauth2.sdk.token.BearerAccessToken)3 UserInfoResponse (com.nimbusds.openid.connect.sdk.UserInfoResponse)3 JSONObject (net.minidev.json.JSONObject)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Test (org.testng.annotations.Test)3 OAuth2ServiceAbstractIntegrationTest (org.wso2.identity.integration.test.oauth2.OAuth2ServiceAbstractIntegrationTest)3 AccessTokenInfo (uk.gov.di.authentication.oidc.entity.AccessTokenInfo)3 AuthorizationCode (com.nimbusds.oauth2.sdk.AuthorizationCode)2 UserInfoErrorResponse (com.nimbusds.openid.connect.sdk.UserInfoErrorResponse)2 AccessTokenStore (uk.gov.di.authentication.shared.entity.AccessTokenStore)2 APIGatewayProxyRequestEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent)1 APIGatewayProxyResponseEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent)1 User (com.authlete.common.types.User)1 Federation (com.authlete.jaxrs.server.federation.Federation)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JWT (com.nimbusds.jwt.JWT)1