0

当我们添加 Micronaut 安全性时,所有 URL 都受到保护。在使用@Secured(SecurityRule.IS_ANONYMOUS)注释时仍然面临 401 异常

public interface ISubCategoryOperation {
    @Get("/{categoryId}/sub-category")
    @Secured(SecurityRule.IS_ANONYMOUS)
    Maybe<?> get(@NotNull String categoryId);
}

接口方法用表示@Secured(SecurityRule.IS_ANONYMOUS)但仍不能转到控制器方法

Http客户端

@Client(id="feteBirdProduct", path = "/category")
public interface ISubCategoryClient extends ISubCategoryOperation{
}

控制器

@Controller("/category/{categoryId}/sub-category")
public class SubCategoryController implements ISubCategoryOperation {
    @Override
    public Maybe<?> get(@PathVariable String categoryId) {
        return Maybe.Just(null);
    }

卷曲

curl -X GET "http://localhost:8080/api/v1/category/60236833af7a1d49478d2bef/sub-category" -H  "accept: application/json"

Http 客户端日志

15:17:18.504 [default-nioEventLoopGroup-1-6] DEBUG i.m.h.client.netty.DefaultHttpClient - Sending HTTP GET to http://localhost:8081/category/60236833af7a1d49478d2bef/sub-category
15:17:18.535 [default-nioEventLoopGroup-1-6] DEBUG i.m.h.client.netty.DefaultHttpClient - Received response 401 from http://localhost:8081/category/60236833af7a1d49478d2bef/sub-category
4

0 回答 0