I have implemented REST service using Jersey. To give more security, I have added jersey security annotation into REST method(@PermitAll
, @DenyAll
).
Below is my sample REST service:
@GET
@Path("/getall")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public String getChartSupportedData(@QueryParam("items") int result) {
// my code goes here
}
But the problem is that previously I have used javax.servlet.Filter
filter to validate URI.
web.xml:
<filter>
<filter-name>ApplicationFilter</filter-name>
<filter-class>web.filter.ApplicationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ApplicationFilter</filter-name>
<url-pattern>/rest/api/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
According to access some REST services, HttpServletRequest
should contain a valid token (generated by the application).
Some REST end points doesn't require a token to access the service. In that case, I have to bypass that in filter implementation:
private static String[] bypassPaths = { "/data/getall" };
So my requirement is something like that.
If we declared some REST end point as @PermitAll
that path should not have declare in filter as bypass path so that anyone can access it without valid token.
But the problem is that filter is always filtering when the request comes into server and, if it's not in the bypass array the request doesn't continue even I declared as @PermitAll
.
I would like to know if can I combine those two security options in same web application.