diff --git a/public/components/security/main.tsx b/public/components/security/main.tsx index 133bc6f3a7..ebe1ca3a10 100644 --- a/public/components/security/main.tsx +++ b/public/components/security/main.tsx @@ -7,12 +7,17 @@ import { EuiTabs, EuiTab, EuiPanel, + EuiCallOut, EuiEmptyPrompt, EuiSpacer, } from '@elastic/eui'; import { Users } from './users/users'; import { Roles } from './roles/roles'; import { Policies } from './policies/policies'; +import { GenericRequest } from '../../react-services/generic-request'; +import { API_USER_STATUS_RUN_AS } from '../../../server/lib/cache-api-user-has-run-as'; +import { AppState } from '../../react-services/app-state'; +import { ErrorHandler } from '../../react-services/error-handler'; import { RolesMapping } from './roles-mapping/roles-mapping'; import { withReduxProvider, withGlobalBreadcrumb, withUserAuthorizationPrompt } from '../common/hocs'; import { compose } from 'redux'; @@ -55,11 +60,34 @@ export const WzSecurity = compose( const [selectedTabId, setSelectedTabId] = useState(tab && tab[1] || 'users'); + const listenerLocationChanged = () => { const tab = window.location.href.match(securityTabRegExp); setSelectedTabId(tab && tab[1] || 'users') } - // This allows to redirect to a Security tab if you click a Security link in menu when you're already in a Security section + + const checkRunAsUser = async () => { + const currentApi = AppState.getCurrentAPI(); + try { + const ApiCheck = await GenericRequest.request('POST', + '/api/check-api', + currentApi + ); + return ApiCheck.data.allow_run_as; + + } catch (error) { + ErrorHandler.handle(error, 'Error checking the current API'); + } + } + + const [allowRunAs, setAllowRunAs] = useState(); + useEffect(() => { + checkRunAsUser() + .then(result => setAllowRunAs(result)) + .catch(error => console.log(error, 'Error checking if run_as user is enabled')) + }, []) + + // This allows to redirect to a Security tab if you click a Security link in menu when you're already in a Security section useEffect(() => { window.addEventListener('popstate', listenerLocationChanged) return () => window.removeEventListener('popstate', listenerLocationChanged); @@ -71,7 +99,7 @@ export const WzSecurity = compose( const onSelectedTabChanged = id => { window.location.href = window.location.href.replace(`tab=${selectedTabId}`, `tab=${id}`); - setSelectedTabId(id); + setSelectedTabId(id); }; const renderTabs = () => { @@ -87,6 +115,20 @@ export const WzSecurity = compose( )); }; + + const isNotRunAs = () => { + return ( + + + + + + + + ); + } + + return ( @@ -103,10 +145,13 @@ export const WzSecurity = compose( } {selectedTabId === 'roleMapping' && - + <> + {allowRunAs !== API_USER_STATUS_RUN_AS.ENABLED && allowRunAs !== undefined && isNotRunAs()} + + } ); -}); \ No newline at end of file +}); diff --git a/public/components/security/roles-mapping/components/rule-editor.tsx b/public/components/security/roles-mapping/components/rule-editor.tsx index f6cb6e5bdc..05f6bf5ddc 100644 --- a/public/components/security/roles-mapping/components/rule-editor.tsx +++ b/public/components/security/roles-mapping/components/rule-editor.tsx @@ -53,7 +53,6 @@ export const RuleEditor = ({ save, initialRule, isLoading, isReserved, internalU const default_user_field = currentPlatform === WAZUH_SECURITY_PLUGIN_OPEN_DISTRO_FOR_ELASTICSEARCH ? 'user_name' : 'username'; const default_rule = { user_field: default_user_field, searchOperation: 'FIND', value: 'wazuh' }; - useEffect(() => { if (initialRule) { setStateFromRule(JSON.stringify(initialRule)); @@ -279,80 +278,80 @@ export const RuleEditor = ({ save, initialRule, isLoading, isReserved, internalU aria-label="Code Editor" /> )) || ( - - -

Map internal users

-
- - - - - -

Custom rules

-
- - {logicalOperator === 'AND' ? 'All are true' : 'Any are true'} - - } - isOpen={isLogicalPopoverOpen} - closePopover={closeLogicalPopover} - anchorPosition="downCenter" - > -
- - - selectOperator('AND')} - > - {logicalOperator === 'AND' && }All are true + + +

Map internal users

+
+ + + + + +

Custom rules

+
+ + {logicalOperator === 'AND' ? 'All are true' : 'Any are true'} +
+ } + isOpen={isLogicalPopoverOpen} + closePopover={closeLogicalPopover} + anchorPosition="downCenter" + > +
+ + + selectOperator('AND')} + > + {logicalOperator === 'AND' && }All are true - - - - - selectOperator('OR')} - > - {logicalOperator === 'OR' && }Any are true + + + + + selectOperator('OR')} + > + {logicalOperator === 'OR' && }Any are true - - -
- - {printRules()} +
+
+
+
+ {printRules()} - addNewRule()} - > - Add new rule + addNewRule()} + > + Add new rule -
- )} + + )}