AW-542 Guest user can not see any Categories

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2456 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-02-21 16:12:12 +00:00
parent 295d1cd0b6
commit cab7aa3b4e
28 changed files with 633 additions and 71 deletions

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.repo.admin.patch.impl;
import java.util.List;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.service.cmr.admin.PatchException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
/**
* Grant <b>Consumer</b> role to <b>Guest</b> in <b>Category Root</b> folder.
* <p>
* This patch expects the folder to be present.
*/
public class CategoryRootPermissionPatch extends AbstractPatch
{
private static final String MSG_RESULT = "patch.categoryRootPermission.result";
private static final String ERR_NOT_FOUND = "patch.categoryRootPermission.err.not_found";
private PermissionService permissionService;
private ImporterBootstrap spacesBootstrap;
private SearchService searchService;
private NamespaceService namespaceService;
private NodeService nodeService;
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
public void setSpacesBootstrap(ImporterBootstrap spacesBootstrap)
{
this.spacesBootstrap = spacesBootstrap;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
@Override
protected String applyInternal() throws Exception
{
String categoryRootPath = "/cm:categoryRoot";
// find category root
NodeRef rootNodeRef = nodeService.getRootNode(spacesBootstrap.getStoreRef());
List<NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef, categoryRootPath, null, namespaceService, false);
if (nodeRefs.size() == 0)
{
String msg = I18NUtil.getMessage(ERR_NOT_FOUND, categoryRootPath);
throw new PatchException(msg);
}
NodeRef categoryRootRef = nodeRefs.get(0);
// apply permission
permissionService.setPermission(categoryRootRef, PermissionService.GUEST_AUTHORITY, PermissionService.READ, true);
// done
String msg = I18NUtil.getMessage(MSG_RESULT, categoryRootPath);
return msg;
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.repo.admin.patch.impl;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
/**
* Change Guest Person permission from Guest to Read
*
* Guest (now Consumer) permission is not valid for cm:person type.
*/
public class GuestPersonPermissionPatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.guestPersonPermission.result";
private PersonService personService;
private PermissionService permissionService;
private String guestId = "guest";
public GuestPersonPermissionPatch()
{
super();
}
public void setGuestId(String guestId)
{
this.guestId = guestId;
}
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
@Override
protected String applyInternal() throws Exception
{
if (personService.personExists(guestId))
{
NodeRef personRef = personService.getPerson(guestId);
permissionService.setInheritParentPermissions(personRef, false);
permissionService.deletePermission(personRef, guestId, PermissionService.CONSUMER, true);
permissionService.setPermission(personRef, guestId, PermissionService.READ, true);
}
return I18NUtil.getMessage(MSG_SUCCESS);
}
}

View File

@@ -177,7 +177,7 @@ public class GuestUserPatch extends AbstractPatch
NodeRef personRef = personService.getPerson(guestId);
permissionService.setInheritParentPermissions(personRef, false);
permissionService.setPermission(personRef, guestId, PermissionService.READ, true);
permissionService.setPermission(personRef, guestId, PermissionService.CONSUMER, true);
}
@@ -237,8 +237,8 @@ public class GuestUserPatch extends AbstractPatch
private void setGuestHomePermissions(NodeRef nodeRef)
{
permissionService.setInheritParentPermissions(nodeRef, false);
permissionService.setPermission(nodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.GUEST, true);
permissionService.setPermission(nodeRef, guestId, PermissionService.GUEST, true);
permissionService.setPermission(nodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER, true);
permissionService.setPermission(nodeRef, guestId, PermissionService.CONSUMER, true);
}
private NodeRef setCompanyHomeSpacePermissions(NodeRef storeRootNodeRef, String companyHomeChildName)
@@ -259,7 +259,7 @@ public class GuestUserPatch extends AbstractPatch
NodeRef companyHomeRef = nodeRefs.get(0);
permissionService.setInheritParentPermissions(companyHomeRef, false);
permissionService.setPermission(companyHomeRef, PermissionService.ALL_AUTHORITIES, PermissionService.GUEST,
permissionService.setPermission(companyHomeRef, PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER,
true);
return companyHomeRef;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.repo.admin.patch.impl;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PermissionService;
/**
* Change Spaces Root Node permission from Guest to Read
*
* Guest (now Consumer) permission is not valid for sys:store_root type.
*/
public class SpacesRootPermissionPatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.spacesRootPermission.result";
private ImporterBootstrap spacesBootstrap;
private NodeService nodeService;
private PermissionService permissionService;
public SpacesRootPermissionPatch()
{
super();
}
public void setSpacesBootstrap(ImporterBootstrap spacesBootstrap)
{
this.spacesBootstrap = spacesBootstrap;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
@Override
protected String applyInternal() throws Exception
{
NodeRef rootNodeRef = nodeService.getRootNode(spacesBootstrap.getStoreRef());
permissionService.deletePermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER, true);
permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true);
return I18NUtil.getMessage(MSG_SUCCESS);
}
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.repo.admin.patch.impl;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReference;
import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The permission 'Guest' has been renamed to 'Consumer'.
*
* @author David Caruana
*/
public class UpdateGuestPermissionPatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.updateGuestPermission.result";
private HibernateHelper helper;
public UpdateGuestPermissionPatch()
{
helper = new HibernateHelper();
}
public void setSessionFactory(SessionFactory sessionFactory)
{
this.helper.setSessionFactory(sessionFactory);
}
@Override
protected String applyInternal() throws Exception
{
List<String> createdNames = helper.createPermissionReferences();
int updatedPermEntries = helper.updatePermissionEntries();
// build the result message
String msg = I18NUtil.getMessage(MSG_SUCCESS, createdNames, updatedPermEntries);
// done
return msg;
}
private static class HibernateHelper extends HibernateDaoSupport
{
private static final String NAME_OLD = "Guest";
private static final String NAME_NEW = "Consumer";
private static final String[] NAMES = new String[] {"Consumer"};
private static final String QUERY_UPDATE_PERM_ENTRY_NAME = "permission.patch.UpdatePermissionName";
public List<String> createPermissionReferences()
{
List<String> createdNames = new ArrayList<String>(4);
for (String name : NAMES)
{
// create permission references as required, double checking for their existence first
PermissionReference ref = new PermissionReferenceImpl();
ref.setTypeUri(ContentModel.TYPE_CMOBJECT.getNamespaceURI());
ref.setTypeName(ContentModel.TYPE_CMOBJECT.getLocalName());
ref.setName(name);
// it acts as its own key
PermissionReference found = (PermissionReference) getHibernateTemplate().get(
PermissionReferenceImpl.class,
ref);
if (found == null)
{
// it was not found, so create it
getHibernateTemplate().save(ref);
createdNames.add(name);
}
}
return createdNames;
}
public int updatePermissionEntries()
{
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
// flush any outstanding entities
session.flush();
Query query = session.getNamedQuery(HibernateHelper.QUERY_UPDATE_PERM_ENTRY_NAME);
query.setString("nameNew", NAME_NEW)
.setString("nameOld", NAME_OLD);
int updateCount = query.executeUpdate();
return new Integer(updateCount);
}
};
Integer updateCount = (Integer) getHibernateTemplate().execute(callback);
// done
return updateCount.intValue();
}
}
}