Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016

1,236 views

Published on

Grails 3.1 enhances and improves the profile system introduced in Grails 3.0. One of the new profiles ease the creation and development of applications where the the front-end is an Angular JS application, and the backend is a Grails REST API.

In this session, Álvaro (member of the Grails team at OCI, Grails committer and author of several plugins) will demonstrate how to use the Angular profile to create an application using Grails 3.1, Angular JS and Spring Security REST.

The workshop is published at http://alvarosanchez.github.io/grails-angularjs-springsecurity-workshop/

Published in: Software
  • Be the first to comment

Creating applications with Grails, Angular JS and Spring Security - GR8Conf US 2016

  1. 1. Creating applications with Grails, Angular JS and Spring Security Álvaro Sánchez-Mariscal
  2. 2. Álvaro Sánchez-Mariscal Software Engineer Grails Development Team sanchezmariscala@ociweb.com
  3. 3. OCI is the new home of Grails More at ociweb.com/grails
  4. 4. The workshop http://bit.ly/grails-angular-gr8conf
  5. 5. Creating REST API’s with Grails
  6. 6. The REST Profile • Targeted at building REST applications. • REST Specific plugins and commands. • No GSP, asset pipeline, UI plugins. • JSON / Markup views instead.
  7. 7. The REST Profile • Profile specific commands: • create-domain-resource - creates an @Resource domain • create-restful-controller - creates a RestfulController
  8. 8. The REST Profile • Statically compiled, extensible JSON views: json.person { name "bob" } {"person":{"name":"bob"}}
  9. 9. Create the project $ grails create-app -profile rest-api -features hibernate5,json-views todo | Application created at /tmp/todo
  10. 10. Create a domain resource $ grails create-domain-resource todo | Created grails-app/domain/todo/Todo.groovy | Created src/test/groovy/todo/TodoSpec.groovy
  11. 11. REST Domain class package com.example
 
 import grails.rest.Resource
 
 @Resource(uri = '/todos')
 class Todo {
 
 String description
 boolean completed
 
 }
  12. 12. Demo - REST API
  13. 13. Create a restful controller $ grails create-restful-controller todo.Todo | Created grails-app/controllers/todo/TodoController.groovy
  14. 14. RESTful Controller package com.example
 
 import grails.rest.RestfulController
 
 class TodoController extends RestfulController {
 
 static responseFormats = ['json']
 
 TodoController() {
 super(Todo)
 }
 
 def pending() {
 respond Todo.findAllByCompleted(false), view: 'index'
 }
 }
  15. 15. JSON View import com.example.Todo
 
 model {
 Todo todo
 }
 
 json {
 hal.links(todo)
 id todo.id
 description todo.description
 completed todo.completed
 }
  16. 16. Demo - JSON Views
  17. 17. Working with the Angular JS profile
  18. 18. The Angular JS Profile • Extends the REST profile. • Adds project setup for AngularJS. • Code generation for AngularJS. • Scaffolding available via plugin.
  19. 19. 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
  20. 20. Create the project $ grails create-app -profile angular -features hibernate5,json-views todo | Application created at /tmp/todo
  21. 21. Scaffold all the things! $ grails ng-generate-all todo.Todo
  22. 22. Demo - AngularJS scaffolding
  23. 23. Adding Security with Spring Security REST
  24. 24. 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.
  25. 25. Create the project $ grails create-app -profile angular -features hibernate,json-views,security todo | Application created at /tmp/todo
  26. 26. 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);
  27. 27. Demo - All together
  28. 28. Thank you! Álvaro Sánchez-Mariscal

×