message: Add check for OidcUserAuthority
diff: @@ -24,13 +24,19 @@ import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator;
  import org.springframework.security.oauth2.core.OAuth2TokenValidator;
  import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
  import org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority;
  -import org.springframework.security.oauth2.jwt.*;
  +import org.springframework.security.oauth2.jwt.Jwt;
  +import org.springframework.security.oauth2.jwt.JwtDecoder;
  +import org.springframework.security.oauth2.jwt.JwtDecoders;
  +import org.springframework.security.oauth2.jwt.JwtValidators;
  +import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
  import org.springframework.security.provisioning.InMemoryUserDetailsManager;
  import org.springframework.util.StringUtils;
  +import java.util.ArrayList;
  import java.util.Collection;
  import java.util.HashSet;
  import java.util.List;
  +import java.util.Map;
  import java.util.Set;
  import static java.util.stream.Collectors.toList;
  @@ -114,18 +120,24 @@ public class OAuth2SecurityConfiguration extends WebSecurityConfigurerAdapter {
  Set<GrantedAuthority> mappedAuthorities = new HashSet<>();
  authorities.forEach(authority -> {
  + OidcUserInfo userInfo = null;
  + // Check for OidcUserAuthority because Spring Security 5.2 returns
  + // each scope as a GrantedAuthority, which we don't care about.
  + if (authority instanceof OidcUserAuthority) {
  OidcUserAuthority oidcUserAuthority = (OidcUserAuthority) authority;
  - OidcUserInfo userInfo = oidcUserAuthority.getUserInfo();
  + userInfo = oidcUserAuthority.getUserInfo();
  + }
  if (userInfo == null) {
  mappedAuthorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.USER));
  } else {
  - Collection<String> groups = (Collection<String>) userInfo.getClaims().get("groups");
  - if (groups == null) {
  - groups = (Collection<String>) userInfo.getClaims().get("roles");
  - }
  + Map<String, Object> claims = userInfo.getClaims();
  + Collection<String> groups = (Collection<String>) claims.getOrDefault("groups",
  + claims.getOrDefault("roles", new ArrayList<>()));
  +
  mappedAuthorities.addAll(groups.stream()
  .filter(group -> group.startsWith("ROLE_"))
  - .map(SimpleGrantedAuthority::new).collect(toList()));
  + .map(SimpleGrantedAuthority::new)
  + .collect(toList()));
  }
  });
  @@ -135,8 +147,7 @@ public class OAuth2SecurityConfiguration extends WebSecurityConfigurerAdapter {
  @Bean
  JwtDecoder jwtDecoder() {
  - NimbusJwtDecoderJwkSupport jwtDecoder = (NimbusJwtDecoderJwkSupport)
  - JwtDecoders.fromOidcIssuerLocation(issuerUri);
  + NimbusJwtDecoder jwtDecoder = (NimbusJwtDecoder) JwtDecoders.fromOidcIssuerLocation(issuerUri);
  OAuth2TokenValidator<Jwt> audienceValidator = new AudienceValidator(jHipsterProperties.getSecurity().getOauth2().getAudience());
  OAuth2TokenValidator<Jwt> withIssuer = JwtValidators.createDefaultWithIssuer(issuerUri);
  