Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple Micronaut REST API secured with JWT authentication and role-based access control.
@Controller("/todos")
@Secured(SecurityRule.IS_AUTHENTICATED)
public class TodoController {
@Get
public List<String> listTodos() {
return Arrays.asList("Task 1", "Task 2");
}
@Post
@Secured({"ROLE_USER"})
public String addTodo(@Body String todo) {
return todo;
}
}
// application.yml
micronaut:
security:
enabled: true
token:
jwt:
signatures:
secret:
generator:
secret: 'verySecretKey'Micronaut Security is a set of modules within the Micronaut framework that provides authentication, authorization, and security features for building secure, reactive microservices and serverless applications in Java, Kotlin, and Groovy.
Origin & Creator
Created by the Micronaut team (Object Computing, Inc.) starting in 2018 as part of the Micronaut framework.
Industrial Note
Micronaut Security is particularly favored in microservices, serverless functions, and cloud-native applications where low-latency, reactive security enforcement is critical.