question: public String escapeLDAPSearchFilter ( String filter ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < filter . length ( ) ; i ++ ) { char curChar = filter . charAt ( i ) ; switch ( curChar ) { case '\\' : sb . append ( "\\5c" ) ; break ; case '*' : sb . append ( "\\2a" ) ; break ; case '(' : sb . append ( "\\28" ) ; break ; case ')' : sb . append ( "\\29" ) ; break ; case '' : sb . append ( "\\00" ) ; break ; default : sb . append ( curChar ) ; } } return sb . toString ( ) ; }
target:  Escapes the given string for use within an LDAP search filter. This implementation is provided courtesy of OWASP: https://www.owasp.org/index.php/Preventing_LDAP_Injection_in_Java