O'Reilly logo

Java 9: Building Robust Modular Applications by Jason Lee, Peter Verhas, Dr. Edward Lavieri

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling authorization requests

With our endpoints now secured, we need a way for the clients to request authorization. To do that, we'll expose a new endpoint, unsecured, of course, as follows:

 @POST @Path("authorize") @Consumes(MediaType.TEXT_PLAIN) public Response getAuthorization(String clientCode) { if (clientCode != null && clientCode.equals(deskDroidService.code)) { String jwt = Jwts.builder() .setSubject("DeskDroid") .signWith(SignatureAlgorithm.HS512, KeyGenerator.getKey( deskDroidService.getApplicationContext())) .compact(); LocalBroadcastManager.getInstance( deskDroidService.getApplicationContext()) .sendBroadcast(new Intent( DeskDroidService.CODE_ACCEPTED)); return Response.ok(jwt).build(); } return Response.status(Response.Status.UNAUTHORIZED).build(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required