UNPKG

graphdb-workbench

Version:
2 lines 15 kB
(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{85:function(e,r,t){"use strict";t.r(r);t(2),t(9),t(17),t(18);var s=t(0);const o=angular.module("graphdb.framework.security.controllers",["ngCookies","ui.bootstrap","graphdb.framework.core.services.jwtauth","graphdb.framework.core.services.openIDService","graphdb.framework.rest.security.service","toastr"]),n=function(e){let r=s.UserType.USER;const t={READ_REPO:{},WRITE_REPO:{}},o={};for(let n=0;n<e.length;n++){const i=e[n];if(i===s.UserRole.ROLE_ADMIN)r=s.UserType.ADMIN;else if(i===s.UserRole.ROLE_REPO_MANAGER)r!==s.UserType.ADMIN&&(r=s.UserType.REPO_MANAGER);else if(i===s.UserRole.ROLE_USER)r=s.UserType.USER;else if(0!==i.indexOf("ROLE_")){const e=i.indexOf("_",i.indexOf("_")+1),r=i.substr(0,e),s=i.substr(e+1);t[r][s]=!0,o[s]=o[s]||{},"READ_REPO"===r?o[s].read=!0:"WRITE_REPO"===r&&(o[s].write=!0)}}return{userType:r,userTypeDescription:s.UserUtils.getUserRoleName(r),grantedAuthorities:t,repositories:o}};o.controller("LoginCtrl",["$scope","$http","toastr","$jwtAuth","$openIDAuth","$location","$rootScope",function(e,r,t,s,o,n,i){e.username="",e.password="",e.loginWithOpenID=function(){s.loginOpenID()},n.search().noaccess?t.error("User has no access rights or configuration error.","Login error"):n.search().expired&&t.error("Your authentication token has expired. Please login again.","Login error"),e.isGDBLoginEnabled=function(){return s.passwordLoginEnabled},e.isOpenIDEnabled=function(){return s.openIDEnabled},e.login=function(){return r({method:"POST",url:"rest/login/"+encodeURIComponent(e.username),headers:{"X-GraphDB-Password":e.password}}).success((function(e,r,t){s.authenticate(e,t("Authorization")).then(()=>{i.returnToUrl?n.url(i.returnToUrl):n.path("/")})})).error((function(r,s){if(401===s)t.error("Wrong credentials!","Error"),e.wrongCredentials=!0,e.username="",e.password="";else{const e=getError(r);t.error(e,s)}}))}}]),o.controller("UsersCtrl",["$scope","$uibModal","toastr","$window","$jwtAuth","$timeout","ModalService","SecurityRestService",function(e,r,t,s,o,i,a,u){e.loader=!0,e.securityEnabled=function(){return o.isSecurityEnabled()},e.hasExternalAuth=function(){return o.hasExternalAuth()},e.getAuthImplementation=function(){return o.getAuthImplementation()},e.freeAccessEnabled=function(){return o.isFreeAccessEnabled()},e.getUsers=function(){u.getUsers().success((function(r){e.users=r;for(let r=0;r<e.users.length;r++){const t=n(e.users[r].grantedAuthorities);e.users[r].userType=t.userType,e.users[r].userTypeDescription=t.userTypeDescription,e.users[r].repositories=t.repositories}e.loader=!1})).error((function(r){const s=getError(r);t.error(s,"Error"),e.loader=!1}))},e.getUsers(),e.$on("repositoryIsSet",(function(){e.getUsers()})),e.toggleSecurity=function(){if(o.toggleSecurity(!o.isSecurityEnabled()),o.isSecurityEnabled()){const r=i((function(){s.location.reload()}),500);e.$on("$destroy",(function(){i.cancel(r)}))}},e.toggleFreeAccess=function(t){!o.isFreeAccessEnabled()||o.isFreeAccessEnabled()&&t?u.getFreeAccess().then((function(s){let n=s.data.authorities,i=s.data.appSettings||{DEFAULT_SAMEAS:!0,DEFAULT_INFERENCE:!0,EXECUTE_COUNT:!0,IGNORE_SHARED_QUERIES:!1,DEFAULT_VIS_GRAPH_SCHEMA:!0};r.open({templateUrl:"js/angular/security/templates/modal/default-authorities.html",controller:"DefaultAuthoritiesCtrl",resolve:{data:function(){return{defaultAuthorities:function(){const r={READ_REPO:{},WRITE_REPO:{}},t=_.mapKeys(e.getRepositories(),(function(e){return e.id}));return _.each(n,(function(e){0===e.indexOf("WRITE_REPO_")?t.hasOwnProperty(e.substr(11))&&(r.WRITE_REPO[e.substr(11)]=!0):0===e.indexOf("READ_REPO_")&&t.hasOwnProperty(e.substr(10))&&(r.READ_REPO[e.substr(10)]=!0)})),r},appSettings:i}}}}).result.then((function(e){n=e.authorities,i=e.appSettings,o.toggleFreeAccess(t||!o.isFreeAccessEnabled(),n,i,t)}))})):o.toggleFreeAccess(!o.isFreeAccessEnabled(),[])},e.editFreeAccess=function(){e.toggleFreeAccess(!0)},e.removeUser=function(r){a.openSimpleModal({title:"Confirm delete",message:"Are you sure you want to delete the user '"+r+"'?",warning:!0}).result.then((function(){e.loader=!0,u.deleteUser(r).success((function(){e.getUsers()})).error((function(r){const s=getError(r);t.error(s,"Error"),e.loader=!1}))}))},e.encodeURIComponent=function(e){return encodeURIComponent(e)}}]),o.controller("DefaultAuthoritiesCtrl",["$scope","$http","$uibModalInstance","data","$rootScope",function(e,r,t,s,o){e.grantedAuthorities=s.defaultAuthorities(),e.appSettings=s.appSettings,e.hasActiveLocation=function(){return!_.isEmpty(o.globalLocation)},e.getRepositories=function(){return o.globalRepositories},e.ok=function(){const r=[];e.repositoryCheckError=!0;for(const t in e.grantedAuthorities.WRITE_REPO)e.grantedAuthorities.WRITE_REPO[t]&&(r.push("WRITE_REPO_"+t),r.push("READ_REPO_"+t),e.repositoryCheckError=!1);for(const t in e.grantedAuthorities.READ_REPO)e.grantedAuthorities.READ_REPO[t]&&-1===r.indexOf("READ_REPO_"+t)&&(r.push("READ_REPO_"+t),e.repositoryCheckError=!1);e.repositoryCheckError||t.close({authorities:r,appSettings:e.appSettings})},e.cancel=function(){t.dismiss("cancel")}}]),o.controller("CommonUserCtrl",["$scope","$http","toastr","$window","$timeout","$location","$jwtAuth",function(e,r,t,o,n,i,a){e.isAdmin=function(){return a.hasRole(s.UserRole.ROLE_ADMIN)},e.hasExternalAuth=function(){return a.hasExternalAuth()},e.hasEditRestrictions=function(){return e.user&&e.user.username===s.UserType.ADMIN},e.isOverrideAuth=function(){return a.isDefaultAuthEnabled()},e.setGrantedAuthorities=function(){!function(e){function r(){for(let r=0;r<arguments.length;r++){const t=arguments[r];_.indexOf(e.user.grantedAuthorities,t)<0&&e.user.grantedAuthorities.push(t)}}if(e.user.grantedAuthorities=[],e.repositoryCheckError=!0,e.userType===s.UserType.ADMIN)e.repositoryCheckError=!1,r(s.UserRole.ROLE_ADMIN);else if(e.userType===s.UserType.REPO_MANAGER)e.repositoryCheckError=!1,r(s.UserRole.ROLE_REPO_MANAGER);else{r(s.UserRole.ROLE_USER);for(const t in e.grantedAuthorities.WRITE_REPO)e.grantedAuthorities.WRITE_REPO[t]&&(e.repositoryCheckError=!1,r("WRITE_REPO_"+t,"READ_REPO_"+t));for(const t in e.grantedAuthorities.READ_REPO)e.grantedAuthorities.READ_REPO[t]&&(e.repositoryCheckError=!1,r("READ_REPO_"+t))}}(e)},e.hasReadPermission=function(r){return e.userType===s.UserType.ADMIN||e.userType===s.UserType.REPO_MANAGER||e.grantedAuthorities.READ_REPO[r]||e.grantedAuthorities.WRITE_REPO[r]||"SYSTEM"!==r&&(e.grantedAuthorities.READ_REPO["*"]||e.grantedAuthorities.WRITE_REPO["*"])},e.hasWritePermission=function(r){return e.userType===s.UserType.ADMIN||e.userType===s.UserType.REPO_MANAGER||e.grantedAuthorities.WRITE_REPO[r]||"SYSTEM"!==r&&e.grantedAuthorities.WRITE_REPO["*"]},e.readCheckDisabled=function(r){return e.hasWritePermission(r)||"SYSTEM"!==r&&"*"!==r&&e.grantedAuthorities.READ_REPO["*"]||e.hasEditRestrictions()},e.writeCheckDisabled=function(r){return e.userType===s.UserType.ADMIN||e.userType===s.UserType.REPO_MANAGER||"SYSTEM"!==r&&"*"!==r&&e.grantedAuthorities.WRITE_REPO["*"]||e.hasEditRestrictions()},e.userType=s.UserType.USER,e.grantedAuthorities={READ_REPO:{},WRITE_REPO:{}},e.validatePassword=function(){return e.noPassword?(e.passwordError="",e.confirmPasswordError="",!0):e.user.password!==e.user.confirmpassword?(e.user.password?(e.passwordError="",e.confirmPasswordError="Confirm password!"):(e.passwordError="Enter password!",e.confirmPasswordError=""),!1):(e.passwordError="",e.confirmPasswordError="",!0)},e.isLocalAuthentication=function(){return"Local"===a.getAuthImplementation()},e.updateUser=function(){if(!e.validateForm())return!1;e.isLocalAuthentication()&&e.setGrantedAuthorities(),e.repositoryCheckError||e.updateUserHttp()},e.setNoPassword=function(){e.noPassword&&(e.user.password="",e.user.confirmpassword="",e.passwordError="",e.confirmPasswordError="")}}]),o.controller("AddUserCtrl",["$scope","$http","toastr","$window","$timeout","$location","$jwtAuth","$controller","SecurityRestService","ModalService",function(e,r,t,o,n,i,a,u,c,p){angular.extend(this,u("CommonUserCtrl",{$scope:e})),e.mode="add",e.saveButtonText="Create",e.goBack=function(){const r=n((function(){o.history.back()}),100);e.$on("$destroy",(function(){n.cancel(r)}))},e.pageTitle="Create new user",e.passwordPlaceholder="Password",e.user={username:"",password:"",confirmpassword:"",grantedAuthorities:[],appSettings:{DEFAULT_SAMEAS:!0,DEFAULT_INFERENCE:!0,EXECUTE_COUNT:!0,IGNORE_SHARED_QUERIES:!1,DEFAULT_VIS_GRAPH_SCHEMA:!0}},e.submit=function(){e.noPassword&&e.userType===s.UserType.ADMIN?p.openSimpleModal({title:"Create administrator",message:"If the password is unset and security is enabled, this administrator will not be able to log into GraphDB through the workbench. Are you sure that you want to continue?",warning:!0}).result.then((function(){e.createUser()})):e.createUser()},e.createUserHttp=function(){e.loader=!0,c.createUser({username:e.user.username,pass:e.user.password,appSettings:e.user.appSettings,grantedAuthorities:e.user.grantedAuthorities}).success((function(){t.success("The user "+e.user.username+" has been created.");const r=n((function(){e.loader=!1,o.history.back()}),2e3);e.$on("$destroy",(function(){n.cancel(r)}))})).error((function(r){const s=getError(r);e.loader=!1,t.error(s,"Error")}))},e.createUser=function(){e.validateForm()&&(e.setGrantedAuthorities(),e.repositoryCheckError||e.createUserHttp())},e.validateForm=function(){let r=!0;return e.user.username?e.usernameError="":(e.usernameError="Enter username!",r=!1),e.noPassword?(e.passwordError="",e.confirmPasswordError=""):(e.user.password?e.passwordError="":(e.passwordError="Enter password!",r=!1),e.user.confirmpassword&&e.user.password===e.user.confirmpassword?e.confirmPasswordError="":(e.confirmPasswordError="Confirm password!",r=!1)),r}}]),o.controller("EditUserCtrl",["$scope","$http","toastr","$window","$routeParams","$timeout","$location","$jwtAuth","$controller","SecurityRestService","ModalService",function(e,r,t,o,i,a,u,c,p,d,l){angular.extend(this,p("CommonUserCtrl",{$scope:e})),e.mode="edit",e.saveButtonText="Save",e.goBack=function(){const r=a((function(){o.history.back()}),100);e.$on("$destroy",(function(){a.cancel(r)}))},e.params=i,e.pageTitle="Edit user: "+e.params.userId,e.passwordPlaceholder="New password",e.userType=s.UserType.USER;const E={DEFAULT_SAMEAS:!0,DEFAULT_INFERENCE:!0,EXECUTE_COUNT:!0,IGNORE_SHARED_QUERIES:!1,DEFAULT_VIS_GRAPH_SCHEMA:!0};c.hasRole(s.UserRole.ROLE_ADMIN)||u.url("settings"),e.getUserData=function(){d.getUser(e.params.userId).success((function(r){e.userData=r,e.user={username:e.userData.username},e.user.password="",e.user.confirmpassword="",e.user.external=e.userData.external,e.user.appSettings=r.appSettings||E,e.userType=s.UserType.USER;const t=n(r.grantedAuthorities);e.userType=t.userType,e.grantedAuthorities=t.grantedAuthorities})).error((function(e){const r=getError(e);t.error(r,"Error")}))},e.getUserData(),e.submit=function(){e.noPassword&&e.userType===s.UserType.ADMIN?l.openSimpleModal({title:"Save administrator settings",message:"If you unset the password and then enable security, this administrator will not be able to log into GraphDB through the workbench. Are you sure that you want to continue?",warning:!0}).result.then((function(){e.updateUser()})):e.updateUser()},e.updateUserHttp=function(){e.loader=!0,d.updateUser({username:e.user.username,pass:e.noPassword?"":e.user.password||void 0,appSettings:e.user.appSettings,grantedAuthorities:e.user.grantedAuthorities}).success((function(){t.success("The user "+e.user.username+" was updated.");const r=a((function(){e.loader=!1,o.history.back()}),2e3);e.$on("$destroy",(function(){a.cancel(r)})),e.user.username===c.getPrincipal().username&&(c.getPrincipal().appSettings=e.user.appSettings)})).error((function(r){const s=getError(r);e.loader=!1,t.error(s,"Error")}))},e.validateForm=function(){return e.validatePassword()}}]),o.controller("RolesMappingController",["$scope","toastr","SecurityRestService",function(e,r,t){e.debugMapping=function(e,r){const s=r.split(":");t.getRolesMapping({role:e,method:s[1],mapping:s[0]})};e.$on("repositoryIsSet",(function(){t.getRoles().success((function(r){e.roleMappings=r,e.roles=_.keys(e.roleMappings),e.mappings=_.keys(e.roleMappings[e.roles[0]]);const t=_.map(e.roles,(function(r){return[r,_.filter(e.roleMappings[r]).length]}));e.roles=_.reverse(_.map(_.orderBy(t,(function(e){return e[1]})),(function(e){return e[0]})))})).error((function(t){const s=getError(t);e.loader=!1,r.error(s,"Error")}))}))}]),o.controller("ChangeUserPasswordSettingsCtrl",["$scope","toastr","$window","$timeout","$jwtAuth","$rootScope","$controller","SecurityRestService","ModalService",function(e,r,t,o,i,a,u,c,p){angular.extend(this,u("CommonUserCtrl",{$scope:e})),e.mode="settings",e.hasEditRestrictions=function(){return!0},e.saveButtonText="Save",e.goBack=function(){const r=o((function(){t.history.back()}),100);e.$on("$destroy",(function(){o.cancel(r)}))},e.currentUserData=function(){return i.getPrincipal()},e.updateCurrentUserData=function(){_.assign(i.getPrincipal(),e.userData)},e.redirectAdmin=function(){e.currentUserData()||a.redirectToLogin()},e.pageTitle="Settings",e.passwordPlaceholder="New password",e.grantedAuthorities={READ_REPO:{},WRITE_REPO:{}};const d=function(r){r.userData=angular.copy(r.currentUserData()),r.user={username:r.userData.username},r.user.password="",r.user.confirmpassword="",r.user.external=r.userData.external,r.user.appSettings=r.userData.appSettings,void 0===r.user.appSettings.DEFAULT_VIS_GRAPH_SCHEMA&&(r.user.appSettings.DEFAULT_VIS_GRAPH_SCHEMA=!0);const t=n(r.userData.authorities);e.userType=t.userType,e.grantedAuthorities=t.grantedAuthorities};e.currentUserData()?d(e):e.$on("securityInit",(function(e){e.currentScope.redirectAdmin(),d(e.currentScope)})),e.loader=!1,e.submit=function(){e.noPassword&&e.userType===s.UserType.ADMIN?p.openSimpleModal({title:"Save administrator settings",message:"If you unset the password and then enable security, this administrator will not be able to log into GraphDB through the workbench. Are you sure that you want to continue?",warning:!0}).result.then((function(){e.updateUser()})):e.updateUser()},e.updateUserHttp=function(){e.loader=!0,c.updateUserData({username:e.user.username,pass:e.noPassword?"":e.user.password||void 0,appSettings:e.user.appSettings}).success((function(){e.updateCurrentUserData(),r.success("The user "+e.user.username+" was updated.");const s=o((function(){e.loader=!1,t.history.back()}),2e3);e.$on("$destroy",(function(){o.cancel(s)}))})).error((function(t){const s=getError(t);e.loader=!1,r.error(s,"Error")}))},e.updateUser=function(){if(!e.validateForm())return!1;e.updateUserHttp()},e.validateForm=function(){return e.validatePassword()}}]),o.controller("DeleteUserCtrl",["$scope","$uibModalInstance","username",function(e,r,t){e.username=t,e.ok=function(){r.close()},e.cancel=function(){r.dismiss("cancel")}}])}}]); //# sourceMappingURL=12.bb55709d82da219afedf.bundle.js.map