Code Monkey home page Code Monkey logo

raml-to-jaxrs-jsr-250-plugin's Introduction

JSR-250 annotations for raml-for-jax-rs

With raml-for-jax-rs 3.0 the plugin mechanism to enhance the generation of JAX-RS resources is redesigned. This allows to write custom plugins enabling generation of dynamic content for the created JAX-RS resources. This project is one of the first using this extension.

When generating JAX-RS resources these should be secured by using JSR-250 annotations like @DenyAll, @PermitAll and @RolesAllowed. This project provides the plugins for raml-for-jax-rs to enable this feature for RAML files.

Maven Configuration

To enable the plugin it needs to be declared as dependency to raml-to-jaxrs-maven-plugin like this:

<build>
  <plugins>
    <plugin>
      <groupId>org.raml.jaxrs</groupId>
      <artifactId>raml-to-jaxrs-maven-plugin</artifactId>
      <version>3.0.2</version>
      <dependencies>
        <dependency>
          <groupId>io.mathan.raml</groupId>
          <artifactId>raml-to-jaxrs-jsr-250-plugin</artifactId>
          <version>1.0.0</version>
        </dependency>
      </dependencies>
      ...
    </plugin>
  </plugins>
</build>

Available plugins

The supported plugins use the prefix jsr250. The names match the JSR-250 annotation names.

JSR-250 annotation Plugin name
@DenyAll jsr250.denyAll
@PermitAll jsr250.permitAll
@RolesAllowed jsr250.rolesAllowed

Usage

To use the plugins you have to declare them on resource level or resource method level. For jsr250.denyAll and jsr250.permitAll the declaration of the plugin name is sufficient. When using jsr250.rolesAllowed the roles to allow have to specified as arguments to the plugin.

The following sample RAML permits the access on resource level to all roles. The access to the get method is limited to the role SpecialRole and the access to the put method is denied. Please not that any of the plugins can be declared on resource or resource method level.

/sample:
  (ramltojaxrs.resources):
    plugins:
      - name: jsr250.permitAll
  get:
    (ramltojaxrs.methods):
      plugins:
        - name: jsr250.rolesAllowed
          arguments: [SpecialRole]
    responses:
      200:
        body:
          type: BodyType
  put:
    (ramltojaxrs.methods):
      plugins:
        - name: jsr250.denyAll
    body:
      type: BodyType
    responses:
      200:
        body:
          type: BodyType

The result will then look like this:

@Path("/sample")
@PermitAll
public interface Sample {
  @GET
  @Produces("application/json")
  @RolesAllowed({"SpecialRole"})
  @Consumes
  GetSampleResponse getSample();

  @PUT
  @Consumes("application/json")
  @DenyAll
  PutSampleResponse putSample(String entity);
}

raml-to-jaxrs-jsr-250-plugin's People

Contributors

reallyinsane avatar

Watchers

 avatar  avatar

raml-to-jaxrs-jsr-250-plugin's Issues

Support for RAML 0.8

Hello,
Am currently trying to inject JSR-250 annotations using your plugin but am having issues while generating the java code from the RAML. Maven complains the moment i put in the plugins attribute.

Does this plugin work with RAML 0.8 or only 1.0 upwards?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.