Results 1 to 7 of 7
  1. #1
    BordomSUCKS is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Post 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.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Hi. I made it like that
    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");
        }
    But I needed get CN you can change little bit my code and get all fields from certifications.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    BordomSUCKS is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    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.

  4. #4
    BordomSUCKS is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default 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.

  5. #5
    BordomSUCKS is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    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.

  6. #6
    BordomSUCKS is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default 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.

  7. #7
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    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

  1. Connecting do Domino (Lotus Notes)
    By Dipke in forum New To Java
    Replies: 0
    Last Post: 09-10-2010, 06:01 PM
  2. hi guys help me in connecting lotus notes with applet
    By funkygarzon in forum Java Applets
    Replies: 1
    Last Post: 08-10-2010, 11:01 AM
  3. Create and play midi notes
    By tor in forum New To Java
    Replies: 0
    Last Post: 04-26-2010, 12:18 AM
  4. Form Notes
    By creel in forum Java Applets
    Replies: 0
    Last Post: 02-02-2008, 01:25 AM
  5. printing MIDI notes on a music staff
    By kbyrne in forum AWT / Swing
    Replies: 0
    Last Post: 12-29-2007, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •