Microunaut HTTP 403 after authentication

Viewed 690

I have 2 micronaut services: users and products and a Zuul Gateway in front.

I can loggin (users) and make HTTP GET requests (products), but when I try to do a HTTP POST or PATCH I got a 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"

works HTTP 200

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

Forbidden HTTP 403

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

Someone have any idea?

micronaut.version 1.3.0

2 Answers

The problem is a Bug in Eclipse+Maven+Annotation Processing doesn't works. After generate the Micronaut inner classes the first time, the Build Project or Build All execution from Eclipse does not run Annotation Processing again. To fix that we have to run maven.

To Micronaut works in Eclipse you have to run the Maven command by Run as -> Maven Build or command line:

mvn clean compile

or

mvn clean test-compile

Configuring maven-compiler-plugin properly fix the bad compilation.

    <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>
Related