mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged up to HEAD.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3129 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -32,12 +32,16 @@ import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.importer.ExportSource;
|
||||
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.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.alfresco.util.GUID;
|
||||
@@ -86,6 +90,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
|
||||
private QName viewIdRef;
|
||||
|
||||
private AuthorityDAO authorityDAO;
|
||||
|
||||
public LDAPGroupExportSource()
|
||||
{
|
||||
super();
|
||||
@@ -141,6 +147,11 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
this.errorOnMissingMembers = errorOnMissingMembers;
|
||||
}
|
||||
|
||||
public void setAuthorityDAO(AuthorityDAO authorityDAO)
|
||||
{
|
||||
this.authorityDAO = authorityDAO;
|
||||
}
|
||||
|
||||
public void generateExport(XMLWriter writer)
|
||||
{
|
||||
HashSet<Group> rootGroups = new HashSet<Group>();
|
||||
@@ -222,7 +233,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
String toId = lookup.get(sl.to).guid;
|
||||
|
||||
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(),
|
||||
viewRef.toPrefixString(namespaceService), attrs);
|
||||
@@ -234,7 +246,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
ContentModel.ASSOC_MEMBER.toPrefixString(namespaceService), 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(),
|
||||
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
|
||||
{
|
||||
QName nodeUUID = QName.createQName("sys:node-uuid", namespaceService);
|
||||
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, childQName.getLocalName(), childQName
|
||||
.toPrefixString(), null, QName.createQName(ContentModel.USER_MODEL_URI, group.gid).toPrefixString(
|
||||
namespaceService));
|
||||
attrs.addAttribute(viewId.getNamespaceURI(), viewId.getLocalName(), viewId
|
||||
.toPrefixString(), null, group.guid);
|
||||
attrs.addAttribute(viewId.getNamespaceURI(), viewId.getLocalName(), viewId.toPrefixString(), null, group.guid);
|
||||
|
||||
writer.startElement(ContentModel.TYPE_AUTHORITY_CONTAINER.getNamespaceURI(),
|
||||
ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER
|
||||
@@ -301,6 +314,23 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
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(),
|
||||
ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER
|
||||
.toPrefixString(namespaceService));
|
||||
@@ -337,9 +367,10 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
SearchResult result = (SearchResult) searchResults.next();
|
||||
Attributes attributes = result.getAttributes();
|
||||
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);
|
||||
|
||||
@@ -421,9 +452,9 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
}
|
||||
Attributes attributes = result.getAttributes();
|
||||
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++)
|
||||
{
|
||||
@@ -447,9 +478,10 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -471,9 +503,10 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -495,7 +528,7 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
{
|
||||
if (isGroup == null)
|
||||
{
|
||||
throw new ExportSourceImporterException("Type not recognised for DN"+dn);
|
||||
throw new ExportSourceImporterException("Type not recognised for DN" + dn);
|
||||
}
|
||||
else if (isGroup)
|
||||
{
|
||||
@@ -580,7 +613,7 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
|
||||
private Group(String gid)
|
||||
{
|
||||
this.gid = "GROUP_" + gid;
|
||||
this.gid = "GROUP_" + gid;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -613,8 +646,8 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
|
||||
private SecondaryLink(String from, String to)
|
||||
{
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@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();
|
||||
ExportSource source = (ExportSource) ctx.getBean("ldapGroupExportSource");
|
||||
|
||||
TransactionService txs = (TransactionService) ctx.getBean("transactionComponent");
|
||||
UserTransaction tx = txs.getUserTransaction();
|
||||
tx.begin();
|
||||
|
||||
File file = new File(args[0]);
|
||||
Writer writer = new BufferedWriter(new FileWriter(file));
|
||||
XMLWriter xmlWriter = createXMLExporter(writer);
|
||||
source.generateExport(xmlWriter);
|
||||
xmlWriter.close();
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
private static XMLWriter createXMLExporter(Writer writer)
|
||||
|
@@ -19,7 +19,6 @@ package org.alfresco.repo.security.authentication.ldap;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@@ -31,6 +30,7 @@ import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
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.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -50,7 +51,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
public class LDAPPersonExportSource implements ExportSource
|
||||
{
|
||||
private static Log s_logger = LogFactory.getLog(LDAPPersonExportSource.class);
|
||||
|
||||
|
||||
private String personQuery = "(objectclass=inetOrgPerson)";
|
||||
|
||||
private String searchBase;
|
||||
@@ -149,24 +150,28 @@ public class LDAPPersonExportSource implements ExportSource
|
||||
|
||||
SearchControls userSearchCtls = new SearchControls();
|
||||
userSearchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
System.out.println("COUNT "+userSearchCtls.getCountLimit());
|
||||
System.out.println("TIME "+userSearchCtls.getTimeLimit());
|
||||
|
||||
userSearchCtls.setCountLimit(Integer.MAX_VALUE);
|
||||
|
||||
|
||||
NamingEnumeration searchResults = ctx.search(searchBase, personQuery, userSearchCtls);
|
||||
while (searchResults.hasMoreElements())
|
||||
{
|
||||
SearchResult result = (SearchResult) searchResults.next();
|
||||
Attributes attributes = result.getAttributes();
|
||||
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);
|
||||
|
||||
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
|
||||
.getLocalName(), ContentModel.TYPE_PERSON.toPrefixString(namespaceService), attrs);
|
||||
|
||||
@@ -199,13 +204,17 @@ public class LDAPPersonExportSource implements ExportSource
|
||||
.toPrefixString(namespaceService), new AttributesImpl());
|
||||
|
||||
// cater for null
|
||||
String attribute = attributeMapping.get(key);
|
||||
if (attribute != null)
|
||||
String attributeName = attributeMapping.get(key);
|
||||
if (attributeName != null)
|
||||
{
|
||||
String value = (String) attributes.get(attribute).get(0);
|
||||
if (value != null)
|
||||
Attribute attribute = attributes.get(attributeName);
|
||||
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();
|
||||
ExportSource source = (ExportSource) ctx.getBean("ldapPeopleExportSource");
|
||||
|
||||
TransactionService txs = (TransactionService) ctx.getBean("transactionComponent");
|
||||
UserTransaction tx = txs.getUserTransaction();
|
||||
tx.begin();
|
||||
|
||||
File file = new File(args[0]);
|
||||
Writer writer = new BufferedWriter(new FileWriter(file));
|
||||
XMLWriter xmlWriter = createXMLExporter(writer);
|
||||
source.generateExport(xmlWriter);
|
||||
xmlWriter.close();
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
private static XMLWriter createXMLExporter(Writer writer)
|
||||
|
Reference in New Issue
Block a user