Deleting LDAP record with 0x0A in CN (Java) - java

I'm trying to delete ADLDS user records created by Microsoft's conflict resolution model.
Microsoft describes the creation of the new records as
The new RDN will be <Old RDN>\0ACNF:<objectGUID>
These are the records I'm trying to delete from my environment.
My search for uid=baduser will return two CNs:
cn=John R. Doe 123456
and
cn=John R. Doe 123456 CNF:123e4567-e89b-12d3-a456-426614174000
The second record has the \0A in the cn.
Executing a ctx.destroySubcontext(cn) on it errors out like this:
cn=John R. Doe 123456CNF:123e4567-e89b-12d3-a456-426614174000,c=US: [LDAP: error code 34 - 0000208F: NameErr: DSID-0310022D, problem 2006 (BAD_NAME), data 8349
What am I missing to be able to delete a record with a cn that contains a line feed character?
note: I also can't seem to read/modify this \0A record using JXplorer. Clicking on the record after a search results in the same BAD_NAME error.

String commonName = attr.get("cn").get().toString().replace("\n", "\\\\0A");
A simple replacement of the \n character worked for me.

Related

Build facturx invoice with Mustang library

I do try to build a factur-x using Mustang library.
For minimum profile, a Buyer legal registration identifier is required.
For this I build a trade party object:
TradeParty recipient = new TradeParty(
"My Client",
"My address",
"06000",
"City",
"FR")
.setID("123 456 789 10111");
My issue is the following:
I'm able to build an XML (that's what I want)
I'm not able to set the organization ID and pass the schemeID to 0002 (for french factur-X).
I didn't find how to set
Here is what is expected:
<ram:SpecifiedLegalOrganization>
<ram:ID schemeID="0002">123 456 789 10111</ram:ID>
</ram:SpecifiedLegalOrganization>
I do also have to set the business process type, which is specific for Chorus Pro (in france):
<ram:BusinessProcessSpecifiedDocumentContextParameter>
<ram:ID>A1</ram:ID>
</ram:BusinessProcessSpecifiedDocumentContextParameter>
Here, A1 means invoice deposit, A2 means prepaid invoice deposit, ... By default (in the absence of this field), the case A1 is applied.
The output for recipient :
<ram:BuyerTradeParty>
<ram:ID>123 456 789 10111</ram:ID>
<ram:Name>My Client</ram:Name>
<ram:PostalTradeAddress>
<ram:PostcodeCode>06000</ram:PostcodeCode>
<ram:LineOne>My address</ram:LineOne>
<ram:CityName>City</ram:CityName>
<ram:CountryID>FR</ram:CountryID>
</ram:PostalTradeAddress>
</ram:BuyerTradeParty>
SpecifiedLegalOrganisation/ID has been added to Mustang 2.5 https://www.mustangproject.org/mustang-2-5-0/, please report an issue via https://github.com/ZUGFeRD/mustangproject/issues if there are further requirements vis á vis Chorus Pro I am not aware of.
as you indicated (and as described in the english FX spec 1.05 e.g. on page 115 as well as in the technical annex to ZUGFeRD with a cardinality 0..1) BT-23, i.e. ram:BusinessProcessSpecifiedDocumentContextParameter is optional so you can just omit it unless you need other values. Do you require to set anything nonstandard here?
However, so far nobody ever requested being able to set the legalorganisation +ID and scheme ID, which means that probably nobody ever used Mustang so far to write invoices vis á vis the french authorities (only to german ones or for factur-x B2B invoices).
However, I just added the possibility, you can now use someTradeParty.setLegalOrganisation(new LegalOrganisation("0815", "0002")). This will become part of the next release, could you please confirm that this works and is all you need?

Does presence of "|" [Bitwise Or] in query PARAM value have impact on performance Java Hibernate

Recently I encountered a strange issue where I had a table called person which has columns personid, name, age, username, ...
There are around 200 entries for username which as '|' in value.
i.e. for ex :
1] abc | def
2] mno | pqr
and so on.
I Have return an Spring Boot based Rest API which deletes person based on username but I am observing that the API takes more than expected time when we try to delete person whose username value has "|" in it.
i.e. time taken to delete 10 records for username with "|" is app 10 mins but the usernames without "|" values takes process transaction with in 4 min.
I tried to google a lot to find the impact of it but could not find any corresponding proof on it causing performance issue. Hence I am reaching out here .
Query used:
select * from person where username = trim (:name)
API Details:
Takes List of Usernames to be deleted or inactivated as input and have some set of basic validation before performing delete.

updating an excel file with apache metamodel

I'm trying to incorporate Apache MetaModel into a project and keep running into a weird problem. I update an Excel spreadsheet row in code. The code finds the right row, deletes it, then appends the row (with my update) to the bottom of the spreadsheet. I'd like the update to happen in-place, with the same data staying in the same row. I thought it was something I was doing wrong, then set up a stupid simple project to duplicate the behavior. Unfortunately, the problem remains.
Here's the xlsx file:
Name Address City State Zip
Bob 123 Main St. Norman OK 11111
Fred 989 Elm Street Chicago IL 22222
Mary 555 First Street San Francisco CA 33333
Now, I want to update Bob's Zip to "None".
package MMTest;
import java.io.File;
import org.apache.metamodel.UpdateableDataContext;
import org.apache.metamodel.excel.ExcelDataContext;
import org.apache.metamodel.schema.Column;
import org.apache.metamodel.schema.Schema;
import org.apache.metamodel.schema.Table;
import org.apache.metamodel.update.Update;
public class MMTest {
public static void main(String[] args) {
UpdateableDataContext excel = new ExcelDataContext(new File("C:/test/test.xlsx"));
Schema schema = excel.getDefaultSchema();
Table[] tables = schema.getTables();
assert tables.length == 1;
Table table = schema.getTables()[0];
Column Name = table.getColumnByName("Name");
Column Zip = table.getColumnByName("Zip");
excel.executeUpdate(new Update(table).where(Name).eq("Bob").value(Zip, "None"));
}
}
Pretty simple right? Nope.
This is the result:
Name Address City State Zip
<blank line>
Fred 989 Elm Street Chicago IL 22222
Mary 555 First Street San Francisco CA 33333
Bob 123 Main St. Norman OK None
Am I missing something simple? The documentation is pretty sparse, but I've read everything the internet has to offer on this package. I appreciate your time.
Late to the party, but I've recently bumped into this issue and haven't spotted an answer elsewhere yet. The actual deleting takes place in ExcelDeleteBuilder.java
If you aren't concerned about maintaining row order, you could change
for (Row row : rowsToDelete) {
sheet.removeRow(row);
}
to
for (Row row : rowsToDelete) {
int rowNum = row.getRowNum() + 1;
sheet.removeRow(row);
sheet.shiftRows(rowNum, sheet.getLastRowNum(), -1);
}
See Apache POI docs for a better understanding of shiftRows().
As Adi pointed out, you'll still end up with the "updated" row being moved to the bottom, but in my use case the empty row is successfully removed.
N.B. I'm working from Apache Metamodel 4.5.4
You are not missing anything. The ExcelDataContext is not providing it's own update behavior. It is defaulting to use apache meta-model's default store agnostic implementation for updating the data. That implementation of UpdateCallback uses DeleteAndInsertCallback which is causing the behavior you are observing. It picks the row to be updated, updates it with a new value in memory, deletes the original row and inserts the updated row(which ends up in the bottom which is ExcelDataContext behavior).
You can open an issue at https://issues.apache.org/jira/browse/METAMODEL
Attach your sample code and data.
Best would be a failing unit test in
https://git-wip-us.apache.org/repos/asf/metamodel.git

Extracting packed data using regular expressions

I have data in a database in the format below:
a:19:{s:9:"raceclass";a:5:{i:0;a:1:{i:0;s:7:"250cc B";}i:1;a:1:{i:1;s:6:"OPEN B";}i:2;a:1:{i:2;s:9:"Plus 25 B";}i:3;a:1:{i:3;s:8:"Vet 30 B";}i:4;a:1:{i:4;s:7:"Vintage";}}s:9:"firstname";a:1:{i:0;a:1:{i:0;s:5:"James";}}s:12:"middle_FIELD";a:1:{i:0;a:1:{i:0;s:1:"R";}}s:8:"lastname";a:1:{i:0;a:1:{i:0;s:9:"Slaughter";}}s:5:"email";a:1:{i:0;a:1:{i:0;s:29:"jslaughter#xtrememxseries.com";}}s:8:"address1";a:1:{i:0;a:1:{i:0;s:18:"21 DiMartino Court";}}s:4:"city";a:1:{i:0;a:1:{i:0;s:6:"Walden";}}s:5:"state";a:1:{i:0;a:1:{i:0;s:8:"New York";}}s:3:"zip";a:1:{i:0;a:1:{i:0;s:5:"12586";}}s:7:"country";a:1:{i:0;a:1:{i:0;s:13:"United States";}}s:6:"gender";a:1:{i:0;a:1:{i:0;s:4:"Male";}}s:3:"dob";a:1:{i:0;a:1:{i:0;s:10:"06/04/1974";}}s:5:"phone";a:1:{i:0;a:1:{i:0;s:12:"845-713-4421";}}s:5:"skill";a:1:{i:0;a:1:{i:0;s:12:" AMATEUR (B)";}}s:11:"ridernumber";a:1:{i:0;a:1:{i:0;s:2:"69";}}s:8:"bikemake";a:1:{i:0;a:1:{i:0;s:3:"HON";}}s:8:"enginecc";a:1:{i:0;a:1:{i:0;s:3:"450";}}s:9:"amanumber";a:1:{i:0;a:1:{i:0;s:7:"1094649";}}s:10:"amaexpdate";a:1:{i:0;a:1:{i:0;s:5:"03/12";}}}
How can I write a regular expression to manipulate the above string to get data in the following format?:
raceclass - 250cc B, OPEN B, Plus 25 B, Vet30, Vintage
firstname - James
middle_FIELD - R
address1 = 21 DiMartino Court
city - walden
state - New york
zip - 12586
country - United States
gender - Male
dob - 06/04/1974
phone - 845-713-4421
skill - AMATEUR (B)
ridernumber - 69
bikemake - HON
enginecc - 450
amanumber - 1094649
amaexpdate - 03/12
This data isn't suitable for a regular expression. You should use a proper parser with a proper grammar for handling this string. There are several good options for that in Java, such as ANTLR.
Alternatively, if that is not an option it looks like you only want to handle things between "". Take a look at the java class Scanner. You should be able to get something working with that. Just look through the string and look for a ". If found start to gather text into a buffer. Once you have found another " ignore tokens until you have found the next " or the end of the input text.

String .replaceAll() unexpected behaviors while getting data from Sqlite database

I am wondering with this behavior. In my application I am getting data from server , or my own created database. ( I clone server database)
.replaceAll ( "\r\n" , "<br/>" ) ;
When the data is come from server that it replace. But When data is get from sqlite database its unable to replace the above. As I have try .replaceAll ( "a" , "??" ) ; and its working.
The database data is
Bradley Ambrose is the freelance cameraman who recorded the John Key and John Banks tea meeting.\r\n\r\nHe intentionally placed a black bag with a recording device on the table where Key and Banks were sitting, although he claims it was a mistake, If that were true then how did so many people get a copy of it???\r\n\r\nAlso this guy bloody changed his name from Brad White what the hell is this guy an international man of mystery or something.
I have also debug that issue in detail. But the is not replaced even code is executed the above line successfully.
I have also try
replaceAll ( "\n" , "<br/>" )
replaceAll ( "\r" , "<br/>" )
There is debugging picture.
Does the input string contain actual CR and LF characters or pairs of \ and r and \ and n?
The regex won't work in latter case. It would require .replaceAll("\\\\r\\\\n" , "<br/>")
Can you try with Pattern#quote() ?
Something like:
System.out.println("hello\r\n\r\n something".replaceAll(Pattern.quote("\r\n"), ""));
The code is fine. The data you are seeing in the debug screen is wrong. Do the same debug session and insert a system.out.println and check the output with the output in the debug screen.
Unless you you mean the database actually has the string "\r\n". The above assumes that the database actually contains the carrige return and line feed characters. If your database actually has the backslash character followed by the 'n' character then your regex needs a simple tweak. s.replaceAll("\\\\r\\\\n", "")

Categories