1 | package gov.va.med.edp.web.controller;
|
---|
2 |
|
---|
3 | import org.springframework.web.servlet.mvc.AbstractController;
|
---|
4 | import org.springframework.web.servlet.ModelAndView;
|
---|
5 | import org.springframework.util.StringUtils;
|
---|
6 | import org.springframework.util.Assert;
|
---|
7 | import org.springframework.beans.factory.InitializingBean;
|
---|
8 |
|
---|
9 | import javax.servlet.http.HttpServletRequest;
|
---|
10 | import javax.servlet.http.HttpServletResponse;
|
---|
11 | import java.util.Set;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Controller for handling logout.
|
---|
15 | * <p/>
|
---|
16 | * Only logic for logout other than invalidating the session is remove the swfID from the list of recognized ones
|
---|
17 | * for this session. If the count drops to 0, or the swfID is not supplied, then invalidate the session.
|
---|
18 | */
|
---|
19 | public class LogoutController extends AbstractController implements InitializingBean {
|
---|
20 |
|
---|
21 | public static final String DEFAULT_VIEW_NAME = "logout";
|
---|
22 |
|
---|
23 | private String viewName = DEFAULT_VIEW_NAME;
|
---|
24 |
|
---|
25 | public void afterPropertiesSet() throws Exception {
|
---|
26 | Assert.notNull(viewName, "viewName must not be null");
|
---|
27 | }
|
---|
28 |
|
---|
29 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
---|
30 | String swfID = request.getParameter("swfID");
|
---|
31 | if (!StringUtils.hasLength(swfID)) {
|
---|
32 | request.getSession().invalidate();
|
---|
33 | } else {
|
---|
34 | String ids = (String) request.getSession().getAttribute(SessionConstants.RECOGNIZED_SWF_IDS_KEY);
|
---|
35 | Set idSet = StringUtils.commaDelimitedListToSet(ids);
|
---|
36 | if (idSet.isEmpty()) {
|
---|
37 | request.getSession().invalidate();
|
---|
38 | } else {
|
---|
39 | idSet.remove(swfID);
|
---|
40 | if (idSet.isEmpty()) {
|
---|
41 | request.getSession().setAttribute(SessionConstants.RECOGNIZED_SWF_IDS_KEY, null);
|
---|
42 | request.getSession().invalidate();
|
---|
43 | } else {
|
---|
44 | ids = StringUtils.collectionToCommaDelimitedString(idSet);
|
---|
45 | request.getSession().setAttribute(SessionConstants.RECOGNIZED_SWF_IDS_KEY, ids);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | return new ModelAndView(getViewName());
|
---|
51 | }
|
---|
52 |
|
---|
53 | public String getViewName() {
|
---|
54 | return viewName;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void setViewName(String viewName) {
|
---|
58 | this.viewName = viewName;
|
---|
59 | }
|
---|
60 | }
|
---|