2727import static com .azure .spring .autoconfigure .aad .AADOAuth2ErrorCode .CONDITIONAL_ACCESS_POLICY ;
2828import static com .azure .spring .autoconfigure .aad .AADOAuth2ErrorCode .INVALID_REQUEST ;
2929import static com .azure .spring .autoconfigure .aad .AADOAuth2ErrorCode .SERVER_SERVER ;
30+ import static com .azure .spring .autoconfigure .aad .Constants .DEFAULT_AUTHORITY_SET ;
3031import static com .azure .spring .autoconfigure .aad .Constants .ROLE_PREFIX ;
3132
3233/**
@@ -49,7 +50,7 @@ public AADOAuth2UserService(AADAuthenticationProperties aadAuthenticationPropert
4950 public OidcUser loadUser (OidcUserRequest userRequest ) throws OAuth2AuthenticationException {
5051 // Delegate to the default implementation for loading a user
5152 OidcUser oidcUser = oidcUserService .loadUser (userRequest );
52- final Set <SimpleGrantedAuthority > authorities ;
53+ Set <SimpleGrantedAuthority > authorities ;
5354 try {
5455 // https://github.com/MicrosoftDocs/azure-docs/issues/8121#issuecomment-387090099
5556 // In AAD App Registration configure oauth2AllowImplicitFlow to true
@@ -71,14 +72,12 @@ public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2Authenticatio
7172 .filter (aadAuthenticationProperties ::isAllowedGroup )
7273 .map (group -> ROLE_PREFIX + group )
7374 .collect (Collectors .toSet ());
74- Set <String > allRoles = oidcUser .getAuthorities ()
75- .stream ()
76- .map (GrantedAuthority ::getAuthority )
77- .collect (Collectors .toSet ());
78- allRoles .addAll (groupRoles );
79- authorities = allRoles .stream ()
80- .map (SimpleGrantedAuthority ::new )
81- .collect (Collectors .toSet ());
75+ authorities = groupRoles .stream ()
76+ .map (SimpleGrantedAuthority ::new )
77+ .collect (Collectors .toSet ());
78+ if (authorities .isEmpty ()) {
79+ authorities = DEFAULT_AUTHORITY_SET ;
80+ }
8281 } catch (MalformedURLException e ) {
8382 throw toOAuth2AuthenticationException (INVALID_REQUEST , "Failed to acquire token for Graph API." , e );
8483 } catch (ServiceUnavailableException e ) {
0 commit comments