jersey security and session management

前端 未结 7 999
甜味超标
甜味超标 2020-11-29 16:53

Is there a way to get session management or security programatically in Jersey, e.g. web-application session management? Or are transactions, sessions, and security all han

7条回答
  •  庸人自扰
    2020-11-29 17:28

    You can user @path to group the services under single name space. example .

    @Path("/helloworld")
    public class HelloWorld {
    
        @GET
        @Produces("text/plain")
        public String hello() {
    
    
            return "";
    
    
        }
    }
    Instead of @Path("/helloworld") use
    @Path("admin/helloworld") to expose you class as rest and bind filter on "admin/"
    in web.xml as below.
    
    
                jersey-serlvet
                com.sun.jersey.spi.container.servlet.ServletContainer
                
                    com.sun.jersey.config.property.packages
                    /
                
                1
            
            
                jersey-serlvet
                /rest/*
            
             
                myfilter
                com.Filterclass
            
            
                myfilter
                /rest/admin/*
             
    
    
        public class Filterclass implements Filter {
           public void doFilter(ServletRequest request, ServletResponse response,
                    FilterChain chain)
                    throws IOException, ServletException {
                      try{
                           chain.doFilter(request, response);
                        }catch(Exception e){
                       e.printStackTrace();
                           }
              }
        }

    You can validate you session in this filter class.

提交回复
热议问题