Skip to content

Commit

Permalink
Fix the problem of NoSuchMethod error of auth provider (#66)
Browse files Browse the repository at this point in the history
Current plugin cannot work due to removal of method `run.halo.app.infra.SystemSetting.AuthProvider#enabled` in Halo 2.20.0. This PR fixes it by using new alternative method `run.halo.app.infra.SystemSetting.AuthProvider#states`.

/kind bug

```release-note
修复无法在 Halo 2.20.0 中正常登录的问题
```
  • Loading branch information
JohnNiang authored Oct 14, 2024
1 parent 5853d41 commit 6076665
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull;
Expand Down Expand Up @@ -160,7 +161,10 @@ Mono<Set<String>> fetchEnabledProviders() {
return client.fetch(ConfigMap.class, SystemSetting.SYSTEM_CONFIG)
.map(configMap -> {
var authProvider = getAuthProvider(configMap);
return authProvider.getEnabled();
return authProvider.getStates().stream()
.filter(SystemSetting.AuthProviderState::isEnabled)
.map(SystemSetting.AuthProviderState::getName)
.collect(Collectors.toSet());
})
.defaultIfEmpty(Set.of());
}
Expand All @@ -180,8 +184,8 @@ private static SystemSetting.AuthProvider getAuthProvider(ConfigMap configMap) {
authProvider = JsonUtils.jsonToObject(providerGroup, SystemSetting.AuthProvider.class);
}

if (authProvider.getEnabled() == null) {
authProvider.setEnabled(new HashSet<>());
if (authProvider.getStates() == null) {
authProvider.setStates(List.of());
}
return authProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ void findByRegistrationId_withValidId_returnsClientRegistration() {
.thenReturn(Mono.just(authProvider));
ConfigMap systemConfig = new ConfigMap();
systemConfig.setData(Map.of(SystemSetting.AuthProvider.GROUP,
"{\"enabled\":[\"github\"]}"));
"""
{"states":[{"name":"github", "enabled":true}]}\
"""));
when(client.fetch(eq(ConfigMap.class), eq(SystemSetting.SYSTEM_CONFIG)))
.thenReturn(Mono.just(systemConfig));

Expand Down

0 comments on commit 6076665

Please sign in to comment.