public static Function < X509CertificateAuthentication , String > patternExtractor ( final String key , final Function < ? super X509CertificateAuthentication , String > fallback ) { requireNonNull ( key , "key" ) ; requireNonNull ( fallback , "fallback" ) ; final Pattern pattern = Pattern . compile ( key + "=(.+?)(?:,|$)" , Pattern . CASE_INSENSITIVE ) ; return authentication -> { final Object principal = authentication . getPrincipal ( ) ; if ( principal instanceof X500Principal ) { final X500Principal x500Principal = ( X500Principal ) principal ; final Matcher matcher = pattern . matcher ( x500Principal . getName ( ) ) ; if ( matcher . find ( ) ) { return matcher . group ( 1 ) ; } } return fallback . apply ( authentication ) ; } ; }
Creates a new case - insensitive pattern extractor with the given pattern .