diff --git a/server/src/main/java/run/ikaros/server/core/tag/TagEndpoint.java b/server/src/main/java/run/ikaros/server/core/tag/TagEndpoint.java index a3aca79a..ead5a64b 100644 --- a/server/src/main/java/run/ikaros/server/core/tag/TagEndpoint.java +++ b/server/src/main/java/run/ikaros/server/core/tag/TagEndpoint.java @@ -5,10 +5,10 @@ import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder; import io.swagger.v3.oas.annotations.enums.ParameterIn; +import java.security.Principal; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.springdoc.webflux.core.fn.SpringdocRouteBuilder; -import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.stereotype.Component; import org.springframework.util.Assert; import org.springframework.web.reactive.function.server.RouterFunction; @@ -151,10 +151,11 @@ private Mono listAttachmentTagsByAttachmentId(ServerRequest requ private Mono create(ServerRequest request) { return request.bodyToMono(Tag.class) - .flatMap(tag -> userService.getUserIdFromSecurityContext() - .map(tag::setUserId) - .onErrorResume(AuthenticationCredentialsNotFoundException.class, - e -> Mono.just(tag))) + .flatMap(tag -> request.principal() + .map(Principal::getName) + .flatMap(userService::getUserByUsername) + .map(user -> user.entity().getId()) + .map(tag::setUserId)) .flatMap(tagService::create) .flatMap(tag -> ServerResponse.ok().bodyValue(tag)); }