1. Home
  2. /
  3. Micronaut-security
  4. /
  5. Micronaut Security Simple REST API

Micronaut Security Simple REST API - Micronaut-security Typing CST Test

Loading…

Micronaut Security Simple REST API — Micronaut-security Code

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 Language Guide

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.

Primary Use Cases

  • ▸Secure REST APIs with JWT or OAuth2
  • ▸Microservices with role-based access control
  • ▸Serverless applications requiring authentication
  • ▸Integrating with LDAP, OAuth2, or SAML identity providers
  • ▸Declarative security for endpoints and methods

Notable Features

  • ▸JWT authentication and token validation
  • ▸OAuth2 and OpenID Connect integration
  • ▸Role-based and attribute-based access control
  • ▸Reactive security for non-blocking applications
  • ▸Annotation-driven security configuration

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.

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher