mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Site Service: refactored site service to use groups to manage site users
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10375 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 Alfresco Software Limited.
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.site.SiteInfo;
|
||||
import org.alfresco.repo.site.SiteModel;
|
||||
import org.alfresco.repo.site.SiteService;
|
||||
import org.alfresco.repo.site.SiteServiceImpl;
|
||||
import org.alfresco.service.cmr.security.AccessPermission;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
|
||||
/**
|
||||
* Patch's the site permission model to use groups to contain users.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class SitePermissionRefactorPatch extends AbstractPatch
|
||||
{
|
||||
/** Messages */
|
||||
private static final String STATUS_MSG = "patch.sitePermissionRefactorPatch.result";
|
||||
|
||||
/** Services */
|
||||
private SiteService siteService;
|
||||
private PermissionService permissionService;
|
||||
private AuthorityService authorityService;
|
||||
|
||||
/**
|
||||
* Set site service
|
||||
*
|
||||
* @param siteService the site service
|
||||
*/
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the permission service
|
||||
*
|
||||
* @param permissionService the permission service
|
||||
*/
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* The authority service
|
||||
*
|
||||
* @param authorityService the authority service
|
||||
*/
|
||||
public void setAuthorityService(AuthorityService authorityService)
|
||||
{
|
||||
this.authorityService = authorityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
|
||||
*/
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
// Set all the sites in the repository
|
||||
List<SiteInfo> sites = this.siteService.listSites(null, null);
|
||||
for (SiteInfo siteInfo : sites)
|
||||
{
|
||||
// Create the site's groups
|
||||
String siteGroup = authorityService.createAuthority(
|
||||
AuthorityType.GROUP,
|
||||
null,
|
||||
((SiteServiceImpl)this.siteService).getSiteGroupName(siteInfo.getShortName(),
|
||||
false));
|
||||
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
|
||||
for (String permission : permissions)
|
||||
{
|
||||
// Create a group for the permission
|
||||
String permissionGroup = authorityService.createAuthority(
|
||||
AuthorityType.GROUP,
|
||||
siteGroup,
|
||||
((SiteServiceImpl)this.siteService).getSitePermissionGroupName(
|
||||
siteInfo.getShortName(),
|
||||
permission,
|
||||
false));
|
||||
|
||||
// Assign the group the relevant permission on the site
|
||||
permissionService.setPermission(siteInfo.getNodeRef(), permissionGroup, permission, true);
|
||||
}
|
||||
|
||||
// Take the current members and assign them to the appropriate groups
|
||||
Set<AccessPermission> currentPermissions = this.permissionService.getAllSetPermissions(siteInfo.getNodeRef());
|
||||
for (AccessPermission permission : currentPermissions)
|
||||
{
|
||||
// Only support user's being transfered (if public the everyone group will stay on the node)
|
||||
if (permission.getAuthorityType() == AuthorityType.USER)
|
||||
{
|
||||
// Add this authority to the appropriate group
|
||||
String group = ((SiteServiceImpl)this.siteService).getSitePermissionGroupName(
|
||||
siteInfo.getShortName(),
|
||||
permission.getPermission(),
|
||||
true);
|
||||
this.authorityService.addAuthority(group, permission.getAuthority());
|
||||
|
||||
// Remove the permission from the node
|
||||
this.permissionService.deletePermission(siteInfo.getNodeRef(), permission.getAuthority(), permission.getPermission());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Report status
|
||||
return I18NUtil.getMessage(STATUS_MSG);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user