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

Feat/crud role mapping #1169

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to the Wazuh app for Splunk project will be documented in th

- Support for Wazuh 4.2.3
- Added Crud Roles on security section. [#1168](https://github.com/wazuh/wazuh-splunk/pull/1168)
- Added Crud Role Mapping on security section. [#1169](https://github.com/wazuh/wazuh-splunk/pull/1169)

## Wazuh v4.2.2 - Splunk Enterprise v8.1.4, v8.2.2 - Revision 4202

Expand Down
99 changes: 99 additions & 0 deletions SplunkAppForWazuh/appserver/controllers/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
"""
Wazuh app - API backend module.

Copyright (C) 2015-2021 Wazuh, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Find more information about this on the LICENSE file.
"""

import splunk.appserver.mrsparkle.controllers as controllers
from splunk.appserver.mrsparkle.lib.decorators import expose_page
from log import log

import jsonbak as json
import splunk.auth as splunk_auth
import re


def to_json(data: str):
"""
Apply few fixes to a String representation of an object in order
to be parsed as a JSON object following the (RFC 8259) standard.

Parameters
----------
data : str
The string to be parsed.

Returns
----------
data : JSON object or str
The parsed string as a JSON object if possible, as a string otherwise.
"""
data = re.sub('\'\{', '{', data) # Replace '{ with {
data = re.sub('\}\'', '}', data) # Replace }' with }
data = re.sub('\'', '"', data) # Replace ' with "
data = re.sub('None', '"None"', data) # Replace None with "None"

try:
return json.loads(data)
except ValueError:
log().error("Users - to_json() - invalid string representation of "
+ "a JSON object. Unable to parse.")
raise


class Users(controllers.BaseController):
"""
Users class

Implements methods to retrieve users registered in Splunk.
"""

def __init__(self):
"""
Constructor
"""
try:
controllers.BaseController.__init__(self)
self.logger = log()
except Exception as e:
self.logger.error("Users: Error initializing object")

@expose_page(methods='GET')
def get_current_user(self):
"""
Returns the user logged in.
"""
try:
self.logger.debug("Users: get_current_user()")
user = splunk_auth.getCurrentUser()
return json.dumps(user)
except Exception as e:
self.logger.error("Users: Error getting Splunk's current user")
return json.dumps({"error": str(e)})

@expose_page(methods='GET')
def get_users(self):
"""
Returns a list with every user registered in this Splunk's instance.
"""
try:
self.logger.debug("Users: get_users()")
# The method listUsers() returns an EntityCollection object, which
# is not JSON serializable. The string representation does not match
# a JSON representation neither, so a few fixes must be done first.
# We are going to parse the string representation of the object
# following the (RFC 8259) standard.
users = splunk_auth.listUsers().__str__()
users = to_json(users)
return json.dumps(users)
except Exception as e:
self.logger.error("Users: Error getting internal Splunk's users")
return json.dumps({"error": str(e)})
61 changes: 61 additions & 0 deletions SplunkAppForWazuh/appserver/static/css/styles/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,11 @@ span.wrong {
font-weight: 400;
}

.tSize20 {
font-size: 20px;
font-weight: 400;
}

.noBorderBottom {
border-bottom: none !important;
}
Expand Down Expand Up @@ -1775,6 +1780,62 @@ input:focus {
margin-right: 50px !important;
}

.conf-operator-selector {
margin-top: 5px !important;
margin-right: 50px !important;
margin-left: 50px !important;
border-color: #c3cbd4 !important;
color: #5c6773 !important;
}

.delete-button-icon {
color: #BD271E;
display: inline-block;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
height: 40px;
line-height: 40px;
text-align: center;
white-space: nowrap;
max-width: 100%;
vertical-align: middle;
font-family: "Inter UI", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-weight: 400;
letter-spacing: -.005em;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-webkit-font-kerning: normal;
font-kerning: normal;
font-size: 16px;
font-size: 1rem;
line-height: 1.5;
text-decoration: none;
border: solid 1px transparent;
transition: all 250ms ease-in-out;
border: none;
background-color: transparent;
box-shadow: none;
height: auto;
min-height: 24px;
min-width: 24px;
line-height: 0;
padding: 4px;
border-radius: 4px;
}

.customRoleMappingInput{
margin-top: 5px !important;
}

.new-custom-rule-container{
width: 50%;
display: flex;
align-items: center;
justify-content: space-between;
}

.settings-edit-ossec {
margin-right: -10px !important;
margin-top: -2px !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ define(['../module'], function(module) {
return false
}
}
],
roles: [
'$requestService',
async $requestService => {
try {
return await $requestService.apiReq('/security/roles')
} catch (err) {
return { error: 'Cannot fetch roles from API' }
}
}
],
splunkUsers: [
'$splunkUsers',
async $splunkUsers => {
try {
return await $splunkUsers.getInternalUsers()
} catch (err) {
return { error: 'Cannot fetch splunk users from API' }
}
}
]
}
})
Expand Down
Loading