Fix failing unit test. Person cache case sensitivity issues due to fix for ETWOTWO-389.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@17140 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Dave Ward
2009-10-23 16:07:57 +00:00
parent f1999bb3d3
commit 104d6258a5
7 changed files with 84 additions and 410 deletions

View File

@@ -243,31 +243,6 @@
</property>
</bean>
-->
<bean id="personDaoImpl" class="org.alfresco.repo.security.person.PersonDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="localeDAO">
<ref bean="localeDAO" />
</property>
<property name="qnameDAO">
<ref bean="qnameDAO" />
</property>
<property name="contentDataDAO">
<ref bean="contentDataDAO" />
</property>
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>
<property name="tenantService">
<ref bean="tenantService"/>
</property>
<!-- The store in which people are persisted. -->
<property name="storeUrl">
<value>${spaces.store}</value>
</property>
</bean>
<!-- support to match user names -->
@@ -319,9 +294,6 @@
<property name="personCache">
<ref bean="personCache" />
</property>
<property name="personDao">
<ref bean="personDaoImpl" />
</property>
<property name="permissionsManager">
<ref bean="personServicePermissionsManager" />
</property>

View File

@@ -289,12 +289,6 @@
<property name="tenantAdminService" ref="tenantAdminService" />
</bean>
<bean id="personDaoBootstrap" class="org.alfresco.repo.security.person.PersonDaoBootstrap" >
<property name="personDaoImpl">
<ref bean="personDaoImpl"/>
</property>
</bean>
<!-- Bootstrap any extensions -->
<import resource="classpath*:alfresco/extension/bootstrap/*-context.xml" />

View File

@@ -400,42 +400,6 @@
]]>
</query>
<!-- Lowercase: ETHREEOH-1431 and ETWOTWO-1012 -->
<sql-query name="person.getPersonIgnoreCase">
<return alias="n" class="org.alfresco.repo.domain.hibernate.NodeImpl"/>
SELECT
{n.*}
FROM
alf_node n
JOIN alf_node_properties p ON n.id = p.node_id
JOIN alf_child_assoc c on c.child_node_id = n.id
JOIN alf_store s on s.id = n.store_id
WHERE
c.qname_localname = :userNameLowerCase AND
c.type_qname_id = :assocTypeQNameID AND
p.qname_id = :qnamePropId AND
n.type_qname_id = :qnameTypeId AND
n.node_deleted = :False AND
s.protocol = :storeProtocol AND
s.identifier = :storeIdentifier
</sql-query>
<sql-query name="person.getAllPeople">
<return alias="n" class="org.alfresco.repo.domain.hibernate.NodeImpl"/>
SELECT
{n.*}
FROM
alf_node n
JOIN alf_node_properties p ON n.id = p.node_id
JOIN alf_store s on s.id = n.store_id
WHERE
p.qname_id = :qnamePropId AND
n.type_qname_id = :qnameTypeId AND
n.node_deleted = :False AND
s.protocol = :storeProtocol AND
s.identifier = :storeIdentifier
</sql-query>
<!--
<query name="permission.GetAccessControlEntriesForAuthority">

View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) 2005-2007 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.security.person;
import java.util.List;
import java.util.Set;
import org.alfresco.service.cmr.repository.NodeRef;
public interface PersonDao
{
public List<NodeRef> getPersonOrNull(final String searchUserName, UserNameMatcher matcher);
public Set<NodeRef> getAllPeople();
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright (C) 2005-2007 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.security.person;
import org.alfresco.util.AbstractLifecycleBean;
import org.springframework.context.ApplicationEvent;
public class PersonDaoBootstrap extends AbstractLifecycleBean
{
private PersonDaoImpl personDaoImpl;
public void setPersonDaoImpl(PersonDaoImpl personDaoImpl)
{
this.personDaoImpl = personDaoImpl;
}
@Override
protected void onBootstrap(ApplicationEvent event)
{
personDaoImpl.init();
}
@Override
protected void onShutdown(ApplicationEvent event)
{
// nothing to do
}
}

View File

@@ -1,204 +0,0 @@
/*
* Copyright (C) 2005-2007 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.security.person;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.LocaleDAO;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodePropertyValue;
import org.alfresco.repo.domain.PropertyMapKey;
import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.repo.domain.contentdata.ContentDataDAO;
import org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class PersonDaoImpl extends HibernateDaoSupport implements PersonDao
{
private static final String QUERY_PERSON_GET_PERSON_IGNORE_CASE = "person.getPersonIgnoreCase";
private static final String QUERY_PERSON_GET_ALL_PEOPLE = "person.getAllPeople";
private QNameDAO qnameDAO;
private Long assocTypeQNameID;
private Long qNamePropId;
private Long qNameTypeId;
private LocaleDAO localeDAO;
private ContentDataDAO contentDataDAO;
private DictionaryService dictionaryService;
private StoreRef storeRef;
private TenantService tenantService;
public void setStoreUrl(String storeUrl)
{
this.storeRef = new StoreRef(storeUrl);
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void init()
{
assocTypeQNameID = qnameDAO.getOrCreateQName(ContentModel.ASSOC_CHILDREN).getFirst();
qNamePropId = qnameDAO.getOrCreateQName(ContentModel.PROP_USERNAME).getFirst();
qNameTypeId = qnameDAO.getOrCreateQName(ContentModel.TYPE_PERSON).getFirst();
}
@SuppressWarnings("unchecked")
public List<NodeRef> getPersonOrNull(final String searchUserName, UserNameMatcher matcher)
{
/*
* Related JIRA:
* https://issues.alfresco.com/jira/browse/MOB-387
* https://issues.alfresco.com/jira/browse/ETHREEOH-1431
* https://issues.alfresco.com/jira/browse/ETWOTWO-1012
*
* When usernames are case-insensitive, it could happen that the DB is NOT.
* DB queries should therefore return values regardless of the DB collation.
* The original, case-preserving username is stored with the node properties.
* To solve the query issue, a LOWERCASE version of the username is stored on
* the path (alf_child_assoc.qname_localname). This is queried for using the
* lowercase version of the searched-for username. The case results pruning
* is done (as it always was) as a post-search task.
*
* Note that the upgrade scripts had to change to force lowercase names as well.
*/
final StoreRef personStoreRef = tenantService.getName(storeRef);
List<NodeRef> answer = new ArrayList<NodeRef>();
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
SQLQuery query = (SQLQuery) session.getNamedQuery(QUERY_PERSON_GET_PERSON_IGNORE_CASE);
query.setParameter("assocTypeQNameID", assocTypeQNameID);
query.setParameter("qnamePropId", qNamePropId);
query.setParameter("qnameTypeId", qNameTypeId);
query.setParameter("userNameLowerCase", searchUserName.toLowerCase()); // Lowercase: ETHREEOH-1431
query.setParameter("False", Boolean.FALSE);
query.setParameter("storeProtocol", personStoreRef.getProtocol());
query.setParameter("storeIdentifier", personStoreRef.getIdentifier());
return query.list();
}
};
List<Node> results = (List<Node>) getHibernateTemplate().execute(callback);
for (Node node : results)
{
NodeRef nodeRef = node.getNodeRef();
Map<PropertyMapKey, NodePropertyValue> nodeProperties = node.getProperties();
// Convert the QName IDs
Map<QName, Serializable> converted = HibernateNodeDaoServiceImpl.convertToPublicProperties(
nodeProperties, qnameDAO, localeDAO, contentDataDAO, dictionaryService);
Serializable value = converted.get(ContentModel.PROP_USERNAME);
String realUserName = DefaultTypeConverter.INSTANCE.convert(String.class, value);
if (matcher.matches(searchUserName, realUserName))
{
answer.add(nodeRef);
}
}
return answer;
}
@SuppressWarnings("unchecked")
public Set<NodeRef> getAllPeople()
{
final StoreRef personStoreRef = tenantService.getName(storeRef);
Set<NodeRef> answer = new HashSet<NodeRef>();
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
SQLQuery query = (SQLQuery) session.getNamedQuery(QUERY_PERSON_GET_ALL_PEOPLE);
query.setParameter("qnamePropId", qNamePropId);
query.setParameter("qnameTypeId", qNameTypeId);
query.setParameter("False", Boolean.FALSE);
query.setParameter("storeProtocol", personStoreRef.getProtocol());
query.setParameter("storeIdentifier", personStoreRef.getIdentifier());
return query.list();
}
};
List<Node> results = (List<Node>) getHibernateTemplate().execute(callback);
for (Node node : results)
{
NodeRef nodeRef = node.getNodeRef();
answer.add(nodeRef);
}
return answer;
}
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
public void setLocaleDAO(LocaleDAO localeDAO)
{
this.localeDAO = localeDAO;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
public void setContentDataDAO(ContentDataDAO contentDataDAO)
{
this.contentDataDAO = contentDataDAO;
}
}

View File

@@ -25,15 +25,19 @@
package org.alfresco.repo.security.person;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
@@ -131,14 +135,15 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
private boolean includeAutoCreated = false;
private PersonDao personDao;
private AclDaoComponent aclDao;
private PermissionsManager permissionsManager;
/** a transactionally-safe cache to be injected */
private SimpleCache<String, NodeRef> personCache;
private SimpleCache<String, Map<String, NodeRef>> personCache;
/** People Container ref cache (Tennant aware) */
private Map<String, NodeRef> peopleContainerRefs = new ConcurrentHashMap<String, NodeRef>(4);
private UserNameMatcher userNameMatcher;
@@ -181,7 +186,6 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
PropertyCheck.mandatory(this, "namespacePrefixResolver", namespacePrefixResolver);
PropertyCheck.mandatory(this, "policyComponent", policyComponent);
PropertyCheck.mandatory(this, "personCache", personCache);
PropertyCheck.mandatory(this, "personDao", personDao);
PropertyCheck.mandatory(this, "aclDao", aclDao);
PropertyCheck.mandatory(this, "homeFolderManager", homeFolderManager);
@@ -233,11 +237,6 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
this.homeFolderManager = homeFolderManager;
}
public void setPersonDao(PersonDao personDao)
{
this.personDao = personDao;
}
public void setAclDao(AclDaoComponent aclDao)
{
this.aclDao = aclDao;
@@ -254,7 +253,7 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
* @param personCache
* a transactionally safe cache
*/
public void setPersonCache(SimpleCache<String, NodeRef> personCache)
public void setPersonCache(SimpleCache<String, Map<String, NodeRef>> personCache)
{
this.personCache = personCache;
}
@@ -345,10 +344,34 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
private NodeRef getPersonOrNull(String searchUserName)
{
NodeRef returnRef = this.personCache.get(searchUserName);
if (returnRef == null)
String cacheKey = searchUserName.toLowerCase();
Map<String, NodeRef> allRefs = this.personCache.get(cacheKey);
if (allRefs == null)
{
List<NodeRef> refs = personDao.getPersonOrNull(searchUserName, userNameMatcher);
List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(getPeopleContainer(),
ContentModel.ASSOC_CHILDREN, QName.createQName("cm", searchUserName.toLowerCase(),
namespacePrefixResolver));
allRefs = new LinkedHashMap<String, NodeRef>(childRefs.size() * 2);
// add to cache
personCache.put(cacheKey, allRefs);
for (ChildAssociationRef childRef : childRefs)
{
NodeRef nodeRef = childRef.getChildRef();
Serializable value = nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
String realUserName = DefaultTypeConverter.INSTANCE.convert(String.class, value);
allRefs.put(realUserName, nodeRef);
}
}
List<NodeRef> refs = new ArrayList<NodeRef>(allRefs.size());
for (Entry<String, NodeRef> entry : allRefs.entrySet())
{
if (userNameMatcher.matches(searchUserName, entry.getKey()))
{
refs.add(entry.getValue());
}
}
NodeRef returnRef = null;
if (refs.size() > 1)
{
returnRef = handleDuplicates(refs, searchUserName);
@@ -357,10 +380,6 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
{
returnRef = refs.get(0);
}
// add to cache
this.personCache.put(searchUserName, returnRef);
}
return returnRef;
}
@@ -657,30 +676,40 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
}
}
personCache.remove(userName.toLowerCase());
return personRef;
}
public NodeRef getPeopleContainer()
{
String cacheKey = tenantService.getCurrentUserDomain();
NodeRef peopleNodeRef = peopleContainerRefs.get(cacheKey);
if (peopleNodeRef == null)
{
NodeRef rootNodeRef = nodeService.getRootNode(tenantService.getName(storeRef));
List<ChildAssociationRef> children = nodeService.getChildAssocs(rootNodeRef, RegexQNamePattern.MATCH_ALL, QName.createQName(SYSTEM_FOLDER_SHORT_QNAME,
namespacePrefixResolver));
List<ChildAssociationRef> children = nodeService.getChildAssocs(rootNodeRef, RegexQNamePattern.MATCH_ALL,
QName.createQName(SYSTEM_FOLDER_SHORT_QNAME, namespacePrefixResolver));
if (children.size() == 0)
{
throw new AlfrescoRuntimeException("Required people system path not found: " + SYSTEM_FOLDER_SHORT_QNAME);
throw new AlfrescoRuntimeException("Required people system path not found: "
+ SYSTEM_FOLDER_SHORT_QNAME);
}
NodeRef systemNodeRef = children.get(0).getChildRef();
children = nodeService.getChildAssocs(systemNodeRef, RegexQNamePattern.MATCH_ALL, QName.createQName(PEOPLE_FOLDER_SHORT_QNAME, namespacePrefixResolver));
children = nodeService.getChildAssocs(systemNodeRef, RegexQNamePattern.MATCH_ALL, QName.createQName(
PEOPLE_FOLDER_SHORT_QNAME, namespacePrefixResolver));
if (children.size() == 0)
{
throw new AlfrescoRuntimeException("Required people system path not found: " + PEOPLE_FOLDER_SHORT_QNAME);
throw new AlfrescoRuntimeException("Required people system path not found: "
+ PEOPLE_FOLDER_SHORT_QNAME);
}
NodeRef peopleNodeRef = children.get(0).getChildRef();
peopleNodeRef = children.get(0).getChildRef();
peopleContainerRefs.put(cacheKey, peopleNodeRef);
}
return peopleNodeRef;
}
@@ -733,7 +762,14 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
public Set<NodeRef> getAllPeople()
{
return personDao.getAllPeople();
List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(getPeopleContainer(),
ContentModel.ASSOC_CHILDREN, RegexQNamePattern.MATCH_ALL);
Set<NodeRef> refs = new HashSet<NodeRef>(childRefs.size()*2);
for (ChildAssociationRef childRef : childRefs)
{
refs.add(childRef.getChildRef());
}
return refs;
}
public Set<NodeRef> getPeopleFilteredByProperty(QName propertyKey, Serializable propertyValue)
@@ -794,7 +830,6 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
{
NodeRef personRef = childAssocRef.getChildRef();
String username = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
this.personCache.put(username, personRef);
permissionsManager.setPermissions(personRef, username, username);
// Make sure there is an authority entry - with a DB constraint for uniqueness
@@ -812,7 +847,7 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
public void beforeDeleteNode(NodeRef nodeRef)
{
String username = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
this.personCache.remove(username);
this.personCache.remove(username.toLowerCase());
}
// IOC Setters
@@ -960,8 +995,10 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
ChildAssociationRef assoc = nodeService.getPrimaryParent(nodeRef);
nodeService.moveNode(nodeRef, assoc.getParentRef(), assoc.getTypeQName(), newAssocQName);
// Fix cache
personCache.remove(uidBefore);
personCache.put(uidAfter, nodeRef);
if (uidBefore != null)
{
personCache.remove(uidBefore.toLowerCase());
}
}
else
{