1 7 package org.jboss.security.auth.certs; 8 9 import java.security.Principal ; 10 import java.security.cert.X509Certificate ; 11 import org.jboss.security.CertificatePrincipal; 12 import org.jboss.security.SimplePrincipal; 13 14 20 public class SubjectCNMapping 21 implements CertificatePrincipal 22 { 23 29 public Principal toPrinicipal(X509Certificate [] certs) 30 { 31 Principal cn = null; 32 Principal subject = certs[0].getSubjectDN(); 33 String dn = subject.getName().toLowerCase(); 35 int index = dn.indexOf("cn="); 36 if( index >= 0 ) 37 { 38 int comma = dn.indexOf(',', index); 39 if( comma < 0 ) 40 comma = dn.length(); 41 String name = dn.substring(index+3, comma); 42 cn = new SimplePrincipal(name); 43 } 44 else 45 { 46 cn = subject; 48 } 49 return cn; 50 } 51 } 52 | Popular Tags |