I have exposed some rest api using Jersey 2
(Tomcat server) and successfully implemented Basic authentication
(only needed authentication stuff not authorization) using ContainerRequestFilter
filter as below
public class AuthFilter implements ContainerRequestFilter{
@Context
HttpServletRequest request;
@Override
public void filter(ContainerRequestContext context) {
............................
//getting username/password authorization header and validating
When I told the same to my Lead, he said don't use filters as every time your rest api is hit, this filter will get invoked.Therefore, implement basic authentication security at container level.I am using Tomcat server.
In web.xml
, this is defined
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
Is the above he is referring to? Can anyone please guide me how to implement the way my lead is saying?