球衣安全和会话管理

问题描述:

有没有办法在Jersey中以编程方式获取会话管理或安全性,例如Web应用程序会话管理?或者交易,会话和安全是否都由部署Jersey应用程序的容器处理?

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 handled by the container in which the Jersey application is deployed?

会话管理是部署泽西岛的集装箱的权限。在大多数生产案例中,它将部署在执行会话管理的容器中。

Session management is the purview of the container in which Jersey is deployed. In most production cases, it will be deployed within a container that performs session management.

以下代码是获取会话对象和存储的泽西资源的简单示例会话中的值,并在后续调用中检索它们。

The code below is a simple example of a jersey resource that gets the session object and stores values in the session and retrieves them on subsequent calls.

@Path("/helloworld")
public class HelloWorld {

    @GET
    @Produces("text/plain")
    public String hello(@Context HttpServletRequest req) {

        HttpSession session= req.getSession(true);
        Object foo = session.getAttribute("foo");
        if (foo!=null) {
            System.out.println(foo.toString());
        } else {
            foo = "bar";
            session.setAttribute("foo", "bar");
        }
        return foo.toString();


    }
}