From cc6116e682aa638cc98bf46e3dc23c61db7165a3 Mon Sep 17 00:00:00 2001 From: Dave Ward Date: Mon, 23 Mar 2009 15:58:56 +0000 Subject: [PATCH] Enable cold bootstrap without waking up authentication component. Made ImporterComponent use AuthenticationContext rather than AuthenticationService. Was then able to roll back temporary fix to AuthenticationFilter (from 13673). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13727 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/import-export-context.xml | 8 ++++---- .../repo/importer/ImporterComponent.java | 19 +++++++++++-------- .../AbstractAuthenticationComponent.java | 10 ++++++++++ .../authentication/AuthenticationContext.java | 7 +++++++ .../AuthenticationContextImpl.java | 5 +++++ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/config/alfresco/import-export-context.xml b/config/alfresco/import-export-context.xml index cb3aeae6d8..666cdb7638 100644 --- a/config/alfresco/import-export-context.xml +++ b/config/alfresco/import-export-context.xml @@ -40,8 +40,8 @@ - - + + @@ -81,8 +81,8 @@ - - + + diff --git a/source/java/org/alfresco/repo/importer/ImporterComponent.java b/source/java/org/alfresco/repo/importer/ImporterComponent.java index fde27cacf3..684be617e7 100644 --- a/source/java/org/alfresco/repo/importer/ImporterComponent.java +++ b/source/java/org/alfresco/repo/importer/ImporterComponent.java @@ -40,6 +40,7 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.importer.view.NodeContext; import org.alfresco.repo.policy.BehaviourFilter; +import org.alfresco.repo.security.authentication.AuthenticationContext; import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition; import org.alfresco.service.cmr.dictionary.ClassDefinition; @@ -59,7 +60,6 @@ import org.alfresco.service.cmr.rule.RuleService; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.service.cmr.security.PermissionService; @@ -107,7 +107,7 @@ public class ImporterComponent private RuleService ruleService; private PermissionService permissionService; private AuthorityService authorityService; - private AuthenticationService authenticationService; + private AuthenticationContext authenticationContext; private OwnableService ownableService; // binding markers @@ -198,11 +198,11 @@ public class ImporterComponent } /** - * @param authenticationService authenticationService + * @param authenticationContext authenticationContext */ - public void setAuthenticationService(AuthenticationService authenticationService) + public void setAuthenticationContext(AuthenticationContext authenticationContext) { - this.authenticationService = authenticationService; + this.authenticationContext = authenticationContext; } /** @@ -536,6 +536,7 @@ public class ImporterComponent /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#importNode(org.alfresco.repo.importer.ImportNode) */ + @SuppressWarnings("unchecked") public NodeRef importNode(ImportNode context) { // import node @@ -714,6 +715,7 @@ public class ImporterComponent /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#end() */ + @SuppressWarnings("unchecked") public void end() { // Bind all node references to destination space @@ -917,6 +919,7 @@ public class ImporterComponent * @param properties * @return */ + @SuppressWarnings("unchecked") private Map bindProperties(ImportNode context) { Map properties = context.getProperties(); @@ -1261,7 +1264,7 @@ public class ImporterComponent NodeRef nodeRef = assocRef.getChildRef(); // Note: non-admin authorities take ownership of new nodes - if (!(authorityService.hasAdminAuthority() || authenticationService.isCurrentUserTheSystemUser())) + if (!(authenticationContext.isCurrentUserTheSystemUser() || authorityService.hasAdminAuthority())) { ownableService.takeOwnership(nodeRef); } @@ -1269,7 +1272,7 @@ public class ImporterComponent // apply permissions List permissions = null; AccessStatus writePermission = permissionService.hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS); - if (authenticationService.isCurrentUserTheSystemUser() || writePermission.equals(AccessStatus.ALLOWED)) + if (authenticationContext.isCurrentUserTheSystemUser() || writePermission.equals(AccessStatus.ALLOWED)) { permissions = bindPermissions(node.getAccessControlEntries()); @@ -1449,7 +1452,7 @@ public class ImporterComponent // Apply permissions List permissions = null; AccessStatus writePermission = permissionService.hasPermission(existingNodeRef, PermissionService.CHANGE_PERMISSIONS); - if (authenticationService.isCurrentUserTheSystemUser() || writePermission.equals(AccessStatus.ALLOWED)) + if (authenticationContext.isCurrentUserTheSystemUser() || writePermission.equals(AccessStatus.ALLOWED)) { boolean inheritPermissions = node.getInheritPermissions(); if (!inheritPermissions) diff --git a/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java b/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java index 1cf8442d1b..7eea3be6ed 100644 --- a/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java +++ b/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java @@ -320,6 +320,16 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC return authenticationContext.isSystemUserName(userName); } + /** + * Is the current user the system user? + * + * @return boolean + */ + public boolean isCurrentUserTheSystemUser() + { + return authenticationContext.isCurrentUserTheSystemUser(); + } + /** * Get the name of the Guest User note: for MT, will get guest for default domain only * diff --git a/source/java/org/alfresco/repo/security/authentication/AuthenticationContext.java b/source/java/org/alfresco/repo/security/authentication/AuthenticationContext.java index db302990e8..810ffe6f15 100644 --- a/source/java/org/alfresco/repo/security/authentication/AuthenticationContext.java +++ b/source/java/org/alfresco/repo/security/authentication/AuthenticationContext.java @@ -24,6 +24,8 @@ */ package org.alfresco.repo.security.authentication; +import org.alfresco.service.Auditable; + import net.sf.acegisecurity.Authentication; import net.sf.acegisecurity.UserDetails; @@ -87,6 +89,11 @@ public interface AuthenticationContext * True if this is the System user ? */ public boolean isSystemUserName(String userName); + + /** + * Is the current user the system user? + */ + public boolean isCurrentUserTheSystemUser(); /** * Get the name of the Guest User. Note: for MT, will get guest for default domain only diff --git a/source/java/org/alfresco/repo/security/authentication/AuthenticationContextImpl.java b/source/java/org/alfresco/repo/security/authentication/AuthenticationContextImpl.java index d45cd9d192..ff08c27c0c 100644 --- a/source/java/org/alfresco/repo/security/authentication/AuthenticationContextImpl.java +++ b/source/java/org/alfresco/repo/security/authentication/AuthenticationContextImpl.java @@ -102,6 +102,11 @@ public class AuthenticationContextImpl implements AuthenticationContext return getSystemUserName().equals(this.tenantService.getBaseNameUser(userName)); } + public boolean isCurrentUserTheSystemUser() + { + return isSystemUserName(getCurrentUserName()); + } + public String getGuestUserName(String tenantDomain) { return this.tenantService.getDomainUser(getGuestUserName(), tenantDomain);