<servlet> <servlet-name>Rest_Servlet</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>cn.firewarm.testRestShiro.rest</param-value> </init-param> <init-param> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> <param-value>cn.firewarm.testRestShiro.filter.TestFilter</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> |
public class TestFilter implements ContainerRequestFilter { public ContainerRequest filter(ContainerRequest request) { if(判断条件){ return request; }else{ Response response = Response.ok("error").status(401).type(MediaType.APPLICATION_JSON).build(); throw new WebApplicationException(response); // Throw new UnAuthor |