File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
db-service/src/main/java/ch/semafor/intens/ws/service Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 2121import org .slf4j .LoggerFactory ;
2222import org .springframework .beans .factory .annotation .Autowired ;
2323import org .springframework .beans .factory .annotation .Value ;
24+ import org .springframework .core .env .Environment ;
2425import org .springframework .http .HttpStatus ;
2526import org .springframework .security .core .Authentication ;
2627import org .springframework .security .core .authority .SimpleGrantedAuthority ;
@@ -64,6 +65,9 @@ public class BaseServiceImpl {
6465 UserService userService ;
6566 @ Autowired
6667 AppProperties properties ;
68+ @ Autowired
69+ private Environment environment ;
70+
6771
6872 @ Autowired
6973 StatelessKieSession kieSession ;
@@ -408,7 +412,13 @@ public Owner getOwner() {
408412
409413 // oauth2 mode
410414 Map <String , Object > principalAttrs = SecurityUtils .getPrincipalAttributes ();
411- if ( principalAttrs .containsKey ("given_name" ) || principalAttrs .containsKey (properties .getOauthUserField ())){
415+ String key = "given_name" ;
416+ for (String profile : environment .getActiveProfiles ()) {
417+ if (profile .equals ("oauth2" )) {
418+ key = properties .getOauthUserField ();
419+ }
420+ }
421+ if ( principalAttrs .containsKey (key )){
412422 Collection <SimpleGrantedAuthority > authorities = (Collection <SimpleGrantedAuthority >)
413423 SecurityContextHolder .getContext ().getAuthentication ().getAuthorities ();
414424 Owner currentUser = new Owner ((String ) principalAttrs .get (properties .getOauthUserField ()));
You can’t perform that action at this time.
0 commit comments