mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-30 18:15:39 +00:00
44674: Fix for ALF-17189 - The "Company Home" item in the top navigator menu and in the toolbar panel is invisible, if login as guest first then directly access the login page via URL. 44701: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.1-BUG-FIX 44700: Fix for ALF-10369 - support for OPTIONS requests for WebScript framework and Share proxy 44709: ALF-17164 Fix version.properties which was wrong in sdk zip 44710: ALF-14570 ("Check out" outboud rule works incorrect) 44722: MNT-246: Need the ability to configure a proxy with Enterprise Sync. - RemoteConnectorServiceImpl will now use an http/https proxy if the standard system properties for Java network proxy configuration are found. See http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html (Section 2.1 and 2.2) 44730: Merged V4.1 to V4.1-BUG-FIX 44461: Merged PATCHES/V4.1.1 to V4.1 44060: ALF-16962 / MNT-221 Links from a deleted user cause error in the "Links" page 44129: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap - Now we emulate the behaviour of ACLEntryAfterInvocationProvider in SolrQueryHTTPClient, thus limiting otherwise unconstrained SOLR queries to return a finite number of results - New solr subsystem parameter solr.query.maximumResultsFromUnlimitedQuery introduced - Its default value is ${system.acl.maxPermissionChecks}, thus providing backward compatibility with old behaviour (1000 results max) - When there are no other limits in the search parameters, this value will be used to limit the number of results - SolrJSONResultSet.getResultSetMetata().getLimitedBy() will return an appropriate LimitBy value, according to how the query was limited 44130: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap - Improved calculation of SolrJSONResultSet.getResultSetMetata().getLimitedBy() to better emulate ACLEntryAfterInvocationProvider 44141: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap - Correction to handling of limited queries (Share search works again!) 44291: ALF-17094 / MNT-222 InvalidNodeRefException on user deletion in Share UI 44462: Merged PATCHES/V4.0.2 to V4.1 44221: ALF-17038 / MNT-226: Out-of-order versions for existing data during migration from 3.4.9 to 4.0.2.19 - Have been able to remove the need for any Comparators in the normal case. As Dave said, he thought it was ordered already. It is with "assoc.assoc_index ASC, assoc.id ASC". Required a bit of re factoring of Version2ServiceImpl to do it as they were referenced/used in a couple of other classes. - Modified all 43 Oracle sequences to include ORDER in the create statement. Probably only really was needed to do it on alf_child_assoc_seq to fix this issue, but it will stop similar issues in other clustered database setups. Did not change the upgrade scripts, as this will give us a clue that there will be existing data issues. - The name of a Comparator<Version> may be specified in the Alfresco global property: org.alfresco.repo.version.common.VersionLabelComparator and it will be used by BOTH Version2ServiceImpl and VersionServiceImpl. They in turn pass it on to Version2ServiceImpl instances when they create them. - A VersionLabelComparator already existed (still deprecated as we don't normally use it) and works: org.alfresco.repo.version.common.VersionLabelComparator. - Customers with out of sequence ids on Oracle RDBMS using a clustered database may 'correct on the fly' the order of their versions by setting the alfresco global property described above. - Have tested both with and without a comparator in development environment. Using break points and Collections.shuffle(version) in an expression was able to simulate out of order IDs. - New unit tests added to VersionHistoryImplTest and VersionServiceImplTest to test db ids out of order 44336: ALF-15935: Fixed SecureContext errors when ticket has expired. MNT-180 44467: Fixed compilation failure 44520: ALF-16590: Improved fix after testing by Mark Lugert 44563: Merged DEV to V4.1 (with corrections) 44547: ALF-17132: Possible XSS - arbitrary url parameters re-sent to the browser Escaping of keys and values of request attributes 44610: Merged PATCHES/V4.0.2 to V4.1 44435: ALF-17183: Merged DEV to V4.0.2 (4.0.2.22) 44429: MNT-232: Upgrade from 3.4.9 to 4.0.2 - FAILED - Initialize rootRefs in the property definition to prevent NPE. 44591: Fix to CIFS reported user free space when disk quotas are not enabled. 44595: ALF-17184 / MNT-243 Minimal fix for disk size and user quotas. (Bring values into line with API.) 44601: ALF-17184 / MNT-243 - Implementation of file size on Abstract Tennant Routing Content Store. 44608: ALF-15935 / MNT-180: Moved closeFile() call to closeConnection() cleanup method, always call closeFile() Do not check if file is marked as closed during cleanup, only open files should still be in the file table. 44652: ALF-17117: Created article or publication cant be viewed on WQS site - Fixes by Dmitry Vaserin - Removed unnecessary outer read locks from getRelatedAssets and getRelatedAsset to prevent deadlock - Correct markup error when node doesn't have tags 44653: ALF-17117: Created article or publication cant be viewed on WQS site - Missed file from previous checkin 44682: ALF-17118 WQS: Impossible to upload document to publications space - Only first part to do with the transformation failure has been committed. 44731: Merged V4.1 to V4.1-BUG-FIX (RECORD ONLY) 44441: Merge V4.1-BUG-FIX to V4.1 44270: Merge V3.4-BUG-FIX to V4.1-BUG-FIX 44266: BDE-111: harden generation of Windows installers - make sure build fails if installer generation fails - generate Windows unsigned installers in a place that is cleaned later, avoiding leftovers 44598: Merged V4.1-BUG-FIX to V4.1 44541: Fix for ALF-17151 SOLR - add support to disable permission checks 44577: Final part for ALF-16558 SOLR tracking does not do incremental updates but one single chunk - fixed code so SolrSearchers are held for as little time as possible 44607: Merged V4.1-BUG-FIX to V4.1 44603: ALF-14201: upgrade activiti to 5.7-20121211 44606: ALF-14201: upgrade activiti to 5.7-20121211 in Maven poms git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@44732 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
555 lines
16 KiB
Java
555 lines
16 KiB
Java
/*
|
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
|
*
|
|
* This file is part of Alfresco
|
|
*
|
|
* Alfresco is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Alfresco 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 Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package org.alfresco.filesys.repo;
|
|
|
|
import java.io.IOException;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
import org.alfresco.jlan.server.SrvSession;
|
|
import org.alfresco.jlan.server.filesys.DiskDeviceContext;
|
|
import org.alfresco.jlan.server.filesys.DiskFullException;
|
|
import org.alfresco.jlan.server.filesys.DiskInterface;
|
|
import org.alfresco.jlan.server.filesys.NetworkFile;
|
|
import org.alfresco.jlan.server.filesys.TreeConnection;
|
|
import org.alfresco.jlan.server.filesys.quota.QuotaManager;
|
|
import org.alfresco.jlan.server.filesys.quota.QuotaManagerException;
|
|
import org.alfresco.jlan.util.MemorySize;
|
|
import org.alfresco.jlan.util.StringList;
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
import org.alfresco.service.cmr.repository.ContentService;
|
|
import org.alfresco.service.cmr.usage.ContentUsageService;
|
|
import org.alfresco.util.PropertyCheck;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* Content Quota Manager Class
|
|
*
|
|
* <p>Implementation of JLAN QuotaManager interface for the Alfresco repository.
|
|
* <p>Keeps an in memory quota for each active user. After a configurable length of
|
|
* time quotas are removed from memory.
|
|
*
|
|
* @author gkspencer
|
|
*
|
|
*/
|
|
public class ContentQuotaManager implements QuotaManager, Runnable {
|
|
|
|
// Debug logging
|
|
|
|
private static final Log logger = LogFactory.getLog(ContentQuotaManager.class);
|
|
|
|
// User details idle check interval
|
|
|
|
private static final long UserQuotaCheckInterval = 1 * 60 * 1000; // 1 minute
|
|
private static final long UserQuotaExpireInterval = 5 * 60 * 1000; // 5 minutes
|
|
|
|
// Associated filesystem driver
|
|
|
|
private DiskInterface m_filesys;
|
|
|
|
// Content usage service
|
|
|
|
private ContentUsageService m_usageService;
|
|
|
|
private ContentService contentService;
|
|
|
|
// Track live usage of users that are writing files
|
|
|
|
private Map<String, UserQuotaDetails> m_liveUsage;
|
|
private Object m_liveUsageLock = new Object();
|
|
|
|
// User details inactivity checker thread
|
|
|
|
private Thread m_thread;
|
|
private boolean m_shutdown;
|
|
|
|
public void init()
|
|
{
|
|
PropertyCheck.mandatory(this, "contentService", getContentService());
|
|
PropertyCheck.mandatory(this, "contentUsageService", m_usageService);
|
|
}
|
|
|
|
/**
|
|
* Get the usage service
|
|
*
|
|
* @return ContentUsageService
|
|
*/
|
|
public final ContentUsageService getUsageService() {
|
|
return m_usageService;
|
|
}
|
|
|
|
/**
|
|
* Set the usage service
|
|
*
|
|
* @param usageService ContentUsageService
|
|
*/
|
|
public final void setUsageService(ContentUsageService usageService) {
|
|
m_usageService = usageService;
|
|
}
|
|
|
|
/**
|
|
* Return the free space available in bytes
|
|
*
|
|
* @return long
|
|
*/
|
|
public long getAvailableFreeSpace() {
|
|
|
|
// Get the live free space value from the content store, if supported
|
|
|
|
long freeSpace = contentService.getStoreFreeSpace();
|
|
if ( freeSpace == -1L) {
|
|
|
|
// Content store does not support sizing, return a large dummy value
|
|
|
|
freeSpace = ContentDiskDriver.DiskFreeDefault;
|
|
}
|
|
|
|
return freeSpace;
|
|
}
|
|
|
|
/**
|
|
* Return the free space available to the specified user/session
|
|
*
|
|
* @param sess SrvSession
|
|
* @param tree TreeConnection
|
|
* @return long
|
|
*/
|
|
public long getUserFreeSpace(SrvSession sess, TreeConnection tree) {
|
|
|
|
// Check if content usage is enabled
|
|
|
|
if ( m_usageService.getEnabled() == false)
|
|
return -1L;
|
|
|
|
// Check if there is a live usage record for the user
|
|
|
|
UserQuotaDetails userQuota = getQuotaDetails(sess, true);
|
|
if ( userQuota != null) {
|
|
synchronized (userQuota) {
|
|
return userQuota.getAvailableSpace();
|
|
}
|
|
}
|
|
|
|
// No quota details available
|
|
|
|
return -1L;
|
|
}
|
|
|
|
/**
|
|
* Allocate space on the filesystem.
|
|
*
|
|
* @param sess SrvSession
|
|
* @param tree TreeConnection
|
|
* @param file NetworkFile
|
|
* @param alloc long requested allocation size
|
|
* @return long granted allocation size
|
|
* @exception IOException
|
|
*/
|
|
public long allocateSpace(SrvSession sess, TreeConnection tree, NetworkFile file, long alloc)
|
|
throws IOException {
|
|
|
|
// Check if content usage is enabled
|
|
|
|
if ( m_usageService.getEnabled() == false)
|
|
return alloc;
|
|
|
|
// Check if there is a live usage record for the user
|
|
|
|
UserQuotaDetails userQuota = getQuotaDetails(sess, true);
|
|
long allowedAlloc = 0L;
|
|
|
|
if ( userQuota != null) {
|
|
|
|
// Check if the user has a usage quota
|
|
|
|
synchronized ( userQuota) {
|
|
|
|
if ( userQuota.hasUserQuota()) {
|
|
|
|
// Check if the user has enough free space allocation
|
|
|
|
if ( alloc > 0 && userQuota.getAvailableSpace() >= alloc) {
|
|
userQuota.addToCurrentUsage( alloc);
|
|
allowedAlloc = alloc;
|
|
}
|
|
}
|
|
else {
|
|
|
|
// Update the live usage
|
|
userQuota.addToCurrentUsage( alloc);
|
|
allowedAlloc = alloc;
|
|
}
|
|
}
|
|
}
|
|
else if ( logger.isDebugEnabled())
|
|
logger.debug("Failed to allocate " + alloc + " bytes for sess " + sess.getUniqueId());
|
|
|
|
// Check if the allocation was allowed
|
|
|
|
if ( allowedAlloc < alloc) {
|
|
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled())
|
|
logger.debug("Allocation failed userQuota=" + userQuota);
|
|
|
|
throw new DiskFullException();
|
|
}
|
|
else if ( logger.isDebugEnabled())
|
|
logger.debug("Allocated " + alloc + " bytes, userQuota=" + userQuota);
|
|
|
|
// Return the allocation size
|
|
|
|
return allowedAlloc;
|
|
}
|
|
|
|
/**
|
|
* Release space to the free space for the filesystem.
|
|
*
|
|
* @param sess SrvSession
|
|
* @param tree TreeConnection
|
|
* @param fid int
|
|
* @param path String
|
|
* @param alloc long
|
|
* @exception IOException
|
|
*/
|
|
public void releaseSpace(SrvSession sess, TreeConnection tree, int fid, String path, long alloc)
|
|
throws IOException {
|
|
|
|
// Check if content usage is enabled
|
|
|
|
if ( m_usageService.getEnabled() == false)
|
|
return;
|
|
|
|
// Check if there is a live usage record for the user
|
|
|
|
UserQuotaDetails userQuota = getQuotaDetails(sess, true);
|
|
|
|
if ( userQuota != null) {
|
|
|
|
synchronized ( userQuota) {
|
|
|
|
// Release the space from the live usage value
|
|
|
|
userQuota.subtractFromCurrentUsage( alloc);
|
|
}
|
|
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled())
|
|
logger.debug("Released " + alloc + " bytes, userQuota=" + userQuota);
|
|
}
|
|
else if ( logger.isDebugEnabled())
|
|
logger.debug("Failed to release " + alloc + " bytes for sess " + sess.getUniqueId());
|
|
}
|
|
|
|
/**
|
|
* Start the quota manager.
|
|
*
|
|
* @param disk DiskInterface
|
|
* @param ctx DiskDeviceContext
|
|
* @exception QuotaManagerException
|
|
*/
|
|
public void startManager(DiskInterface disk, DiskDeviceContext ctx)
|
|
throws QuotaManagerException
|
|
{
|
|
|
|
if(logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Start Quota Manager");
|
|
}
|
|
|
|
// Save the filesystem driver details
|
|
m_filesys = disk;
|
|
|
|
// Allocate the live usage table
|
|
|
|
m_liveUsage = new HashMap<String, UserQuotaDetails>();
|
|
|
|
// Create the inactivity checker thread
|
|
m_thread = new Thread(this);
|
|
m_thread.setDaemon(true);
|
|
m_thread.setName("ContentQuotaManagerChecker");
|
|
m_thread.start();
|
|
}
|
|
|
|
/**
|
|
* Stop the quota manager
|
|
*
|
|
* @param disk DiskInterface
|
|
* @param ctx DiskDeviceContext
|
|
* @exception QuotaManagerException
|
|
*/
|
|
public void stopManager(DiskInterface disk, DiskDeviceContext ctx)
|
|
throws QuotaManagerException
|
|
{
|
|
|
|
if(logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Stop Quota Manager");
|
|
}
|
|
|
|
// Clear out the live usage details
|
|
synchronized (m_liveUsageLock)
|
|
{
|
|
m_liveUsage.clear();
|
|
m_shutdown = true;
|
|
}
|
|
|
|
// Shutdown the checker thread
|
|
|
|
m_thread.interrupt();
|
|
}
|
|
|
|
/**
|
|
* Get the usage details for the session/user
|
|
*
|
|
* @param sess SrvSession
|
|
* @param loadDetails boolean
|
|
* @return UserQuotaDetails or null
|
|
*/
|
|
private UserQuotaDetails getQuotaDetails(SrvSession sess, boolean loadDetails) {
|
|
|
|
synchronized (m_liveUsageLock) {
|
|
|
|
UserQuotaDetails userQuota = null;
|
|
|
|
String userName = AuthenticationUtil.getFullyAuthenticatedUser();
|
|
|
|
if ( sess != null && userName != null)
|
|
{
|
|
// Get the live usage values
|
|
userQuota = m_liveUsage.get(userName);
|
|
|
|
if ( userQuota == null && loadDetails == true)
|
|
{
|
|
// User is not in the live tracking table, load details for the user
|
|
|
|
try
|
|
{
|
|
logger.debug("user is not in cache - load details");
|
|
userQuota = loadUsageDetails(userName);
|
|
}
|
|
catch ( QuotaManagerException ex)
|
|
{
|
|
if ( logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Unable to load usage details", ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Return the user quota details
|
|
|
|
return userQuota;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Load the user quota details
|
|
*
|
|
* @param user - name of the user.
|
|
* @return UserQuotaDetails
|
|
* @throws QuotaManagerException
|
|
*/
|
|
private UserQuotaDetails loadUsageDetails(String userName)
|
|
throws QuotaManagerException {
|
|
|
|
// Check if the user name is available
|
|
|
|
UserQuotaDetails quotaDetails = null;
|
|
|
|
try
|
|
{
|
|
if ( userName == null || userName.length() == 0)
|
|
{
|
|
logger.debug("user name is null or empty - throw QuotaManagerException");
|
|
throw new QuotaManagerException("No user name for client");
|
|
}
|
|
|
|
// Get the usage quota and current usage values for the user
|
|
|
|
long userQuota = m_usageService.getUserQuota( userName);
|
|
long userUsage = m_usageService.getUserUsage( userName);
|
|
|
|
// Create the user quota details for live tracking
|
|
|
|
quotaDetails = new UserQuotaDetails( userName, userQuota);
|
|
if ( userUsage > 0L)
|
|
{
|
|
quotaDetails.setCurrentUsage( userUsage);
|
|
}
|
|
|
|
// Add the details to the live tracking table
|
|
|
|
// Check if another thread has added the details
|
|
|
|
UserQuotaDetails details = m_liveUsage.get( userName);
|
|
if ( details != null)
|
|
{
|
|
quotaDetails = details;
|
|
}
|
|
else
|
|
{
|
|
m_liveUsage.put( userName, quotaDetails);
|
|
}
|
|
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled())
|
|
{
|
|
logger.debug( "Added live usage tracking " + quotaDetails);
|
|
}
|
|
}
|
|
catch ( Exception ex)
|
|
{
|
|
|
|
// Log the error
|
|
|
|
if ( logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Failed to load usage for" + userName, ex);
|
|
}
|
|
// Failed to load usage details
|
|
|
|
throw new QuotaManagerException("Failed to load usage for " + userName + ", " + ex);
|
|
}
|
|
|
|
// Return the user usage details
|
|
|
|
return quotaDetails;
|
|
}
|
|
|
|
/**
|
|
* Inactivity checker, run in a seperate thread
|
|
*/
|
|
public void run() {
|
|
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled())
|
|
logger.debug("Content quota manager checker thread starting");
|
|
|
|
// Loop forever
|
|
|
|
StringList removeNameList = new StringList();
|
|
|
|
m_shutdown = false;
|
|
|
|
while ( m_shutdown == false)
|
|
{
|
|
|
|
// Sleep for the required interval
|
|
|
|
try
|
|
{
|
|
Thread.sleep( UserQuotaCheckInterval);
|
|
}
|
|
catch (InterruptedException ex)
|
|
{
|
|
}
|
|
|
|
// Check for shutdown
|
|
|
|
if ( m_shutdown == true)
|
|
{
|
|
// Debug
|
|
|
|
if ( logger.isDebugEnabled())
|
|
logger.debug("Content quota manager checker thread closing");
|
|
|
|
return;
|
|
}
|
|
|
|
// Check if there are any user quota details to check
|
|
synchronized (m_liveUsageLock)
|
|
{
|
|
if ( m_liveUsage != null && m_liveUsage.size() > 0)
|
|
{
|
|
try
|
|
{
|
|
// Timestamp to check if the quota details is inactive
|
|
|
|
long checkTime = System.currentTimeMillis() - UserQuotaExpireInterval;
|
|
|
|
// Loop through the user quota details
|
|
|
|
removeNameList.remoteAllStrings();
|
|
Iterator<String> userNames = m_liveUsage.keySet().iterator();
|
|
|
|
while ( userNames.hasNext()) {
|
|
|
|
// Get the user quota details and check if it has been inactive in the last check interval
|
|
|
|
String userName = userNames.next();
|
|
UserQuotaDetails quotaDetails = m_liveUsage.get( userName);
|
|
|
|
synchronized (quotaDetails) {
|
|
if ( quotaDetails.getLastUpdated() < checkTime) {
|
|
|
|
// Add the user name to the remove list, inactive
|
|
|
|
removeNameList.addString( userName);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Remove inactive records from the live quota tracking
|
|
|
|
while ( removeNameList.numberOfStrings() > 0)
|
|
{
|
|
|
|
// Get the current user name and remove the record
|
|
|
|
String userName = removeNameList.removeStringAt( 0);
|
|
UserQuotaDetails quotaDetails = m_liveUsage.remove( userName);
|
|
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled())
|
|
logger.debug("Removed inactive usage tracking, " + quotaDetails);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Log errors if not shutting down
|
|
|
|
if ( m_shutdown == false)
|
|
logger.debug(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void setContentService(ContentService contentService)
|
|
{
|
|
this.contentService = contentService;
|
|
}
|
|
|
|
public ContentService getContentService()
|
|
{
|
|
return contentService;
|
|
}
|
|
}
|