1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.controller;
17
18 import java.util.Iterator;
19 import java.util.Map;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionMessage;
28 import org.apache.struts.action.ActionMessages;
29 import org.apache.struts.actions.MappingDispatchAction;
30 import org.seasar.tuigwaa.security.Action;
31 import org.seasar.tuigwaa.security.SecurityService;
32 import org.seasar.tuigwaa.system.SiteConfig;
33 import org.seasar.tuigwaa.system.SiteService;
34 import org.seasar.tuigwaa.util.TgwContext;
35
36 import com.isenshi.util.extlib.StrutsUtil;
37
38 /***
39 * @author nishioka
40 */
41 public class SiteSecurityAction extends MappingDispatchAction {
42
43 private SecurityService securityService;
44
45 private SiteService siteService;
46
47 public SiteSecurityAction(SecurityService securityService, SiteService siteService) {
48 this.securityService = securityService;
49 this.siteService = siteService;
50 }
51
52 public ActionForward edit(ActionMapping mapping, ActionForm form,
53 HttpServletRequest request, HttpServletResponse response)
54 throws Exception {
55 SiteConfig siteConfig = TgwContext.getSiteConfig();
56 SiteSecurityForm siteSecurityForm = new SiteSecurityForm(securityService,siteConfig);
57 request.getSession().setAttribute("siteSecurityForm", siteSecurityForm);
58 return mapping.findForward("success");
59 }
60
61 public ActionForward save(ActionMapping mapping, ActionForm form,
62 HttpServletRequest request, HttpServletResponse response)
63 throws Exception {
64
65 SiteSecurityForm securityForm = (SiteSecurityForm)form;
66 Map map = securityForm.getSecurityMap();
67 String siteName = TgwContext.getSiteName();
68
69 Iterator itr = map.keySet().iterator();
70 while(itr.hasNext()){
71 Action action = (Action)itr.next();
72 String[] grantRoleNames = (String[])map.get(action);
73 securityService.setPermissions(siteName, action, grantRoleNames, null);
74 }
75 siteService.saveSiteConfig(siteName);
76 StrutsUtil.clearSessionForm(request, mapping);
77
78 ActionMessages messages = new ActionMessages();
79 messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
80 "msg.siteSecurity.save"));
81 saveMessages(request, messages);
82 return edit(mapping, form, request, response);
83 }
84 }