1

I am working on an application which has backend in Grails and front end in Angular Js.

Can anyone suggest best architect/design to implement Role based User authentication. For example Student users should be able to see specific pages and content areas on some pages, Teachers should see some other contents but Admin should be able to see all of pages and contents.

enter image description here

as in image, in one page, one module is Teacher only, other is Admin only and one block is for everyone.

Thanks in advance.

Muhammad Abid
  • 791
  • 3
  • 12

2 Answers2

2

You could use Spring Security Core with Spring Security Rest for authentication through an Ajax call with Angular JS.

quindimildev
  • 1,278
  • 8
  • 19
0

In short, you could use the resolve attribute of the $routeProvider like this:

module.config(["$routeProvider", "AuthorizationsService",
  function($routeProvider, AuthorizationsService) {
    $routeProvider
    .when("/home", {
      templateUrl: '/home.html',
      controller: 'homeController',
      resolve: {
        access: // call a authorization service
      }
    })
    .when("/student", {
      templateUrl: '/admin.html',
      controller: 'adminController',
      resolve: {
        access: // call a authorization service
      }
    })
    .otherwise({
      redirectTo: "/home"
    });

And you would need to create a factory that resolves or rejects the user (this would do all the heavy lifting)

module.factory("AuthorizationsService", ["$q",
  function($q) {

   var checkPermission = function {
     // check and set the permissions from http service
     // return a promise
   };

   return {
     checkPermission: checkPermission
   }
}]);

This article has a more extensive explaination. You might also find this SO article useful

Community
  • 1
  • 1
sjokkogutten
  • 1,746
  • 2
  • 18
  • 22