Message Boards

Servlet filters not working in DXP 7.0

Vishnu S Kumar, modified 2 Years ago.

Servlet filters not working in DXP 7.0

Regular Member Posts: 131 Join Date: 7/28/17 Recent Posts

Here is our filter code


@Component(
		 immediate = true, 
		 property = {
		 "servlet-context-name=", 
		 "servlet-filter-name=Auth Filter",
		 "url-pattern= /secured/*", 
		 }, 
		 service = Filter.class
	 )
public class AuthFilter implements Filter  {}

If I configure this "url-pattern=/*", it works for all URL paths. However, "url-pattern= /secured/*" doesn't work.

Test Case:
localhost:8080/o/user/secured/url1 - Failed
localhost:8080/o/user/secured/- Failed

No error in the log.

thumbnail
Mohammed Yasin, modified 2 Years ago.

RE: Servlet filters not working in DXP 7.0 (Answer)

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

Hi,

Using  url-pattern="/secured/*"   will consider localhost:8080/secured/* pattern,

So in your case you may need to use url-pattern="/o/user/secured/*"  for filtering localhost:8080/o/user/secured/url1 pattern.

 

Vishnu S Kumar, modified 2 Years ago.

RE: RE: Servlet filters not working in DXP 7.0

Regular Member Posts: 131 Join Date: 7/28/17 Recent Posts

. It worked. Liferay docs really need to be improved. I was exactly following their docs and it failed.

thumbnail
Olaf Kock, modified 2 Years ago.

RE: RE: Servlet filters not working in DXP 7.0

Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent Posts

Thank you for the suggestion for an improvement of LIferay Docs, Vishnu. Would you mind sharing which docs you followed? After all, you're referring to a 5 year old release, and documentation has changed a lot in the past 5 years.

​​​​​​​In other words, it might long be documented in a different way.

Or it may not be documented, because the behavior might be assumed: I've never seen any /pattern/* being expected to match /something-else/pattern/something in the java world - that's precisely what wildcards are for.