简体   繁体   English

如何以编程方式从 magnolia cms 注销

[英]How to logout programmatically from magnolia cms

I'd like to create custom REST for logging out users.我想为注销用户创建自定义 REST 。 I created jax-rs based endpoint definition with one method /logout :我使用一种方法/logout创建了基于 jax-rs 的端点定义:

@Path("/test")
public class MyEndpoint<D extends EndpointDefinition>  extends AbstractEndpoint<D> {

    @Path("/logout")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public void logout() {
        //how to logout user here?
    }
}

What code should I put in place of //how to logout user here?我应该用什么代码代替//how to logout user here? to make it work?让它工作?

You can inject the following component and trigger logout from it.您可以注入以下组件并从中触发注销。

info.magnolia.context.UserContext

I created working solution based on info.magnolia.cms.security.LogoutFilter我创建了基于info.magnolia.cms.security.LogoutFilter的工作解决方案

@Path("/logout")
@GET
@Produces(MediaType.APPLICATION_JSON)
public void logout(@Context HttpServletRequest request) {
    info.magnolia.context.Context ctx = MgnlContext.getInstance();
    if (ctx instanceof UserContext) {
        AuditLoggingUtil.log((UserContext) ctx);
        ((UserContext) ctx).logout();
    }

    if (request.getSession(false) != null) {
        request.getSession().invalidate();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM