View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  }