import { KibanaRequest } from 'kibana/server' ; import type { SecurityPluginSetup } from '../../../security/server' ; import { ML_SAVED_OBJECT_TYPE } from '../../common/types/saved_objects' ; export function authorizationProvider ( authorization ) { async function authorizationCheck ( request ) { const shouldAuthorizeRequest = authorization ?. mode . useRbacForRequest ( request ) ?? false ; if ( shouldAuthorizeRequest === false ) { return { canCreateGlobally : true , canCreateAtSpace : true , } ; } const checkPrivilegesWithRequest = authorization . checkPrivilegesWithRequest ( request ) ; const checkPrivilegesDynamicallyWithRequest = authorization . checkPrivilegesDynamicallyWithRequest ( request ) ; const createMLJobAuthorizationAction = authorization . actions . savedObject . get ( ML_SAVED_OBJECT_TYPE , 'create' ) ; const canCreateGlobally = ( await checkPrivilegesWithRequest . globally ( { kibana : [ createMLJobAuthorizationAction ] , } ) ) . hasAllRequested ; const canCreateAtSpace = ( await checkPrivilegesDynamicallyWithRequest ( { kibana : [ createMLJobAuthorizationAction ] } ) ) . hasAllRequested ; return { canCreateGlobally , canCreateAtSpace , } ; } return { authorizationCheck } ; }