Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:08:02+00:00 2026-05-26T15:08:02+00:00

Let me begin by stating that this is a question of aesthetics. I’ve solved

  • 0

Let me begin by stating that this is a question of aesthetics. I’ve solved my own problem, I’m just curious about better ways of doing it.

So, I’ve got a certificate DN, something like this:

CN=Jimmy Blooptoop,OU=Someplace,OU=Employees,DC=Bloopsoft-Inc

Now, I want to grab the CN out of that. In java, there isn’t native support to grab anything but the full DN from the X509 certificate without using some 3rd party library like bouncy castle – which I can’t use. So I’ve got to parse it out, which isn’t much of problem. The only thing that makes it slightly tricky is the fact that the CN isn’t always going to be formatted as <first name> <last name>. More often than not, it’s actually going to be <last name>, <first name> <middle initial>. So, in the example above, the CN could be Jimmy Blooptoop or Blooptoop, Jimmy J (short for the Joop of course).

After going and reading up about about regular expressions, I wrote the following, which works well enough:

Matcher m = Pattern.compile("CN=[A-Za-z]*[, ]*[ A-Za-z]*").matcher(dn);
if (m.find())
  cn = m.group();

I’m just curious if there are expressions that would look less like crap. I’m fairly confident that there are since I worked that out after reading just an introduction to regex.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:08:02+00:00Added an answer on May 26, 2026 at 3:08 pm

    How about javax.naming.ldap.LdapName?

    String dn = "CN=Jimmy Blooptoop,OU=Someplace,OU=Employees,DC=Bloopsoft-Inc";
    LdapName ln = new LdapName(dn);
    
    for(Rdn rdn : ln.getRdns()) {
        if(rdn.getType().equalsIgnoreCase("CN")) {
            System.err.println("CN is: " + rdn.getValue());
            break;
        }
    }
    

    It’s not the most beautiful interface since there is something missing like LdapName#getByType(String) but it saves you the trouble of having to think about what strange features DNs might have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now before we begin let me inform you all that this is just a
Before I begin, let me just say that I know my question is almost
(Let me begin by saying that a) I appreciate this is the wrong place
To begin with, let me say that I understand how and why the problem
let me begin by stating that's i'm dreadful at math. i'm attempting to reposition
Let me begin by saying this; I know that similar questions exist, but they
Let me begin by saying I realize this isn't the best idea from an
This is somewhat of a broad question, but it is one that I continue
Let me begin this topic by explaining my background experience with web design. I
Let's begin with some definitions: An expression is a construct that produces (returns) a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.