LDAP bug fixes

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3092 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2006-06-13 15:58:13 +00:00
parent 4d3c3e6659
commit dd527a2dcf
6 changed files with 198 additions and 83 deletions

View File

@@ -287,6 +287,10 @@
<property name="memberAttribute"> <property name="memberAttribute">
<value>member</value> <value>member</value>
</property> </property>
<property name="authorityDAO">
<ref bean="authorityDAO"/>
</property>
</bean> </bean>
<!-- Job definitions to import LDAP people and groups --> <!-- Job definitions to import LDAP people and groups -->
@@ -397,6 +401,13 @@
<property name="namespacePrefixResolver"> <property name="namespacePrefixResolver">
<ref bean="namespaceService"/> <ref bean="namespaceService"/>
</property> </property>
<property name="caches">
<set>
<ref bean="permissionsAccessCache"/>
</set>
</property>
</bean> </bean>
<!-- The bean that imports xml descibing groups --> <!-- The bean that imports xml descibing groups -->
@@ -437,6 +448,16 @@
<property name="namespacePrefixResolver"> <property name="namespacePrefixResolver">
<ref bean="namespaceService"/> <ref bean="namespaceService"/>
</property> </property>
<!-- caches to clear on import of groups -->
<property name="caches">
<set>
<ref bean="userToAuthorityCache"/>
<ref bean="permissionsAccessCache"/>
</set>
</property>
<!-- userToAuthorityCache -->
</bean> </bean>
</beans> </beans>

View File

@@ -21,14 +21,14 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.transaction.UserTransaction; import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -52,21 +52,23 @@ public class ExportSourceImporter implements ImporterJobSPI
private ExportSource exportSource; private ExportSource exportSource;
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
private StoreRef storeRef; private StoreRef storeRef;
private String path; private String path;
private boolean clearAllChildren; private boolean clearAllChildren;
private NodeService nodeService; private NodeService nodeService;
private SearchService searchService; private SearchService searchService;
private NamespacePrefixResolver namespacePrefixResolver; private NamespacePrefixResolver namespacePrefixResolver;
private TransactionService transactionService; private TransactionService transactionService;
private Set<SimpleCache> caches;
public ExportSourceImporter() public ExportSourceImporter()
{ {
super(); super();
@@ -96,7 +98,7 @@ public class ExportSourceImporter implements ImporterJobSPI
{ {
this.storeRef = new StoreRef(storeRef); this.storeRef = new StoreRef(storeRef);
} }
public void setTransactionService(TransactionService transactionService) public void setTransactionService(TransactionService transactionService)
{ {
this.transactionService = transactionService; this.transactionService = transactionService;
@@ -111,8 +113,11 @@ public class ExportSourceImporter implements ImporterJobSPI
{ {
this.nodeService = nodeService; this.nodeService = nodeService;
} }
public void setCaches(Set<SimpleCache> caches)
{
this.caches = caches;
}
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent) public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
{ {
@@ -124,6 +129,7 @@ public class ExportSourceImporter implements ImporterJobSPI
this.searchService = searchService; this.searchService = searchService;
} }
@SuppressWarnings("unchecked")
public void doImport() public void doImport()
{ {
UserTransaction userTransaction = null; UserTransaction userTransaction = null;
@@ -132,18 +138,28 @@ public class ExportSourceImporter implements ImporterJobSPI
userTransaction = transactionService.getUserTransaction(); userTransaction = transactionService.getUserTransaction();
userTransaction.begin(); userTransaction.begin();
authenticationComponent.setSystemUserAsCurrentUser(); authenticationComponent.setSystemUserAsCurrentUser();
if(clearAllChildren) if (clearAllChildren)
{ {
List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(storeRef), path, null, namespacePrefixResolver, false); List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(storeRef), path, null,
for(NodeRef ref: refs) namespacePrefixResolver, false);
for (NodeRef ref : refs)
{ {
for(ChildAssociationRef car: nodeService.getChildAssocs(ref)) for (ChildAssociationRef car : nodeService.getChildAssocs(ref))
{ {
nodeService.deleteNode(car.getChildRef()); nodeService.deleteNode(car.getChildRef());
} }
} }
} }
if (caches != null)
{
for (SimpleCache cache : caches)
{
cache.clear();
}
}
File tempFile = TempFileProvider.createTempFile("ExportSourceImporter-", ".xml"); File tempFile = TempFileProvider.createTempFile("ExportSourceImporter-", ".xml");
Writer writer = new BufferedWriter(new FileWriter(tempFile)); Writer writer = new BufferedWriter(new FileWriter(tempFile));
XMLWriter xmlWriter = createXMLExporter(writer); XMLWriter xmlWriter = createXMLExporter(writer);
@@ -157,12 +173,36 @@ public class ExportSourceImporter implements ImporterJobSPI
importerService.importView(reader, location, REPLACE_BINDING, null); importerService.importView(reader, location, REPLACE_BINDING, null);
reader.close(); reader.close();
if (caches != null)
{
for (SimpleCache cache : caches)
{
cache.clear();
}
}
userTransaction.commit(); userTransaction.commit();
} }
catch(Throwable t) catch (Throwable t)
{ {
try { if (userTransaction != null) {userTransaction.rollback();} } catch (Exception ex) {} try
try {authenticationComponent.clearCurrentSecurityContext(); } catch (Exception ex) {} {
if (userTransaction != null)
{
userTransaction.rollback();
}
}
catch (Exception ex)
{
}
try
{
authenticationComponent.clearCurrentSecurityContext();
}
catch (Exception ex)
{
}
throw new ExportSourceImporterException("Failed to import", t); throw new ExportSourceImporterException("Failed to import", t);
} }
finally finally

View File

@@ -32,12 +32,16 @@ import javax.naming.directory.Attributes;
import javax.naming.directory.InitialDirContext; import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls; import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult; import javax.naming.directory.SearchResult;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.importer.ExportSource; import org.alfresco.repo.importer.ExportSource;
import org.alfresco.repo.importer.ExportSourceImporterException; import org.alfresco.repo.importer.ExportSourceImporterException;
import org.alfresco.repo.security.authority.AuthorityDAO;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.EqualsHelper; import org.alfresco.util.EqualsHelper;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
@@ -86,6 +90,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
private QName viewIdRef; private QName viewIdRef;
private AuthorityDAO authorityDAO;
public LDAPGroupExportSource() public LDAPGroupExportSource()
{ {
super(); super();
@@ -141,6 +147,11 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
this.errorOnMissingMembers = errorOnMissingMembers; this.errorOnMissingMembers = errorOnMissingMembers;
} }
public void setAuthorityDAO(AuthorityDAO authorityDAO)
{
this.authorityDAO = authorityDAO;
}
public void generateExport(XMLWriter writer) public void generateExport(XMLWriter writer)
{ {
HashSet<Group> rootGroups = new HashSet<Group>(); HashSet<Group> rootGroups = new HashSet<Group>();
@@ -222,7 +233,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
String toId = lookup.get(sl.to).guid; String toId = lookup.get(sl.to).guid;
AttributesImpl attrs = new AttributesImpl(); AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(viewIdRef.getNamespaceURI(), viewIdRef.getLocalName(), viewIdRef.toPrefixString(), null, fromId); attrs.addAttribute(viewIdRef.getNamespaceURI(), viewIdRef.getLocalName(), viewIdRef.toPrefixString(), null,
fromId);
writer.startElement(viewRef.getNamespaceURI(), viewRef.getLocalName(), writer.startElement(viewRef.getNamespaceURI(), viewRef.getLocalName(),
viewRef.toPrefixString(namespaceService), attrs); viewRef.toPrefixString(namespaceService), attrs);
@@ -234,7 +246,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
ContentModel.ASSOC_MEMBER.toPrefixString(namespaceService), new AttributesImpl()); ContentModel.ASSOC_MEMBER.toPrefixString(namespaceService), new AttributesImpl());
AttributesImpl attrsRef = new AttributesImpl(); AttributesImpl attrsRef = new AttributesImpl();
attrsRef.addAttribute(viewIdRef.getNamespaceURI(), viewIdRef.getLocalName(), viewIdRef.toPrefixString(), null, toId); attrsRef.addAttribute(viewIdRef.getNamespaceURI(), viewIdRef.getLocalName(), viewIdRef.toPrefixString(), null,
toId);
attrsRef.addAttribute(childQName.getNamespaceURI(), childQName.getLocalName(), childQName.toPrefixString(), attrsRef.addAttribute(childQName.getNamespaceURI(), childQName.getLocalName(), childQName.toPrefixString(),
null, QName.createQName(ContentModel.USER_MODEL_URI, sl.to).toPrefixString(namespaceService)); null, QName.createQName(ContentModel.USER_MODEL_URI, sl.to).toPrefixString(namespaceService));
@@ -255,13 +268,13 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
private void addRootGroup(HashMap<String, Group> lookup, Group group, XMLWriter writer) throws SAXException private void addRootGroup(HashMap<String, Group> lookup, Group group, XMLWriter writer) throws SAXException
{ {
QName nodeUUID = QName.createQName("sys:node-uuid", namespaceService);
AttributesImpl attrs = new AttributesImpl(); AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, childQName.getLocalName(), childQName attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, childQName.getLocalName(), childQName
.toPrefixString(), null, QName.createQName(ContentModel.USER_MODEL_URI, group.gid).toPrefixString( .toPrefixString(), null, QName.createQName(ContentModel.USER_MODEL_URI, group.gid).toPrefixString(
namespaceService)); namespaceService));
attrs.addAttribute(viewId.getNamespaceURI(), viewId.getLocalName(), viewId attrs.addAttribute(viewId.getNamespaceURI(), viewId.getLocalName(), viewId.toPrefixString(), null, group.guid);
.toPrefixString(), null, group.guid);
writer.startElement(ContentModel.TYPE_AUTHORITY_CONTAINER.getNamespaceURI(), writer.startElement(ContentModel.TYPE_AUTHORITY_CONTAINER.getNamespaceURI(),
ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER
@@ -301,6 +314,23 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
addgroup(lookup, child, writer); addgroup(lookup, child, writer);
} }
if ((authorityDAO != null ) && authorityDAO.authorityExists(group.gid))
{
NodeRef authNodeRef = authorityDAO.getAuthorityNodeRefOrNull(group.gid);
if (authNodeRef != null)
{
String uguid = authorityDAO.getAuthorityNodeRefOrNull(group.gid).getId();
writer.startElement(nodeUUID.getNamespaceURI(), nodeUUID.getLocalName(), nodeUUID
.toPrefixString(namespaceService), new AttributesImpl());
writer.characters(uguid.toCharArray(), 0, uguid.length());
writer.endElement(nodeUUID.getNamespaceURI(), nodeUUID.getLocalName(), nodeUUID
.toPrefixString(namespaceService));
}
}
writer.endElement(ContentModel.TYPE_AUTHORITY_CONTAINER.getNamespaceURI(), writer.endElement(ContentModel.TYPE_AUTHORITY_CONTAINER.getNamespaceURI(),
ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER
.toPrefixString(namespaceService)); .toPrefixString(namespaceService));
@@ -337,9 +367,10 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
SearchResult result = (SearchResult) searchResults.next(); SearchResult result = (SearchResult) searchResults.next();
Attributes attributes = result.getAttributes(); Attributes attributes = result.getAttributes();
Attribute gidAttribute = attributes.get(groupIdAttributeName); Attribute gidAttribute = attributes.get(groupIdAttributeName);
if(gidAttribute == null) if (gidAttribute == null)
{ {
throw new ExportSourceImporterException("Group returned by group search does not have mandatory group id attribute "+attributes); throw new ExportSourceImporterException(
"Group returned by group search does not have mandatory group id attribute " + attributes);
} }
String gid = (String) gidAttribute.get(0); String gid = (String) gidAttribute.get(0);
@@ -421,9 +452,9 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
} }
Attributes attributes = result.getAttributes(); Attributes attributes = result.getAttributes();
Attribute objectclass = attributes.get("objectclass"); Attribute objectclass = attributes.get("objectclass");
if(objectclass == null) if (objectclass == null)
{ {
throw new ExportSourceImporterException("Failed to find attribute objectclass for DN "+dn); throw new ExportSourceImporterException("Failed to find attribute objectclass for DN " + dn);
} }
for (int i = 0; i < objectclass.size(); i++) for (int i = 0; i < objectclass.size(); i++)
{ {
@@ -447,9 +478,10 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
try try
{ {
Attribute groupIdAttribute = attributes.get(groupIdAttributeName); Attribute groupIdAttribute = attributes.get(groupIdAttributeName);
if(groupIdAttribute == null) if (groupIdAttribute == null)
{ {
throw new ExportSourceImporterException("Group missing group id attribute DN ="+dn + " att = "+groupIdAttributeName); throw new ExportSourceImporterException("Group missing group id attribute DN ="
+ dn + " att = " + groupIdAttributeName);
} }
id = (String) groupIdAttribute.get(0); id = (String) groupIdAttribute.get(0);
} }
@@ -471,9 +503,10 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
try try
{ {
Attribute userIdAttribute = attributes.get(userIdAttributeName); Attribute userIdAttribute = attributes.get(userIdAttributeName);
if(userIdAttribute == null) if (userIdAttribute == null)
{ {
throw new ExportSourceImporterException("User missing user id attribute DN ="+dn + " att = "+userIdAttributeName); throw new ExportSourceImporterException("User missing user id attribute DN ="
+ dn + " att = " + userIdAttributeName);
} }
id = (String) userIdAttribute.get(0); id = (String) userIdAttribute.get(0);
} }
@@ -495,7 +528,7 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
{ {
if (isGroup == null) if (isGroup == null)
{ {
throw new ExportSourceImporterException("Type not recognised for DN"+dn); throw new ExportSourceImporterException("Type not recognised for DN" + dn);
} }
else if (isGroup) else if (isGroup)
{ {
@@ -580,7 +613,7 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
private Group(String gid) private Group(String gid)
{ {
this.gid = "GROUP_" + gid; this.gid = "GROUP_" + gid;
} }
@Override @Override
@@ -613,8 +646,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
private SecondaryLink(String from, String to) private SecondaryLink(String from, String to)
{ {
this.from = from; this.from = from;
this.to = to; this.to = to;
} }
@Override @Override
@@ -648,17 +681,22 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
} }
} }
public static void main(String[] args) throws IOException public static void main(String[] args) throws Exception
{ {
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
ExportSource source = (ExportSource) ctx.getBean("ldapGroupExportSource"); ExportSource source = (ExportSource) ctx.getBean("ldapGroupExportSource");
TransactionService txs = (TransactionService) ctx.getBean("transactionComponent");
UserTransaction tx = txs.getUserTransaction();
tx.begin();
File file = new File(args[0]); File file = new File(args[0]);
Writer writer = new BufferedWriter(new FileWriter(file)); Writer writer = new BufferedWriter(new FileWriter(file));
XMLWriter xmlWriter = createXMLExporter(writer); XMLWriter xmlWriter = createXMLExporter(writer);
source.generateExport(xmlWriter); source.generateExport(xmlWriter);
xmlWriter.close(); xmlWriter.close();
tx.commit();
} }
private static XMLWriter createXMLExporter(Writer writer) private static XMLWriter createXMLExporter(Writer writer)

View File

@@ -19,7 +19,6 @@ package org.alfresco.repo.security.authentication.ldap;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@@ -31,6 +30,7 @@ import javax.naming.directory.Attributes;
import javax.naming.directory.InitialDirContext; import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls; import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult; import javax.naming.directory.SearchResult;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.importer.ExportSource; import org.alfresco.repo.importer.ExportSource;
@@ -38,6 +38,7 @@ import org.alfresco.repo.importer.ExportSourceImporterException;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ApplicationContextHelper;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -50,7 +51,7 @@ import org.xml.sax.helpers.AttributesImpl;
public class LDAPPersonExportSource implements ExportSource public class LDAPPersonExportSource implements ExportSource
{ {
private static Log s_logger = LogFactory.getLog(LDAPPersonExportSource.class); private static Log s_logger = LogFactory.getLog(LDAPPersonExportSource.class);
private String personQuery = "(objectclass=inetOrgPerson)"; private String personQuery = "(objectclass=inetOrgPerson)";
private String searchBase; private String searchBase;
@@ -149,24 +150,28 @@ public class LDAPPersonExportSource implements ExportSource
SearchControls userSearchCtls = new SearchControls(); SearchControls userSearchCtls = new SearchControls();
userSearchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); userSearchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
System.out.println("COUNT "+userSearchCtls.getCountLimit());
System.out.println("TIME "+userSearchCtls.getTimeLimit());
userSearchCtls.setCountLimit(Integer.MAX_VALUE); userSearchCtls.setCountLimit(Integer.MAX_VALUE);
NamingEnumeration searchResults = ctx.search(searchBase, personQuery, userSearchCtls); NamingEnumeration searchResults = ctx.search(searchBase, personQuery, userSearchCtls);
while (searchResults.hasMoreElements()) while (searchResults.hasMoreElements())
{ {
SearchResult result = (SearchResult) searchResults.next(); SearchResult result = (SearchResult) searchResults.next();
Attributes attributes = result.getAttributes(); Attributes attributes = result.getAttributes();
Attribute uidAttribute = attributes.get(userIdAttributeName); Attribute uidAttribute = attributes.get(userIdAttributeName);
if (uidAttribute == null)
{
throw new ExportSourceImporterException(
"User returned by user search does not have mandatory user id attribute " + attributes);
}
String uid = (String) uidAttribute.get(0); String uid = (String) uidAttribute.get(0);
if(s_logger.isDebugEnabled()) if (s_logger.isDebugEnabled())
{ {
s_logger.debug("Adding user for "+uid); s_logger.debug("Adding user for " + uid);
} }
System.out.println("User "+uid);
writer.startElement(ContentModel.TYPE_PERSON.getNamespaceURI(), ContentModel.TYPE_PERSON writer.startElement(ContentModel.TYPE_PERSON.getNamespaceURI(), ContentModel.TYPE_PERSON
.getLocalName(), ContentModel.TYPE_PERSON.toPrefixString(namespaceService), attrs); .getLocalName(), ContentModel.TYPE_PERSON.toPrefixString(namespaceService), attrs);
@@ -199,13 +204,17 @@ public class LDAPPersonExportSource implements ExportSource
.toPrefixString(namespaceService), new AttributesImpl()); .toPrefixString(namespaceService), new AttributesImpl());
// cater for null // cater for null
String attribute = attributeMapping.get(key); String attributeName = attributeMapping.get(key);
if (attribute != null) if (attributeName != null)
{ {
String value = (String) attributes.get(attribute).get(0); Attribute attribute = attributes.get(attributeName);
if (value != null) if (attribute != null)
{ {
writer.characters(value.toCharArray(), 0, value.length()); String value = (String) attribute.get(0);
if (value != null)
{
writer.characters(value.toCharArray(), 0, value.length());
}
} }
} }
@@ -292,17 +301,21 @@ public class LDAPPersonExportSource implements ExportSource
} }
} }
public static void main(String[] args) throws IOException public static void main(String[] args) throws Exception
{ {
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
ExportSource source = (ExportSource) ctx.getBean("ldapPeopleExportSource"); ExportSource source = (ExportSource) ctx.getBean("ldapPeopleExportSource");
TransactionService txs = (TransactionService) ctx.getBean("transactionComponent");
UserTransaction tx = txs.getUserTransaction();
tx.begin();
File file = new File(args[0]); File file = new File(args[0]);
Writer writer = new BufferedWriter(new FileWriter(file)); Writer writer = new BufferedWriter(new FileWriter(file));
XMLWriter xmlWriter = createXMLExporter(writer); XMLWriter xmlWriter = createXMLExporter(writer);
source.generateExport(xmlWriter); source.generateExport(xmlWriter);
xmlWriter.close(); xmlWriter.close();
tx.commit();
} }
private static XMLWriter createXMLExporter(Writer writer) private static XMLWriter createXMLExporter(Writer writer)

View File

@@ -18,6 +18,7 @@ package org.alfresco.repo.security.authority;
import java.util.Set; import java.util.Set;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityType;
public interface AuthorityDAO public interface AuthorityDAO
@@ -96,4 +97,12 @@ public interface AuthorityDAO
* @return * @return
*/ */
boolean authorityExists(String name); boolean authorityExists(String name);
/**
* Get a node ref for the authority if one exists
*
* @param name
* @return
*/
NodeRef getAuthorityNodeRefOrNull(String name);
} }

View File

@@ -50,11 +50,17 @@ public class AuthorityDAOImpl implements AuthorityDAO
public static final StoreRef STOREREF_USERS = new StoreRef("user", "alfrescoUserStore"); public static final StoreRef STOREREF_USERS = new StoreRef("user", "alfrescoUserStore");
private NodeService nodeService; private NodeService nodeService;
private NamespacePrefixResolver namespacePrefixResolver; private NamespacePrefixResolver namespacePrefixResolver;
private QName qnameAssocSystem; private QName qnameAssocSystem;
private QName qnameAssocAuthorities; private QName qnameAssocAuthorities;
private SearchService searchService; private SearchService searchService;
private DictionaryService dictionaryService; private DictionaryService dictionaryService;
private SimpleCache<String, ArrayList<NodeRef>> userToAuthorityCache; private SimpleCache<String, ArrayList<NodeRef>> userToAuthorityCache;
public AuthorityDAOImpl() public AuthorityDAOImpl()
@@ -91,11 +97,10 @@ public class AuthorityDAOImpl implements AuthorityDAO
public boolean authorityExists(String name) public boolean authorityExists(String name)
{ {
NodeRef ref = getAuthorityOrNull(name); NodeRef ref = getAuthorityOrNull(name);
return ref != null; return ref != null;
} }
public void addAuthority(String parentName, String childName) public void addAuthority(String parentName, String childName)
{ {
NodeRef parentRef = getAuthorityOrNull(parentName); NodeRef parentRef = getAuthorityOrNull(parentName);
@@ -120,11 +125,8 @@ public class AuthorityDAOImpl implements AuthorityDAO
{ {
throw new UnknownAuthorityException("An authority was not found for " + childName); throw new UnknownAuthorityException("An authority was not found for " + childName);
} }
nodeService.addChild( nodeService.addChild(parentRef, childRef, ContentModel.ASSOC_MEMBER, QName.createQName("usr", childName,
parentRef, namespacePrefixResolver));
childRef,
ContentModel.ASSOC_MEMBER,
QName.createQName("usr", childName, namespacePrefixResolver));
} }
} }
@@ -140,22 +142,14 @@ public class AuthorityDAOImpl implements AuthorityDAO
{ {
throw new UnknownAuthorityException("An authority was not found for " + parentName); throw new UnknownAuthorityException("An authority was not found for " + parentName);
} }
nodeService.createNode( nodeService.createNode(parentRef, ContentModel.ASSOC_MEMBER, QName.createQName("usr", name,
parentRef, namespacePrefixResolver), ContentModel.TYPE_AUTHORITY_CONTAINER, props);
ContentModel.ASSOC_MEMBER,
QName.createQName("usr", name, namespacePrefixResolver),
ContentModel.TYPE_AUTHORITY_CONTAINER,
props);
} }
else else
{ {
NodeRef authorityContainerRef = getAuthorityContainer(); NodeRef authorityContainerRef = getAuthorityContainer();
nodeService.createNode( nodeService.createNode(authorityContainerRef, ContentModel.ASSOC_CHILDREN, QName.createQName("usr", name,
authorityContainerRef, namespacePrefixResolver), ContentModel.TYPE_AUTHORITY_CONTAINER, props);
ContentModel.ASSOC_CHILDREN,
QName.createQName("usr", name, namespacePrefixResolver),
ContentModel.TYPE_AUTHORITY_CONTAINER,
props);
} }
} }
@@ -430,9 +424,8 @@ public class AuthorityDAOImpl implements AuthorityDAO
{ {
for (ResultSetRow row : rs) for (ResultSetRow row : rs)
{ {
String test = DefaultTypeConverter.INSTANCE.convert( String test = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row
String.class, .getNodeRef(), ContentModel.PROP_AUTHORITY_NAME));
nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_AUTHORITY_NAME));
if (test.equals(name)) if (test.equals(name))
{ {
return row.getNodeRef(); return row.getNodeRef();
@@ -457,9 +450,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
private NodeRef getAuthorityContainer() private NodeRef getAuthorityContainer()
{ {
NodeRef rootNodeRef = nodeService.getRootNode(STOREREF_USERS); NodeRef rootNodeRef = nodeService.getRootNode(STOREREF_USERS);
List<ChildAssociationRef> results = nodeService.getChildAssocs( List<ChildAssociationRef> results = nodeService.getChildAssocs(rootNodeRef, RegexQNamePattern.MATCH_ALL,
rootNodeRef,
RegexQNamePattern.MATCH_ALL,
qnameAssocSystem); qnameAssocSystem);
NodeRef sysNodeRef = null; NodeRef sysNodeRef = null;
if (results.size() == 0) if (results.size() == 0)
@@ -470,10 +461,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
{ {
sysNodeRef = results.get(0).getChildRef(); sysNodeRef = results.get(0).getChildRef();
} }
results = nodeService.getChildAssocs( results = nodeService.getChildAssocs(sysNodeRef, RegexQNamePattern.MATCH_ALL, qnameAssocAuthorities);
sysNodeRef,
RegexQNamePattern.MATCH_ALL,
qnameAssocAuthorities);
NodeRef authNodeRef = null; NodeRef authNodeRef = null;
if (results.size() == 0) if (results.size() == 0)
{ {
@@ -485,4 +473,10 @@ public class AuthorityDAOImpl implements AuthorityDAO
} }
return authNodeRef; return authNodeRef;
} }
public NodeRef getAuthorityNodeRefOrNull(String name)
{
return getAuthorityOrNull(name);
}
} }