Grant rights to the collection(Apache Solr) - solr

I have this security.json configuration
How can I grant separate rights to the google.cloud.integration.1 collection?
With the current configuration, the google.cloud.integration.1 collection or alias cannot be deleted, I get error 403
solr version 8.11
{
"authentication": {
"class": "com.us.CustomSSLAuthenticationPlugin"
},
"authorization": {
"class": "com.us.BasedAuthorizationPlugin",
"user-role": {
"CN=...": [
"admin_ro"
]
},
"permissions": [
{
"collection": "google.cloud.integration.1",
"path": "/admin/collections",
"params": {
"action": [
"LIST",
"LISTALIASES",
"CREATEALIAS",
"DELETEALIAS",
"CLUSTERSTATUS",
"ADDREPLICA"
]
},
"role": [
"admin_rw",
"admin_ow",
"admin_ro",
"solr-internal-traffic"
]
},
{
"collection": null,
"path": "/admin/collections",
"params": {
"action": [
"LIST",
"LISTALIASES",
"CLUSTERSTATUS"
]
},
"role": [
"rb55_bhb_epkid_rw",
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"collection": null,
"path": "/admin/collections",
"params": {
"action": [
"LIST",
"LISTALIASES",
"CREATEALIAS",
"DELETEALIAS",
"CLUSTERSTATUS",
"ADDREPLICA"
]
},
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"collection": null,
"path": "/admin/configs",
"params": {
"action": [
"LIST"
]
},
"role": [
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"collection": null,
"path": "/admin/configs",
"params": {
"action": [
"LIST",
"CREATE",
"DELETE",
"UPDATE"
]
},
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "update",
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "config-edit",
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "schema-edit",
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "security-edit",
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "core-admin-edit",
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "collection-admin-edit",
"role": [
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "read",
"role": [
"admin_ro",
"admin_rw",
"solr-internal-traffic"
]
},
{
"name": "config-read",
"role": [
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "schema-read",
"role": [
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "security-read",
"role": [
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "core-admin-read",
"role": [
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "collection-admin-read",
"role": [
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "metrics-read",
"role": [
"admin_ro",
"admin_rw",
"jmx_ro",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "all",
"role": [
"admin_ro",
"admin_rw",
"admin_ow",
"solr-internal-traffic"
]
},
{
"name": "read",
"role": "default-deny-all"
},
{
"name": "schema-read",
"role": "default-deny-all"
},
{
"name": "config-read",
"role": "default-deny-all"
},
{
"name": "collection-admin-read",
"role": "default-deny-all"
},
{
"name": "metrics-read",
"role": "default-deny-all"
},
{
"name": "core-admin-read",
"role": "default-deny-all"
},
{
"name": "security-read",
"role": "default-deny-all"
},
{
"name": "update",
"role": "default-deny-all"
},
{
"name": "schema-edit",
"role": "default-deny-all"
},
{
"name": "config-edit",
"role": "default-deny-all"
},
{
"name": "collection-admin-edit",
"role": "default-deny-all"
},
{
"name": "core-admin-edit",
"role": "default-deny-all"
},
{
"name": "security-edit",
"role": "default-deny-all"
},
{
"name": "all",
"role": "default-deny-all"
}
]
}
}
I want to make the collection google.cloud.integration.1 could be deleted

Related

Removing and printing name/value pair from json using jolt

I want to remove a name/value pair from inside a json array and print it outside. I started by trying this and then expanding the whole request to be a json array. The solution mentioned above does not seem to be working.
Input :
[
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
},
{
"name": "Details",
"value": {
"createdDate": "today",
"description": "offer",
"id": null
}
}
],
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
},
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
},
{
"name": "Details",
"value": {
"createdDate": "today",
"description": "offer",
"id": null
}
}
],
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
}
]
Desired Output :
[
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
}
],
"Details": {
"createdDate": "today",
"description": "offer",
"id": null
},
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
},
{
"createdBy": "Admin",
"createdDate": "2022-09-08",
"modifiedBy": "Admin",
"attrs": [
{
"name": "Type",
"value": "Postpaid"
},
{
"name": "subscriber",
"value": "Paid"
}
],
"Details": {
"createdDate": "today",
"description": "offer",
"id": null
},
"relatedInfo": [
{
"type": "Number",
"name": "000000"
},
{
"type": "Type",
"name": "Post"
}
]
}
]
Current Jolt spec:
[
{
"operation": "shift",
"spec": {
"*": "[&]",
"attrs": {
"*": {
"name": {
"*": { "#2": "&4" },
"Details": {
"#(2,value)": "&1"
}
}
}
}
}
}
]
I can't seem to figure out how the jolt spec would change in case of the array
So far so good, just need to combine the attributes at a common node. To do this, I've used the identifiers [&1] and [&5] in order to reach the level of the outermost index within the tree such as
[
{
"operation": "shift",
"spec": {
"*": {
"*": "[&1].&",
"attrs": {
"*": {
"name": {
"*": {
"#2": "[&5].&4"
},
"Details": {
"#(2,value)": "[&5].&1"
}
}
}
}
}
}
}
]

Performance issue running mongodb aggregation

I need to run a query that joins documents from two collections, I wrote an aggregation query but it takes too much time when running in the production database with many documents. Is there any way to write this query in a more efficient way?
Query in Mongo playground: https://mongoplayground.net/p/dLb3hsJHNYt
There are two collections users and activities. I need to run a query to get some users (from users collection), and also their last activity (from activities collection).
Database:
db={
"users": [
{
"_id": 1,
"email": "user1#gmail.com",
"username": "user1",
"country": "BR",
"creation_date": 1646873628
},
{
"_id": 2,
"email": "user2#gmail.com",
"username": "user2",
"country": "US",
"creation_date": 1646006402
}
],
"activities": [
{
"_id": 1,
"email": "user1#gmail.com",
"activity": "like",
"timestamp": 1647564787
},
{
"_id": 2,
"email": "user1#gmail.com",
"activity": "comment",
"timestamp": 1647564834
},
{
"_id": 3,
"email": "user2#gmail.com",
"activity": "like",
"timestamp": 1647564831
}
]
}
Inefficient Query:
db.users.aggregate([
{
// Get users using some filters
"$match": {
"$expr": {
"$and": [
{ "$not": { "$in": [ "$country", [ "AR", "CA" ] ] } },
{ "$gte": [ "$creation_date", 1646006400 ] },
{ "$lte": [ "$creation_date", 1648684800 ] }
]
}
}
},
{
// Get the last activity within the time range
"$lookup": {
"from": "activities",
"as": "last_activity",
"let": { "cur_email": "$email" },
"pipeline": [
{
"$match": {
"$expr": {
"$and": [
{ "$eq": [ "$email", "$$cur_email" ] },
{ "$gte": [ "$timestamp", 1647564787 ] },
{ "$lte": [ "$timestamp", 1647564834 ] }
]
}
}
},
{ "$sort": { "timestamp": -1 } },
{ "$limit": 1 }
]
}
},
{
// Remove users with no activity
"$match": {
"$expr": {
"$gt": [ { "$size": "$last_activity" }, 0 ] }
}
}
])
Result:
[
{
"_id": 1,
"country": "BR",
"creation_date": 1.646873628e+09,
"email": "user1#gmail.com",
"last_activity": [
{
"_id": 2,
"activity": "comment",
"email": "user1#gmail.com",
"timestamp": 1.647564788e+09
}
],
"username": "user1"
},
{
"_id": 2,
"country": "US",
"creation_date": 1.646006402e+09,
"email": "user2#gmail.com",
"last_activity": [
{
"_id": 3,
"activity": "like",
"email": "user2#gmail.com",
"timestamp": 1.647564831e+09
}
],
"username": "user2"
}
]
I'm more familiar with relational databases, so I'm struggling a little to run this query efficiently.
Thanks!

Update nested object using positional-filters on different levels - MongoDb update

Considering I have the following collection (ignoring documents _id):
Collection
[
{
"Id": "1",
"Level2": [
{
"Id": "1.1",
"Level3": [
{
"Id": "1.1.1",
"Level3_4": {
"Transport": "Car",
"Level4": [
{
"Id": "1.1.1.1",
"Status": "run",
"Direction": "N"
},
{
"Id": "1.1.1.2",
"Status": "run",
"Direction": "S"
},
{
"Id": "1.1.1.3",
"Status": "pause",
"Direction": "S"
},
{
"Id": "1.1.1.4",
"Status": "run",
"Direction": "W"
}
]
}
},
{
"Id": "1.1.2",
"Level3_4": {
"Transport": "Bus",
"Level4": [
{
"Id": "1.1.2.1",
"Status": "run",
"Direction": "S"
},
{
"Id": "1.1.2.2",
"Status": "stop",
"Direction": "N"
},
{
"Id": "1.1.2.3",
"Status": "stop",
"Direction": "W"
},
{
"Id": "1.1.2.4",
"Status": "run",
"Direction": "E"
}
]
}
}
]
},
{
"Id": "1.2",
"Level3": [
{
"Id": "1.2.1",
"Level3_4": {
"Transport": "Train",
"Level4": [
{
"Id": "1.2.1.1",
"Status": "run",
"Direction": "N"
}
]
}
},
{
"Id": "1.2.2",
"Level3_4": {
"Transport": "Bus",
"Level4": []
}
}
]
}
]
}
]
Update
I want to update all documents in the collection such as:
Level2.Level3.Level3_4.Level4.Status: "pause"
Using updateOne and without upsert
All Level4 that match the next conditions
Conditions
where:
Level2.Level3.Id $in ["1.1.1","1.1.2"] AND
Level2.Level3.Level3_4.Level4.Status $in ["run", "stop"] AND
Level2.Level3.Level3_4.Level4.Direction $in ["N", "S"]
RESULT
The result collection should be:
[
{
"Id": "1",
"Level2": [
{
"Id": "1.1",
"Level3": [
{
"Id": "1.1.1",
"Level3_4": {
"Transport": "Car",
"Level4": [
{
"Id": "1.1.1.1",
"Status": "pause",
"Direction": "N"
},
{
"Id": "1.1.1.2",
"Status": "pause",
"Direction": "S"
},
{
"Id": "1.1.1.3",
"Status": "pause",
"Direction": "S"
},
{
"Id": "1.1.1.4",
"Status": "run",
"Direction": "W"
}
]
}
},
{
"Id": "1.1.2",
"Level3_4": {
"Transport": "Bus",
"Level4": [
{
"Id": "1.1.2.1",
"Status": "pause",
"Direction": "S"
},
{
"Id": "1.1.2.2",
"Status": "pause",
"Direction": "N"
},
{
"Id": "1.1.2.3",
"Status": "stop",
"Direction": "W"
},
{
"Id": "1.1.2.4",
"Status": "run",
"Direction": "E"
}
]
}
}
]
} ...
]
}
]
I'm struggling with the $set operator and arrayFilters. How can I accomplish this?
This is where I went so far:
db.test.update({},
{
$set: {
"Level2.$[level2].Level3.$[level3].Level3_4.Level4.$[level4].Status": "pause"
}
},
{
arrayFilters: [
{
"level3.Id": {
$in: [
"1.1.1",
"1.1.2"
]
}
},
{
"level4.Status": {
$in: [
"run",
"stop"
]
}
},
{
"level4.Direction": {
$in: [
"N",
"S"
]
}
}
]
}
)
However it doesn't work... What am I doing wrong?
You were almost there :)
Just the issue was with the last array filter and in $set
I have Updated the query:
db.session.update(
{},
{
$set: {
"Level2.$[].Level3.$[level3].Level3_4.Level4.$[level4].Status": "pause"
}
},
{
arrayFilters: [
{
"level3.Id": {
$in: [
"1.1.1",
"1.1.2"
]
}
},
{
"level4.Status": {
$in: [
"run",
"stop"
]
},
"level4.Direction": {
$in: [
"N",
"S"
]
}
}
]
}
)
Hope this will help :)

Allow SOLR core only for a single user

I can't find any information on how to allow access to specific SOLR core just for a single user. I am using SOLR7. This is what I've got:
security.json
{
"authentication": {
"blockUnknown": true,
"class": "solr.BasicAuthPlugin",
"credentials": {
"test_admin": "xxx",
"infographics": "xxx",
"test_user": "xxx"
},
"": {
"v": 0
}
},
"authorization": {
"class": "solr.RuleBasedAuthorizationPlugin",
"permissions": [
{
"name": "all",
"role": "admin",
"index": 1
},
{
"name": "update",
"role": "general",
"index": 2
},
{
"name": "read",
"role": [
"general",
"infographics",
"test_user"
],
"index": 3
},
{
"name": "collection-admin-read",
"role": "general",
"index": 4
},
{
"name": "core-admin-read",
"role": "general",
"index": 5
},
{
"name": "core-specific-permission",
"collection": "test-core",
"role": "test_user",
"before": 3,
"index": 6
}
],
"user-role": {
"test_admin": [
"admin",
"general"
],
"infographics": "infographics",
"test_user": "test_user"
},
"": {
"v": 0
}
}
}
I've added a permission for collection "test-core":
{
"name": "core-specific-permission",
"collection": "test-core",
"role": "test_user",
"before": 3,
"index": 6
}
I authenticate with test_user when calling: /solr/test-core/select?q=*:*, this works fine, but it also can access other cores, for e.g.: /solr/other-core/select?q=*:*.
If I remove test_user from read permission:
{
"name": "read",
"role": [
"general",
"infographics"
],
"index": 3
},
then I am not able to query any core. Getting 403. For test_user I'd like to allow access to only this core /solr/test-core/select?q=*:* and nothing else. Any idea how can I achieve this?

how to apply if-else for a complex JSON array

here is the Sample Json:-
[
{
"index": 0,
"object": {
"uri": "entities/oAFpSUX",
"type": "configuration/entityTypes/Pet",
"createdBy": "abc#xyz.com",
"createdTime": 1531431176965,
"updatedBy": "abc#xyz.com",
"updatedTime": 1531431177691,
"attributes": {
"Weight": [
{
"label": "5 lbs",
"value": {
"PetWeightMeasurement": [
{
"ov": true,
"value": "5",
}
],
"PetWeightUOM": [
{
"ov": true,
"value": "lbs",
"lookupCode": "lbs",
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Weight/1AeFvD8Kj"
}
],
"Identifiers": [
{
"label": "5155445576",
"value": {
"Type": [
{
"ov": false,
"value": "CRMO_Pet_Id",
}
],
"ID": [
{
"ov": true,
"value": "5155445576",
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Identifiers/1AeFvCrHh"
}
],
"Vaccination": [
{
"label": "Bordatella - 2018-10-26",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Bordatella",
"lookupCode": "4",
"lookupRawValue": "Bordatella",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "3"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/Type/1AeFvA2X7"
}
],
"ExpirationDate": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/ExpirationDate",
"ov": true,
"value": "2018-10-26",
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/ExpirationDate/1AeFvA6nN"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr"
},
{
"label": "Distemper - 2018-10-25",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Distemper",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "4"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9YhJ/Type/1AeFv9cxZ"
}
],....
My question: I was able to get the value of "$..Vaccination..value.Type..value" as "Bordatella" so that works fine. However what I now want is that if the value is 'Bordatella' then I want to extract the "value" under "ExpirationDate". Can someone please help me how I can extract that "value" under "ExpirationDate" ? I am not sure if I need to do that with some custom Groovy code of using jmeter's if controller. Any help would be greatly appreciated!
Thanks.
There are several ways to run jq queries from within Java - e.g.
https://github.com/eiiches/jackson-jq
https://github.com/arakelian/java-jq (available from Maven Central)
Java Native Access wrapper https://github.com/bskaggs/jjq . Supported platform is Linux only.
Assuming the sample input has been revised in the obvious way to make it valid JSON, the following jq filter will produce the output as shown:
.[].object.attributes.Vaccination[].value
| select(.Type[].value == "Bordatella")
| .ExpirationDate[].value
Output:
"2018-10-26"
Alternative
Here's a jq filter that is agnostic about the relative location of the "Vaccination" object:
..
| objects
| select(has("Vaccination"))
| .Vaccination[].value?
| select(.Type[].value == "Bordatella")
| .ExpirationDate[].value
Given the following JSON response:
[
{
"index": 0,
"object": {
"uri": "entities/oAFpSUX",
"type": "configuration/entityTypes/Pet",
"createdBy": "a...#xyz.com",
"createdTime": 1531431176965,
"updatedBy": "a...#xyz.com",
"updatedTime": 1531431177691,
"attributes": {
"Weight": [
{
"label": "5 lbs",
"value": {
"PetWeightMeasurement": [
{
"ov": true,
"value": "5"
}
],
"PetWeightUOM": [
{
"ov": true,
"value": "lbs",
"lookupCode": "lbs"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Weight/1AeFvD8Kj"
}
],
"Identifiers": [
{
"label": "5155445576",
"value": {
"Type": [
{
"ov": false,
"value": "CRMO_Pet_Id"
}
],
"ID": [
{
"ov": true,
"value": "5155445576"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Identifiers/1AeFvCrHh"
}
],
"Vaccination": [
{
"label": "Bordatella - 2018-10-26",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Bordatella",
"lookupCode": "4",
"lookupRawValue": "Bordatella",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "3"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/Type/1AeFvA2X7"
}
],
"ExpirationDate": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/ExpirationDate",
"ov": true,
"value": "2018-10-26",
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/ExpirationDate/1AeFvA6nN"
}
]
},
"ov": true,
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr"
},
{
"label": "Distemper - 2018-10-25",
"value": {
"Type": [
{
"type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",
"ov": true,
"value": "Distemper",
"lookupAttributes": [
{
"name": "Sort Order",
"value": "4"
}
],
"uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9YhJ/Type/1AeFv9cxZ"
}
]
}
}
]
}
}
}
]
Add JSR223 PostProcessor as a child of the request which returns the above response
Put the following code into "Script" area:
new groovy.json.JsonSlurper().parse(prev.getResponseData()).get(0).get('object').get('attributes').get('Vaccination').each { vaccination ->
if (vaccination.get('value').get('Type').get(0).get('value').equals('Bordatella')) {
def expirationDate = vaccination.get('value').get('ExpirationDate').get(0).get('value')
log.info('ExpirationDate: ' + expirationDate)
vars.put('ExpirationDate', expirationDate)
}
}
If everything goes well (your JSON response matches the Groovy code) the ExpirationDate will be:
printed to jmeter.log file
stored as ${ExpirationDate} JMeter Variable
Demo:
More information:
Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Resources