You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/11/19 15:44:33 UTC
svn commit: r476830 - in /lenya/trunk/src: impl/java/org/apache/lenya/
modules-core/administration/config/cocoon-xconf/
modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/
modules-core/administration/usecases/ modules-core/usecase-im...
Author: andreas
Date: Sun Nov 19 06:44:32 2006
New Revision: 476830
URL: http://svn.apache.org/viewvc?view=rev&rev=476830
Log:
Added usecase permission GUI
Added:
lenya/trunk/src/modules-core/administration/config/cocoon-xconf/usecase-admin-usecases.xconf
lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/Usecases.java
lenya/trunk/src/modules-core/administration/usecases/usecases.jx
lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseSelector.java
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles
lenya/trunk/src/modules-core/administration/config/cocoon-xconf/tabs.xconf
lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizerImpl.java
lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRoles.java
lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRolesBuilder.java
lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java
lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseResolver.java
lenya/trunk/src/pubs/default/config/ac/usecase-policies.xml
Modified: lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/lenya.roles Sun Nov 19 06:44:32 2006
@@ -109,7 +109,7 @@
<role name="org.apache.lenya.cms.usecase.UsecaseSelector"
shorthand="usecases"
- default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
+ default-class="org.apache.lenya.cms.usecase.UsecaseSelector"/>
<role name="org.apache.lenya.cms.usecase.UsecaseInvoker"
shorthand="usecase-invoker"
Modified: lenya/trunk/src/modules-core/administration/config/cocoon-xconf/tabs.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/administration/config/cocoon-xconf/tabs.xconf?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/modules-core/administration/config/cocoon-xconf/tabs.xconf (original)
+++ lenya/trunk/src/modules-core/administration/config/cocoon-xconf/tabs.xconf Sun Nov 19 06:44:32 2006
@@ -26,6 +26,7 @@
<tab name="users" label="Users" usecase="admin.users"/>
<tab name="groups" label="Groups" usecase="admin.groups"/>
<tab name="ipRanges" label="IP Ranges" usecase="admin.ipRanges"/>
+ <tab name="usecases" label="Usecases" usecase="admin.usecases"/>
<tab name="trash" label="Delete Trash" usecase="admin.emptyTrash"/>
<tab name="serverStatus" label="Server Status" usecase="admin.serverStatus"/>
<tab name="sessions" label="Sessions" usecase="admin.sessions"/>
Added: lenya/trunk/src/modules-core/administration/config/cocoon-xconf/usecase-admin-usecases.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/administration/config/cocoon-xconf/usecase-admin-usecases.xconf?view=auto&rev=476830
==============================================================================
--- lenya/trunk/src/modules-core/administration/config/cocoon-xconf/usecase-admin-usecases.xconf (added)
+++ lenya/trunk/src/modules-core/administration/config/cocoon-xconf/usecase-admin-usecases.xconf Sun Nov 19 06:44:32 2006
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+ This file defines the publication specific use-cases
+-->
+
+ <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'admin.usecases']">
+
+ <component-instance name="admin.usecases" logger="lenya.admin" class="org.apache.lenya.cms.ac.usecases.Usecases">
+ <view template="modules/administration/usecases/usecases.jx" menu="true">
+ <tab group="admin" name="usecases"/>
+ </view>
+ </component-instance>
+
+ </xconf>
Added: lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/Usecases.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/Usecases.java?view=auto&rev=476830
==============================================================================
--- lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/Usecases.java (added)
+++ lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/Usecases.java Sun Nov 19 06:44:32 2006
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.ac.usecases;
+
+import java.util.Arrays;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.lenya.ac.Authorizer;
+import org.apache.lenya.ac.Role;
+import org.apache.lenya.cms.ac.usecase.UsecaseAuthorizer;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.URLInformation;
+import org.apache.lenya.cms.usecase.UsecaseResolver;
+
+/**
+ * Edit usecase policies.
+ */
+public class Usecases extends AccessControlUsecase {
+
+ protected void initParameters() {
+ super.initParameters();
+
+ UsecaseResolver resolver = null;
+ try {
+ resolver = (UsecaseResolver) this.manager.lookup(UsecaseResolver.ROLE);
+ String[] allUsecases = resolver.getUsecaseNames();
+ SortedSet rootUsecases = new TreeSet();
+ for (int i = 0; i < allUsecases.length; i++) {
+ if (allUsecases[i].indexOf("/") == -1) {
+ rootUsecases.add(allUsecases[i]);
+ }
+ }
+
+ String[] usecases = (String[]) rootUsecases.toArray(new String[rootUsecases.size()]);
+
+ setParameter("usecases", usecases);
+
+ Role[] roles = getAccessController().getAccreditableManager().getRoleManager()
+ .getRoles();
+ String[] roleNames = new String[roles.length];
+ for (int r = 0; r < roles.length; r++) {
+ roleNames[r] = roles[r].getId();
+ }
+ Arrays.sort(roleNames);
+ setParameter("roles", roleNames);
+
+ Publication pub = getPublication();
+ setParameter("publicationId", pub.getId());
+ setParameter("templates", pub.getTemplateIds());
+
+ for (int u = 0; u < usecases.length; u++) {
+ for (int r = 0; r < roles.length; r++) {
+ boolean value = getUsecaseAuthorizer().isPermitted(usecases[u], pub, roles[r]);
+ setParameter(usecases[u] + ":" + roles[r], Boolean.valueOf(value));
+ }
+ }
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
+ }
+
+ }
+
+ protected Publication getPublication() throws PublicationException {
+ String pubId = new URLInformation(getSourceURL()).getPublicationId();
+ Publication pub = getDocumentFactory().getPublication(pubId);
+ return pub;
+ }
+
+ protected void doExecute() throws Exception {
+ super.doExecute();
+
+ String[] usecases = (String[]) getParameter("usecases");
+ String[] roleNames = (String[]) getParameter("roles");
+
+ Publication pub = getPublication();
+ for (int u = 0; u < usecases.length; u++) {
+ for (int r = 0; r < roleNames.length; r++) {
+ String key = usecases[u] + ":" + roleNames[r];
+ boolean value = getParameterAsBoolean(key, false);
+ Role role = getAccessController().getAccreditableManager().getRoleManager()
+ .getRole(roleNames[r]);
+ getUsecaseAuthorizer().setPermission(usecases[u], pub, role, value);
+ }
+ }
+
+ }
+
+ private UsecaseAuthorizer authorizer;
+
+ protected UsecaseAuthorizer getUsecaseAuthorizer() {
+ if (this.authorizer == null) {
+ Authorizer[] authorizers = getAccessController().getAuthorizers();
+ for (int i = 0; i < authorizers.length; i++) {
+ if (authorizers[i] instanceof UsecaseAuthorizer) {
+ this.authorizer = (UsecaseAuthorizer) authorizers[i];
+ }
+ }
+ }
+ return this.authorizer;
+ }
+
+}
Added: lenya/trunk/src/modules-core/administration/usecases/usecases.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/administration/usecases/usecases.jx?view=auto&rev=476830
==============================================================================
--- lenya/trunk/src/modules-core/administration/usecases/usecases.jx (added)
+++ lenya/trunk/src/modules-core/administration/usecases/usecases.jx Sun Nov 19 06:44:32 2006
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id: user.jx 473861 2006-11-12 03:51:14Z gregor $ -->
+
+<page:page
+ xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
+ xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
+ >
+
+ <page:body>
+ <jx:import uri="fallback://lenya/usecases/templates/tabs.jx"/>
+ <div id="contentblock1" class="lenya-tab">
+ <h1><i18n:text>Usecases</i18n:text></h1>
+
+ <form method="post" id="form-usecases">
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <p>
+ Here you can choose which usecases should be executable
+ by which roles.
+ </p>
+ <jx:if test="${usecase.getParameter('templates').size() > 0}">
+ <p><strong>Note:</strong><br/>
+ If you submit this form, all usecase permissions
+ are stored for the publication "<jx:out value="${usecase.getParameter('publicationId')}"/>".
+ If you want to set the inherited usecase permissions of a template publication, please go
+ to the administration GUI of one of the templates
+ (<jx:forEach var="template" items="${usecase.getParameter('templates')}">
+ <a href="${request.contextPath + '/' + template + '/authoring/index.html?lenya.usecase=admin.usecases'}"><jx:out value="${template}"/></a>
+ </jx:forEach>).
+ </p>
+ </jx:if>
+ <jx:import uri="fallback://lenya/usecases/templates/messages.jx"/>
+ <table class="lenya-table">
+ <jx:set var="i" value="0"/>
+ <jx:forEach var="usecaseName" items="${usecase.getParameter('usecases')}">
+ <jx:if test="${i % 10 == 0}">
+ <tr>
+ <td colspan="${1 + usecase.getParameter('roles').size()}" style="border-left: 0; border-right: 0;">
+ <p>
+ <input type="submit" name="submit" value="Submit" i18n:attr="value"/>
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <th><i18n:text>Usecase</i18n:text></th>
+ <jx:forEach var="role" items="${usecase.getParameter('roles')}">
+ <th><i18n:text><jx:out value="${role}"/></i18n:text></th>
+ </jx:forEach>
+ </tr>
+ </jx:if>
+ <jx:set var="i" value="${i + 1}"/>
+ <tr>
+ <td><jx:out value="${usecaseName}"/></td>
+ <jx:forEach var="role" items="${usecase.getParameter('roles')}">
+ <td>
+ <jx:set var="name" value="${usecaseName + ':' + role}"/>
+ <jx:set var="value" value="${usecase.getParameter(name)}"/>
+ <jx:choose>
+ <jx:when test="${value == java.lang.Boolean.TRUE}">
+ <input name="${name}" type="checkbox" checked="checked"/>
+ </jx:when>
+ <jx:otherwise>
+ <input name="${name}" type="checkbox"/>
+ </jx:otherwise>
+ </jx:choose>
+ </td>
+ </jx:forEach>
+ </tr>
+ </jx:forEach>
+ </table>
+ <p style="width: 50%">
+ <input type="submit" name="submit" value="Submit" i18n:attr="value"/>
+ </p>
+ </form>
+ </div>
+ </page:body>
+</page:page>
Modified: lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizerImpl.java?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizerImpl.java (original)
+++ lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizerImpl.java Sun Nov 19 06:44:32 2006
@@ -38,6 +38,7 @@
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Role;
+import org.apache.lenya.ac.cache.BuildException;
import org.apache.lenya.ac.cache.CachingException;
import org.apache.lenya.ac.cache.SourceCache;
import org.apache.lenya.cms.ac.PolicyUtil;
@@ -155,13 +156,7 @@
getLogger().debug("Authorizing usecase [" + usecase + "]");
boolean authorized = false;
- UsecaseRolesBuilder builder = new UsecaseRolesBuilder();
- UsecaseRoles usecaseRoles;
- try {
- usecaseRoles = (UsecaseRoles) getCache().get(_configurationUri, builder);
- } catch (CachingException e) {
- throw new AccessControlException(e);
- }
+ UsecaseRoles usecaseRoles = getUsecaseRoles(_configurationUri);
if (usecaseRoles == null) {
throw new AccessControlException("Usecase policies configuration not found at ["
@@ -188,6 +183,17 @@
return authorized;
}
+ protected UsecaseRoles getUsecaseRoles(String _configurationUri) throws AccessControlException {
+ UsecaseRolesBuilder builder = new UsecaseRolesBuilder();
+ UsecaseRoles usecaseRoles;
+ try {
+ usecaseRoles = (UsecaseRoles) getCache().get(_configurationUri, builder);
+ } catch (CachingException e) {
+ throw new AccessControlException(e);
+ }
+ return usecaseRoles;
+ }
+
private ServiceManager manager;
/**
@@ -267,6 +273,40 @@
}
} else {
throw new AccessControlException("No such file or directory: " + configurationFile);
+ }
+ }
+
+ public boolean isPermitted(String usecase, Publication publication, Role role)
+ throws AccessControlException {
+ String configUri = getConfigurationURI(publication);
+ UsecaseRoles usecaseRoles = getUsecaseRoles(configUri);
+ String[] roles = usecaseRoles.getRoles(usecase);
+ return Arrays.asList(roles).contains(role.getId());
+ }
+
+ public void setPermission(String usecase, Publication publication, Role role, boolean granted)
+ throws AccessControlException {
+ String configUri = getConfigurationURI(publication);
+ if (configUri.startsWith("aggregate-")) {
+ configUri = configUri.substring("aggregate-".length());
+ }
+ UsecaseRoles usecaseRoles = getUsecaseRoles(configUri);
+ List roles = Arrays.asList(usecaseRoles.getRoles(usecase));
+ String roleId = role.getId();
+ if (granted) {
+ if (!roles.contains(roleId)) {
+ usecaseRoles.addRole(usecase, roleId);
+ }
+ } else {
+ if (roles.contains(roleId)) {
+ usecaseRoles.removeRole(usecase, roleId);
+ }
+ }
+ UsecaseRolesBuilder builder = new UsecaseRolesBuilder();
+ try {
+ builder.save(usecaseRoles, configUri, this.manager);
+ } catch (BuildException e) {
+ throw new AccessControlException(e);
}
}
Modified: lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRoles.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRoles.java?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRoles.java (original)
+++ lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRoles.java Sun Nov 19 06:44:32 2006
@@ -18,25 +18,28 @@
package org.apache.lenya.cms.ac.usecase;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
* Class to manage roles for a usecase.
- *
+ *
* @version $Id$
*/
public class UsecaseRoles {
-
+
private Map usecaseToRoles = new HashMap();
-
+
/**
* Ctor.
*/
public UsecaseRoles() {
- // do nothing
+ // do nothing
}
-
+
/**
* Sets the roles for a usecase.
* @param usecaseId The usecase ID.
@@ -45,10 +48,10 @@
public void setRoles(String usecaseId, String[] roleIds) {
this.usecaseToRoles.put(usecaseId, roleIds);
}
-
+
/**
- * Returns the roles for a usecase.
- * If no roles are defined for this usecase, an array of size 0 is returned.
+ * Returns the roles for a usecase. If no roles are defined for this
+ * usecase, an array of size 0 is returned.
* @param usecaseId The usecase ID.
* @return A role array.
*/
@@ -61,7 +64,7 @@
}
return usecaseRoles;
}
-
+
/**
* Checks if a usecase has roles.
* @param usecaseId The usecase ID.
@@ -69,6 +72,44 @@
*/
public boolean hasRoles(String usecaseId) {
return this.usecaseToRoles.containsKey(usecaseId);
+ }
+
+ /**
+ * @return All available usecase names.
+ */
+ public String[] getUsecaseNames() {
+ Set names = this.usecaseToRoles.keySet();
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+
+ /**
+ * @param usecase The usecase name.
+ * @param role The role ID.
+ */
+ public void addRole(String usecase, String role) {
+ String[] usecaseRoles = getRoles(usecase);
+ Set newRoles = new HashSet();
+ newRoles.addAll(Arrays.asList(usecaseRoles));
+ newRoles.add(role);
+ this.usecaseToRoles.put(usecase, newRoles.toArray(new String[newRoles.size()]));
+ }
+
+ /**
+ * @param usecase The usecase.
+ * @param role The role.
+ */
+ public void removeRole(String usecase, String role) {
+ String[] usecaseRoles = getRoles(usecase);
+ Set newRoles = new HashSet();
+ newRoles.addAll(Arrays.asList(usecaseRoles));
+
+ if (!newRoles.contains(role)) {
+ throw new RuntimeException("The role [" + role + "] is not set for usecase [" + usecase
+ + "]");
+ }
+
+ newRoles.remove(role);
+ this.usecaseToRoles.put(usecase, newRoles.toArray(new String[newRoles.size()]));
}
}
Modified: lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRolesBuilder.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRolesBuilder.java?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRolesBuilder.java (original)
+++ lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/ac/usecase/UsecaseRolesBuilder.java Sun Nov 19 06:44:32 2006
@@ -22,9 +22,12 @@
import java.util.HashSet;
import java.util.Set;
+import org.apache.avalon.framework.service.ServiceManager;
import org.apache.lenya.ac.AccessController;
import org.apache.lenya.ac.cache.BuildException;
import org.apache.lenya.ac.cache.InputStreamBuilder;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.util.Assert;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
import org.w3c.dom.Document;
@@ -55,7 +58,8 @@
} catch (Exception e) {
throw new BuildException(e);
}
- assert document.getDocumentElement().getLocalName().equals(USECASES_ELEMENT);
+ Assert.isTrue("Correct usecase policies XML", document.getDocumentElement().getLocalName()
+ .equals(USECASES_ELEMENT));
NamespaceHelper helper = new NamespaceHelper(AccessController.NAMESPACE,
AccessController.DEFAULT_PREFIX, document);
@@ -64,7 +68,7 @@
USECASE_ELEMENT);
for (int i = 0; i < usecaseElements.length; i++) {
String usecaseId = usecaseElements[i].getAttribute(ID_ATTRIBUTE);
-
+
// add roles only if not overridden by child publication
if (!usecaseRoles.hasRoles(usecaseId)) {
Element[] roleElements = helper.getChildren(usecaseElements[i], ROLE_ELEMENT);
@@ -78,6 +82,35 @@
}
}
return usecaseRoles;
+ }
+
+ /**
+ * Saves the usecase roles.
+ * @param usecaseRoles The roles.
+ * @param sourceUri The source to save to.
+ * @param manager The service manager.
+ * @throws BuildException if an error occurs.
+ */
+ public void save(UsecaseRoles usecaseRoles, String sourceUri, ServiceManager manager) throws BuildException {
+ try {
+ NamespaceHelper helper = new NamespaceHelper(AccessController.NAMESPACE,
+ AccessController.DEFAULT_PREFIX, USECASES_ELEMENT);
+ String[] usecaseNames = usecaseRoles.getUsecaseNames();
+ for (int u = 0; u < usecaseNames.length; u++) {
+ Element usecaseElement = helper.createElement(USECASE_ELEMENT);
+ helper.getDocument().getDocumentElement().appendChild(usecaseElement);
+ usecaseElement.setAttribute(ID_ATTRIBUTE, usecaseNames[u]);
+ String[] roles = usecaseRoles.getRoles(usecaseNames[u]);
+ for (int r = 0; r < roles.length; r++) {
+ Element roleElement = helper.createElement(ROLE_ELEMENT);
+ usecaseElement.appendChild(roleElement);
+ roleElement.setAttribute(ID_ATTRIBUTE, roles[r]);
+ }
+ }
+ SourceUtil.writeDOM(helper.getDocument(), sourceUri, manager);
+ } catch (Exception e) {
+ throw new BuildException(e);
+ }
}
}
Modified: lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java (original)
+++ lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java Sun Nov 19 06:44:32 2006
@@ -17,6 +17,9 @@
*/
package org.apache.lenya.cms.usecase;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
@@ -56,7 +59,13 @@
*/
public void service(ServiceManager _manager) throws ServiceException {
this.manager = _manager;
- this.selector = (ServiceSelector) _manager.lookup(Usecase.ROLE + "Selector");
+ }
+
+ protected ServiceSelector getSelector() throws ServiceException {
+ if (this.selector == null) {
+ this.selector = (ServiceSelector) this.manager.lookup(Usecase.ROLE + "Selector");
+ }
+ return this.selector;
}
/**
@@ -66,7 +75,7 @@
if (usecase == null) {
throw new IllegalArgumentException("The usecase to release must not be null.");
}
- this.selector.release(usecase);
+ getSelector().release(usecase);
}
@@ -93,9 +102,9 @@
if (publication != null) {
PublicationTemplateManager templateManager = null;
try {
- templateManager = (PublicationTemplateManager) this.manager.lookup(PublicationTemplateManager.ROLE);
- newName = (String) templateManager.getSelectableHint(publication,
- this.selector,
+ templateManager = (PublicationTemplateManager) this.manager
+ .lookup(PublicationTemplateManager.ROLE);
+ newName = (String) templateManager.getSelectableHint(publication, getSelector(),
name);
} finally {
if (templateManager != null) {
@@ -142,11 +151,12 @@
}
/**
- * @see org.apache.lenya.cms.usecase.UsecaseResolver#resolve(java.lang.String, java.lang.String)
+ * @see org.apache.lenya.cms.usecase.UsecaseResolver#resolve(java.lang.String,
+ * java.lang.String)
*/
public Usecase resolve(String webappUrl, String name) throws ServiceException {
Object usecaseName = getUsecaseName(webappUrl, name);
- return (Usecase) this.selector.select(usecaseName);
+ return (Usecase) getSelector().select(usecaseName);
}
/**
@@ -155,7 +165,26 @@
*/
public boolean isRegistered(String webappUrl, String name) throws ServiceException {
String usecaseName = getUsecaseName(webappUrl, name);
- return this.selector.isSelectable(usecaseName);
+ return getSelector().isSelectable(usecaseName);
+ }
+
+ /**
+ * @return The names of all registered usecases in alphabetical order.
+ */
+ public String[] getUsecaseNames() {
+ if (this.usecaseNames == null) {
+ throw new IllegalStateException("No usecase registered!");
+ }
+ return (String[]) this.usecaseNames.toArray(new String[this.usecaseNames.size()]);
+ }
+
+ private SortedSet usecaseNames;
+
+ public void register(String usecaseName) {
+ if (this.usecaseNames == null) {
+ this.usecaseNames = new TreeSet();
+ }
+ this.usecaseNames.add(usecaseName);
}
}
Added: lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseSelector.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseSelector.java?view=auto&rev=476830
==============================================================================
--- lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseSelector.java (added)
+++ lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseSelector.java Sun Nov 19 06:44:32 2006
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.usecase;
+
+import java.util.Iterator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.ExtendedComponentSelector;
+
+/**
+ * Usecase selector.
+ */
+public class UsecaseSelector extends ExtendedComponentSelector implements ThreadSafe, Startable, Serviceable {
+
+ private SortedSet usecaseNames;
+ private ServiceManager manager;
+
+ /**
+ * @return The names of all registered usecases in alphabetical order.
+ */
+ public String[] getUsecaseNames() {
+ return (String[]) this.usecaseNames.toArray(new String[this.usecaseNames.size()]);
+ }
+
+ public void configure(Configuration config) throws ConfigurationException {
+ super.configure(config);
+
+ this.usecaseNames = new TreeSet();
+ Configuration[] usecaseConfigs = config.getChildren("component-instance");
+ for (int i = 0; i < usecaseConfigs.length; i++) {
+ this.usecaseNames.add(usecaseConfigs[i].getAttribute("name"));
+ }
+ }
+
+ public void start() throws Exception {
+ UsecaseResolver resolver = null;
+ try {
+ resolver = (UsecaseResolver) this.manager.lookup(UsecaseResolver.ROLE);
+ for (Iterator i = this.usecaseNames.iterator(); i.hasNext(); ) {
+ resolver.register((String) i.next());
+ }
+ }
+ finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ public void stop() throws Exception {
+ }
+
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+}
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java Sun Nov 19 06:44:32 2006
@@ -39,6 +39,27 @@
* @return A boolean value.
* @throws AccessControlException when something went wrong.
*/
- public boolean authorizeUsecase(String usecase, Role[] roles, Publication publication,
+ boolean authorizeUsecase(String usecase, Role[] roles, Publication publication,
String requestURI) throws AccessControlException;
+
+ /**
+ * @param usecase The usecase.
+ * @param publication The publication.
+ * @param role The role.
+ * @param granted If the usecase shall be permitted.
+ * @throws AccessControlException if an error occurs.
+ */
+ void setPermission(String usecase, Publication publication, Role role, boolean granted)
+ throws AccessControlException;
+
+ /**
+ * @param usecase The usecase.
+ * @param publication The publication.
+ * @param role The role.
+ * @return A boolean value.
+ * @throws AccessControlException if an error occurs.
+ */
+ boolean isPermitted(String usecase, Publication publication, Role role)
+ throws AccessControlException;
+
}
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseResolver.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseResolver.java?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseResolver.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/UsecaseResolver.java Sun Nov 19 06:44:32 2006
@@ -17,6 +17,8 @@
*/
package org.apache.lenya.cms.usecase;
+import java.util.TreeSet;
+
import org.apache.avalon.framework.service.ServiceException;
/**
@@ -56,4 +58,14 @@
*/
void release(Usecase usecase) throws ServiceException;
+ /**
+ * @return The names of all registered usecases in alphabetical order.
+ */
+ String[] getUsecaseNames();
+
+ /**
+ * @param usecaseName The usecase to register.
+ */
+ void register(String usecaseName);
+
}
Modified: lenya/trunk/src/pubs/default/config/ac/usecase-policies.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/config/ac/usecase-policies.xml?view=diff&rev=476830&r1=476829&r2=476830
==============================================================================
--- lenya/trunk/src/pubs/default/config/ac/usecase-policies.xml (original)
+++ lenya/trunk/src/pubs/default/config/ac/usecase-policies.xml Sun Nov 19 06:44:32 2006
@@ -197,6 +197,9 @@
<role id="admin" method="grant"/>
<role id="edit" method="grant"/>
</usecase>
+ <usecase id="admin.usecases">
+ <role id="admin" method="grant"/>
+ </usecase>
<usecase id="admin.addGroup">
<role id="admin" method="grant"/>
</usecase>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org