text: "use strict";!function(){angular.module("ui.auth.services",[]),angular.module("ui.auth.directives",["ui.auth.services"]),angular.module("ui.auth",["ngResource","ui.auth.services","ui.auth.directives"])}(),function(){function e(e,r,n){function t(e,r){var n=new a({grantType:"password",username:e,password:r}),t=n.$save();return t.then(u)}function i(e){if(c)return h;c=!0;var r=new a({grantType:"refresh_token",refreshToken:e}),n=r.$save();return h=n.then(function(e){return c=!1,e}).then(u)}function o(){var n=e(r.serverURL+"/oauth/user");return n.get().$promise}function s(){var e=n.get("CurrentUserService");return e.isLoggedIn()}function u(e){return localStorage.setItem(r.preffix,JSON.stringify(e)),e}var a=e(r.serverURL+"/oauth/token"),c=!1,h=void 0;return{login:t,refresh:i,fetchCurrentUser:o,isLoggedIn:s}}angular.module("ui.auth.services").factory("AuthenticationService",e),e.$inject=["$resource","AuthConfig","$injector"]}(),function(){function e(e,r,n){e(r.serverURL+"/authorization/:action",{action:"@action"});return{hasPermission:function(e){var r=n.get("CurrentUserService"),t=r.getPermissions();return t.indexOf(e.trim())>=0},hasPermissions:function(e){for(var r=!0,n=0;n<e.length;n++)if(!this.hasPermission(e[n])){r=!1;break}return r},hasSomePermissions:function(e){var r=this;return _.some(e,function(e){return r.hasPermission(e)})},hasRol:function(e){var r=n.get("CurrentUserService"),t=r.getRols();return t.indexOf(e.trim())>=0},authorize:function(e,r){var t=n.get("CurrentUserService");if(e===!0&&void 0===user)return this.enums.LOGIN_REQUIRED;if(e&&t.isLoggedIn()&&(void 0===r||0===r.length))return this.enums.AUTHORIZED;if(r){var i=this.hasPermissions(r);return i?this.enums.AUTHORIZED:this.enums.NOT_AUTHORIZED}},enums:{LOGIN_REQUIRED:"loginRequired",NOT_AUTHORIZED:"notAuthorized",AUTHORIZED:"authorized"}}}angular.module("ui.auth.services").factory("AuthorizationService",e),e.$inject=["$resource","AuthConfig","$injector"]}(),function(){angular.module("ui.auth.services").provider("AuthConfig",function(){var e={};this.config=function(r){angular.extend(e,r)},this.$get=[function(){return e}]})}(),function(){function e(e,r,n){return{request:function(e){var r=n.get("TokenService"),t=r.getToken();return t&&(e.headers.Authorization="Bearer "+t),e.headers["Content-Type"]="application/json",e},requestError:function(t){var i=n.get("AuthConfig");return 401===t.status&&r.path(i.loginPath),e.reject(t)},response:function(e){return e},responseError:function(t){var i=n.get("AuthConfig"),o=n.get("$window"),s=n.get("$http");if(500===t.status&&"POST"===t.config.method&&t.config.url===i.serverURL+"/token"&&(r.path(i.loginPath),o.location.reload()),401===t.status){if(t.data&&403===t.data.code)return r.path("/"),e.reject(t);if(r.path()===i.loginPath)return e.reject(t);var u=n.get("AuthenticationService"),a=n.get("TokenService"),c=u.refresh(a.getRefreshToken());return c.then(function(e){return a.setToken(e),e}).then(function(e){return t.config.headers.Authorization="Bearer "+e.token,s(t.config)})}return e.reject(t)}}}angular.module("ui.auth.services").factory("HttpInterceptor",e),e.$inject=["$q","$location","$injector"]}(),function(){function e(e,r){return{restrict:"A",scope:{somePermissions:"=",permissions:"="},link:function(n,t,i){var o,s,u=void 0!==n.permissions||void 0!==n.somePermissions||void 0!==i.requiresLogin,a=e.isLoggedIn(),c=u&&!a;i.whenLogin&&(c=a?"hide"===i.whenLogin:"show"===i.whenLogin),n.permissions&&(o=n.permissions,angular.isArray(o)||(o=n.permissions.split(","))),o&&(c=!r.hasPermissions(o)),n.somePermissions&&(s=n.somePermissions,angular.isArray(s)||(s=n.somePermissions.split(",")),c=!r.hasSomePermissions(s)),c&&t.remove()}}}angular.module("ui.auth.directives").directive("auth",e),e.$inject=["AuthenticationService","AuthorizationService"]}();