I'm currently populating a List from a .audit file and extracting out two pieces of information into a Map. Here is what the file looks like:
type : REGISTRY_SETTING
description : "1.9.56 Network security: Do not store LAN Manager hash value on next password change: Enabled"
info : "This control defines whether the LAN Manager (LM) hash value for the new password is stored when the password is changed."
solution : "Make sure 'Do not store LAN Manager hash value on next password change' is Enabled."
reference : "PCI-DSS|8.4,800-53|AC-3,800-53|SC-5,800-53|CM-7,800-53|CM-6,CCE|CCE-8937-5"
see_also : "https://benchmarks.cisecurity.org/tools2/windows/CIS_Microsoft_Windows_7_Benchmark_v1.2.0.pdf"
value_type : POLICY_DWORD
reg_key : "HKLM\System\CurrentControlSet\Control\Lsa"
reg_item : "NoLMHash"
value_data : 1
type : REGISTRY_SETTING
description : "1.13.3 Notify antivirus programs when opening attachments: Enabled"
info : "This control defines whether antivirus program to be notified when opening attachments."
solution : "Make sure 'Notify antivirus programs when opening attachments' is Enabled."
reference : "800-53|SI-3,PCI-DSS|5.1.1,CCE|CCE-10076-8,PCI-DSS|5.1"
see_also : "https://benchmarks.cisecurity.org/tools2/windows/CIS_Microsoft_Windows_7_Benchmark_v1.2.0.pdf"
value_type : POLICY_DWORD
reg_key : "HKU\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments"
reg_item : "ScanWithAntiVirus"
value_data : 3
reg_ignore_hku_users : "S-1-5-18,S-1-5-19,S-1-5-20"
I need the Map to be in a <description,value_data> format, regardless of whether anything comes after value_data Eg:
Key: "1.9.56 Network security: Do not store LAN Manager hash value on next password changed."
Value: 1
Here is my current code for populating the Map with it's key values:
String descriptionString = Pattern.quote("description") + "(.*?)" + Pattern.quote("info");
Pattern descriptionPattern = Pattern.compile(descriptionString);
Matcher descriptionMatcher = descriptionPattern.matcher(auditContentList.get(i));
while(descriptionMatcher.find())
{
System.out.println("Key found ");
customItemMap.put(descriptionMatcher.group(1),"");
}
Problem is I cant use two regexes simultaneously to populate the same index of the Map at any given time. Is there any better way to do this?
for your sample data, maybe you should try this :
description.*?"(.*?)"[\s\S]*?value_data.*?(\d+)
i've test it [here]
Related
I have a TextView which should be updated every updateTime (for example, 1000) milliseconds. Text for updating is retrieved through HTTP-connection from Web server . Web server supports two major requests: request for getting and request for setting values in MySQL database.
PHP-script interacts with the only table in the only database that has structure as shown below :
ID (shortint) | deviceState (integer)
In order to lessen output internet traffic, variable names and possible values in requests are replaced according to table below:
{
"REQUEST_TYPE " - > "q" : ("REQUEST_FOR_GETTING_DEVICE_STATE" - > "0",
"REQUEST_FOR_SETTING_DEVICE_STATE" - > "1");
"ID" -> "w" : integer;
// table stores only one device with (ID) 1
"DEVICE_STATE" - > "e" : integer;
}
Examples of requests:
1) "http://wave-rp-bot.esy.es/server.php?q=0&w=1" - retrieves state of device with (ID) 1 which is stored in a database.
2) "http://wave-rp-bot.esy.es/server.php?q=1&w=1&e=0" - sets state of device with (ID) 1 which is stored in a database as 0.
There is no significant difference If "GET" or "POST" type of requests is used. However, the last one is preferred in terms of security. How can I do this If it's started and stopped by pressing a Button-element.
As an answer I would prefer to get Android project where necessary behaviour is implemented.
I've been working on a program with a .mdb database from a third party client. Everything was fine until I've tried to update elements on the database. The sortOrder field is not correct. I've tried to change it to general with MS Access, and had no luck. The message I get when I execute the update query is:
java.lang.IllegalArgumentException: Given index Index#150ab4ed[
name: (EXART) PrimaryKey
number: 2
isPrimaryKey: true
isForeignKey: false
data: IndexData#3c435123[
dataNumber: 2
pageNumber: 456
isBackingPrimaryKey: true
isUnique: true
ignoreNulls: false
columns: [
ReadOnlyColumnDescriptor#50fe837a[
column: Column#636e8cc[
name: (EXART) ARCodArt
type: 0xa (TEXT)
number: 0
length: 30
variableLength: true
compressedUnicode: true
textSortOrder: SortOrder[3082(0)]
]
flags: 1
]
]
initialized: false
pageCache: IndexPageCache#3a62c01e[
pages: (uninitialized)
]
]
] is not usable for indexed lookups due to unsupported collating sort order SortOrder[3082(0)] for text index
at com.healthmarketscience.jackcess.impl.IndexCursorImpl.createCursor(IndexCursorImpl.java:111)
at com.healthmarketscience.jackcess.CursorBuilder.toCursor(CursorBuilder.java:302)
at net.ucanaccess.commands.IndexSelector.getCursor(IndexSelector.java:150)
at net.ucanaccess.commands.CompositeCommand.persist(CompositeCommand.java:83)
at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:268)
at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:169)
at cultifortgestio.EntradaEixidaDades.Insercio(EntradaEixidaDades.java:76)
As you can see, Access does not change the sortOrder at all, I think it should be 1033, and it keeps being 3082. Is there a way to change this? As i said, changing in Access and performing a Compact and Repair database didn't work for me.
As with other similar situations, the solution was to change the sort order of the affected database. This is usually done by
opening the database in Access,
changing the "New database sort order" (see screenshot below) to "General - Legacy", and then
performing a Compact and Repair Database operation.
However, the wrinkle in this case was that the Windows locale was set to "Spanish", so the "General" sort options in Access do not map to a value that UCanAccess (Jackcess, actually) can update. The solution for the asker was to temporarily change their Windows locale to "English ...", perform the above steps to change the database sort order, and then change the Windows locale back.
For those who would prefer not to mess with their Windows locale settings, an alternative solution would be to have UCanAccess create a new empty database file via the newDatabaseVersion option, e.g.,
String connStr = "jdbc:ucanaccess://C:/someplace/new.accdb;newDatabaseVersion=V2010";
try (Connection conn = DriverManager.getConnection(connStr)) {
}
open the new database in Access, and then transfer the tables from the old database file into the new one using the Import feature. The database file created by UCanAccess will have a sort order that is compatible with update operations.
I have a well-logged pool of several java servers behind an F5 load balancer (professionally managed, it's not sending traffic to >1 host) running Tomcat with my application installed, connecting to a sharded mongo cluster. I'm using a base64-encoded SHA-1 hash of the primary natural key as the _id. When a new record is to be created, I do a pretty basic:
BasicDBObject query = new BasicDBObject();
query.put("userId", userId);
query.put("_id", id);
DBObject user = getUsersCollection().findOne(query);
if (user == null) {
getUsersCollection().insert(new UserObject(userId));
}
This is simplified. In fact there are multiple checks for the pre-existence of this user, including one which should throw a custom exception, and none are triggered. The traffic logs indicate a single incoming create request, and here's an example of what happens:
2014-01-19 20:03:45,167 [http-bio-7950-exec-827]:[...] : ERROR FATAL [...] - Internal server error
[...]: com.mongodb.MongoException$DuplicateKey: { "serverUsed" : "[...]" , "singleShard" : "replicaset_2/host1:27017,host2:27017,host3:27017" , "err" : "E11000 duplicate key error index: Users.$_id_ dup key: { : \"HASH\" }" , "code" : 11000 , "n" : 0 , "lastOp" : { "$ts" : 1390190614 , "$inc" : 1} , "connectionId" : 335764 , "ok" : 1.0}
Yet in my Users collection the record has been created:
db.Users.findOne({_id:"HASH"}):
{
"_id" : "HASH",
"createDate" : ISODate("2014-01-20T04:03:45.161Z"),
...
}
I'm pasting this as important because of the timestamps. We have a timezone issue, but that aside I interpret the 6ms difference as clock skew between the mongo cluster and my application servers. There is no other record of this incoming traffic (and it is logged as it bounces from server to server, even - nothing else!) So I am 99.999% confident that my SINGLE LEGITIMATE insert call is both inserting and throwing an error.
Any theories as to how/why this is happening would be greatly appreciated. I'll run tracers and examples if needed to answer questions with more information.
You are searching for a user using both _id and userId fields. Try to comment out this line: query.put("_id", id);.
It's not clear in your code where Java variable userId comes from. It's also not clear how UserObject sets an _id if at all.
Overall it looks like the way you search for user and the way you create him does not match, i.e. what defines a unique key on that user.
One fix could to replace these lines:
query.put("userId", userId);
query.put("_id", id);
with:
query.put("_id", userId);
To make _id field to be your userId.
I have one problem, I have collection and I want to set text search index to 2 fields(description and title). But when I add second index I get following error and text search stopped working.
{ "serverUsed" : "localhost/127.0.0.1:27017" , "ok" : 0.0 , "errmsg" : "too many text index for: testdb.users"}
when I delete one index search start work again. what is the problem? One collections support full text search index only for one field????
I am using the current version of mongodb under windows and I am using mongodb java driver API.
Thanks
MongoDB only allows one text-index per collection.
But you can use a text-index which spans multiple fields:
db.collection.ensureIndex( {
description: "text",
title: "text"
} );
That way you will get results when the phrase you are searching for is found in either. When this is not what you want, like when you have two search-queries which each return results from one of the fields but not the other, you have two options.
use a multi-field text index, but discard the results which come from the wrong field on the application layer.
extract one of the two fields to a different collection. The documents in that collection could either contain full copies, redacted copies or just the field you index and the _id of the original document.
To create a text based index on a key, use command db.collectionName.ensureIndex({'textColumnName': 'text'}). After this index is applied, use the search commands to search for a word i.e. db.collectionName.find({$text: {$search:'your text here'}}). There is a text score based on which the results are ranked, to see it project it in the score key like this : db.collectionName.find({$text: {$search:'your text here'}}, {score: {$meta: 'textScore'}}).sort({score: {$meta: 'textScore'}}).
If we create a text index on the title field of the movies collection, and then perform the text search db.movies.find( { $text : { $search : "Big Lebowski" } } ). The following documents will be returned, assuming they are in the movies collection:
{ "title" : "The Big Lebowski" , star: "Jeff Bridges" }
{ "title" : "Big" , star : "Tom Hanks" }
{ "title" : "Big Fish" , star: "Ewan McGregor" }
This is because, there will be a ***logical OR***ing on Big & Lebowski.
I am getting started with mongodb and I would like to do an operation where I attempt to insert a user with a username, password, and email. I have built unique indexes on username and email so the insert will fail if the specified username or email already exists.
So now I would like to report to the user that either, their email is already registered, or that the username the chose is taken. So I have gotten as far as:
CommandResult result = db.getLastError();
However, I dont see an easy way to read the error other than parsing through the single error message that it is giving me.
{ "serverUsed" : "127.0.0.1:27017" ,
"err" : "E11000 duplicate key error index: mojulo.users.$username_1 dup key: { : \"blahblah\" }" ,
"code" : 11000 ,
"n" : 0 ,
"connectionId" : 12 ,
"ok" : 1.0}
Also it appears that this is only reporting the first error that it encounters, is there anyway to do the check for both email and username in a single query?
If you want to do a check for both, then you will have to issue a query yourself to check for it. If you just insert documents, then it will report the first violation of a unique index only. The code E11000 should only indicate a duplicate key error which should make it easy to spot that it happens. You will need to parse the error message to figure out the collection though.