creating applications with grails, angular js and spring security - gr8conf us 2016
TRANSCRIPT
![Page 1: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/1.jpg)
Creating applications with Grails, Angular JS and Spring Security
Álvaro Sánchez-Mariscal
![Page 2: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/2.jpg)
Álvaro Sánchez-Mariscal Software Engineer Grails Development Team [email protected]
![Page 3: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/3.jpg)
![Page 6: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/6.jpg)
Creating REST API’s with Grails
![Page 7: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/7.jpg)
The REST Profile
• Targeted at building REST applications.
• REST Specific plugins and commands.
• No GSP, asset pipeline, UI plugins.
• JSON / Markup views instead.
![Page 8: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/8.jpg)
The REST Profile
• Profile specific commands:
• create-domain-resource - creates an
@Resource domain
• create-restful-controller - creates a RestfulController
![Page 9: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/9.jpg)
The REST Profile• Statically compiled, extensible JSON views:
json.person{name"bob"}
{"person":{"name":"bob"}}
![Page 10: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/10.jpg)
Create the project
$ grails create-app -profile rest-api -features hibernate5,json-views todo
| Application created at /tmp/todo
![Page 11: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/11.jpg)
Create a domain resource
$ grails create-domain-resource todo
| Created grails-app/domain/todo/Todo.groovy| Created src/test/groovy/todo/TodoSpec.groovy
![Page 12: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/12.jpg)
REST Domain classpackage com.exampleimport grails.rest.Resource@Resource(uri = '/todos') class Todo { String description boolean completed}
![Page 13: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/13.jpg)
Demo - REST API
![Page 14: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/14.jpg)
Create a restful controller
$ grails create-restful-controller todo.Todo
| Created grails-app/controllers/todo/TodoController.groovy
![Page 15: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/15.jpg)
RESTful Controllerpackage com.exampleimport grails.rest.RestfulControllerclass TodoController extends RestfulController { static responseFormats = ['json'] TodoController() { super(Todo) } def pending() { respond Todo.findAllByCompleted(false), view: 'index' } }
![Page 16: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/16.jpg)
JSON Viewimport com.example.Todomodel { Todo todo} json { hal.links(todo) id todo.id description todo.description completed todo.completed}
![Page 17: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/17.jpg)
Demo - JSON Views
![Page 18: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/18.jpg)
Working with the Angular JS profile
![Page 19: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/19.jpg)
The Angular JS Profile
• Extends the REST profile.
• Adds project setup for AngularJS.
• Code generation for AngularJS.
• Scaffolding available via plugin.
![Page 20: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/20.jpg)
The Angular JS Profile• Profile specific commands:
• create-ng-controller
• create-ng-service
• create-ng-domain
• create-ng-directive
• create-ng-component
• create-ng-module
![Page 21: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/21.jpg)
Create the project
$ grails create-app -profile angular -features hibernate5,json-views todo
| Application created at /tmp/todo
![Page 22: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/22.jpg)
Scaffold all the things!
$ grails ng-generate-all todo.Todo
![Page 23: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/23.jpg)
Demo - AngularJS scaffolding
![Page 24: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/24.jpg)
Adding Security with Spring Security REST
![Page 25: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/25.jpg)
Spring Security REST• Compatibility layer over Spring Security Core.
• Login and logout REST endpoints.
• Token validation filter.
• Stateless by default, with JWT (signed and encrypted)
• Memcached, Redis, GORM and Grails Cache token storages.
• Implicit grant support through 3rd party providers.
• RFC 6750 Bearer Token support.
![Page 26: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/26.jpg)
Create the project
$ grails create-app -profile angular -features hibernate,json-views,security todo
| Application created at /tmp/todo
![Page 27: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/27.jpg)
The interceptor
angular .module("todo") .factory('authInterceptor', function ($rootScope, $window) { return { request: function (config) { config.headers = config.headers || {}; if ($window.sessionStorage.token) { config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token; } return config; } }; }) .config(function ($httpProvider) { $httpProvider.interceptors.push('authInterceptor'); }) .controller("TodoController", TodoController);
![Page 28: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/28.jpg)
Demo - All together
![Page 29: Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016](https://reader035.vdocuments.site/reader035/viewer/2022062523/587142e51a28ab55588b4dc9/html5/thumbnails/29.jpg)
Thank you!
Álvaro Sánchez-Mariscal