Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBAC #2417

Merged
merged 195 commits into from
Sep 22, 2020
Merged

RBAC #2417

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
da85f99
[4.0] Remove known-fields (#2408)
pablotr9 Jul 29, 2020
2e6ec9d
Remove angular kibana-visualization
juankaromo Jul 29, 2020
b219fee
Fix Wazuh plugin name on XPACK role creation section
pablotr9 Jul 29, 2020
d0eb724
Added security management section
juankaromo Jul 29, 2020
20f73a4
Add users management section
juankaromo Jul 29, 2020
acc12dd
Added policies
juankaromo Jul 30, 2020
1c31ea3
added hooks and hocs to check user permissions
Desvelao Jul 31, 2020
115885a
fix useWindowSize hook first state
Desvelao Jul 31, 2020
c6d570f
Added roles
juankaromo Jul 31, 2020
fce8696
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
juankaromo Jul 31, 2020
cc7ecaf
Added roles policies load
juankaromo Jul 31, 2020
3f03d39
created function to check rbac missing requirement to use with compon…
Desvelao Jul 31, 2020
a02a785
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Jul 31, 2020
5f85e34
Added control RBAC to some buttons
victorst79 Jul 31, 2020
6e533db
Added policies
juankaromo Jul 31, 2020
85b640e
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
juankaromo Jul 31, 2020
8317cda
work in RBAC UI: changes in Management sections, adjustments in WzBut…
Desvelao Aug 3, 2020
eb5f8f3
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 3, 2020
2573ea8
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 4, 2020
371fa20
fixes in list-editor.js file permissions
Desvelao Aug 4, 2020
7a3739e
added hooks and hocs for user roles, fix argument name in a user perm…
Desvelao Aug 4, 2020
a48ec4f
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 4, 2020
696efb3
Add XPACK users administration from the app
pablotr9 Aug 4, 2020
410688e
Fix cron-scheduler error handler
pablotr9 Aug 4, 2020
85819cf
added user roles check
victorst79 Aug 4, 2020
315684d
added function to check user role or roles
victorst79 Aug 5, 2020
09f14d8
updated permissions hooks with conditonal, WzButtonPermissions suppor…
Desvelao Aug 5, 2020
a0eede7
Merge branch 4.0-7.8-0-rbac
Desvelao Aug 5, 2020
724fde3
modify userRole check function
victorst79 Aug 5, 2020
72ced95
refactored checkMissingUserPermissions function to a service like a c…
Desvelao Aug 5, 2020
e513b39
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 5, 2020
f3a7c7e
added reducers and action creators for userRoles and userPermissions …
Desvelao Aug 5, 2020
51f7d92
remove adminMode in sample data section
victorst79 Aug 5, 2020
6181370
fixes in names hooks used in withUserRoles, created WzEmptyPromptNoPe…
Desvelao Aug 5, 2020
694ad16
Merge branch 4.0-7.8.0-rbac
Desvelao Aug 5, 2020
1759c0c
Added policy creation
juankaromo Aug 5, 2020
7f16846
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
juankaromo Aug 5, 2020
4e9a4a0
Create policy
juankaromo Aug 6, 2020
d567dd9
added export hooks and hocs in index file, added types to WzButtonPer…
Desvelao Aug 7, 2020
dcbc470
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 7, 2020
e6a9eac
fix Management/Groups section permission requirement
Desvelao Aug 7, 2020
658b7a9
substitution work continues for adminMode
victorst79 Aug 7, 2020
b337614
removing adminMode related logic
Desvelao Aug 10, 2020
9bd20a9
simplify edit configuration button, icons buttons in columns-agents.j…
Desvelao Aug 10, 2020
2983841
Add create/edit Roles section
pablotr9 Aug 10, 2020
bc14d7a
Handle failed items
pablotr9 Aug 10, 2020
b4f0bb5
Fix role creation/edition
pablotr9 Aug 10, 2020
5420034
commented admin mode requirement for update wazuh.yml file and remove…
Desvelao Aug 10, 2020
d267788
Add default role tag to Roles table
pablotr9 Aug 10, 2020
a4d1ea8
removed some dennied hardcoded permissions and remove admin mode if s…
Desvelao Aug 10, 2020
14bd206
added type definitions in globla breadcrumb HOC and hook, WzButtonPer…
Desvelao Aug 10, 2020
9b62f63
added withReduxProvider HOC
Desvelao Aug 10, 2020
0cda704
improved checkMissingUserPermissions function. Added user authorizati…
Desvelao Aug 10, 2020
2072c62
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 10, 2020
c5412c8
fix hardcoded administrator role in appStateReducers
Desvelao Aug 10, 2020
22ba31e
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 10, 2020
b22f71a
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 11, 2020
2bbec80
fix some HOCs description file
Desvelao Aug 11, 2020
c44f29c
fixes with agent 'Never connected' status in some components like pro…
Desvelao Aug 11, 2020
2516b21
Allow editing policies
pablotr9 Aug 11, 2020
25a3e09
fix node list api request
Desvelao Aug 11, 2020
f0e68ac
fix space between role names in WzButtonPermissions tooltip and simpl…
Desvelao Aug 11, 2020
d0a2ddc
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 11, 2020
a6799e3
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 12, 2020
cfc8d88
removed '/v4' from API endpoints
Desvelao Aug 12, 2020
ed62496
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 12, 2020
f11edb5
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 12, 2020
e005c90
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
juankaromo Aug 12, 2020
4091e33
fix redirect to Security tabs from menu and change 'tab' param when c…
Desvelao Aug 12, 2020
cd2ad53
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 12, 2020
d59e4eb
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 12, 2020
271a2de
removed warning in EuiBadge of Roles table and double tooltip
Desvelao Aug 12, 2020
e0f21e9
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Aug 12, 2020
aef7770
Remove users creation/edition
pablotr9 Aug 13, 2020
4ade6fd
Roles/Policies section improvements
pablotr9 Aug 13, 2020
ce47ace
Fix create role button
pablotr9 Aug 13, 2020
b14c7e0
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 13, 2020
e8e0198
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 14, 2020
3f08bfa
[4.0] Configuration/Google Cloud Pub/Sub, Configuration fixes and and…
Desvelao Aug 14, 2020
0b9440c
Fix save app configuration. The 'configuration' variable was not defi…
Desvelao Aug 17, 2020
ead3321
fix show a success toast in settings/configuration when there is an e…
Desvelao Aug 17, 2020
faec034
Merge branch '4.0-7.8' of https://github.com/wazuh/wazuh-kibana-app i…
juankaromo Aug 18, 2020
a93814a
Redesign Security Events tab (#2440)
pablotr9 Aug 19, 2020
e796afd
Refactor Module/Events tab:
Desvelao Aug 20, 2020
180db38
Merge pull request #2442 from wazuh/4.0-7.8.0-rbac.refactor-module-ev…
juankaromo Aug 20, 2020
773b1ea
Set index patterns name as constants
pablotr9 Aug 21, 2020
9d48060
Merge pull request #2447 from wazuh/4.0-7.8-set-ip-as-constants
juankaromo Aug 24, 2020
7f551fd
Add new DevTools (#2448)
pablotr9 Aug 24, 2020
464e545
Fix errors found with Wazuh 4.0 (#2445)
pablotr9 Aug 25, 2020
5909dd7
Load users table and allow editing users
pablotr9 Aug 26, 2020
156f43a
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
pablotr9 Aug 26, 2020
f7122d0
Fix useApiRequest hook
pablotr9 Aug 26, 2020
96a7dc5
Minor fix
pablotr9 Aug 27, 2020
616c996
Set index patterns name as constants
pablotr9 Aug 21, 2020
ff3d095
Add Opendistro get users list endpoint
pablotr9 Aug 27, 2020
477dfdf
Adapt Security section to Opendistro
pablotr9 Aug 27, 2020
49a0d92
Fix redirect to Agent Welcome screen from Agent configuration
pablotr9 Aug 27, 2020
c7f03f2
Fix sample alerts prefix
pablotr9 Aug 27, 2020
d3f051d
Fix vulnerabilities visualization label
pablotr9 Aug 27, 2020
1e10c5c
Fix double tooltip in delete reporting button in Management/Reporting…
Desvelao Aug 28, 2020
7acf5d2
Dev/rbac run as RC1 (#2454)
juankaromo Sep 2, 2020
bfce83b
Fix wazuh-registry creation
juankaromo Sep 3, 2020
5e397d4
Add default factory
pablotr9 Sep 3, 2020
6826b25
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
pablotr9 Sep 3, 2020
3e4af73
add return response in /api/login endpoint
Desvelao Sep 3, 2020
47c9061
Refresh token if API is changed
pablotr9 Sep 3, 2020
2554cdf
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
pablotr9 Sep 3, 2020
cf8573c
Explicit resources in button and prompt components
Desvelao Sep 3, 2020
1e63fc5
Clean initial user permissions and roles in Redux store
Desvelao Sep 3, 2020
82101e2
Add check partial recource of user permissions
Desvelao Sep 3, 2020
7b14392
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 3, 2020
f0c1c07
Fix typo
pablotr9 Sep 3, 2020
1a7e5c9
Remove brace imports, textmate theme file and props in euiCodeEditor
Desvelao Sep 3, 2020
f258f2c
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 3, 2020
8aaaf10
fix missing parenthesis in permission resource of WzButtonPermissions
Desvelao Sep 3, 2020
9f0d24f
Revert "Remove codemirror"
pablotr9 Sep 4, 2020
411a965
Fix section selected in Settings sub menu when you aren't in Settings…
Desvelao Sep 4, 2020
5274e3a
Restore old devtools
pablotr9 Sep 4, 2020
65a417b
Fix plugin installation & restore brace
pablotr9 Sep 4, 2020
651b7e6
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
pablotr9 Sep 4, 2020
b846ce1
Add themes to editors
pablotr9 Sep 4, 2020
07eb2c0
Add agents count of nodes in Management/Status
Desvelao Sep 4, 2020
e47c33f
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 4, 2020
a5bb8dc
Do not create index pattern on Kibana restart
pablotr9 Sep 7, 2020
854848a
Fix visualizations expansion in Management/Cluster
Desvelao Sep 7, 2020
4f04430
Fix getToken method
pablotr9 Sep 7, 2020
814a1dc
removed default value for 'remove_from_bucket' in Configuration/Amazo…
Desvelao Sep 7, 2020
3b9ff4b
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 7, 2020
806ffa5
Update agent register guide to 4.x
pablotr9 Sep 8, 2020
fdfbe97
Removed no used constant in React component for HTML custom field
Desvelao Sep 8, 2020
8292503
Fix visualization in Statictics when cluster mode is disabled
Desvelao Sep 8, 2020
5471d9b
Refresh backend token on api check connection
pablotr9 Sep 8, 2020
492e9b5
Wait token refresh until there's a selected API
pablotr9 Sep 8, 2020
7cd1270
Refresh token on selected API change
pablotr9 Sep 8, 2020
dccc200
Remove console.log
pablotr9 Sep 8, 2020
a98cfbb
Fix permanent prompt of permissions to manage users in Security secti…
Desvelao Sep 8, 2020
8c8c4a0
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 8, 2020
19e2661
Modified the components which renders the required user permissions a…
Desvelao Sep 9, 2020
a4a6f97
Adapt the function to check the missings user permissions to support …
Desvelao Sep 9, 2020
7a16590
Adapt buttons in Rules/Decoders/Lists to multiple one of permissions
Desvelao Sep 9, 2020
2646fa4
Replaced action Euibutton in List editor by WzButtonPermissions and f…
Desvelao Sep 9, 2020
8483592
Fix refresh visualizations in Management/Statistics
Desvelao Sep 9, 2020
9504fcd
Fix policies cretion
pablotr9 Sep 9, 2020
d3d1398
Fix API selection management with RBAC
pablotr9 Sep 9, 2020
9e59297
Removed console warnings due to React components
Desvelao Sep 9, 2020
c1cb672
Fix the check that the sample data indices exist in Module/Dashboard
Desvelao Sep 10, 2020
ef66e85
Fix sample data manager.name field
pablotr9 Sep 10, 2020
11dbb1d
Fix last registered agent in Status section
pablotr9 Sep 10, 2020
25c8620
Fix GET request in DevTools
pablotr9 Sep 10, 2020
ad78b9e
Fix Promise.error in fetch-api.js
Desvelao Sep 10, 2020
ca52e57
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 10, 2020
687a0ee
Fix inventory data and groups report
pablotr9 Sep 10, 2020
df7f55a
Fix export button was missing in Configuration for and agent
Desvelao Sep 10, 2020
fe59714
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 10, 2020
28428b7
Fix styles of manage agents select in group for Dark mode
Desvelao Sep 10, 2020
08c0d9f
Fix colored stats in dark mode, had color: white as style and didn't …
Desvelao Sep 10, 2020
c5b7207
Fix filter by pci_dss in ruleset table
pablotr9 Sep 11, 2020
d28eae7
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
pablotr9 Sep 11, 2020
d40c964
Fix apply filter to search bar in Agents from Management directory
Desvelao Sep 11, 2020
fa41c37
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 11, 2020
4a483ae
Fix new term search in WzSearchBar didn't refresh when there was a pr…
Desvelao Sep 11, 2020
f720e4b
Improvements in WzSearchBar components:
Desvelao Sep 11, 2020
dad09c8
Improvements in WzRestartClusterOrManagerCallout:
Desvelao Sep 11, 2020
02f0891
Adapt /api/request with path=/ping endpoint to Wazuh 4.0
Desvelao Sep 11, 2020
5e1e44e
Changes in makePing method of fetch-api.js:
Desvelao Sep 11, 2020
484f388
Fix DevTools requests
pablotr9 Sep 14, 2020
afe43c4
Fix group reports
pablotr9 Sep 14, 2020
a16576b
Fix WazuhApi makeRequest output format
pablotr9 Sep 14, 2020
d3776b0
Update default API credentials
pablotr9 Sep 14, 2020
8ddfa92
Improvements in Management/Logs:
Desvelao Sep 14, 2020
56fd2f1
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 14, 2020
9d2c991
Fix enhance 'rule.mitre.id' cell in discover of Module/Events if the …
Desvelao Sep 14, 2020
cff1a8f
Fix in WzRuleInfo component a 'index' variable was not defined
Desvelao Sep 14, 2020
5650a2c
Remove administrator permissions in API configuration section
pablotr9 Sep 14, 2020
1b77704
Fix predefined-jobs fields
jsanchez91 Sep 14, 2020
23b550a
Merge branch '4.0-7.8.0-rbac' of github.com:wazuh/wazuh-kibana-app in…
jsanchez91 Sep 14, 2020
1e13049
Improvements in protection of backend endpoints which require adminis…
Desvelao Sep 14, 2020
fb18e06
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 14, 2020
fa765c2
Fix close flyout of Technique link in Security Alerts table of Module…
Desvelao Sep 16, 2020
e97fd24
Fix description of withWindowSize and useWindowSize files
Desvelao Sep 16, 2020
35c0ac3
Fix the columns of Discover component didn't change when select an agent
Desvelao Sep 16, 2020
e1aafee
Apply the query to the "SecurityAlerts" table
jsanchez91 Sep 16, 2020
42e4623
Merge branch '4.0-7.8.0-rbac' of github.com:wazuh/wazuh-kibana-app in…
jsanchez91 Sep 16, 2020
957c300
Fix columns width of Discover component:
Desvelao Sep 16, 2020
9669543
Merge branch '4.0-7.8.0-rbac' of https://github.com/wazuh/wazuh-kiban…
Desvelao Sep 16, 2020
4bc5aab
Added SCA to Modules directory
Desvelao Sep 16, 2020
083b39d
Fix HealthCheck errors
pablotr9 Sep 17, 2020
38b683c
Fix reauthenticate in ApiInterceptor.request
Desvelao Sep 18, 2020
06cf9a3
Fixes in endpoint of sample data:
Desvelao Sep 18, 2020
cfd3a10
Moved reauthenticate logic to WzRequest.genericReq
Desvelao Sep 18, 2020
efa186e
Removed wzUserRoles service:
Desvelao Sep 18, 2020
7d31742
Clean code:
Desvelao Sep 18, 2020
cd6e24e
Fix Agent status tooltip
pablotr9 Sep 21, 2020
8773239
Created withGuard HOC
Desvelao Sep 21, 2020
bc3fe43
Fixes in the prompts of the modules with custom tabs:
Desvelao Sep 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { resolve } from 'path';
import { WazuhPlugin, LegacySetup } from './server/plugin';
import { WAZUH_ALERTS_PATTERN, WAZUH_MONITORING_PATTERN } from './util/constants'

export default (kibana) => {
return new kibana.Plugin({
Expand All @@ -23,7 +24,7 @@ export default (kibana) => {
id: 'wazuh',
title: 'Wazuh',
description: 'Wazuh app for Kibana',
icon: 'plugins/wazuh/img/icon_blue.svg',
icon: 'plugins/wazuh/img/icon_blue.png',
main: 'plugins/wazuh/app'
},
hacks: ['plugins/wazuh/icon-style'],
Expand Down Expand Up @@ -60,7 +61,7 @@ export default (kibana) => {

xpackMainPlugin.registerFeature({
id: featureId,
name: 'C',
name: 'Wazuh',
navLinkId: featureId,
icon: '/plugins/wazuh/img/icon_blue.svg',
app: [featureId],
Expand All @@ -70,8 +71,8 @@ export default (kibana) => {
app: [featureId],
api: [],
savedObject: {
all: ['wazuh-alerts-3.x-*', 'wazuh-monitoring-3.x-*'],
read: ['wazuh-alerts-3.x-*', 'wazuh-monitoring-3.x-*']
all: [WAZUH_ALERTS_PATTERN, WAZUH_MONITORING_PATTERN],
read: [WAZUH_ALERTS_PATTERN, WAZUH_MONITORING_PATTERN]
},
ui: ['save', 'show']
},
Expand All @@ -80,7 +81,7 @@ export default (kibana) => {
api: [],
savedObject: {
all: [],
read: ['wazuh-alerts-3.x-*', 'wazuh-monitoring-3.x-*']
read: [WAZUH_ALERTS_PATTERN, WAZUH_MONITORING_PATTERN]
},
ui: ['show']
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"revision": "4001",
"code": "4001-0",
"kibana": {
"version": "7.8.1"
"version": "7.8.0"
},
"description": "Wazuh app",
"main": "index.js",
Expand Down Expand Up @@ -50,6 +50,7 @@
"install": "^0.10.1",
"js2xmlparser": "^3.0.0",
"json2csv": "^4.1.2",
"jwt-decode": "^2.2.0",
"needle": "^2.0.1",
"node-cron": "^1.1.2",
"pdfmake": "^0.1.37",
Expand Down
21 changes: 11 additions & 10 deletions public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ import './services';
import './controllers';
import './factories';

// Imports to update adminMode when app starts
import { checkAdminMode } from './controllers/management/components/management/configuration/utils/wz-fetch';
// Imports to update currentPlatform when app starts
import { checkCurrentSecurityPlatform } from './controllers/management/components/management/configuration/utils/wz-fetch';
import store from './redux/store';
import { updateAdminMode } from './redux/actions/appStateActions';
import { updateCurrentPlatform } from './redux/actions/appStateActions';
import { WzAuthentication } from './react-services/wz-authentication'

import { getAngularModule } from 'plugins/kibana/discover/kibana_services';
const app = getAngularModule('app/wazuh');
Expand Down Expand Up @@ -111,12 +112,12 @@ app.run([
changeWazuhNavLogo();
app.$injector = _$injector;

// Set adminMode in Redux when app starts.
// It prevents the first rendering, which depends on adminMode, from blinking due to a request to the app backend
checkAdminMode()
.then(adminMode => {
store.dispatch(updateAdminMode(adminMode))
})
.catch(() => {/* Do nothing if it fails */ })
// Set currentSecurity platform in Redux when app starts.
checkCurrentSecurityPlatform().then((item) => {
store.dispatch(updateCurrentPlatform(item))
}).catch(() => {})

// Init the process of refreshing the user's token when app start.
WzAuthentication.refresh();
}
]);
19 changes: 18 additions & 1 deletion public/components/add-modules-data/WzSampleDataWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ import {
} from '@elastic/eui';
import WzSampleData from './sample-data'
import WzReduxProvider from '../../redux/wz-redux-provider';
import { withUserAuthorizationPrompt } from '../../components/common/hocs/withUserAuthorization';
import store from '../../redux/store';
import { updateSelectedSettingsSection } from '../../redux/actions/appStateActions';
import { WAZUH_ROLE_ADMINISTRATOR_NAME } from '../../../util/constants';

export class WzSampleDataWrapper extends Component {
export class WzSampleDataProvider extends Component {
constructor(props) {
super(props);
this.state = {};
}

componentDidMount(){
store.dispatch(updateSelectedSettingsSection('sample_data'));
}

render() {
return (
<EuiPage>
Expand Down Expand Up @@ -64,3 +72,12 @@ export class WzSampleDataWrapper extends Component {
);
}
}

const WzSampleDataWrapperWithAdministrator = withUserAuthorizationPrompt(null, [WAZUH_ROLE_ADMINISTRATOR_NAME])(WzSampleDataProvider);
export function WzSampleDataWrapper() {
return (
<WzReduxProvider>
<WzSampleDataWrapperWithAdministrator />
</WzReduxProvider>
)
}
81 changes: 26 additions & 55 deletions public/components/add-modules-data/sample-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*/

import React, { Component, Fragment } from 'react';
import { checkAdminMode } from '../../controllers/management/components/management/configuration/utils/wz-fetch';
import { updateAdminMode } from '../../redux/actions/appStateActions';
import { WzButtonPermissions } from '../../components/common/permissions/button';

import {
EuiFlexItem,
Expand All @@ -29,14 +28,10 @@ import {

import { toastNotifications } from 'ui/notify';
import { WzRequest } from '../../react-services/wz-request';
import { connect } from 'react-redux';
import { AppState } from '../../react-services/app-state';
import { WAZUH_ROLE_ADMINISTRATOR_NAME } from '../../../util/constants';

interface IWzSampleDataProps{
adminMode?: boolean
updateAdminMode: (adminMode: boolean) => void
};

class WzSampleData extends Component<IWzSampleDataProps> {
export default class WzSampleData extends Component {
categories: {title: string, description: string, image: string, categorySampleAlertsIndex: string}[]
generateAlertsParams: any
state: {
Expand Down Expand Up @@ -79,20 +74,9 @@ class WzSampleData extends Component<IWzSampleDataProps> {
});
}
async componentDidMount(){
// Check adminMode
try{
const adminMode: boolean = await checkAdminMode();
if(this.props.adminMode !== adminMode){
this.props.updateAdminMode(adminMode);
};
if(!adminMode){ // redirect to root path of the application
window.location.href = `#/`;
};
}catch(error){}

// Check if sample data for each category was added
try{
const results = await PromiseAllRecusiveObject(this.categories.reduce((accum, cur) => {
const results = await PromiseAllRecursiveObject(this.categories.reduce((accum, cur) => {
accum[cur.categorySampleAlertsIndex] = WzRequest.genericReq('GET', `/elastic/samplealerts/${cur.categorySampleAlertsIndex}`)
return accum
},{}));
Expand All @@ -108,14 +92,15 @@ class WzSampleData extends Component<IWzSampleDataProps> {

// Get information about cluster/manager
try{
const managerInfo = await WzRequest.apiReq('GET', '/manager/info', {});
const clusterName = AppState.getClusterInfo().cluster;
const managerName = AppState.getClusterInfo().manager;
this.generateAlertsParams.manager = {
name: managerInfo.data.data.name
name: managerName
};
if (managerInfo.data.data.cluster) {
if (clusterName && clusterName !== 'Disabled') {
this.generateAlertsParams.cluster = {
name: managerInfo.data.data.cluster.name,
node: managerInfo.data.data.cluster.node_name
name: clusterName,
node: clusterName
};
};

Expand Down Expand Up @@ -173,7 +158,6 @@ class WzSampleData extends Component<IWzSampleDataProps> {
}
renderCard(category){
const { addDataLoading, exists, removeDataLoading } = this.state[category.categorySampleAlertsIndex];
const { adminMode } = this.props;
return (
<EuiFlexItem key={`sample-data-${category.title}`}>
<EuiCard
Expand All @@ -186,20 +170,21 @@ class WzSampleData extends Component<IWzSampleDataProps> {
<EuiFlexGroup justifyContent="flexEnd">
<EuiFlexItem grow={false}>
{exists && (
<EuiButton
isLoading={removeDataLoading}
isDisabled={!adminMode}
<WzButtonPermissions
color='danger'
onClick={() => this.removeSampleData(category)}>
{removeDataLoading && 'Removing data' || 'Remove data'}
</EuiButton>
roles={[WAZUH_ROLE_ADMINISTRATOR_NAME]}
onClick={() => this.removeSampleData(category)}
>
{removeDataLoading && 'Removing data' || 'Remove data'}
</WzButtonPermissions>
) || (
<EuiButton
<WzButtonPermissions
isLoading={addDataLoading}
isDisabled={!adminMode}
onClick={() => this.addSampleData(category)}>
{addDataLoading && 'Adding data' || 'Add data'}
</EuiButton>
roles={[WAZUH_ROLE_ADMINISTRATOR_NAME]}
onClick={() => this.addSampleData(category)}
>
{addDataLoading && 'Adding data' || 'Add data'}
</WzButtonPermissions>
)}
</EuiFlexItem>
</EuiFlexGroup>
Expand All @@ -224,29 +209,15 @@ const zipObject = (keys = [], values = []) => {
}, {})
}

const PromiseAllRecusiveObject = function (obj) {
const PromiseAllRecursiveObject = function (obj) {
const keys = Object.keys(obj);
return Promise.all(keys.map(key => {
const value = obj[key];
// Promise.resolve(value) !== value should work, but !value.then always works
if (typeof value === 'object' && !value.then) {
return PromiseAllRecusiveObject(value);
return PromiseAllRecursiveObject(value);
}
return value;
}))
.then(result => zipObject(keys, result));
};

const mapStateToProps = state => {
return {
adminMode: state.appStateReducers.adminMode
};
};

const mapDispatchToProps = dispatch => {
return {
updateAdminMode: adminMode => dispatch(updateAdminMode(adminMode))
}
};

export default connect(mapStateToProps,mapDispatchToProps)(WzSampleData);
};
Loading