I am encountering a problem in my micronaut app. If I want to visit '/index', I have to login. When I'am logged in the '/index' page is correctly displayed. At this very moment if I want to visit the '/periods/list/my' I'am redirirect to the 'unauthorized-target-url'
The strangest thing is that visiting '/index' is still ok... Could this be a security configuration problem ?
HomeController.java
@Secured(SecurityRule.IS_ANONYMOUS)
@Controller("/")
public class HomeController {
@Get("/")
@View("index")
@Secured(SecurityRule.IS_AUTHENTICATED)
Map<String, Object> index(@Nullable Principal principal) {
...
}
}
PeriodController.java
@Controller("/periods")
@Secured(SecurityRule.IS_ANONYMOUS)
public class PeriodController {
@Get("/list/my")
@View("periods/my")
@Secured(SecurityRule.IS_AUTHENTICATED)
Map<String, Object> myPeriods(@Nullable Principal principal) {
...
}
}
application.yml
micronaut:
application:
name: ws
security:
enabled: true
endpoints:
login:
enabled: true
logout:
enabled: true
path: '/logout'
interceptUrlMap:
-
pattern: /public/**
httpMethod: GET
access:
- isAnonymous()
session:
enabled: true
login-success-target-url: '/'
login-failure-target-url: '/login/authFailed'
logout-target-url: '/'
unauthorized-target-url: '/unauthorized'
forbidden-target-url: '/forbidden'
session:
http:
cookie: true
header: false
logs
11:47:20.134 [nioEventLoopGroup-1-4] DEBUG i.m.h.server.netty.NettyHttpServer - Server localhost:8080 Received Request: GET /periods/list/my
11:47:20.134 [nioEventLoopGroup-1-4] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matching route GET - /periods/list/my
11:47:20.134 [nioEventLoopGroup-1-4] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matched route GET - /periods/list/my to controller class com.gvhr.controllers.PeriodController
11:47:20.135 [pool-1-thread-4] DEBUG i.m.s.t.reader.HttpHeaderTokenReader - Looking for bearer token in Authorization header
11:47:20.135 [pool-1-thread-4] DEBUG i.m.s.t.TokenAuthenticationFetcher - Unauthenticated request GET, /periods/list/my, no token found.
11:47:20.135 [pool-1-thread-4] DEBUG i.m.security.filters.SecurityFilter - Failure to authenticate request. GET /periods/list/my.
11:47:20.135 [pool-1-thread-4] DEBUG i.m.security.filters.SecurityFilter - Unauthorized request GET /periods/list/my. The rule provider io.micronaut.security.rules.SecuredAnnotationRule rejected the request.
11:47:20.149 [nioEventLoopGroup-1-5] DEBUG i.m.h.server.netty.NettyHttpServer - Server localhost:8080 Received Request: GET /unauthorized
11:47:20.149 [nioEventLoopGroup-1-5] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matching route GET - /unauthorized
11:47:20.149 [nioEventLoopGroup-1-5] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matched route GET - /unauthorized to controller class com.gvhr.controllers.HomeController