44import org .springframework .context .annotation .Configuration ;
55import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
66import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
7+ import org .springframework .security .core .GrantedAuthority ;
8+ import org .springframework .security .oauth2 .client .userinfo .DefaultOAuth2UserService ;
9+ import org .springframework .security .oauth2 .client .userinfo .OAuth2UserRequest ;
10+ import org .springframework .security .oauth2 .client .userinfo .OAuth2UserService ;
11+ import org .springframework .security .oauth2 .core .OAuth2AccessToken ;
12+ import org .springframework .security .oauth2 .core .user .DefaultOAuth2User ;
13+ import org .springframework .security .oauth2 .core .user .OAuth2User ;
714import org .springframework .security .web .SecurityFilterChain ;
815
16+ import java .util .HashSet ;
17+ import java .util .Set ;
18+
919@ Configuration
1020@ EnableWebSecurity
1121public class WebSecurityConfig {
@@ -21,4 +31,30 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
2131
2232 return http .build ();
2333 }
34+
35+ private OAuth2UserService <OAuth2UserRequest , OAuth2User > oidcUserService () {
36+ final OAuth2UserService delegate = new DefaultOAuth2UserService ();
37+
38+ return (userRequest ) -> {
39+ OAuth2User user = delegate .loadUser (userRequest );
40+
41+ OAuth2AccessToken accessToken = userRequest .getAccessToken ();
42+ Set <GrantedAuthority > mappedAuthorities = new HashSet <>();
43+
44+
45+
46+ Object rbac = user .getAttributes ().get ("nationalrbacaccess" );
47+
48+
49+
50+ // TODO
51+ // 1) Fetch the authority information from the protected resource using accessToken
52+ // 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
53+
54+ // 3) Create a copy of oidcUser but use the mappedAuthorities instead
55+ user = new DefaultOAuth2User (mappedAuthorities , user .getAttributes (), "name" );
56+
57+ return user ;
58+ };
59+ }
2460}
0 commit comments