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.AclEntry;
    19  import org.acegisecurity.acl.AclManager;
    20
    21  import org.springframework.beans.factory.InitializingBean;
    22
    23  import org.springframework.util.Assert;
    24
    25  import org.springframework.web.bind.RequestUtils;
    26  import org.springframework.web.servlet.ModelAndView;
    27  import org.springframework.web.servlet.mvc.Controller;
    28
    29  import java.io.IOException;
    30
    31  import java.util.HashMap;
    32  import java.util.Map;
    33
    34  import javax.servlet.ServletException;
    35  import javax.servlet.http.HttpServletRequest;
    36  import javax.servlet.http.HttpServletResponse;
    37
    38
    39  /***
    40   * Controller for "administer" index page.
    41   *
    42   * @author Ben Alex
    43   * @version $Id: AdminPermissionController.java,v 1.4 2005/11/17 00:56:08 benalex Exp $
    44   */
    45  public class AdminPermissionController implements Controller, InitializingBean {
    46      //~ Instance fields ========================================================
    47
    48      private AclManager aclManager;
    49      private ContactManager contactManager;
    50
    51      //~ Methods ================================================================
    52
    53      public void setAclManager(AclManager aclManager) {
    54          this.aclManager = aclManager;
    55      }
    56
    57      public AclManager getAclManager() {
    58          return aclManager;
    59      }
    60
    61      public void setContactManager(ContactManager contact) {
    62          this.contactManager = contact;
    63      }
    64
    65      public ContactManager getContactManager() {
    66          return contactManager;
    67      }
    68
    69      public void afterPropertiesSet() throws Exception {
    70          Assert.notNull(contactManager,
    71              "A ContactManager implementation is required");
    72          Assert.notNull(aclManager, "An aclManager implementation is required");
    73      }
    74
    75      public ModelAndView handleRequest(HttpServletRequest request,
    76          HttpServletResponse response) throws ServletException, IOException {
    77          int id = RequestUtils.getRequiredIntParameter(request, "contactId");
    78
    79          Contact contact = contactManager.getById(new Long(id));
    80          AclEntry[] acls = aclManager.getAcls(contact);
    81
    82          Map model = new HashMap();
    83          model.put("contact", contact);
    84          model.put("acls", acls);
    85
    86          return new ModelAndView("adminPermission", "model", model);
    87      }
    88  }