Skip to content

Commit 0fea507

Browse files
committed
fix: token key based on profile
1 parent f2a90b9 commit 0fea507

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

db-service/src/main/java/ch/semafor/intens/ws/service/BaseServiceImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.slf4j.LoggerFactory;
2222
import org.springframework.beans.factory.annotation.Autowired;
2323
import org.springframework.beans.factory.annotation.Value;
24+
import org.springframework.core.env.Environment;
2425
import org.springframework.http.HttpStatus;
2526
import org.springframework.security.core.Authentication;
2627
import 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()));

0 commit comments

Comments
 (0)