This code is some old pre spring security code:
Code:
public class MyX509Provider extends X509PreAuthenticatedProcessingFilter
{
public Authentication authenticate(Authentication authentication)
throws AuthenticationException
{
X509Certificate clientCertificate =
(X509Certificate)authentication.getCredentials();
String subjectDN = clientCertificate.getSubjectDN().getName();
String certCommonName = "";
StringTokenizer tokens = new StringTokenizer(subjectDN,",");
while (tokens.hasMoreTokens()){
String nextValue=tokens.nextToken();
if (StringUtils.trimLeadingWhitespace(
nextValue).startsWith("CN=")){
certCommonName = StringUtils.trimTrailingWhitespace(
StringUtils.trimLeadingWhitespace(
nextValue).substring(3));
break;
}
}
UserDetails details = lookupUserDetailsFromDB(certCommonName);
grantedAuth = details.getAuthorities();
return new X509AuthenticationToken(
details, clientCertificate, grantedAuth);
}
}
The equivalant for spring security would be:
Code:
<bean id="x509ProcessingFilter" class="org.springframework.security.ui.preauth.x509.X509PreAuthenticatedProcessingFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="principalExtractor">
<bean name="x509SubjectDNExtractor" class="org.springframework.security.ui.preauth.x509.SubjectDnX509PrincipalExtractor">
<!-- the spring default doesnt work if CN is the last attribute
there must be ONLY one capture group -->
<property name="subjectDnRegex" value="CN=(.*?)(?:,|$)" />
</bean>
</property>
</bean>