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 2005/05/24 08:48:28 UTC
svn commit: r178120 - in /lenya/trunk/src:
java/org/apache/lenya/cms/ac/usecases/AccessControl.java
webapp/lenya/usecases/tab/ac/ac.jx
webapp/lenya/usecases/tab/ac/add-credential.jx
webapp/lenya/usecases/tab/ac/ssl-form.jx
Author: andreas
Date: Mon May 23 23:48:28 2005
New Revision: 178120
URL: http://svn.apache.org/viewcvs?rev=178120&view=rev
Log:
fixed SSL form in AC usecases
Added:
lenya/trunk/src/webapp/lenya/usecases/tab/ac/ssl-form.jx
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AccessControl.java
lenya/trunk/src/webapp/lenya/usecases/tab/ac/ac.jx
lenya/trunk/src/webapp/lenya/usecases/tab/ac/add-credential.jx
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AccessControl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AccessControl.java?rev=178120&r1=178119&r2=178120&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AccessControl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AccessControl.java Mon May 23 23:48:28 2005
@@ -17,28 +17,43 @@
package org.apache.lenya.cms.ac.usecases;
import org.apache.cocoon.ProcessingException;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.URLInformation;
import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.Accreditable;
+import org.apache.lenya.ac.AccreditableManager;
import org.apache.lenya.ac.Item;
+import org.apache.lenya.ac.Policy;
import org.apache.lenya.ac.Role;
-import org.apache.lenya.cms.ac.cocoon.PolicyHelper;
+import org.apache.lenya.ac.impl.DefaultAccessController;
+import org.apache.lenya.ac.impl.DefaultPolicy;
+import org.apache.lenya.ac.impl.InheritingPolicyManager;
/**
- * Usecase to display the AccessControl tab in the site area for a document.
- * This is a mix-in class that ideally would inherit both from
- * AccessControlUsecase and DocumentUsecase. FIXME i just took the appropriate
- * code from DocumentUsecase, maybe its possible to have a saner inheritance?
+ * Usecase to display the AccessControl tab in the site area for a document. This is a mix-in class
+ * that ideally would inherit both from AccessControlUsecase and DocumentUsecase. FIXME i just took
+ * the appropriate code from DocumentUsecase, maybe its possible to have a saner inheritance?
*
* @version $Id: AccessControl.java 123980 2005-01-03 15:00:14Z andreas $
*/
public class AccessControl extends AccessControlUsecase {
- private PolicyHelper helper = null;
private Item[] items = null;
+ protected static final String ADD = "add";
+ protected static final String DELETE = "delete";
+
private static String[] types = { "user", "group", "iprange", "role" };
- private static String[] operations = { "add", "delete" };
+ private static String[] operations = { ADD, DELETE };
+
+ protected static final String SSL = "ssl";
+ protected static final String ANCESTOR_SSL = "ancestorSsl";
+ protected static final String DOCUMENT = "document";
+ private String COMPLETE_AREA = "private.completeArea";
/**
* Ctor.
@@ -54,6 +69,16 @@
super.initParameters();
try {
+ URLInformation info = new URLInformation(getSourceURL());
+ setParameter(COMPLETE_AREA, info.getCompleteArea());
+
+ DocumentIdentityMap map = (DocumentIdentityMap) getUnitOfWork().getIdentityMap();
+ Document sourceDocument = map.getFromURL(getSourceURL());
+ setParameter(DOCUMENT, sourceDocument);
+
+ setParameter(SSL, Boolean.toString(isSSLProtected()));
+ setParameter(ANCESTOR_SSL, Boolean.toString(isAncestorSSLProtected()));
+
Role[] roles = getRoleManager().getRoles();
String visitorRole = "";
for (int i = 0; i < roles.length; i++) {
@@ -64,7 +89,6 @@
setParameter("visitorRole", visitorRole);
- this.helper = new PolicyHelper(getLogger());
//FIXME expects the component manager
// helper.setup(objectModel, this.manager, area);
@@ -95,14 +119,14 @@
Role role = getRoleManager().getRole(roleId);
if (role == null) {
- addErrorMessage("role_no_such_role", new String[]{roleId});
+ addErrorMessage("role_no_such_role", new String[] { roleId });
}
- this.helper.manipulateCredential(item, role, operations[j]);
+ manipulateCredential(item, role, operations[j]);
}
}
}
- } catch (final ProcessingException e) {
+ } catch (final Exception e) {
addErrorMessage("Could not read a value.");
getLogger().error("Could not read value for AccessControl usecase. " + e.toString());
}
@@ -114,7 +138,7 @@
* @throws UsecaseException if an error occurs.
*/
void validate() throws UsecaseException {
- // do nothing
+ // do nothing
}
/**
@@ -127,37 +151,132 @@
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
*/
- protected void doExecute() throws Exception {
- super.doExecute();
- if (getParameterAsString("change_ssl") != null) {
- if (getParameterAsString("ssl") != null) {
- this.helper.setUrlSSLProtected(true);
- } else {
- this.helper.setUrlSSLProtected(false);
+ public void doExecute() throws Exception {
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#advance()
+ */
+ public void advance() throws UsecaseException {
+ super.advance();
+ try {
+ if (getParameterAsString("change_ssl") != null) {
+ String ssl = getParameterAsString("ssl");
+ if (ssl != null && ssl.equalsIgnoreCase(Boolean.toString(true))) {
+ setSSLProtected(true);
+ } else {
+ setSSLProtected(false);
+ }
+ deleteParameter("change_ssl");
+ deleteParameter("ssl");
}
+ } catch (Exception e) {
+ throw new UsecaseException(e);
}
-
}
/**
- * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String,
- * java.lang.Object)
+ * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String, java.lang.Object)
*/
public void setParameter(String name, Object value) {
super.setParameter(name, value);
}
/**
- * @return PolicyHelper the policy helper
+ * @return Item the item
*/
- public PolicyHelper getHelper() {
- return this.helper;
+ public Item[] getItems() {
+ return this.items;
}
/**
- * @return Item the item
+ * Returns if one of the ancestors of this URL is SSL protected.
+ * @return A boolean value.
+ * @throws ProcessingException when something went wrong.
*/
- public Item[] getItems() {
- return this.items;
+ protected boolean isAncestorSSLProtected() throws ProcessingException {
+ boolean ssl;
+ try {
+ String ancestorUrl = "";
+ int lastSlashIndex = getSourceURL().lastIndexOf("/");
+ if (lastSlashIndex != -1) {
+ ancestorUrl = getSourceURL().substring(0, lastSlashIndex);
+ }
+
+ Policy policy = getPolicyManager().getPolicy(getAccreditableManager(), ancestorUrl);
+ ssl = policy.isSSLProtected();
+ } catch (AccessControlException e) {
+ throw new ProcessingException("Resolving policy failed: ", e);
+ }
+ return ssl;
+ }
+
+ /**
+ * Returns if one of the ancestors of this URL is SSL protected.
+ * @return A boolean value.
+ * @throws ProcessingException when something went wrong.
+ */
+ protected boolean isSSLProtected() throws ProcessingException {
+ boolean ssl;
+ try {
+ Policy policy = getPolicyManager().getPolicy(getAccreditableManager(), getSourceURL());
+ ssl = policy.isSSLProtected();
+ } catch (AccessControlException e) {
+ throw new ProcessingException("Resolving policy failed: ", e);
+ }
+ return ssl;
+ }
+
+ /**
+ * Sets if this URL is SSL protected.
+ * @param ssl A boolean value.
+ * @throws ProcessingException when something went wrong.
+ */
+ protected void setSSLProtected(boolean ssl) throws ProcessingException {
+ try {
+ DefaultPolicy policy = getPolicyManager().buildSubtreePolicy(getAccreditableManager(),
+ getSourceURL());
+ policy.setSSL(ssl);
+ getPolicyManager().saveSubtreePolicy(getSourceURL(), policy);
+ } catch (AccessControlException e) {
+ throw new ProcessingException("Resolving policy failed: ", e);
+ }
+ }
+
+ protected InheritingPolicyManager getPolicyManager() {
+ return (InheritingPolicyManager) ((DefaultAccessController) getAccessController())
+ .getPolicyManager();
+ }
+
+ protected AccreditableManager getAccreditableManager() {
+ return ((DefaultAccessController) getAccessController()).getAccreditableManager();
+ }
+
+ /**
+ * Changes a credential by adding or deleting an item for a role.
+ * @param item The item to add or delete.
+ * @param role The role.
+ * @param operation The operation, either {@link #ADD}or {@link #DELETE}.
+ * @throws ProcessingException when something went wrong.
+ */
+ protected void manipulateCredential(Item item, Role role, String operation)
+ throws ProcessingException {
+
+ try {
+ DefaultPolicy policy = getPolicyManager().buildSubtreePolicy(getAccreditableManager(),
+ getSourceURL());
+ Accreditable accreditable = (Accreditable) item;
+
+ if (operation.equals(ADD)) {
+ policy.addRole(accreditable, role);
+ } else if (operation.equals(DELETE)) {
+ policy.removeRole(accreditable, role);
+ }
+
+ getPolicyManager().saveSubtreePolicy(getSourceURL(), policy);
+
+ } catch (Exception e) {
+ throw new ProcessingException("Manipulating credential failed: ", e);
+ }
}
-}
+}
\ No newline at end of file
Modified: lenya/trunk/src/webapp/lenya/usecases/tab/ac/ac.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/tab/ac/ac.jx?rev=178120&r1=178119&r2=178120&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/tab/ac/ac.jx (original)
+++ lenya/trunk/src/webapp/lenya/usecases/tab/ac/ac.jx Mon May 23 23:48:28 2005
@@ -20,49 +20,18 @@
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">
- <div>
+ <jx:import uri="tab/head.jx"/>
+ <page:body>
+ <!--
+ <jx:import uri="tab/sitetree.jx"/>
+ -->
<jx:import uri="tab/tabs.jx"/>
- <div id="contentblock1" class="lenya-tab">
+ <div id="contentblock1" class="lenya-tab-sitetree">
<table class="lenya-table-noborder">
<tr>
<td>
- <form method="get" name="form_ssl_{$usecase.getParameter('document').getArea()}">
- <input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
- <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
- <input type="hidden" name="change_ssl" value="true"/>
-
- <jx:choose>
- <jx:when test="${usecase.getParameter('ssl').equals('true') || usecase.getParameter('anchestor-ssl').equals('true')}">
- <jx:choose>
- <jx:when test="${usecase.getParameter('anchestor-ssl').equals('true')}">
- <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_{@area}.submit()" value="true" checked="checked" disabled="disabled">
- <i18n:text>SSL Encryption</i18n:text>
- </input>
- </jx:when>
- <jx:otherwise>
- <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_{@area}.submit()" value="true" checked="checked">
- <i18n:text>SSL Encryption</i18n:text>
- </input>
- </jx:otherwise>
- </jx:choose>
- </jx:when>
- <jx:otherwise>
- <jx:choose>
- <jx:when test="${usecase.getParameter('anchestor-ssl').equals('true')}">
- <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_{@area}.submit()" value="true" disabled="disabled">
- <i18n:text>SSL Encryption</i18n:text>
- </input>
- </jx:when>
- <jx:otherwise>
- <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_{@area}.submit()" value="true">
- <i18n:text>SSL Encryption</i18n:text>
- </input>
- </jx:otherwise>
- </jx:choose>
- </jx:otherwise>
- </jx:choose>
- </form>
- </td>
+ <jx:import uri="tab/ac/ssl-form.jx"/>
+ </td>
</tr>
<tr>
<td>
@@ -109,5 +78,5 @@
</tr>
</table>
</div>
- </div>
+ </page:body>
</page:page>
Modified: lenya/trunk/src/webapp/lenya/usecases/tab/ac/add-credential.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/tab/ac/add-credential.jx?rev=178120&r1=178119&r2=178120&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/tab/ac/add-credential.jx (original)
+++ lenya/trunk/src/webapp/lenya/usecases/tab/ac/add-credential.jx Mon May 23 23:48:28 2005
@@ -23,18 +23,18 @@
name="">
<form method="get">
<input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
- <input type="hidden" name="lenya.step" value="showscreen"/>
- <td><i18n:text><xsl:value-of select="$title"/></i18n:text>:</td>
+ <!--
<td><xsl:apply-templates select="//lenya-info:items[@type = $type]"/></td>
+ -->
<td>
- <xsl:choose>
+ <jx:choose>
<xsl:when test="$larea != 'live'">
<xsl:apply-templates select="//lenya-info:items[@type = 'role']"/>
</xsl:when>
<xsl:otherwise>
- <input type="hidden" name="role_id" value="{//lenya-info:visitor-role}"/>
+ <input type="hidden" name="role_id" value="${usecase.getParameter('visitorRole')}"/>
</xsl:otherwise>
- </xsl:choose>
+ </jx:choose>
</td>
<td>
<input i18n:attr="value" type="submit" name="add_credential_{$type}" value="Add">
Added: lenya/trunk/src/webapp/lenya/usecases/tab/ac/ssl-form.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/tab/ac/ssl-form.jx?rev=178120&view=auto
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/tab/ac/ssl-form.jx (added)
+++ lenya/trunk/src/webapp/lenya/usecases/tab/ac/ssl-form.jx Mon May 23 23:48:28 2005
@@ -0,0 +1,63 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed 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: ac.jx 156161 2005-03-04 15:23:21Z andreas $ -->
+<jx:template
+ xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
+ xmlns="http://www.w3.org/1999/xhtml"
+ name="">
+<jx:set var="area" value="${usecase.getParameter('document').getArea()}"/>
+<form method="get" name="form_ssl_${area}">
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <input type="hidden" name="change_ssl" value="true"/>
+
+ <jx:set var="ssl" value="${usecase.getParameter('ssl')}"/>
+ <jx:set var="ancestorSsl" value="${usecase.getParameter('ancestorSsl')}"/>
+ <jx:choose>
+ <jx:when test="${ssl.equals('true') || ancestorSsl.equals('true')}">
+ <jx:choose>
+ <jx:when test="${ancestorSsl.equals('true')}">
+ <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_${area}.submit()" value="true" checked="checked" disabled="disabled">
+ <i18n:text>SSL Encryption</i18n:text>
+ </input>
+ </jx:when>
+ <jx:otherwise>
+ <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_${area}.submit()" value="true" checked="checked">
+ <i18n:text>SSL Encryption</i18n:text>
+ </input>
+ </jx:otherwise>
+ </jx:choose>
+ </jx:when>
+ <jx:otherwise>
+ <jx:choose>
+ <jx:when test="${ancestorSsl.equals('true')}">
+ <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_${area}.submit()" value="true" disabled="disabled">
+ <i18n:text>SSL Encryption</i18n:text>
+ </input>
+ </jx:when>
+ <jx:otherwise>
+ <input type="checkbox" name="ssl" onclick="document.forms.form_ssl_${area}.submit()" value="true">
+ <i18n:text>SSL Encryption</i18n:text>
+ </input>
+ </jx:otherwise>
+ </jx:choose>
+ </jx:otherwise>
+ </jx:choose>
+</form>
+</jx:template>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org