650U 0 Newbie Poster

I'm currently working on a project where I need to Authenticate the Client using his/her certificate. I have created my own CA, Server and Client certificates and imported them into my browser. Then I wrote a JSP code just to read the certificate. That is the program returns the commonname, email, country, city and info I have in the certificate.

But I need to write a code where I need to check whether the client has the certificate. If YES, then I must display "Welcome <>". If NO, then I must display "Get the Certificate".

I have no idea how to do this. I read many post and found out getRemoteUser could help me doing this. But I am totally stuck here. I am also attaching my code to extract client information from the certificate.

My Code:

<%@page import="java.security.cert.X509Certificate"%>
<%
Object o = request.getAttribute("javax.servlet.request.X509Certificate");
if (o != null) {
X509Certificate certs[] = (X509Certificate[]) o;
X509Certificate cert = certs[0];
%>
<%= cert.getSubjectDN().getName() %>
<%
} else {
%>
Object was null.
<%
}
%>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.