public static Subject tryToAuthenticate(HttpServletRequest request, HttpManagementConfiguration managementConfig)
{
Subject subject = null;
SocketAddress localAddress = getSocketAddress(request);
final AuthenticationProvider authenticationProvider = managementConfig.getAuthenticationProvider(localAddress);
SubjectCreator subjectCreator = authenticationProvider.getSubjectCreator(request.isSecure());
String remoteUser = request.getRemoteUser();
if (remoteUser != null || authenticationProvider instanceof AnonymousAuthenticationManager)
{
subject = authenticateUser(subjectCreator, remoteUser, null);
}
else if(authenticationProvider instanceof ExternalAuthenticationManager
&& Collections.list(request.getAttributeNames()).contains("javax.servlet.request.X509Certificate"))
{
Principal principal = null;
X509Certificate[] certificates =
(X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
if(certificates != null && certificates.length != 0)
{
principal = certificates[0].getSubjectX500Principal();
if(!Boolean.valueOf(String.valueOf(authenticationProvider.getAttribute(ExternalAuthenticationManager.ATTRIBUTE_USE_FULL_DN))))
{
String username;
String dn = ((X500Principal) principal).getName(X500Principal.RFC2253);