Micronaut all routes forbidden

Viewed 500

I created an app in Micronaut using JWT tokens for security

mn create-app --features=security-jwt,data-jdbc,reactor,graalvm example.micronaut.micronautguide --build=gradle --lang=java

And now all my routes are forbidden. How to exclude certain routes (ie. login) from JWT token checking. I tried both without annotation and with annotation IS_ANONYMOUS

package logfetcher;

import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Produces;
import io.micronaut.http.annotation.Produces;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
@Controller("/log")
public class LogFethcerContoller


{
    @Get
    @Secured(
            SecurityRule.IS_ANONYMOUS   )
    @Produces(MediaType.TEXT_PLAIN)
    public String index() {
        return "Hello World";
    }

    @Get("log")
    public String index1() {
        return "Hello World";
    }

}

I get 401 on both routes. How can I have routes that do not need the JWT token.

1 Answers

I get 401 on both routes.

From micronaut-projects.github.io/micronaut-security/3.2.0/guide/#gettingStarted...

By default Micronaut returns HTTP Status Unauthorized (401) for any endpoint invocation. Routes must be explicitly allowed through the provided mechanisms.

Question:

How can I have routes that do not need the JWT token.

There are a number of ways.

From micronaut-projects.github.io/micronaut-security/3.2.0/guide/#securityRule...

The decision to allow access to a particular endpoint to anonymous or authenticated users is determined by a collection of Security Rules.

@PermitAll is one way to do it. Others are documented at the links above.

Related