marcellustavares/liferay-portal — pull request #341 by vilmospapp (2014-10-16 09:25:29+00:00)
Title: LPS-49545 Do not add extra brackets for LDAP search filters to avoid validation errors in some environments

Hi @marcellustavares

We already gone through this fix, but QA asked me for steps for testing and I realised some issues, so I fixed them and now sending it to you for review (I didn't opened new LPS for it, as the LPS is reopened as it wouldn't pass QA).

The issues:
- I've added the LDAPFilterException to LDAPAuth to be thrown, but it blocked OmniAdmin login
- PortalLDAPUtil.searchLDAP() was missing the validation of the search filter
- LDAPUtil.validateFilter() couldn't deal with double or multiple enclosing brackets, hence an invalid filter like: (&(objectClass=inetOrgPerson)(!(cn=test)))) would be handled as valid search filter, though LDAP server would throw an exception like:
```
javax.naming.directory.InvalidSearchFilterException: invalid attribute description; remaining name 'dc=example,dc=com'
at com.sun.jndi.ldap.Filter.encodeSimpleFilter(Filter.java:446)
at com.sun.jndi.ldap.Filter.encodeFilter(Filter.java:146)
at com.sun.jndi.ldap.Filter.encodeFilterString(Filter.java:74)
at com.sun.jndi.ldap.LdapClient.search(LdapClient.java:547)
at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1985)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1847)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1772)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:386)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:356)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:339)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267)
at com.liferay.portal.security.ldap.PortalLDAPUtil.searchLDAP(PortalLDAPUtil.java:826)
```

Please let me know if you find it OK, or not.

Regards,
Vilmos