Skip to content

Commit 6c036b7

Browse files
authored
fix: create subject tag (#762)
1 parent 6a938a9 commit 6c036b7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

server/src/main/java/run/ikaros/server/core/tag/TagEndpoint.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder;
66

77
import io.swagger.v3.oas.annotations.enums.ParameterIn;
8+
import java.security.Principal;
89
import java.util.Optional;
910
import lombok.extern.slf4j.Slf4j;
1011
import org.springdoc.webflux.core.fn.SpringdocRouteBuilder;
11-
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
1212
import org.springframework.stereotype.Component;
1313
import org.springframework.util.Assert;
1414
import org.springframework.web.reactive.function.server.RouterFunction;
@@ -151,10 +151,11 @@ private Mono<ServerResponse> listAttachmentTagsByAttachmentId(ServerRequest requ
151151

152152
private Mono<ServerResponse> create(ServerRequest request) {
153153
return request.bodyToMono(Tag.class)
154-
.flatMap(tag -> userService.getUserIdFromSecurityContext()
155-
.map(tag::setUserId)
156-
.onErrorResume(AuthenticationCredentialsNotFoundException.class,
157-
e -> Mono.just(tag)))
154+
.flatMap(tag -> request.principal()
155+
.map(Principal::getName)
156+
.flatMap(userService::getUserByUsername)
157+
.map(user -> user.entity().getId())
158+
.map(tag::setUserId))
158159
.flatMap(tagService::create)
159160
.flatMap(tag -> ServerResponse.ok().bodyValue(tag));
160161
}

0 commit comments

Comments
 (0)