Securing the endpoints

To secure the REST server, we will use a filter just like we used in Chapter 25, Taking Notes with Monumentum. We'll start by defining the annotation that will specify which endpoints need to be secured, as follows:

    @NameBinding 
    @Retention(RetentionPolicy.RUNTIME) 
    @Target({ElementType.TYPE, ElementType.METHOD}) 
    public @interface Secure {} 

We will apply this preceding annotation to each secured endpoint (annotations condensed to one line for brevity):

 @GET @Path("conversations") @Secure public Response getConversations() { ... @POST @Path("conversations") @Secure public Response sendMessage(Message message) throws InterruptedException { ... @GET @Path("status") @Produces(SseFeature.SERVER_SENT_EVENTS) @Secure public ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.