Results 1 to 7 of 7
Thread: Parsing Help - With Notes
- 06-08-2011, 04:16 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
Parsing Help - With Notes
Code is below for some reason my parse is only pulling out and giving me a result of US@mil.com When I am trying to get the numbers (EDIPI Number)@mil. Any help would be greatly appreciated.
X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Ce rtificate");
if (certs != null) {
String SubjectDN = certs[0].getSubjectDN().getName();
//Split SubjectDN to allow extration of CN field
//SubjectDN format = "CN=LASTNAME.FIRSTNAME.MI.1234567890, O=U.S. Government, OU=DoD, OU=PKI, OU=CONTRACTOR, C=US"
//NOTE: The CN field may vary in structure with the exception of ending in the 10 digit string which makes up the prinicple name
//After the following line is executed the last element in SubjectVals will look like: "CN=LASTNAME.FIRSTNAME.MI.1234567890"
String[] SubjectVals = SubjectDN.split(", ");
//Split SubjectVals to allow extration of name field
//After the following line is executed the last element in SubjectItem will look like: "LASTNAME.FIRSTNAME.MI.1234567890"
String[] SubjectItem = SubjectVals[SubjectVals.length-1].split("=");
//Split SubjectItem to allow extration of use principle name number
//After the following line is executed the last element in SubjectNumber will look like: "1234567890"
String[] SubjectNumber = SubjectItem[1].split("\\.");
//Place the principle name number into the username variable. To change from array format to string format.
//After the following line is executed the username will look like: "1234567890"
username = SubjectNumber[SubjectNumber.length-1];
//append the string @mil to principle name number to get username in finalized active directory format
//After the following line is executed username will look like: "1234567890@mil"
username = username + "@mil";
//if debug mode print out all variables used above. This is for testing
if(debug){
mtLog.fine("SSO: Certificate SubjectDN: "+ SubjectDN);
mtLog.fine("SSO: SubjectVals: " + SubjectVals[SubjectVals.length-1]);
mtLog.fine("SSO: SubjectItems: " + SubjectItem[1]);
mtLog.fine("SSO: Certificate Subject CN ID (Username): " + username);
}Last edited by BordomSUCKS; 06-08-2011 at 04:18 PM. Reason: Had mistake.
- 06-08-2011, 04:36 PM #2
Hi. I made it like that
But I needed get CN you can change little bit my code and get all fields from certifications.Java Code:String login = parseLogin(cert.getSubjectDN().getName()); ... private static String parseLogin(String text) { String[] cn = text.split(","); Map<String, String> map = new LinkedHashMap<String, String>(); for (String value : cn) { String[] pair = value.split("="); if (pair.length == 2) { map.put(pair[0].trim(), pair[1].trim()); } } return map.get("CN"); }Skype: petrarsentev
http://TrackStudio.com
- 06-08-2011, 05:15 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
Would there be an easier way of doing like a find string in the array for the number 1 and do wildcard for the following 9 numbers? As this will always start with the number 1.
- 06-08-2011, 08:12 PM #4
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
Still No Luck
I have tried your code and have not gotten it to even compile when I put your code in place. I am at a loss if anyone could point me in a good direction or offer some assistance I appreciate it.
- 06-08-2011, 09:30 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
I am almost there I am not getting a value of 1234567891, OU@mil how do I create a new value and drop everything after the ,? Thanks in advance.
- 06-08-2011, 10:41 PM #6
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
Where I am at
X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Ce rtificate");
if (certs != null) {
String SubjectDN = certs[0].getSubjectDN().getName();
//Split SubjectDN to allow extration of CN field
//SubjectDN format = "C=US, O=U.S. Government, OU=DoD, OU=PKI, OU=CONTRACTOR, CN=LASTNAME.FIRSTNAME.MI.1234567890"
//NOTE: The CN field may vary in structure with the exception of ending in the 10 digit string which makes up the prinicple name
//After the following line is executed the last element in SubjectVals will look like: "CN=LASTNAME.FIRSTNAME.MI.1234567890"
String[] SubjectVals = SubjectDN.split(",");
//Split SubjectVals to allow extration of name field
//After the following line is executed the last element in SubjectItem will look like: "LASTNAME.FIRSTNAME.MI.1234567890"
String[] SubjectItem = SubjectVals[SubjectVals.length-1].split("=");
//Split SubjectItem to allow extration of use principle name number
//After the following line is executed the last element in SubjectNumber will look like: "1234567890"
String[] SubjectNumber = SubjectItem[1].split("\\.");
//Place the principle name number into the username variable. To change from array format to string format.
//After the following line is executed the username will look like: "1234567890"
String usernames = SubjectNumber[SubjectNumber.length-1];
username = usernames.substring(0, 9);
//append the string @mil to principle name number to get username in finalized active directory format
//After the following line is executed username will look like: "1234567890@mil"
username = username + "@mil";
I believe one of these lines is causing me to retrieve this error.
String usernames = SubjectNumber[SubjectNumber.length-1];
username = usernames.substring(0, 9);
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.StringIndexOutOfBoundsException: String index out of range: 9
java.lang.String.substring(Unknown Source)
com.remedy.arsys.sso.SSOAuthenticator.getAuthentic atedCredentials(SSOAuthenticator.java:162)
com.remedy.arsys.session.Login.establishSession(Un known Source)
com.remedy.arsys.stubs.GoatServlet.postInternal(Un known Source)
com.remedy.arsys.stubs.GoatHttpServlet.doGet(Unkno wn Source)
javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
Why would 9 be out of range? AsI am saying I want the first 10 characters 0-9.
- 06-09-2011, 09:59 AM #7
You need separate your task on two small tasks. First you get data from certificate. That is OK. Then you need get special data. Can you show what it is text you want to parse and what data you want to get?
Skype: petrarsentev
http://TrackStudio.com
Similar Threads
-
Connecting do Domino (Lotus Notes)
By Dipke in forum New To JavaReplies: 0Last Post: 09-10-2010, 06:01 PM -
hi guys help me in connecting lotus notes with applet
By funkygarzon in forum Java AppletsReplies: 1Last Post: 08-10-2010, 11:01 AM -
Create and play midi notes
By tor in forum New To JavaReplies: 0Last Post: 04-26-2010, 12:18 AM -
Form Notes
By creel in forum Java AppletsReplies: 0Last Post: 02-02-2008, 01:25 AM -
printing MIDI notes on a music staff
By kbyrne in forum AWT / SwingReplies: 0Last Post: 12-29-2007, 05:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks