graphdb-workbench
Version:
The web application for GraphDB APIs
2 lines • 15.5 kB
JavaScript
export const __webpack_id__=94229;export const __webpack_ids__=[48477,94229];export const __webpack_modules__={48477:()=>{angular.module("graphdb.framework.security.directives",[]).directive("customPrefixTagsInput",function(){return{restrict:"A",link:function(e,r,t){const s=[];function n(e){return e.startsWith("CUSTOM_")||e.startsWith("!CUSTOM_")}const o="tags-input"===r[0].nodeName.toLowerCase();if(o&&t.ngModel){const i=r.controller("ngModel");o&&(i.$parsers.push(function(e){return Array.isArray(e)&&(i.$warning=e.some(e=>n(e))),e}),s.push(e.$watch(t.ngModel,function(e){Array.isArray(e)&&(i.$warning=e.some(e=>n(e)))},!0)))}s.push(e.$on("$destroy",()=>{s.forEach(e=>e())}))}}})},94229:(e,r,t)=>{t.r(r),t(82493),t(98599),t(60285),t(2243);var s=t(92900),n=(t(48477),t(33760)),o=t(13857);const i=angular.module("graphdb.framework.security.controllers",["ngCookies","ui.bootstrap","graphdb.framework.core.services.jwtauth","graphdb.framework.core.services.openIDService","graphdb.framework.core.services.security-service","toastr","ngTagsInput"]);i.controller("LoginCtrl",["$scope","$http","toastr","$jwtAuth","$openIDAuth","$location","$rootScope","$translate","TrackingService","SecurityService",function(e,r,t,s,n,o,i,a,u,c){e.username="",e.password="",s.reinitializeSecurity(),u.applyTrackingConsent().catch(e=>{const r=getError(e.data,e.status);t.error(r,a.instant("common.error"))}),e.loginWithOpenID=function(){s.loginOpenID()},o.search().noaccess?t.error(a.instant("security.no.rights.config.error"),a.instant("security.login.error")):o.search().expired&&t.error(a.instant("security.auth.token.expired"),a.instant("security.login.error")),e.isGDBLoginEnabled=function(){return s.passwordLoginEnabled},e.isOpenIDEnabled=function(){return s.openIDEnabled},e.login=function(){return c.login(e.username,e.password).then(function({data:e,status:r,headers:t}){s.authenticate(e,t("Authorization")).then(()=>{i.returnToUrl?o.url(i.returnToUrl):o.path("/")})}).catch(function({data:r,status:s}){if(401===s)t.error(a.instant("security.wrong.credentials"),a.instant("common.error")),e.wrongCredentials=!0,e.username="",e.password="";else{const e=getError(r);t.error(e,s)}})}}]),i.controller("UsersCtrl",["$scope","$uibModal","toastr","$window","$jwtAuth","$timeout","ModalService","SecurityService","$translate",function(e,r,t,s,i,a,u,c,d){e.loader=!0,e.securityEnabled=function(){return i.isSecurityEnabled()},e.hasExternalAuth=function(){return i.hasExternalAuth()},e.getAuthImplementation=function(){return i.getAuthImplementation()},e.freeAccessEnabled=function(){return i.isFreeAccessEnabled()},e.getUsers=()=>c.getUsers().then(function(r){e.users=r;for(let r=0;r<e.users.length;r++){const t=(0,o.parseAuthorities)(e.users[r].grantedAuthoritiesUiModel);e.users[r].userType=t.userType,e.users[r].userTypeDescription=t.userTypeDescription,e.users[r].repositories=t.repositories,e.users[r].customRoles=t.customRoles}e.loader=!1}).catch(function(r){const s=getError(r);t.error(s,d.instant("common.error")),e.loader=!1}),e.getUsers(),e.$on("repositoryIsSet",function(){e.getUsers()}),e.toggleSecurity=function(){const e=i.isSecurityEnabled();i.toggleSecurity(!e).then(()=>{e!==i.isSecurityEnabled()&&s.location.reload()})},e.toggleFreeAccess=function(e){!i.isFreeAccessEnabled()||i.isFreeAccessEnabled()&&e?c.getFreeAccess().then(function(r){const t=r.grantedAuthoritiesUiModel,s=r.appSettings||{DEFAULT_SAMEAS:!0,DEFAULT_INFERENCE:!0,EXECUTE_COUNT:!0,IGNORE_SHARED_QUERIES:!1,DEFAULT_VIS_GRAPH_SCHEMA:!0};p(s,t,e)}):i.toggleFreeAccess(!i.isFreeAccessEnabled(),[])};const p=(t,s,a)=>{r.open({templateUrl:"js/angular/security/templates/modal/default-authorities.html",controller:"DefaultAuthoritiesCtrl",resolve:{data:function(){return{defaultAuthorities:function(){const r={[n.READ_REPO]:{},[n.WRITE_REPO]:{},[n.GRAPHQL]:{}},t=_.mapKeys(e.getRepositories(),function(e){return(0,o.createUniqueKey)(e)});return _.each(s,function(e){0===e.indexOf(n.WRITE_REPO_PREFIX)?t.hasOwnProperty(e.substr(11))&&(r[n.WRITE_REPO][e.substr(11)]=!0):0===e.indexOf(n.READ_REPO_PREFIX)?t.hasOwnProperty(e.substr(10))&&(r[n.READ_REPO][e.substr(10)]=!0):0===e.indexOf(n.GRAPHQL_PREFIX)&&t.hasOwnProperty(e.substr(8))&&(r[n.GRAPHQL][e.substr(8)]=!0)}),r},appSettings:t}}}}).result.then(function(e){s=e.authorities,t=e.appSettings,i.toggleFreeAccess(a||!i.isFreeAccessEnabled(),s,t,a)})};e.editFreeAccess=function(){e.toggleFreeAccess(!0)},e.removeUser=function(r){u.openSimpleModal({title:d.instant("common.confirm.delete"),message:d.instant("security.confirm.delete.user",{name:r}),warning:!0}).result.then(function(){e.loader=!0,c.deleteUser(r).then(()=>e.getUsers()).catch(r=>{const s=getError(r);t.error(s,d.instant("common.error")),e.loader=!1})})},e.encodeURIComponent=function(e){return encodeURIComponent(e)}}]),i.controller("DefaultAuthoritiesCtrl",["$scope","$http","$uibModalInstance","data","$rootScope",function(e,r,t,s,i){e.grantedAuthorities=s.defaultAuthorities(),e.appSettings=s.appSettings,e.hasActiveLocation=function(){return!_.isEmpty(i.globalLocation)},e.getRepositories=function(){return i.globalRepositories},e.ok=function(){const r=[];e.repositoryCheckError=!0;for(const t in e.grantedAuthorities.WRITE_REPO)e.grantedAuthorities.WRITE_REPO[t]&&(r.push(n.WRITE_REPO_PREFIX+t),r.push(n.READ_REPO_PREFIX+t),e.repositoryCheckError=!1);for(const t in e.grantedAuthorities.READ_REPO)e.grantedAuthorities.READ_REPO[t]&&-1===r.indexOf(n.READ_REPO_PREFIX+t)&&(r.push(n.READ_REPO_PREFIX+t),e.repositoryCheckError=!1);for(const t in e.grantedAuthorities.GRAPHQL)e.grantedAuthorities.GRAPHQL[t]&&-1===r.indexOf(n.GRAPHQL_PREFIX+t)&&r.push(n.GRAPHQL_PREFIX+t);e.repositoryCheckError||t.close({authorities:r,appSettings:e.appSettings})},e.cancel=function(){t.dismiss("cancel")},e.createUniqueKey=function(e){return(0,o.createUniqueKey)(e)}}]),i.controller("CommonUserCtrl",["$rootScope","$scope","$http","toastr","$window","$timeout","$location","$jwtAuth","$translate","passwordPlaceholder",function(e,r,t,i,a,u,c,d,p,l){e.$on("$translateChangeSuccess",function(){r.passwordPlaceholder=p.instant(l)}),r.isAdmin=function(){return d.hasRole(s.UserRole.ROLE_ADMIN)},r.hasExternalAuth=function(){return d.hasExternalAuth()},r.hasEditRestrictions=function(){return r.user&&r.user.username===s.UserType.ADMIN},r.isOverrideAuth=function(){return d.isDefaultAuthEnabled()},r.setGrantedAuthorities=function(){function e(){for(let e=0;e<arguments.length;e++){const t=arguments[e];_.indexOf(r.user.grantedAuthorities,t)<0&&r.user.grantedAuthorities.push(t)}}if(r.user.grantedAuthorities=[],r.repositoryCheckError=!0,r.userType===s.UserType.ADMIN)r.repositoryCheckError=!1,e(s.UserRole.ROLE_ADMIN);else if(r.userType===s.UserType.REPO_MANAGER)r.repositoryCheckError=!1,e(s.UserRole.ROLE_REPO_MANAGER);else{e(s.UserRole.ROLE_USER);for(const t in r.grantedAuthorities.WRITE_REPO)r.grantedAuthorities.WRITE_REPO[t]&&(r.repositoryCheckError=!1,e(n.WRITE_REPO_PREFIX+t,n.READ_REPO_PREFIX+t));for(const t in r.grantedAuthorities.READ_REPO)r.grantedAuthorities.READ_REPO[t]&&(r.repositoryCheckError=!1,e(n.READ_REPO_PREFIX+t));for(const t in r.grantedAuthorities.GRAPHQL)r.grantedAuthorities.GRAPHQL[t]&&e(n.GRAPHQL_PREFIX+t)}r.customRoles&&r.customRoles.forEach(r=>e("CUSTOM_"+r))},r.$watch("userType",function(){r.isUser()||(r.customRoles="")}),r.isUser=function(){return r.userType===s.UserType.USER},r.hasReadPermission=function(e){const t=(0,o.createUniqueKey)(e);return r.userType===s.UserType.ADMIN||r.userType===s.UserType.REPO_MANAGER||e.id!==n.SYSTEM_REPO&&(r.grantedAuthorities.READ_REPO["*"]||r.grantedAuthorities.WRITE_REPO["*"])||r.grantedAuthorities.READ_REPO[t]||r.grantedAuthorities.WRITE_REPO[t]},r.hasWritePermission=function(e){const t=(0,o.createUniqueKey)(e);return r.userType===s.UserType.ADMIN||r.userType===s.UserType.REPO_MANAGER||e.id!==n.SYSTEM_REPO&&r.grantedAuthorities.WRITE_REPO["*"]||r.grantedAuthorities.WRITE_REPO[t]},r.hasGraphqlPermission=function(e){const t=(0,o.createUniqueKey)(e);return e.id!==n.SYSTEM_REPO&&r.grantedAuthorities.GRAPHQL["*"]||r.grantedAuthorities.GRAPHQL[t]},r.readCheckDisabled=function(e){return r.hasWritePermission(e)||e.id!==n.SYSTEM_REPO&&"*"!==e&&r.grantedAuthorities.READ_REPO["*"]||r.hasEditRestrictions()},r.writeCheckDisabled=function(e){return r.userType===s.UserType.ADMIN||r.userType===s.UserType.REPO_MANAGER||e.id!==n.SYSTEM_REPO&&"*"!==e&&r.grantedAuthorities.WRITE_REPO["*"]||r.hasEditRestrictions()},r.graphqlCheckDisabled=function(e){if(r.userType===s.UserType.ADMIN||r.userType===s.UserType.REPO_MANAGER)return!0;if(r.hasEditRestrictions())return!0;if("*"!==e&&r.grantedAuthorities.GRAPHQL["*"])return!0;if("*"===e&&r.grantedAuthorities.GRAPHQL["*"])return!1;let t;t=null!==e&&"object"==typeof e?r.createUniqueKey(e):e;const n=r.grantedAuthorities.READ_REPO["*"],o=r.grantedAuthorities.WRITE_REPO["*"],i=r.grantedAuthorities.READ_REPO[t],a=r.grantedAuthorities.WRITE_REPO[t];return!(n||o||i||a)},r.createUniqueKey=function(e){return(0,o.createUniqueKey)(e)},r.userType=s.UserType.USER,r.grantedAuthorities={[n.READ_REPO]:{},[n.WRITE_REPO]:{},[n.GRAPHQL]:{}},r.validatePassword=function(){return r.noPassword?(r.passwordError="",r.confirmPasswordError="",!0):r.user.password!==r.user.confirmpassword?(r.user.password?(r.passwordError="",r.confirmPasswordError=p.instant("security.confirm.password")):(r.passwordError=p.instant("security.enter.password"),r.confirmPasswordError=""),!1):(r.passwordError="",r.confirmPasswordError="",!0)},r.isLocalAuthentication=function(){return"Local"===d.getAuthImplementation()},r.updateUser=function(){if(!r.validateForm())return!1;r.isLocalAuthentication()&&r.setGrantedAuthorities(),r.repositoryCheckError||r.updateUserHttp()},r.setNoPassword=function(){r.noPassword&&(r.user.password="",r.user.confirmpassword="",r.passwordError="",r.confirmPasswordError="")},r.shouldDisableSameAs=function(){const e=$("#sameAsCheck");return r.user&&!r.user.appSettings.DEFAULT_INFERENCE&&e.prop("checked")&&(e.prop("checked",!1),r.user.appSettings.DEFAULT_SAMEAS=!1),r.user&&!r.user.appSettings.DEFAULT_INFERENCE},r.isRoleValid=!0,r.addCustomRole=function(e){return r.isRoleValid=!0,e.text=e.text.toUpperCase(),e},r.isCustomRoleValid=function(e){return r.isRoleValid=e.text.length>=2,r.isRoleValid},r.checkUserInput=function(e){8!==e.keyCode&&46!==e.keyCode||(r.isRoleValid=!0)},r.removeErrorOnCut=function(){r.isRoleValid=!0}}]),i.controller("AddUserCtrl",["$scope","$http","toastr","$window","$timeout","$location","$jwtAuth","$controller","SecurityService","ModalService","$translate",function(e,r,t,n,o,i,a,u,c,d,p){angular.extend(this,u("CommonUserCtrl",{$scope:e,passwordPlaceholder:"security.password.placeholder"})),e.mode="add",e.saveButtonText=p.instant("common.create.btn"),e.goBack=function(){const r=o(function(){n.history.back()},100);e.$on("$destroy",function(){o.cancel(r)})},e.pageTitle=p.instant("view.create.user.title"),e.passwordPlaceholder=p.instant("security.password.placeholder"),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?d.openSimpleModal({title:p.instant("security.create.admin"),message:p.instant("security.admin.login.warning"),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}).then(()=>{t.success(p.instant("security.user.created",{name:e.user.username}));const r=o(function(){e.loader=!1,n.history.back()},2e3);e.$on("$destroy",function(){o.cancel(r)})}).catch(r=>{const s=getError(r);e.loader=!1,t.error(s,p.instant("common.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=p.instant("security.enter.username"),r=!1),e.noPassword?(e.passwordError="",e.confirmPasswordError=""):(e.user.password?e.passwordError="":(e.passwordError=p.instant("security.enter.password"),r=!1),e.user.confirmpassword&&e.user.password===e.user.confirmpassword?e.confirmPasswordError="":(e.confirmPasswordError=p.instant("security.confirm.password"),r=!1)),r}}]),i.controller("EditUserCtrl",["$scope","$http","toastr","$window","$routeParams","$timeout","$location","$jwtAuth","$controller","SecurityService","ModalService","$translate",function(e,r,t,n,i,a,u,c,d,p,l,E){angular.extend(this,d("CommonUserCtrl",{$scope:e,passwordPlaceholder:"security.new.password"})),e.mode="edit",e.saveButtonText=E.instant("common.save.btn"),e.goBack=function(){const r=a(function(){n.history.back()},100);e.$on("$destroy",function(){a.cancel(r)})},e.params=i,e.pageTitle=E.instant("view.edit.user.title",{userId:e.params.userId}),e.passwordPlaceholder=E.instant("security.new.password"),e.userType=s.UserType.USER;const h={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(){p.getUser(e.params.userId).then(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||h,e.userType=s.UserType.USER;const t=(0,o.parseAuthorities)(r.grantedAuthoritiesUiModel);e.userType=t.userType,e.grantedAuthorities=t.grantedAuthorities,e.customRoles=t.customRoles}).catch(function(e){const r=getError(e);t.error(r,E.instant("common.error"))})},e.getUserData(),e.submit=function(){e.noPassword&&e.userType===s.UserType.ADMIN?l.openSimpleModal({title:E.instant("security.save.admin.settings"),message:E.instant("security.admin.pass.unset"),warning:!0}).result.then(function(){e.updateUser()}):e.updateUser()},e.updateUserHttp=function(){e.loader=!0,p.updateUser({username:e.user.username,pass:e.noPassword?"":e.user.password||void 0,appSettings:e.user.appSettings,grantedAuthorities:e.user.grantedAuthorities}).then(()=>{t.success(E.instant("security.user.updated",{name:e.user.username}));const r=a(function(){e.loader=!1,n.history.back()},2e3);e.$on("$destroy",function(){a.cancel(r)}),c.getPrincipal().then(r=>{e.user.username===r.username&&(r.appSettings=e.user.appSettings)})}).catch(r=>{const s=getError(r);e.loader=!1,t.error(s,E.instant("common.error"))})},e.validateForm=function(){return e.validatePassword()}}]),i.controller("RolesMappingController",["$scope","toastr","SecurityService","$translate",function(e,r,t,s){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 n=getError(t);e.loader=!1,r.error(n,s.instant("common.error"))})})}]),i.controller("DeleteUserCtrl",["$scope","$uibModalInstance","username",function(e,r,t){e.username=t,e.ok=function(){r.close()},e.cancel=function(){r.dismiss("cancel")}}])}};
//# sourceMappingURL=94229.b735a177baa94b2a23d6.bundle.js.map