UA Security State Manager

State manager service for angular-ua-security package

View project onGitHub

Introduction

The angular-ua-security-state-manager package is a set of functions that can be used in conjunction with angular-ua-security to provide authorization for state transitions when using the angular-ui-router package. It does so by listening for the $stateChangeStart event raised by angular-ui-router before making state transitions. The event handler determines whether the new state (toState) requires authorization (by evaluating whether the state has a roles property), and if so, checks whether the current user has any of the required roles. If the user is authorized, the state transition proceeds, otherwise, it is halted and the user is redirected to a configurable unauthorized state. The package also offers a number of other convienence functions, such as:

  • loggedIn: Returns boolean whether the current user is logged in
  • authorizedToTransitionTo: Returns boolean whether the current user is authorized to move to a state
  • stateRequiresAuthorization: Returns boolean whether the state requires authorization
  • goToHomeState: Uses ui-router's \$state service to transition to the home state
  • goToLoginState: Uses ui-router's \$state service to transition to the login state
  • goToUnauthorizedState: Uses ui-router's \$state service to transition to the unauthorized state

Repository

This repository serves two purposes, 1) to build the angular-ua-security-state-manager package and 2) to provide an example of how to use the state manager service with angular-ua-security package.

Installation

  • Bower bower install angular-ua-security-state-manager
  • Git git clone git@github.com:dspies/ua-security-state-manager.git

Configuration

State Manager

  • stateManagerProvider.setLoginStateName: the name of the state to transition to when the goToLoginState() is called.
  • stateManagerProvider.setHomeStateName: the name of the state to transition to when the goToHomeState() is called.
  • stateManagerProvider.setUnauthorizedStateName: the name of the state to transition to when the goToUnauthorizedState() is called.

Example

angular.module('your-app', ['ua.security'])
  .config(function (stateManagerProvider) {
    stateManagerProvider.setLoginStateName('myCustomLogin');
    stateManagerProvider.setHomeStateName('myCustomHome');
    stateManagerProvider.setUnauthorizedStateName('myCustomUnauthorized');
  });

Builds

This package uses Grunt to perform unit tests and builds.

Building the Library

In order to build the angular-ua-security-state-manager.js library, run the command below. This will create the uncompressed (dev) version and the minified version with a sourcemap file.

grunt build

Building the Application

In order to build the full web application, run the command below. This will create the full HTML application with a mocked backend API for login to demonstrate how the library may be used.

grunt build-app

Authors and Contributors

Problems

Feel free to contact me with any questions or suggestions. I will update the ua-security-state-manager wiki in future with a roadmap. If you have problems, please file an issue or better yet, file a pull request.