Skip to content

Commit bbdd32e

Browse files
author
kaleidox
committed
simplify user id obtaining again
1 parent d0b8f41 commit bbdd32e

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

run/intellij/Prod Debug.run.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<option name="HOST" value="gman.comroid.org"/>
88
<option name="PORT" value="5005"/>
99
<option name="AUTO_RESTART" value="false"/>
10+
<RunnerSettings RunnerId="Debug">
11+
<option name="DEBUG_PORT" value="5005"/>
12+
<option name="LOCAL" value="false"/>
13+
</RunnerSettings>
1014
<method v="2"/>
1115
</configuration>
1216
</component>

src/main/java/de/kaleidox/workbench/model/config/OAuth2Info.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ public record OAuth2Info(
88
String redirectUrl,
99
String authorizationUrl,
1010
String tokenUrl,
11-
String userInfoUrl,
12-
String userNameAttributeName
11+
String userInfoUrl
1312
) {}

src/main/java/de/kaleidox/workbench/web/SecurityConfig.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class SecurityConfig extends DefaultOAuth2UserService {
4848
.authorizationUri(info.authorizationUrl())
4949
.tokenUri(info.tokenUrl())
5050
.userInfoUri(info.userInfoUrl())
51-
.userNameAttributeName(info.userNameAttributeName().replaceAll("\\.", ""))
51+
.userNameAttributeName("userid")
5252
.build())
5353
.toArray(ClientRegistration[]::new);
5454
return registrations.length == 0 ? null : new InMemoryClientRegistrationRepository(registrations);
@@ -99,18 +99,15 @@ public String getUsername() {
9999
@EventListener
100100
public void on(ApplicationStartedEvent ignored) {
101101
setAttributesConverter(input -> source -> {
102-
var userNameAttributeName = input.getClientRegistration()
103-
.getProviderDetails()
104-
.getUserInfoEndpoint()
105-
.getUserNameAttributeName();
106-
if (!userNameAttributeName.contains(".")) return source;
107-
108-
var userId = new SpelExpressionParser().parseRaw(userNameAttributeName)
102+
var userId = new SpelExpressionParser().parseRaw("ocs.data.id")
109103
.getValue(SimpleEvaluationContext.forPropertyAccessors(new MapAccessor())
110104
.withRootObject(source)
111105
.build());
112106

113-
source.put(userNameAttributeName.replaceAll("\\.", ""), userId);
107+
source.put(input.getClientRegistration()
108+
.getProviderDetails()
109+
.getUserInfoEndpoint()
110+
.getUserNameAttributeName(), userId);
114111
return source;
115112
});
116113
}

0 commit comments

Comments
 (0)