mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)
74350: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (5.0/Cloud) 74257: MNT-11659 : Merged PATCHES/V4.2.2 (4.2.2.3) to V4.2-BUG-FIX (4.2.3) 73876: Merged DEV to PATCHES/V4.2.2 (4.2.2.3) 73489 : MNT-9038 : Names of groups are wrong after upgrade. - Renaming of authorities display names git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74900 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -525,3 +525,6 @@ patch.surfConfigFolderPatch.result=Successfully applied ''cm:indexControl'' aspe
|
||||
patch.genericBootstrap.result.deferred=The patch has been deferred
|
||||
|
||||
patch.asynchrounse.checking=Checking for the asynchronous patch ...
|
||||
|
||||
patch.renameSiteAuthorityDisplayName.description=Update authority display name for sites
|
||||
patch.renameSiteAuthorityDisplayName.result=Updating of display names was completed
|
@@ -3767,4 +3767,36 @@
|
||||
<!-- Do we deferr running the surf-config folder patch? -->
|
||||
<property name="deferred"><value>${system.patch.surfConfigFolder.deferred}</value></property>
|
||||
</bean>
|
||||
<bean id="patch.renameSiteAuthorityDisplayName"
|
||||
class="org.alfresco.repo.admin.patch.impl.RenameSiteAuthorityDisplayName"
|
||||
parent="basePatch">
|
||||
<property name="id">
|
||||
<value>patch.renameSiteAuthorityDisplayName</value>
|
||||
</property>
|
||||
<property name="description">
|
||||
<value>patch.renameSiteAuthorityDisplayName.description</value>
|
||||
</property>
|
||||
<property name="fixesFromSchema">
|
||||
<value>0</value>
|
||||
</property>
|
||||
<property name="fixesToSchema">
|
||||
<value>8000</value>
|
||||
</property>
|
||||
<property name="targetSchema">
|
||||
<value>8001</value>
|
||||
</property>
|
||||
<property name="siteService">
|
||||
<ref bean="siteService" />
|
||||
</property>
|
||||
<property name="permissionService">
|
||||
<ref bean="PermissionService" />
|
||||
</property>
|
||||
<property name="authorityService">
|
||||
<ref bean="AuthorityService" />
|
||||
</property>
|
||||
<property name="ruleService">
|
||||
<ref bean="ruleService" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -23,4 +23,4 @@ version.build=r@scm-revision@-b@build-number@
|
||||
|
||||
# Schema number
|
||||
|
||||
version.schema=8000
|
||||
version.schema=8001
|
||||
|
@@ -0,0 +1,204 @@
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.admin.patch.PatchExecuter;
|
||||
import org.alfresco.repo.batch.BatchProcessWorkProvider;
|
||||
import org.alfresco.repo.batch.BatchProcessor;
|
||||
import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.site.SiteServiceImpl;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
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;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
public class RenameSiteAuthorityDisplayName extends AbstractPatch
|
||||
{
|
||||
/** The title we give to the batch process in progress messages / JMX. */
|
||||
private static final String SUCCESS_MSG = "patch.renameSiteAuthorityDisplayName.result";
|
||||
private static final int BATCH_THREADS = 4;
|
||||
private static final int BATCH_SIZE = 250;
|
||||
|
||||
/** Services */
|
||||
private SiteService siteService;
|
||||
private PermissionService permissionService;
|
||||
private AuthorityService authorityService;
|
||||
private RuleService ruleService;
|
||||
|
||||
/** The progress_logger. */
|
||||
private static Log progress_logger = LogFactory.getLog(PatchExecuter.class);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rule service.
|
||||
*
|
||||
* @param ruleService
|
||||
* the rule service
|
||||
*/
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
// NOTE: SiteService is not currently MT-enabled (eg. getSiteRoot) so skip if applied to tenant
|
||||
if (AuthenticationUtil.isRunAsUserTheSystemUser() || !AuthenticationUtil.isMtEnabled())
|
||||
{
|
||||
// Set all the sites in the repository
|
||||
List<SiteInfo> sites = this.siteService.listSites(null, null);
|
||||
renameDispayNames(sites);
|
||||
}
|
||||
// Report status
|
||||
return I18NUtil.getMessage(SUCCESS_MSG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Rename display names of authorities of sites.
|
||||
*
|
||||
* @param siteInfos
|
||||
* list of sites
|
||||
*/
|
||||
private void renameDispayNames(final List<SiteInfo> siteInfos)
|
||||
{
|
||||
final String tenantDomain = tenantAdminService.getCurrentUserDomain();
|
||||
|
||||
final Iterator<SiteInfo> pathItr = siteInfos.listIterator();
|
||||
|
||||
BatchProcessWorkProvider<SiteInfo> siteWorkProvider = new BatchProcessWorkProvider<SiteInfo>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int getTotalEstimatedWorkSize()
|
||||
{
|
||||
return siteInfos.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SiteInfo> getNextWork()
|
||||
{
|
||||
int batchCount = 0;
|
||||
|
||||
List<SiteInfo> nodes = new ArrayList<SiteInfo>(BATCH_SIZE);
|
||||
while (pathItr.hasNext() && batchCount++ != BATCH_SIZE)
|
||||
{
|
||||
nodes.add(pathItr.next());
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// prepare the batch processor and worker object
|
||||
BatchProcessor<SiteInfo> siteBatchProcessor = new BatchProcessor<SiteInfo>(
|
||||
"RenameSiteAuthorityDisplayName",
|
||||
this.transactionHelper,
|
||||
siteWorkProvider,
|
||||
BATCH_THREADS,
|
||||
BATCH_SIZE,
|
||||
this.applicationEventPublisher,
|
||||
progress_logger,
|
||||
BATCH_SIZE * 10);
|
||||
|
||||
BatchProcessWorker<SiteInfo> worker = new BatchProcessWorker<SiteInfo>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getIdentifier(SiteInfo entry)
|
||||
{
|
||||
return entry.getShortName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess() throws Throwable
|
||||
{
|
||||
// Disable rules
|
||||
ruleService.disableRules();
|
||||
// Authentication
|
||||
String systemUser = AuthenticationUtil.getSystemUserName();
|
||||
systemUser = tenantAdminService.getDomainUser(systemUser, tenantDomain);
|
||||
AuthenticationUtil.setRunAsUser(systemUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess() throws Throwable
|
||||
{
|
||||
// Enable rules
|
||||
ruleService.enableRules();
|
||||
// Clear authentication
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(SiteInfo siteInfo) throws Throwable
|
||||
{
|
||||
// Set all the permissions of site
|
||||
Set<AccessPermission> sitePermissions = permissionService.getAllSetPermissions(siteInfo.getNodeRef());
|
||||
for (AccessPermission sitePermission : sitePermissions)
|
||||
{
|
||||
// Use only GROUP authority
|
||||
if (sitePermission.getAuthorityType() == AuthorityType.GROUP)
|
||||
{
|
||||
String authorityName = sitePermission.getAuthority();
|
||||
String currDisplayName = authorityService.getAuthorityDisplayName(authorityName);
|
||||
String necessaryName = ((SiteServiceImpl) siteService).getSiteRoleGroup(siteInfo.getShortName(), sitePermission.getPermission(), false);
|
||||
String alternativeName = ((SiteServiceImpl) siteService).getSiteRoleGroup(siteInfo.getShortName(), sitePermission.getPermission(), true);
|
||||
// check for correct displayName
|
||||
if ((!necessaryName.equalsIgnoreCase(currDisplayName)) || (!alternativeName.equalsIgnoreCase(currDisplayName)))
|
||||
{
|
||||
// fix incorrect display name
|
||||
authorityService.setAuthorityDisplayName(authorityName, necessaryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
siteBatchProcessor.process(worker, true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user