Skip to content

Commit

Permalink
fix: insufficient permissions after login using OAuth2 (#42)
Browse files Browse the repository at this point in the history
### What this PR does?
修复 Halo 2.12 版本后使用此插件提供的 OAuth2 登陆无权限的问题

Fixes #41 

```release-note
修复 Halo 2.12 版本后使用此插件提供的 OAuth2 登陆无权限的问题
```
  • Loading branch information
guqing committed Mar 11, 2024
1 parent c5fa0ba commit 94c7c39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id "io.freefair.lombok" version "8.0.1"
id "run.halo.plugin.devtools" version "0.0.4"
id "run.halo.plugin.devtools" version "0.0.7"
}

group 'run.halo.oauth'
Expand Down Expand Up @@ -29,5 +29,5 @@ test {
}

halo {
version = '2.6.0'
version = '2.13'
}
3 changes: 3 additions & 0 deletions src/main/java/run/halo/oauth/DefaultUserDetailsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
@Component
@RequiredArgsConstructor
public class DefaultUserDetailsService implements ReactiveUserDetailsService {
public static final String AUTHENTICATED_ROLE_NAME = "authenticated";
public static final String ANONYMOUS_ROLE_NAME = "anonymous";

private final ReactiveExtensionClient client;

Expand All @@ -35,6 +37,7 @@ public Mono<UserDetails> findByUsername(String username) {
return listRoleRefs(subject)
.filter(this::isRoleRef)
.map(RoleBinding.RoleRef::getName)
.concatWithValues(AUTHENTICATED_ROLE_NAME, ANONYMOUS_ROLE_NAME)
.collectList()
.map(roleNames -> org.springframework.security.core.userdetails.User.builder()
.username(username)
Expand Down

0 comments on commit 94c7c39

Please sign in to comment.