tmix-security

See https://github.com/01org/tmix-security

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-route.min.js"></script>
<script src="http://01org.github.io/tmix-security/tmix-security.js"></script>
<script type="text/ng-template" id="no-security.html">
    No security; public view.
</script>
<script type="text/ng-template" id="allowed.html">
    This route is allowed.
</script>
<script type="text/ng-template" id="not-allowed.html">
    This route is not allowed (you should not see this; should redirect to /forbidden).
</script>
<script type="text/ng-template" id="forbidden.html">
    Access forbidden.
</script>
<div ng-app="example">
    <ul>
        <li><a href="#/">No Security</a></li>
        <li><a href="#/allowed">Allowed</a></li>
        <li><a href="#/not-allowed">Not Allowed</a></li>
    </ul>
    <ng-view></ng-view>
</div>

CSS

li {
    display: inline-block;
}
ul{
    padding: 0;
}

JavaScript

var app = angular.module('example', ['ngRoute', 'tmix']);
app.config(function ($routeProvider, tmixSecurityProvider) {

    // setup default permissions
    tmixSecurityProvider.setDefaultPermissions(['/allowed']);

    // set up routes, note 'resolve'
    $routeProvider.when('/', {
        templateUrl: 'no-security.html',
    })
        .when('/allowed', {
        templateUrl: 'allowed.html',
        resolve: tmixSecurityProvider.authorizeOrRedirect
    })
        .when('/not-allowed', {
        templateUrl: 'not-allowed.html',
        resolve: tmixSecurityProvider.authorizeOrRedirect
    })
        .when('/forbidden', {
        templateUrl: 'forbidden.html'
    })
        .otherwise({
        redirectTo: '/'
    });
    
});