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);
}
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);
}
}
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");
}
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");
}
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");
}
Aggregations