Tabnine Logo
OidcReactiveOAuth2UserService
Code IndexAdd Tabnine to your IDE (free)

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

Best Java code snippets using org.springframework.security.oauth2.client.oidc.userinfo.OidcReactiveOAuth2UserService (Showing top 12 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

@Override
public Mono<OidcUser> loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
  Assert.notNull(userRequest, "userRequest cannot be null");
  return getUserInfo(userRequest)
    .map(userInfo -> new OidcUserAuthority(userRequest.getIdToken(), userInfo))
    .defaultIfEmpty(new OidcUserAuthority(userRequest.getIdToken(), null))
    .map(authority -> {
      OidcUserInfo userInfo = authority.getUserInfo();
      Set<GrantedAuthority> authorities = new HashSet<>();
      authorities.add(authority);
      String userNameAttributeName = userRequest.getClientRegistration()
            .getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName();
      if (StringUtils.hasText(userNameAttributeName)) {
        return new DefaultOidcUser(authorities, userRequest.getIdToken(), userInfo, userNameAttributeName);
      } else {
        return new DefaultOidcUser(authorities, userRequest.getIdToken(), userInfo);
      }
    });
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenOAuth2UserThenUserInfoNotNull() {
  Map<String, Object> attributes = new HashMap<>();
  attributes.put(StandardClaimNames.SUB, "sub123");
  attributes.put("user", "rob");
  OAuth2User oauth2User = new DefaultOAuth2User(AuthorityUtils.createAuthorityList("ROLE_USER"),
      attributes, "user");
  when(this.oauth2UserService.loadUser(any())).thenReturn(Mono.just(oauth2User));
  assertThat(this.userService.loadUser(userRequest()).block().getUserInfo()).isNotNull();
}
origin: spring-projects/spring-security

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

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: apache/servicemix-bundles

@Override
public Mono<OidcUser> loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
  Assert.notNull(userRequest, "userRequest cannot be null");
  return getUserInfo(userRequest)
    .map(userInfo -> new OidcUserAuthority(userRequest.getIdToken(), userInfo))
    .defaultIfEmpty(new OidcUserAuthority(userRequest.getIdToken(), null))
    .map(authority -> {
      OidcUserInfo userInfo = authority.getUserInfo();
      Set<GrantedAuthority> authorities = new HashSet<>();
      authorities.add(authority);
      String userNameAttributeName = userRequest.getClientRegistration()
            .getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName();
      if (StringUtils.hasText(userNameAttributeName)) {
        return new DefaultOidcUser(authorities, userRequest.getIdToken(), userInfo, userNameAttributeName);
      } else {
        return new DefaultOidcUser(authorities, userRequest.getIdToken(), userInfo);
      }
    });
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenOAuth2UserAndUser() {
  this.registration.userNameAttributeName("user");
  Map<String, Object> attributes = new HashMap<>();
  attributes.put(StandardClaimNames.SUB, "sub123");
  attributes.put("user", "rob");
  OAuth2User oauth2User = new DefaultOAuth2User(AuthorityUtils.createAuthorityList("ROLE_USER"),
      attributes, "user");
  when(this.oauth2UserService.loadUser(any())).thenReturn(Mono.just(oauth2User));
  assertThat(this.userService.loadUser(userRequest()).block().getName()).isEqualTo("rob");
}
origin: apache/servicemix-bundles

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 loadUserWhenOAuth2UserEmptyThenNullUserInfo() {
  when(this.oauth2UserService.loadUser(any())).thenReturn(Mono.empty());
  OidcUser user = this.userService.loadUser(userRequest()).block();
  assertThat(user.getUserInfo()).isNull();
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenOAuth2UserSubjectNotEqualThenOAuth2AuthenticationException() {
  Map<String, Object> attributes = new HashMap<>();
  attributes.put(StandardClaimNames.SUB, "not-equal");
  attributes.put("user", "rob");
  OAuth2User oauth2User = new DefaultOAuth2User(AuthorityUtils.createAuthorityList("ROLE_USER"),
      attributes, "user");
  when(this.oauth2UserService.loadUser(any())).thenReturn(Mono.just(oauth2User));
  assertThatCode(() -> this.userService.loadUser(userRequest()).block())
      .isInstanceOf(OAuth2AuthenticationException.class);
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenOAuth2UserSubjectNullThenOAuth2AuthenticationException() {
  OAuth2User oauth2User = new DefaultOAuth2User(AuthorityUtils.createAuthorityList("ROLE_USER"), Collections.singletonMap("user", "rob"), "user");
  when(this.oauth2UserService.loadUser(any())).thenReturn(Mono.just(oauth2User));
  assertThatCode(() -> this.userService.loadUser(userRequest()).block())
    .isInstanceOf(OAuth2AuthenticationException.class);
}
origin: spring-projects/spring-security

@Test
public void loadUserWhenUserInfoUriNullThenUserInfoNotRetrieved() {
  this.registration.userInfoUri(null);
  OidcUser user = this.userService.loadUser(userRequest()).block();
  assertThat(user.getUserInfo()).isNull();
}
org.springframework.security.oauth2.client.oidc.userinfoOidcReactiveOAuth2UserService

Javadoc

An implementation of an ReactiveOAuth2UserService that supports OpenID Connect 1.0 Provider's.

Most used methods

  • <init>
  • getUserInfo
  • loadUser
  • setOauth2UserService

Popular in Java

  • Finding current android device location
  • getResourceAsStream (ClassLoader)
  • onCreateOptionsMenu (Activity)
  • startActivity (Activity)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • JTextField (javax.swing)
  • CodeWhisperer alternatives
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