View Javadoc

1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package sample.contact;
17  
18  import org.acegisecurity.acl.AclManager;
19  
20  import org.springframework.beans.factory.InitializingBean;
21  
22  import org.springframework.util.Assert;
23  
24  import org.springframework.web.bind.RequestUtils;
25  import org.springframework.web.servlet.ModelAndView;
26  import org.springframework.web.servlet.mvc.Controller;
27  
28  import java.io.IOException;
29  
30  import java.util.HashMap;
31  import java.util.Map;
32  
33  import javax.servlet.ServletException;
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  
37  
38  /***
39   * Controller for deleting an ACL permission.
40   *
41   * @author Ben Alex
42   * @version $Id: DeletePermissionController.java,v 1.4 2005/11/17 00:56:08 benalex Exp $
43   */
44  public class DeletePermissionController implements Controller, InitializingBean {
45      //~ Instance fields ========================================================
46  
47      private AclManager aclManager;
48      private ContactManager contactManager;
49  
50      //~ Methods ================================================================
51  
52      public void setAclManager(AclManager aclManager) {
53          this.aclManager = aclManager;
54      }
55  
56      public AclManager getAclManager() {
57          return aclManager;
58      }
59  
60      public void setContactManager(ContactManager contact) {
61          this.contactManager = contact;
62      }
63  
64      public ContactManager getContactManager() {
65          return contactManager;
66      }
67  
68      public void afterPropertiesSet() throws Exception {
69          Assert.notNull(contactManager,
70              "A ContactManager implementation is required");
71          Assert.notNull(aclManager, "An aclManager implementation is required");
72      }
73  
74      public ModelAndView handleRequest(HttpServletRequest request,
75          HttpServletResponse response) throws ServletException, IOException {
76          int contactId = RequestUtils.getRequiredIntParameter(request,
77                  "contactId");
78          String recipient = RequestUtils.getRequiredStringParameter(request,
79                  "recipient");
80  
81          Contact contact = contactManager.getById(new Long(contactId));
82  
83          contactManager.deletePermission(contact, recipient);
84  
85          Map model = new HashMap();
86          model.put("contact", contact);
87          model.put("recipient", recipient);
88  
89          return new ModelAndView("deletePermission", "model", model);
90      }
91  }