Tabnine Logo
org.springframework.security.oauth2.client.oidc.userinfo
Code IndexAdd Tabnine to your IDE (free)

How to use org.springframework.security.oauth2.client.oidc.userinfo

Best Java code snippets using org.springframework.security.oauth2.client.oidc.userinfo (Showing top 20 results out of 315)

origin: spring-projects/spring-security

private ReactiveOAuth2UserService<OidcUserRequest, OidcUser> getOidcUserService() {
  ResolvableType type = ResolvableType.forClassWithGenerics(ReactiveOAuth2UserService.class, OidcUserRequest.class, OidcUser.class);
  ReactiveOAuth2UserService<OidcUserRequest, OidcUser> bean = getBeanOrNull(type);
  if (bean == null) {
    return new OidcReactiveOAuth2UserService();
  }
  return bean;
}
origin: spring-projects/spring-security

@Test
public void shouldRetrieveUserInfoWhenEndpointDefinedAndScopesOverlapThenTrue() {
  assertThat(OidcUserRequestUtils.shouldRetrieveUserInfo(userRequest())).isTrue();
}
origin: spring-projects/spring-security

@Before
public void setup() {
  this.userService.setOauth2UserService(this.oauth2UserService);
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserInfoSuccessResponseAndUserInfoSubjectNotSameAsIdTokenSubjectThenThrowOAuth2AuthenticationException() {
  this.exception.expect(OAuth2AuthenticationException.class);
  this.exception.expectMessage(containsString("invalid_user_info_response"));
  String userInfoResponse = "{\n" +
    "	\"sub\": \"other-subject\"\n" +
    "}\n";
  this.server.enqueue(jsonResponse(userInfoResponse));
  String userInfoUri = this.server.url("/user").toString();
  ClientRegistration clientRegistration = this.clientRegistrationBuilder
      .userInfoUri(userInfoUri).build();
  this.userService.loadUser(new OidcUserRequest(clientRegistration, this.accessToken, this.idToken));
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserInfoUriIsNullThenUserInfoEndpointNotRequested() {
  OidcUser user = this.userService.loadUser(
    new OidcUserRequest(this.clientRegistrationBuilder.build(), this.accessToken, this.idToken));
  assertThat(user.getUserInfo()).isNull();
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserRequestIsNullThenThrowIllegalArgumentException() {
  this.exception.expect(IllegalArgumentException.class);
  this.userService.loadUser(null);
}
origin: spring-projects/spring-security

  private OidcUserRequest userRequest() {
    return new OidcUserRequest(this.registration.build(), this.accessToken, this.idToken);
  }
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserInfoUriNullThenUserInfoNotRetrieved() {
  this.registration.userInfoUri(null);
  OidcUser user = this.userService.loadUser(userRequest()).block();
  assertThat(user.getUserInfo()).isNull();
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserInfoSuccessResponseAndUserInfoSubjectIsNullThenThrowOAuth2AuthenticationException() {
  this.exception.expect(OAuth2AuthenticationException.class);
  this.exception.expectMessage(containsString("invalid_user_info_response"));
  String userInfoResponse = "{\n" +
      "	\"email\": \"full_name@provider.com\",\n" +
      "	\"name\": \"full name\"\n" +
      "}\n";
  this.server.enqueue(jsonResponse(userInfoResponse));
  String userInfoUri = this.server.url("/user").toString();
  ClientRegistration clientRegistration = this.clientRegistrationBuilder
      .userInfoUri(userInfoUri)
      .userNameAttributeName(StandardClaimNames.EMAIL).build();
  this.userService.loadUser(new OidcUserRequest(clientRegistration, this.accessToken, this.idToken));
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserInfoUriInvalidThenThrowOAuth2AuthenticationException() {
  this.exception.expect(OAuth2AuthenticationException.class);
  this.exception.expectMessage(containsString("[invalid_user_info_response] An error occurred while attempting to retrieve the UserInfo Resource"));
  String userInfoUri = "http://invalid-provider.com/user";
  ClientRegistration clientRegistration = this.clientRegistrationBuilder
      .userInfoUri(userInfoUri).build();
  this.userService.loadUser(new OidcUserRequest(clientRegistration, this.accessToken, this.idToken));
}
origin: spring-projects/spring-security

@Test
public void shouldRetrieveUserInfoWhenNoUserInfoUriThenFalse() {
  this.registration.userInfoUri(null);
  assertThat(OidcUserRequestUtils.shouldRetrieveUserInfo(userRequest())).isFalse();
}
origin: spring-projects/spring-security

  private OidcUserRequest userRequest() {
    return new OidcUserRequest(this.registration.build(), this.accessToken, this.idToken);
  }
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserInfoSuccessResponseThenAcceptHeaderJson() throws Exception {
  String userInfoResponse = "{\n" +
      "	\"sub\": \"subject1\",\n" +
      "   \"name\": \"first last\",\n" +
      "   \"given_name\": \"first\",\n" +
      "   \"family_name\": \"last\",\n" +
      "   \"preferred_username\": \"user1\",\n" +
      "   \"email\": \"user1@example.com\"\n" +
      "}\n";
  this.server.enqueue(jsonResponse(userInfoResponse));
  String userInfoUri = this.server.url("/user").toString();
  ClientRegistration clientRegistration = this.clientRegistrationBuilder
      .userInfoUri(userInfoUri).build();
  this.userService.loadUser(new OidcUserRequest(clientRegistration, this.accessToken, this.idToken));
  assertThat(this.server.takeRequest(1, TimeUnit.SECONDS).getHeader(HttpHeaders.ACCEPT))
      .isEqualTo(MediaType.APPLICATION_JSON_VALUE);
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenAuthorizedScopesDoesNotContainUserInfoScopesThenUserInfoEndpointNotRequested() {
  ClientRegistration clientRegistration = this.clientRegistrationBuilder
      .userInfoUri("http://provider.com/user").build();
  Set<String> authorizedScopes = new LinkedHashSet<>(Arrays.asList("scope1", "scope2"));
  OAuth2AccessToken accessToken = new OAuth2AccessToken(
      OAuth2AccessToken.TokenType.BEARER, "access-token",
      Instant.MIN, Instant.MAX, authorizedScopes);
  OidcUser user = this.userService.loadUser(
    new OidcUserRequest(clientRegistration, accessToken, this.idToken));
  assertThat(user.getUserInfo()).isNull();
}
origin: spring-projects/spring-security

@Test
public void shouldRetrieveUserInfoWhenDifferentScopesThenFalse() {
  this.registration.scope("notintoken");
  assertThat(OidcUserRequestUtils.shouldRetrieveUserInfo(userRequest())).isFalse();
}
origin: spring-projects/spring-security

@Test
public void constructorWhenClientRegistrationIsNullThenThrowIllegalArgumentException() {
  assertThatThrownBy(() -> new OidcUserRequest(null, this.accessToken, this.idToken))
      .isInstanceOf(IllegalArgumentException.class);
}
origin: spring-projects/spring-security

  @Test
  public void loadUserWhenUserInfoSuccessResponseInvalidThenThrowOAuth2AuthenticationException() {
    this.exception.expect(OAuth2AuthenticationException.class);
    this.exception.expectMessage(containsString("[invalid_user_info_response] An error occurred while attempting to retrieve the UserInfo Resource"));

    String userInfoResponse = "{\n" +
      "	\"sub\": \"subject1\",\n" +
      "   \"name\": \"first last\",\n" +
      "   \"given_name\": \"first\",\n" +
      "   \"family_name\": \"last\",\n" +
      "   \"preferred_username\": \"user1\",\n" +
      "   \"email\": \"user1@example.com\"\n";
//            "}\n";        // Make the JSON invalid/malformed
    this.server.enqueue(jsonResponse(userInfoResponse));

    String userInfoUri = this.server.url("/user").toString();

    ClientRegistration clientRegistration = this.clientRegistrationBuilder
        .userInfoUri(userInfoUri).build();

    this.userService.loadUser(new OidcUserRequest(clientRegistration, this.accessToken, this.idToken));
  }

origin: spring-projects/spring-security

@Test
public void loadUserWhenServerErrorThenThrowOAuth2AuthenticationException() {
  this.exception.expect(OAuth2AuthenticationException.class);
  this.exception.expectMessage(containsString("[invalid_user_info_response] An error occurred while attempting to retrieve the UserInfo Resource: 500 Server Error"));
  this.server.enqueue(new MockResponse().setResponseCode(500));
  String userInfoUri = server.url("/user").toString();
  ClientRegistration clientRegistration = this.clientRegistrationBuilder
      .userInfoUri(userInfoUri).build();
  this.userService.loadUser(new OidcUserRequest(clientRegistration, this.accessToken, this.idToken));
}
origin: spring-projects/spring-security

@Test
public void shouldRetrieveUserInfoWhenNotAuthorizationCodeThenFalse() {
  this.registration.authorizationGrantType(AuthorizationGrantType.IMPLICIT);
  assertThat(OidcUserRequestUtils.shouldRetrieveUserInfo(userRequest())).isFalse();
}
origin: spring-projects/spring-security

@Test
public void constructorWhenIdTokenIsNullThenThrowIllegalArgumentException() {
  assertThatThrownBy(() -> new OidcUserRequest(this.clientRegistration, this.accessToken, null))
      .isInstanceOf(IllegalArgumentException.class);
}
org.springframework.security.oauth2.client.oidc.userinfo

Most used classes

  • OidcUserService
  • OidcUserRequest
  • OidcReactiveOAuth2UserService
  • OidcUserRequestUtils
    Utilities for working with the OidcUserRequest
  • OidcReactiveOAuth2UserServiceTests
  • OidcUserServiceTests
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now