From: <fg...@us...> - 2008-06-24 15:07:11
|
Revision: 860 http://openutils.svn.sourceforge.net/openutils/?rev=860&view=rev Author: fgiust Date: 2008-06-24 08:06:13 -0700 (Tue, 24 Jun 2008) Log Message: ----------- 3.5.3, a few improvements to user/role setup Modified Paths: -------------- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AnonymousUserSetupTask.java trunk/openutils-mgnltasks/src/site/changes/changes.xml Added Paths: ----------- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateGroupTask.java trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateRoleTask.java Modified: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AnonymousUserSetupTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AnonymousUserSetupTask.java 2008-06-24 13:24:09 UTC (rev 859) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AnonymousUserSetupTask.java 2008-06-24 15:06:13 UTC (rev 860) @@ -20,6 +20,7 @@ import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.cms.security.Permission; import info.magnolia.cms.security.UserManager; import info.magnolia.cms.util.NodeDataUtil; @@ -36,7 +37,7 @@ /** * A task that can be used to add or remove read only access to the anonymous user (for an easy admin/public switch). * @author fgiust - * @version $Id: $ + * @version $Id$ */ public class AnonymousUserSetupTask extends AbstractRepositoryTask implements Task { @@ -57,7 +58,6 @@ /** * {@inheritDoc} */ - @SuppressWarnings("unchecked") @Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { @@ -66,19 +66,35 @@ Content role = hm.getContent("/" + UserManager.ANONYMOUS_USER); - Content acls = role.getChildByName("acl_website"); + setupAcl(role, "website", "/", this.allowAccess ? Permission.READ : Permission.NONE); + setupAcl(role, "uri", "/*", this.allowAccess ? Permission.ALL : Permission.NONE); + setupAcl(role, "uri", "/.magnolia*", Permission.NONE); + } + /** + * @param role + * @param repository + * @param newpermissions + * @throws RepositoryException + * @throws AccessDeniedException + */ + @SuppressWarnings("unchecked") + private void setupAcl(Content role, String repository, String path, long newpermissions) + throws RepositoryException, AccessDeniedException + { + Content acls = role.getChildByName("acl_" + repository); + Collection<Content> children = acls.getChildren(); boolean found = false; for (Content acl : children) { - if ("/*".equals(acl.getNodeData("path").getString())) + String aclPath = acl.getNodeData("path").getString(); + if (path.equals(aclPath)) { found = true; long permissions = acl.getNodeData("permissions").getLong(); - long newpermissions = this.allowAccess ? Permission.READ : 0; if (permissions != newpermissions) { NodeDataUtil.getOrCreate(acl, "permissions").setValue(newpermissions); @@ -87,7 +103,7 @@ } if (!found) { - log.warn("Security not configured on anonymous user! No acl for /* found."); + log.warn("Security not configured on anonymous user! No acl for {} found on {}", path, repository); } } Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateGroupTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateGroupTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateGroupTask.java 2008-06-24 15:06:13 UTC (rev 860) @@ -0,0 +1,76 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package it.openutils.mgnltasks; + +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.BootstrapSingleResource; +import info.magnolia.module.delta.Task; +import info.magnolia.module.delta.TaskExecutionException; + +import javax.jcr.PathNotFoundException; +import javax.jcr.RepositoryException; + + +/** + * Creates a group if not already existing. + * @author fgiust + * @version $Id$ + */ +public class CheckAndCreateGroupTask extends AbstractRepositoryTask implements Task +{ + + private String group; + + private String bootstrapFile; + + /** + * @param group group name + * @param bootstrapFile bootstrap file used to create the group + */ + public CheckAndCreateGroupTask(String group, String bootstrapFile) + { + super("Checking " + group, "Checking " + group); + this.group = group; + this.bootstrapFile = bootstrapFile; + } + + /** + * {@inheritDoc} + */ + @Override + protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException + { + + HierarchyManager hm = installContext.getHierarchyManager(ContentRepository.USER_GROUPS); + + try + { + hm.getContent(group); + } + catch (PathNotFoundException e) + { + + BootstrapSingleResource bsr = new BootstrapSingleResource("creating group " + group, "creating group " + + group, bootstrapFile); + bsr.execute(installContext); + } + } +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateGroupTask.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateRoleTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateRoleTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateRoleTask.java 2008-06-24 15:06:13 UTC (rev 860) @@ -0,0 +1,78 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package it.openutils.mgnltasks; + +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.BootstrapSingleResource; +import info.magnolia.module.delta.Task; +import info.magnolia.module.delta.TaskExecutionException; + +import javax.jcr.PathNotFoundException; +import javax.jcr.RepositoryException; + + +/** + * Creates a role if not already existing. + * @author fgiust + * @version $Id$ + */ +public class CheckAndCreateRoleTask extends AbstractRepositoryTask implements Task +{ + + private String role; + + private String bootstrapFile; + + /** + * @param role role name + * @param bootstrapFile bootstrap file used to create the role + */ + public CheckAndCreateRoleTask(String role, String bootstrapFile) + { + super("Checking " + role, "Checking " + role); + this.role = role; + this.bootstrapFile = bootstrapFile; + } + + /** + * {@inheritDoc} + */ + @Override + protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException + { + + HierarchyManager hm = installContext.getHierarchyManager(ContentRepository.USER_ROLES); + + try + { + hm.getContent(role); + } + catch (PathNotFoundException e) + { + + BootstrapSingleResource bsr = new BootstrapSingleResource( + "creating role " + role, + "creating role " + role, + bootstrapFile); + bsr.execute(installContext); + } + } +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckAndCreateRoleTask.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Modified: trunk/openutils-mgnltasks/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnltasks/src/site/changes/changes.xml 2008-06-24 13:24:09 UTC (rev 859) +++ trunk/openutils-mgnltasks/src/site/changes/changes.xml 2008-06-24 15:06:13 UTC (rev 860) @@ -8,7 +8,12 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> - <release version="3.5.2" date="2008-06-08" description="in svn"> + <release version="3.5.3" date="2008-06-24" description=""> + <action type="add" dev="fgiust">new CheckAndCreateRoleTask and CheckAndCreateGroupTask</action> + <action type="update" dev="fgiust">AnonymousUserSetupTask now also takes care of changing + permissions on URIs</action> + </release> + <release version="3.5.2" date="2008-06-08" description=""> <action type="add" dev="fgiust">Added [modulename].update.disabled property in SimpleModuleVersionHandler that can be set to true in order to disable module configuration updates</action> <action type="add" dev="fgiust">Added it.openutils.mgnltasks.DisableSubscribersTask</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |