theTenant = JcrTenantUtils.getCurrentTenant();
}
if ( theTenant == null || theTenant.getId() == null ) {
theTenant = JcrTenantUtils.getDefaultTenant();
}
RepositoryFile userHomeFolder = null;
String userId = tenantedUserNameUtils.getPrincipleId( theTenant, username );
final RepositoryFileSid userSid = new RepositoryFileSid( userId );
RepositoryFile tenantHomeFolder = null;
RepositoryFile tenantRootFolder = null;
RepositoryFileSid ownerSid = null;
// Get the Tenant Root folder. If the Tenant Root folder does not exist then exit.
tenantRootFolder =
JcrRepositoryFileUtils.getFileByAbsolutePath( session, ServerRepositoryPaths
.getTenantRootFolderPath( theTenant ), pathConversionHelper, lockHelper, false, null );
if ( tenantRootFolder != null ) {
// Try to see if Tenant Home folder exist
tenantHomeFolder =
JcrRepositoryFileUtils.getFileByAbsolutePath( session, ServerRepositoryPaths
.getTenantHomeFolderPath( theTenant ), pathConversionHelper, lockHelper, false, null );
if ( tenantHomeFolder == null ) {
String ownerId = tenantedUserNameUtils.getPrincipleId( theTenant, username );
ownerSid = new RepositoryFileSid( ownerId, Type.USER );
String tenantAuthenticatedRoleId = tenantedRoleNameUtils.getPrincipleId( theTenant, authenticatedRoleName );
RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid( tenantAuthenticatedRoleId, Type.ROLE );
aclsForTenantHomeFolder =
new RepositoryFileAcl.Builder( userSid ).ace( tenantAuthenticatedRoleSid, EnumSet
.of( RepositoryFilePermission.READ ) );
aclsForUserHomeFolder =
new RepositoryFileAcl.Builder( userSid ).ace( ownerSid, EnumSet.of( RepositoryFilePermission.ALL ) );
tenantHomeFolder =
internalCreateFolder( session, tenantRootFolder.getId(), new RepositoryFile.Builder( ServerRepositoryPaths
.getTenantHomeFolderName() ).folder( true ).title(
Messages.getInstance().getString( "AbstractJcrBackedUserRoleDao.usersFolderDisplayName" ) ).build(),
aclsForTenantHomeFolder.build(), "tenant home folder" ); //$NON-NLS-1$
} else {
String ownerId = tenantedUserNameUtils.getPrincipleId( theTenant, username );