认证后 Microunaut HTTP 403

Microunaut HTTP 403 after authentication

我有 2 个 micronaut 服务:usersproducts 以及前面的 Zuul 网关。

我可以登录 (users) 并发出 HTTP GET 请求 (products),但是当我尝试执行 HTTP POSTPATCH 我有一个 HTTP 403.

users/application.yaml

security:
  enabled: true 
  endpoints:
    login:
      enabled: true 
    oauth:
      enabled: true
  token:
    jwt:
      enabled: true
      signatures:
        secret:
          generator:
            secret: DB4A...
    writer:
      header:
        enabled: true
        headerName: "Authorization"
        prefix: "Bearer "
    propagation:
      enabled: true
      service-id-regex: "products|users"

products/application.yaml

security:
  enabled: true 
  token:
    jwt:
      enabled: true
      signatures:
        secret:
          validation:
            secret: DB4A...
    writer:
      header:
        enabled: true
        headerName: "Authorization"
        prefix: "Bearer "
    propagation:
      enabled: true
      service-id-regex: "products|user"

工作 HTTP 200

@Secured({"ADMIN"})
@Get("/{id}")
public HttpResponse<?> getProduct(String id)
{
... // OK
}

禁止的 HTTP 403

@Secured({"ADMIN"})
@Post("/products")
public HttpResponse<?> update(@Body List<Product> products)
{
... // FORBIDDEN
}

有人知道吗?

micronaut.version 1.3.0

问题是 Eclipse+Maven+Annotation Processing 中的错误不起作用。第一次生成 Micronaut 内部 类 后,从 Eclipse 执行 Build ProjectBuild All 不会再次 运行 注解处理。要解决这个问题,我们必须 运行 maven。

要使 Micronaut 在 Eclipse 中工作,您必须通过 Run as -> Maven Build 或命令行 运行 Maven 命令:

mvn clean compile

mvn clean test-compile

配置 maven-compiler-plugin 正确修复错误的编译。

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.1</version>
      <configuration>
        <source>11</source>
        <target>11</target>
        <release>11</release>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
        <compilerArgs>
          <arg>-parameters</arg>
        </compilerArgs>
        <annotationProcessorPaths combine.self="override">
          <path>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
          </path>
          <path>
            <groupId>io.micronaut</groupId>
            <artifactId>micronaut-core</artifactId>
            <version>3.1.4</version>
          </path>
          <path>
            <groupId>io.micronaut.security</groupId>
            <artifactId>micronaut-security-annotations</artifactId>
            <version>3.1.0</version>
          </path>
          <path>
            <groupId>io.micronaut</groupId>
            <artifactId>micronaut-inject</artifactId>
            <version>3.1.4</version>
          </path>
          <path>
            <groupId>io.micronaut</groupId>
            <artifactId>micronaut-inject-java</artifactId>
            <version>3.1.4</version>
          </path>
          <path>
            <groupId>io.micronaut</groupId>
            <artifactId>micronaut-validation</artifactId>
            <version>3.1.4</version>
          </path>
        </annotationProcessorPaths>
      </configuration>
      <executions>
        <execution>
          <id>test-compile</id>
          <goals>
            <goal>testCompile</goal>
          </goals>
          <configuration>
            <compilerArgs>
              <arg>-parameters</arg>
            </compilerArgs>
            <annotationProcessorPaths>
              <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.10</version>
              </path>
              <path>
                <groupId>io.micronaut</groupId>
                <artifactId>micronaut-inject</artifactId>
                <version>3.1.4</version>
              </path>
              <path>
                <groupId>io.micronaut</groupId>
                <artifactId>micronaut-inject-java</artifactId>
                <version>3.1.4</version>
              </path>
              <path>
                <groupId>io.micronaut</groupId>
                <artifactId>micronaut-validation</artifactId>
                <version>3.1.4</version>
              </path>
            </annotationProcessorPaths>
          </configuration>
        </execution>
      </executions>
    </plugin>