001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers;
034:
035: import org.libresource.Libresource;
036: import org.libresource.LibresourceResourceIdentifier;
037:
038: import org.libresource.kernel.KernelConstants;
039: import org.libresource.kernel.LibresourceSecurityException;
040: import org.libresource.kernel.ejb.model.AclValue;
041: import org.libresource.kernel.interfaces.KernelService;
042:
043: import org.libresource.web.Controller;
044:
045: import java.net.URI;
046:
047: import javax.servlet.http.HttpServletRequest;
048: import javax.servlet.http.HttpServletResponse;
049:
050: public class SecurityController implements Controller {
051: public Object process(URI uri, HttpServletRequest request,
052: HttpServletResponse response) throws Exception {
053: KernelService kernelService = (KernelService) Libresource
054: .getService(KernelConstants.SERVICE);
055: AclValue[] aclValues = kernelService.getAcls(uri);
056: request.setAttribute("acls", aclValues);
057: request.setAttribute("ownerUri", kernelService.getOwner(uri));
058:
059: LibresourceResourceIdentifier resourceIdentifier = kernelService
060: .lookup(uri);
061:
062: String[] kernelPermissions = kernelService
063: .listKernelPermissions();
064: String[] resourcePermissions = Libresource
065: .listAvailablesPermissions(resourceIdentifier);
066:
067: request.setAttribute("kernelPermissions", kernelPermissions);
068: request
069: .setAttribute("resourcePermissions",
070: resourcePermissions);
071:
072: if (request.getParameter("edit") != null) {
073: String editUri = request.getParameter("edit");
074:
075: for (int i = 0; i < aclValues.length; i++) {
076: if (aclValues[i].getOwnerUri().toString().equals(
077: editUri)) {
078: request.setAttribute("editUri", editUri);
079: request.setAttribute("editAcl", aclValues[i]);
080: }
081: }
082: }
083:
084: if (request.getParameter("create") != null) {
085: try {
086: String[] permissions = request
087: .getParameterValues("permission");
088:
089: if (permissions != null) {
090: if (request.getParameter("recursive") != null) {
091: kernelService.createAclRecursively(uri,
092: new URI(request.getParameter("owner")
093: .trim()), permissions);
094: } else {
095: kernelService.createAcl(uri, new URI(request
096: .getParameter("owner").trim()),
097: permissions);
098: }
099:
100: request.setAttribute("acls", kernelService
101: .getAcls(uri));
102: } else {
103: request.setAttribute("securityError",
104: "please check some permissions !");
105:
106: return "/pages/security.jsp";
107: }
108: } catch (LibresourceSecurityException e) {
109: throw e;
110: } catch (Exception e) {
111: request.setAttribute("securityError", e.getMessage());
112:
113: return "/pages/security.jsp";
114: }
115: }
116:
117: if (request.getParameter("delete") != null) {
118: if (request.getParameter("recursive") != null) {
119: kernelService.deleteAcl(uri, new URI(request
120: .getParameter("delete")), true);
121: } else {
122: kernelService.deleteAcl(uri, new URI(request
123: .getParameter("delete")), false);
124: }
125:
126: request.setAttribute("acls", kernelService.getAcls(uri));
127: }
128:
129: return "/pages/security.jsp";
130: }
131: }
|