01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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: package sample.contact;
16:
17: import org.acegisecurity.acls.AclService;
18: import org.acegisecurity.acls.Permission;
19: import org.acegisecurity.acls.domain.BasePermission;
20: import org.acegisecurity.acls.sid.PrincipalSid;
21: import org.acegisecurity.acls.sid.Sid;
22:
23: import org.springframework.beans.factory.InitializingBean;
24:
25: import org.springframework.util.Assert;
26:
27: import org.springframework.web.bind.RequestUtils;
28: import org.springframework.web.servlet.ModelAndView;
29: import org.springframework.web.servlet.mvc.Controller;
30:
31: import java.io.IOException;
32:
33: import java.util.HashMap;
34: import java.util.Map;
35:
36: import javax.servlet.ServletException;
37: import javax.servlet.http.HttpServletRequest;
38: import javax.servlet.http.HttpServletResponse;
39:
40: /**
41: * Controller for deleting an ACL permission.
42: *
43: * @author Ben Alex
44: * @version $Id: DeletePermissionController.java 1754 2006-11-17 02:01:21Z benalex $
45: */
46: public class DeletePermissionController implements Controller,
47: InitializingBean {
48: //~ Instance fields ================================================================================================
49:
50: private AclService aclService;
51: private ContactManager contactManager;
52:
53: //~ Methods ========================================================================================================
54:
55: public void afterPropertiesSet() throws Exception {
56: Assert.notNull(contactManager,
57: "A ContactManager implementation is required");
58: Assert.notNull(aclService,
59: "An aclService implementation is required");
60: }
61:
62: public ModelAndView handleRequest(HttpServletRequest request,
63: HttpServletResponse response) throws ServletException,
64: IOException {
65: // <c:param name="sid" value="${acl.sid.principal}"/><c:param name="permission" value="${acl.permission.mask}"/></c:url>">Del</A>
66: int contactId = RequestUtils.getRequiredIntParameter(request,
67: "contactId");
68: String sid = RequestUtils.getRequiredStringParameter(request,
69: "sid");
70: int mask = RequestUtils.getRequiredIntParameter(request,
71: "permission");
72:
73: Contact contact = contactManager.getById(new Long(contactId));
74:
75: Sid sidObject = new PrincipalSid(sid);
76: Permission permission = BasePermission.buildFromMask(mask);
77:
78: contactManager.deletePermission(contact, sidObject, permission);
79:
80: Map model = new HashMap();
81: model.put("contact", contact);
82: model.put("sid", sidObject);
83: model.put("permission", permission);
84:
85: return new ModelAndView("deletePermission", "model", model);
86: }
87:
88: public void setAclService(AclService aclService) {
89: this .aclService = aclService;
90: }
91:
92: public void setContactManager(ContactManager contact) {
93: this.contactManager = contact;
94: }
95: }
|