mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged BRANCHES/DEV/DAVEW/LDAP to HEAD
14587: Added new node service method getNodesWithoutParentAssocsOfType to public-services-security-context.xml (or at least my best guess at it!) 14586: Use US spelling of synchronization in filenames for consistency 14585: Lower the default user registry sync frequency to daily instead of hourly. Now users and groups are pulled over incrementally on login of missing users. 14583: Unit test for ChainingUserRegistrySynchronizer 14571: Migration patch for existing authorities previously held in users store - Uses AuthorityService to recreate authorities in spaces store with new structure 14555: Authority service changes for LDAP sync improvements - Moved sys:authorities container to spaces store - All authorities now stored directly under sys:authorities - Authorities can now be looked up directly by node service - Secondary child associations used to model group relationships - 'Root' groups for UI navigation determined dynamically by node service query - cm:member association used to relate both authority containers and persons to other authorities - New cm:inZone association relates persons and authority containers to synchronization 'zones' stored under sys:zones - Look up of authority zone and all authorities in a zone to enable multi-zone LDAP sync 14524: Dev branch for finishing LDAP zones and upgrade impact git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14588 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -35,9 +35,9 @@ import net.sf.acegisecurity.GrantedAuthorityImpl;
|
||||
import net.sf.acegisecurity.UserDetails;
|
||||
import net.sf.acegisecurity.providers.dao.User;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.security.sync.UserRegistrySynchronizer;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
@@ -63,6 +63,8 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
|
||||
|
||||
private Set<String> defaultAdministratorUserNames = Collections.emptySet();
|
||||
|
||||
private boolean syncWhenMissingPeopleLogIn = true;
|
||||
|
||||
private boolean autoCreatePeopleOnLogin = true;
|
||||
|
||||
private AuthenticationContext authenticationContext;
|
||||
@@ -72,6 +74,8 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
|
||||
private NodeService nodeService;
|
||||
|
||||
private TransactionService transactionService;
|
||||
|
||||
private UserRegistrySynchronizer userRegistrySynchronizer;
|
||||
|
||||
public AbstractAuthenticationComponent()
|
||||
{
|
||||
@@ -107,6 +111,11 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
public void setUserRegistrySynchronizer(UserRegistrySynchronizer userRegistrySynchronizer)
|
||||
{
|
||||
this.userRegistrySynchronizer = userRegistrySynchronizer;
|
||||
}
|
||||
|
||||
public TransactionService getTransactionService()
|
||||
{
|
||||
@@ -138,6 +147,11 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
|
||||
this.autoCreatePeopleOnLogin = autoCreatePeopleOnLogin;
|
||||
}
|
||||
|
||||
public void setSyncWhenMissingPeopleLogIn(boolean syncWhenMissingPeopleLogIn)
|
||||
{
|
||||
this.syncWhenMissingPeopleLogIn = syncWhenMissingPeopleLogIn;
|
||||
}
|
||||
|
||||
public void authenticate(String userName, char[] password) throws AuthenticationException
|
||||
{
|
||||
// Support guest login from the login screen
|
||||
@@ -434,7 +448,30 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
|
||||
{
|
||||
public String doWork() throws Exception
|
||||
{
|
||||
if (personService.personExists(userName))
|
||||
boolean personExists = personService.personExists(userName);
|
||||
|
||||
// If the person is missing, synchronize or auto-create the missing person if we are allowed
|
||||
if (!personExists)
|
||||
{
|
||||
if ((userName != null) && !userName.equals(AuthenticationUtil.getSystemUserName()))
|
||||
{
|
||||
if (syncWhenMissingPeopleLogIn)
|
||||
{
|
||||
userRegistrySynchronizer.synchronize(false);
|
||||
personExists = personService.personExists(userName);
|
||||
}
|
||||
if (!personExists && autoCreatePeopleOnLogin && personService.createMissingPeople())
|
||||
{
|
||||
AuthorityType authorityType = AuthorityType.getAuthorityType(userName);
|
||||
if (authorityType == AuthorityType.USER)
|
||||
{
|
||||
personService.getPerson(userName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (personExists)
|
||||
{
|
||||
NodeRef userNode = personService.getPerson(userName);
|
||||
if (userNode != null)
|
||||
@@ -443,28 +480,8 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
|
||||
// checks
|
||||
return (String) nodeService.getProperty(userNode, ContentModel.PROP_USERNAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get user name
|
||||
return userName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (autoCreatePeopleOnLogin && (userName != null) && !userName.equals(AuthenticationUtil.getSystemUserName()))
|
||||
{
|
||||
if (personService.createMissingPeople())
|
||||
{
|
||||
AuthorityType authorityType = AuthorityType.getAuthorityType(userName);
|
||||
if (authorityType == AuthorityType.USER)
|
||||
{
|
||||
personService.getPerson(userName);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Get user name
|
||||
return userName;
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
}, getSystemUserName(getUserDomain(userName)));
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2009 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
|
||||
@@ -18,7 +18,7 @@
|
||||
* 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
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
@@ -27,10 +27,11 @@ package org.alfresco.repo.security.authentication;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.management.subsystems.ActivateableBean;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent.UserNameValidationMode;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
|
||||
public class AuthenticationServiceImpl extends AbstractAuthenticationService
|
||||
public class AuthenticationServiceImpl extends AbstractAuthenticationService implements ActivateableBean
|
||||
{
|
||||
MutableAuthenticationDao authenticationDao;
|
||||
|
||||
@@ -65,6 +66,16 @@ public class AuthenticationServiceImpl extends AbstractAuthenticationService
|
||||
{
|
||||
this.authenticationComponent = authenticationComponent;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.management.subsystems.ActivateableBean#isActive()
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return !(this.authenticationComponent instanceof ActivateableBean)
|
||||
|| ((ActivateableBean) this.authenticationComponent).isActive();
|
||||
}
|
||||
|
||||
public void createAuthentication(String userName, char[] password) throws AuthenticationException
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2009 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
|
||||
@@ -18,7 +18,7 @@
|
||||
* 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
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
@@ -27,6 +27,7 @@ package org.alfresco.repo.security.authentication.ldap;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
|
||||
import org.alfresco.repo.management.subsystems.ActivateableBean;
|
||||
import org.alfresco.repo.security.authentication.AbstractAuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
|
||||
@@ -35,11 +36,13 @@ import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationComponent
|
||||
public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationComponent implements ActivateableBean
|
||||
{
|
||||
private boolean escapeCommasInBind = false;
|
||||
|
||||
private boolean escapeCommasInUid = false;
|
||||
|
||||
private boolean active = true;
|
||||
|
||||
private String userNameFormat;
|
||||
|
||||
@@ -69,6 +72,20 @@ public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationCompo
|
||||
{
|
||||
this.escapeCommasInUid = escapeCommasInUid;
|
||||
}
|
||||
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.management.subsystems.ActivateableBean#isActive()
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return this.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the authentication method
|
||||
|
@@ -1,782 +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.authentication.ldap;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attribute;
|
||||
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;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
public class LDAPGroupExportSource implements ExportSource, InitializingBean
|
||||
{
|
||||
private static Log s_logger = LogFactory.getLog(LDAPGroupExportSource.class);
|
||||
|
||||
private String groupQuery = "(objectclass=groupOfNames)";
|
||||
|
||||
private String searchBase;
|
||||
|
||||
private String groupIdAttributeName = "cn";
|
||||
|
||||
private String userIdAttributeName = "uid";
|
||||
|
||||
private String groupType = "groupOfNames";
|
||||
|
||||
private String personType = "inetOrgPerson";
|
||||
|
||||
private LDAPInitialDirContextFactory ldapInitialContextFactory;
|
||||
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
private String memberAttribute = "member";
|
||||
|
||||
private boolean errorOnMissingMembers = false;
|
||||
|
||||
private boolean errorOnDuplicateGID = false;
|
||||
|
||||
private QName viewRef;
|
||||
|
||||
private QName viewId;
|
||||
|
||||
private QName viewAssociations;
|
||||
|
||||
private QName childQName;
|
||||
|
||||
private QName viewValueQName;
|
||||
|
||||
private QName viewIdRef;
|
||||
|
||||
private AuthorityDAO authorityDAO;
|
||||
|
||||
private boolean errorOnMissingGID;
|
||||
|
||||
private boolean errorOnMissingUID;
|
||||
|
||||
public LDAPGroupExportSource()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public void setGroupIdAttributeName(String groupIdAttributeName)
|
||||
{
|
||||
this.groupIdAttributeName = groupIdAttributeName;
|
||||
}
|
||||
|
||||
public void setGroupQuery(String groupQuery)
|
||||
{
|
||||
this.groupQuery = groupQuery;
|
||||
}
|
||||
|
||||
public void setGroupType(String groupType)
|
||||
{
|
||||
this.groupType = groupType;
|
||||
}
|
||||
|
||||
public void setLDAPInitialDirContextFactory(LDAPInitialDirContextFactory ldapInitialDirContextFactory)
|
||||
{
|
||||
this.ldapInitialContextFactory = ldapInitialDirContextFactory;
|
||||
}
|
||||
|
||||
public void setMemberAttribute(String memberAttribute)
|
||||
{
|
||||
this.memberAttribute = memberAttribute;
|
||||
}
|
||||
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
public void setPersonType(String personType)
|
||||
{
|
||||
this.personType = personType;
|
||||
}
|
||||
|
||||
public void setSearchBase(String searchBase)
|
||||
{
|
||||
this.searchBase = searchBase;
|
||||
}
|
||||
|
||||
public void setUserIdAttributeName(String userIdAttributeName)
|
||||
{
|
||||
this.userIdAttributeName = userIdAttributeName;
|
||||
}
|
||||
|
||||
public void setErrorOnMissingMembers(boolean errorOnMissingMembers)
|
||||
{
|
||||
this.errorOnMissingMembers = errorOnMissingMembers;
|
||||
}
|
||||
|
||||
public void setErrorOnMissingGID(boolean errorOnMissingGID)
|
||||
{
|
||||
this.errorOnMissingGID = errorOnMissingGID;
|
||||
}
|
||||
|
||||
public void setErrorOnMissingUID(boolean errorOnMissingUID)
|
||||
{
|
||||
this.errorOnMissingUID = errorOnMissingUID;
|
||||
}
|
||||
|
||||
public void setErrorOnDuplicateGID(boolean errorOnDuplicateGID)
|
||||
{
|
||||
this.errorOnDuplicateGID = errorOnDuplicateGID;
|
||||
}
|
||||
|
||||
public void setAuthorityDAO(AuthorityDAO authorityDAO)
|
||||
{
|
||||
this.authorityDAO = authorityDAO;
|
||||
}
|
||||
|
||||
public void generateExport(XMLWriter writer)
|
||||
{
|
||||
HashSet<Group> rootGroups = new HashSet<Group>();
|
||||
HashMap<String, Group> lookup = new HashMap<String, Group>();
|
||||
HashSet<SecondaryLink> secondaryLinks = new HashSet<SecondaryLink>();
|
||||
|
||||
buildGroupsAndRoots(rootGroups, lookup, secondaryLinks);
|
||||
|
||||
buildXML(rootGroups, lookup, secondaryLinks, writer);
|
||||
|
||||
}
|
||||
|
||||
private void buildXML(HashSet<Group> rootGroups, HashMap<String, Group> lookup, HashSet<SecondaryLink> secondaryLinks, XMLWriter writer)
|
||||
{
|
||||
|
||||
Collection<String> prefixes = namespaceService.getPrefixes();
|
||||
QName childQName = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "childName", namespaceService);
|
||||
|
||||
try
|
||||
{
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, childQName.getLocalName(), childQName.toPrefixString(), null, ContentModel.TYPE_PERSON
|
||||
.toPrefixString(namespaceService));
|
||||
|
||||
writer.startDocument();
|
||||
|
||||
for (String prefix : prefixes)
|
||||
{
|
||||
if (!prefix.equals("xml"))
|
||||
{
|
||||
String uri = namespaceService.getNamespaceURI(prefix);
|
||||
writer.startPrefixMapping(prefix, uri);
|
||||
}
|
||||
}
|
||||
|
||||
writer.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, "view", NamespaceService.REPOSITORY_VIEW_PREFIX + ":" + "view", new AttributesImpl());
|
||||
|
||||
// Create group structure
|
||||
|
||||
for (Group group : rootGroups)
|
||||
{
|
||||
addRootGroup(lookup, group, writer);
|
||||
}
|
||||
|
||||
// Create secondary links.
|
||||
|
||||
for (SecondaryLink sl : secondaryLinks)
|
||||
{
|
||||
addSecondarylink(lookup, sl, writer);
|
||||
}
|
||||
|
||||
for (String prefix : prefixes)
|
||||
{
|
||||
if (!prefix.equals("xml"))
|
||||
{
|
||||
writer.endPrefixMapping(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
writer.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, "view", NamespaceService.REPOSITORY_VIEW_PREFIX + ":" + "view");
|
||||
|
||||
writer.endDocument();
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to create file for import.", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addSecondarylink(HashMap<String, Group> lookup, SecondaryLink sl, XMLWriter writer) throws SAXException
|
||||
{
|
||||
|
||||
String fromId = lookup.get(sl.from).guid;
|
||||
String toId = lookup.get(sl.to).guid;
|
||||
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute(viewIdRef.getNamespaceURI(), viewIdRef.getLocalName(), viewIdRef.toPrefixString(), null, fromId);
|
||||
|
||||
writer.startElement(viewRef.getNamespaceURI(), viewRef.getLocalName(), viewRef.toPrefixString(namespaceService), attrs);
|
||||
|
||||
writer.startElement(viewAssociations.getNamespaceURI(), viewAssociations.getLocalName(), viewAssociations.toPrefixString(namespaceService), new AttributesImpl());
|
||||
|
||||
writer.startElement(ContentModel.ASSOC_MEMBER.getNamespaceURI(), ContentModel.ASSOC_MEMBER.getLocalName(), ContentModel.ASSOC_MEMBER.toPrefixString(namespaceService),
|
||||
new AttributesImpl());
|
||||
|
||||
AttributesImpl attrsRef = new AttributesImpl();
|
||||
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));
|
||||
|
||||
writer.startElement(viewRef.getNamespaceURI(), viewRef.getLocalName(), viewRef.toPrefixString(namespaceService), attrsRef);
|
||||
|
||||
writer.endElement(viewRef.getNamespaceURI(), viewRef.getLocalName(), viewRef.toPrefixString(namespaceService));
|
||||
|
||||
writer.endElement(ContentModel.ASSOC_MEMBER.getNamespaceURI(), ContentModel.ASSOC_MEMBER.getLocalName(), ContentModel.ASSOC_MEMBER.toPrefixString(namespaceService));
|
||||
|
||||
writer.endElement(viewAssociations.getNamespaceURI(), viewAssociations.getLocalName(), viewAssociations.toPrefixString(namespaceService));
|
||||
|
||||
writer.endElement(viewRef.getNamespaceURI(), viewRef.getLocalName(), viewRef.toPrefixString(namespaceService));
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
writer.startElement(ContentModel.TYPE_AUTHORITY_CONTAINER.getNamespaceURI(), ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER
|
||||
.toPrefixString(namespaceService), attrs);
|
||||
|
||||
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.startElement(ContentModel.PROP_AUTHORITY_NAME.getNamespaceURI(), ContentModel.PROP_AUTHORITY_NAME.getLocalName(), ContentModel.PROP_AUTHORITY_NAME
|
||||
.toPrefixString(namespaceService), new AttributesImpl());
|
||||
|
||||
writer.characters(group.gid.toCharArray(), 0, group.gid.length());
|
||||
|
||||
writer.endElement(ContentModel.PROP_AUTHORITY_NAME.getNamespaceURI(), ContentModel.PROP_AUTHORITY_NAME.getLocalName(), ContentModel.PROP_AUTHORITY_NAME
|
||||
.toPrefixString(namespaceService));
|
||||
|
||||
if (group.members.size() > 0)
|
||||
{
|
||||
writer.startElement(ContentModel.PROP_MEMBERS.getNamespaceURI(), ContentModel.PROP_MEMBERS.getLocalName(), ContentModel.PROP_MEMBERS.toPrefixString(namespaceService),
|
||||
new AttributesImpl());
|
||||
|
||||
for (String member : group.members)
|
||||
{
|
||||
writer.startElement(viewValueQName.getNamespaceURI(), viewValueQName.getLocalName(), viewValueQName.toPrefixString(namespaceService), new AttributesImpl());
|
||||
|
||||
writer.characters(member.toCharArray(), 0, member.length());
|
||||
|
||||
writer.endElement(viewValueQName.getNamespaceURI(), viewValueQName.getLocalName(), viewValueQName.toPrefixString(namespaceService));
|
||||
}
|
||||
|
||||
writer.endElement(ContentModel.PROP_MEMBERS.getNamespaceURI(), ContentModel.PROP_MEMBERS.getLocalName(), ContentModel.PROP_MEMBERS.toPrefixString(namespaceService));
|
||||
}
|
||||
|
||||
for (Group child : group.children)
|
||||
{
|
||||
addgroup(lookup, child, writer);
|
||||
}
|
||||
|
||||
writer.endElement(ContentModel.TYPE_AUTHORITY_CONTAINER.getNamespaceURI(), ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER
|
||||
.toPrefixString(namespaceService));
|
||||
|
||||
}
|
||||
|
||||
private void addgroup(HashMap<String, Group> lookup, Group group, XMLWriter writer) throws SAXException
|
||||
{
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
|
||||
writer.startElement(ContentModel.ASSOC_MEMBER.getNamespaceURI(), ContentModel.ASSOC_MEMBER.getLocalName(), ContentModel.ASSOC_MEMBER.toPrefixString(namespaceService),
|
||||
attrs);
|
||||
|
||||
addRootGroup(lookup, group, writer);
|
||||
|
||||
writer.endElement(ContentModel.ASSOC_MEMBER.getNamespaceURI(), ContentModel.ASSOC_MEMBER.getLocalName(), ContentModel.ASSOC_MEMBER.toPrefixString(namespaceService));
|
||||
}
|
||||
|
||||
private void buildGroupsAndRoots(HashSet<Group> rootGroups, HashMap<String, Group> lookup, HashSet<SecondaryLink> secondaryLinks)
|
||||
{
|
||||
InitialDirContext ctx = null;
|
||||
try
|
||||
{
|
||||
ctx = ldapInitialContextFactory.getDefaultIntialDirContext();
|
||||
|
||||
SearchControls userSearchCtls = new SearchControls();
|
||||
userSearchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
|
||||
NamingEnumeration searchResults = ctx.search(searchBase, groupQuery, userSearchCtls);
|
||||
while (searchResults.hasMoreElements())
|
||||
{
|
||||
SearchResult result = (SearchResult) searchResults.next();
|
||||
Attributes attributes = result.getAttributes();
|
||||
Attribute gidAttribute = attributes.get(groupIdAttributeName);
|
||||
if (gidAttribute == null)
|
||||
{
|
||||
if (errorOnMissingGID)
|
||||
{
|
||||
throw new ExportSourceImporterException("Group returned by group search does not have mandatory group id attribute " + attributes);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_logger.warn("Missing GID on " + attributes);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
String gid = (String) gidAttribute.get(0);
|
||||
|
||||
Group group = lookup.get("GROUP_" + gid);
|
||||
if (group == null)
|
||||
{
|
||||
group = new Group(gid);
|
||||
lookup.put(group.gid, group);
|
||||
rootGroups.add(group);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (errorOnDuplicateGID)
|
||||
{
|
||||
throw new ExportSourceImporterException("Duplicate group id found for " + gid);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_logger.warn("Duplicate gid found for " + gid + " -> merging definitions");
|
||||
// Currently we will merge the two definitions together we do not support duplciate GIDs
|
||||
}
|
||||
}
|
||||
Attribute memAttribute = attributes.get(memberAttribute);
|
||||
// check for null
|
||||
if (memAttribute != null)
|
||||
{
|
||||
for (int i = 0; i < memAttribute.size(); i++)
|
||||
{
|
||||
String attribute = (String) memAttribute.get(i);
|
||||
if (attribute != null)
|
||||
{
|
||||
group.distinguishedNames.add(attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Found " + lookup.size());
|
||||
}
|
||||
|
||||
for (Group group : lookup.values())
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Linking " + group.gid);
|
||||
}
|
||||
for (String dn : group.distinguishedNames)
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("... " + dn);
|
||||
}
|
||||
String id;
|
||||
Boolean isGroup = null;
|
||||
|
||||
SearchControls memberSearchCtls = new SearchControls();
|
||||
memberSearchCtls.setSearchScope(SearchControls.OBJECT_SCOPE);
|
||||
NamingEnumeration memberSearchResults;
|
||||
try
|
||||
{
|
||||
memberSearchResults = ctx.search(dn, "(objectClass=*)", memberSearchCtls);
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
s_logger.warn("Failed to resolve distinguished name: " + dn);
|
||||
continue;
|
||||
}
|
||||
while (memberSearchResults.hasMoreElements())
|
||||
{
|
||||
id = null;
|
||||
|
||||
SearchResult result;
|
||||
try
|
||||
{
|
||||
result = (SearchResult) memberSearchResults.next();
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
s_logger.warn("Failed to resolve distinguished name: " + dn);
|
||||
continue;
|
||||
}
|
||||
Attributes attributes = result.getAttributes();
|
||||
Attribute objectclass = attributes.get("objectclass");
|
||||
if (objectclass == null)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to find attribute objectclass for DN " + dn);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < objectclass.size(); i++)
|
||||
{
|
||||
String testType;
|
||||
try
|
||||
{
|
||||
testType = (String) objectclass.get(i);
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
s_logger.warn("Failed to resolve object class attribute for distinguished name: " + dn);
|
||||
continue;
|
||||
}
|
||||
if (testType.equals(groupType))
|
||||
{
|
||||
isGroup = true;
|
||||
try
|
||||
{
|
||||
Attribute groupIdAttribute = attributes.get(groupIdAttributeName);
|
||||
if (groupIdAttribute == null)
|
||||
{
|
||||
if (errorOnMissingGID)
|
||||
{
|
||||
throw new ExportSourceImporterException("Group missing group id attribute DN =" + dn + " att = " + groupIdAttributeName);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_logger.warn("Group missing group id attribute DN =" + dn + " att = " + groupIdAttributeName);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
id = (String) groupIdAttribute.get(0);
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
s_logger.warn("Failed to resolve group identifier " + groupIdAttributeName + " for distinguished name: " + dn);
|
||||
id = "Unknown sub group";
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (testType.equals(personType))
|
||||
{
|
||||
isGroup = false;
|
||||
try
|
||||
{
|
||||
Attribute userIdAttribute = attributes.get(userIdAttributeName);
|
||||
if (userIdAttribute == null)
|
||||
{
|
||||
if (errorOnMissingUID)
|
||||
{
|
||||
throw new ExportSourceImporterException("User missing user id attribute DN =" + dn + " att = " + userIdAttributeName);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_logger.warn("User missing user id attribute DN =" + dn + " att = " + userIdAttributeName);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
id = (String) userIdAttribute.get(0);
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
s_logger.warn("Failed to resolve group identifier " + userIdAttributeName + " for distinguished name: " + dn);
|
||||
id = "Unknown member";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (id != null)
|
||||
{
|
||||
if (isGroup == null)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw new ExportSourceImporterException("Type not recognised for DN" + dn);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (isGroup)
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("... is sub group");
|
||||
}
|
||||
Group child = lookup.get("GROUP_" + id);
|
||||
if (child == null)
|
||||
{
|
||||
if (errorOnMissingMembers)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to find child group " + id);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (rootGroups.contains(child))
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("... Primary created from " + group.gid + " to " + child.gid);
|
||||
}
|
||||
group.children.add(child);
|
||||
rootGroups.remove(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("... Secondary created from " + group.gid + " to " + child.gid);
|
||||
}
|
||||
secondaryLinks.add(new SecondaryLink(group.gid, child.gid));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("... is member");
|
||||
}
|
||||
group.members.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Top " + rootGroups.size());
|
||||
s_logger.debug("Secondary " + secondaryLinks.size());
|
||||
}
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to import people.", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ctx != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ctx.close();
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to import people.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Group
|
||||
{
|
||||
String gid;
|
||||
|
||||
String guid = GUID.generate();
|
||||
|
||||
HashSet<Group> children = new HashSet<Group>();
|
||||
|
||||
HashSet<String> members = new HashSet<String>();
|
||||
|
||||
HashSet<String> distinguishedNames = new HashSet<String>();
|
||||
|
||||
private Group(String gid)
|
||||
{
|
||||
this.gid = "GROUP_" + gid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Group))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Group g = (Group) o;
|
||||
return this.gid.equals(g.gid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return gid.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
private static class SecondaryLink
|
||||
{
|
||||
String from;
|
||||
|
||||
String to;
|
||||
|
||||
private SecondaryLink(String from, String to)
|
||||
{
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Group))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SecondaryLink l = (SecondaryLink) o;
|
||||
return EqualsHelper.nullSafeEquals(this.from, l.from) && EqualsHelper.nullSafeEquals(this.to, l.to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hashCode = 0;
|
||||
if (from != null)
|
||||
{
|
||||
hashCode = hashCode * 37 + from.hashCode();
|
||||
}
|
||||
if (to != null)
|
||||
{
|
||||
hashCode = hashCode * 37 + to.hashCode();
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Define output format
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
format.setNewLineAfterDeclaration(false);
|
||||
format.setIndentSize(3);
|
||||
format.setEncoding("UTF-8");
|
||||
|
||||
// Construct an XML Exporter
|
||||
|
||||
XMLWriter xmlWriter = new XMLWriter(writer, format);
|
||||
return xmlWriter;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
viewRef = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "reference", namespaceService);
|
||||
viewId = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "id", namespaceService);
|
||||
viewIdRef = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "idref", namespaceService);
|
||||
viewAssociations = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "associations", namespaceService);
|
||||
childQName = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "childName", namespaceService);
|
||||
viewValueQName = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "value", namespaceService);
|
||||
|
||||
}
|
||||
}
|
@@ -1,341 +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.authentication.ldap;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attribute;
|
||||
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.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;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.xml.sax.SAXException;
|
||||
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;
|
||||
|
||||
private String userIdAttributeName;
|
||||
|
||||
private LDAPInitialDirContextFactory ldapInitialContextFactory;
|
||||
|
||||
private PersonService personService;
|
||||
|
||||
private Map<String, String> attributeMapping;
|
||||
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
private Map<String, String> attributeDefaults;
|
||||
|
||||
private boolean errorOnMissingUID;
|
||||
|
||||
public LDAPPersonExportSource()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public void setPersonQuery(String personQuery)
|
||||
{
|
||||
this.personQuery = personQuery;
|
||||
}
|
||||
|
||||
public void setSearchBase(String searchBase)
|
||||
{
|
||||
this.searchBase = searchBase;
|
||||
}
|
||||
|
||||
public void setUserIdAttributeName(String userIdAttributeName)
|
||||
{
|
||||
this.userIdAttributeName = userIdAttributeName;
|
||||
}
|
||||
|
||||
public void setLDAPInitialDirContextFactory(LDAPInitialDirContextFactory ldapInitialDirContextFactory)
|
||||
{
|
||||
this.ldapInitialContextFactory = ldapInitialDirContextFactory;
|
||||
}
|
||||
|
||||
public void setPersonService(PersonService personService)
|
||||
{
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
public void setAttributeDefaults(Map<String, String> attributeDefaults)
|
||||
{
|
||||
this.attributeDefaults = attributeDefaults;
|
||||
}
|
||||
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
public void setAttributeMapping(Map<String, String> attributeMapping)
|
||||
{
|
||||
this.attributeMapping = attributeMapping;
|
||||
}
|
||||
|
||||
public void setErrorOnMissingUID(boolean errorOnMissingUID)
|
||||
{
|
||||
this.errorOnMissingUID = errorOnMissingUID;
|
||||
}
|
||||
|
||||
public void generateExport(XMLWriter writer)
|
||||
{
|
||||
QName nodeUUID = QName.createQName("sys:node-uuid", namespaceService);
|
||||
|
||||
Collection<String> prefixes = namespaceService.getPrefixes();
|
||||
QName childQName = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, "childName", namespaceService);
|
||||
|
||||
try
|
||||
{
|
||||
writer.startDocument();
|
||||
|
||||
for (String prefix : prefixes)
|
||||
{
|
||||
if (!prefix.equals("xml"))
|
||||
{
|
||||
String uri = namespaceService.getNamespaceURI(prefix);
|
||||
writer.startPrefixMapping(prefix, uri);
|
||||
}
|
||||
}
|
||||
|
||||
writer.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, "view",
|
||||
NamespaceService.REPOSITORY_VIEW_PREFIX + ":" + "view", new AttributesImpl());
|
||||
|
||||
HashSet<String> uids = new HashSet<String>();
|
||||
|
||||
InitialDirContext ctx = null;
|
||||
try
|
||||
{
|
||||
ctx = ldapInitialContextFactory.getDefaultIntialDirContext();
|
||||
|
||||
// Authentication has been successful.
|
||||
// Set the current user, they are now authenticated.
|
||||
|
||||
SearchControls userSearchCtls = new SearchControls();
|
||||
userSearchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
|
||||
userSearchCtls.setCountLimit(Integer.MAX_VALUE);
|
||||
|
||||
NamingEnumeration<SearchResult> searchResults = ctx.search(searchBase, personQuery, userSearchCtls);
|
||||
RESULT_LOOP: while (searchResults.hasMoreElements())
|
||||
{
|
||||
SearchResult result = (SearchResult) searchResults.next();
|
||||
Attributes attributes = result.getAttributes();
|
||||
Attribute uidAttribute = attributes.get(userIdAttributeName);
|
||||
if (uidAttribute == null)
|
||||
{
|
||||
if (errorOnMissingUID)
|
||||
{
|
||||
throw new ExportSourceImporterException(
|
||||
"User returned by user search does not have mandatory user id attribute "
|
||||
+ attributes);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_logger.warn("User returned by user search does not have mandatory user id attribute "
|
||||
+ attributes);
|
||||
continue RESULT_LOOP;
|
||||
}
|
||||
}
|
||||
String uid = (String) uidAttribute.get(0);
|
||||
|
||||
if (uids.contains(uid))
|
||||
{
|
||||
s_logger.warn("Duplicate uid found - there will be more than one person object for this user - "
|
||||
+ uid);
|
||||
}
|
||||
|
||||
uids.add(uid);
|
||||
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Adding user for " + uid);
|
||||
}
|
||||
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, childQName.getLocalName(), childQName
|
||||
.toPrefixString(), null, QName.createQName("cm", uid, namespaceService).toPrefixString(namespaceService));
|
||||
|
||||
writer.startElement(ContentModel.TYPE_PERSON.getNamespaceURI(), ContentModel.TYPE_PERSON
|
||||
.getLocalName(), ContentModel.TYPE_PERSON.toPrefixString(namespaceService), attrs);
|
||||
|
||||
for (String key : attributeMapping.keySet())
|
||||
{
|
||||
QName keyQName = QName.createQName(key, namespaceService);
|
||||
|
||||
writer.startElement(keyQName.getNamespaceURI(), keyQName.getLocalName(), keyQName
|
||||
.toPrefixString(namespaceService), new AttributesImpl());
|
||||
|
||||
// cater for null
|
||||
String attributeName = attributeMapping.get(key);
|
||||
if (attributeName != null)
|
||||
{
|
||||
Attribute attribute = attributes.get(attributeName);
|
||||
if (attribute != null)
|
||||
{
|
||||
String value = (String) attribute.get(0);
|
||||
if (value != null)
|
||||
{
|
||||
writer.characters(value.toCharArray(), 0, value.length());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String defaultValue = attributeDefaults.get(key);
|
||||
if (defaultValue != null)
|
||||
{
|
||||
writer.characters(defaultValue.toCharArray(), 0, defaultValue.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String defaultValue = attributeDefaults.get(key);
|
||||
if (defaultValue != null)
|
||||
{
|
||||
writer.characters(defaultValue.toCharArray(), 0, defaultValue.length());
|
||||
}
|
||||
}
|
||||
|
||||
writer.endElement(keyQName.getNamespaceURI(), keyQName.getLocalName(), keyQName
|
||||
.toPrefixString(namespaceService));
|
||||
}
|
||||
|
||||
if (personService.personExists(uid))
|
||||
{
|
||||
String uguid = personService.getPerson(uid).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_PERSON.getNamespaceURI(), ContentModel.TYPE_PERSON
|
||||
.getLocalName(), ContentModel.TYPE_PERSON.toPrefixString(namespaceService));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to import people.", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ctx != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ctx.close();
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to import people.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String prefix : prefixes)
|
||||
{
|
||||
if (!prefix.equals("xml"))
|
||||
{
|
||||
writer.endPrefixMapping(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
writer.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, "view", NamespaceService.REPOSITORY_VIEW_PREFIX
|
||||
+ ":" + "view");
|
||||
|
||||
writer.endDocument();
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExportSourceImporterException("Failed to create file for import.", e);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Define output format
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
format.setNewLineAfterDeclaration(false);
|
||||
format.setIndentSize(3);
|
||||
format.setEncoding("UTF-8");
|
||||
|
||||
// Construct an XML Exporter
|
||||
|
||||
XMLWriter xmlWriter = new XMLWriter(writer, format);
|
||||
return xmlWriter;
|
||||
}
|
||||
}
|
@@ -28,6 +28,7 @@ import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.management.subsystems.ActivateableBean;
|
||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextManager;
|
||||
import org.alfresco.repo.security.authentication.AbstractChainingAuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
@@ -80,7 +81,15 @@ public class SubsystemChainingAuthenticationComponent extends AbstractChainingAu
|
||||
ApplicationContext context = this.applicationContextManager.getApplicationContext(instance);
|
||||
try
|
||||
{
|
||||
result.add((AuthenticationComponent) context.getBean(sourceBeanName));
|
||||
AuthenticationComponent authenticationComponent = (AuthenticationComponent) context
|
||||
.getBean(sourceBeanName);
|
||||
// Only add active authentication components. E.g. we might have an ldap context that is only used for
|
||||
// synchronizing
|
||||
if (!(authenticationComponent instanceof ActivateableBean)
|
||||
|| ((ActivateableBean) authenticationComponent).isActive())
|
||||
{
|
||||
result.add(authenticationComponent);
|
||||
}
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e)
|
||||
{
|
||||
|
@@ -27,6 +27,7 @@ package org.alfresco.repo.security.authentication.subsystems;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.management.subsystems.ActivateableBean;
|
||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextManager;
|
||||
import org.alfresco.repo.security.authentication.AbstractChainingAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
@@ -83,7 +84,15 @@ public class SubsystemChainingAuthenticationService extends AbstractChainingAuth
|
||||
ApplicationContext context = this.applicationContextManager.getApplicationContext(instance);
|
||||
try
|
||||
{
|
||||
return (AuthenticationService) context.getBean(sourceBeanName);
|
||||
AuthenticationService authenticationService = (AuthenticationService) context.getBean(sourceBeanName);
|
||||
// Only add active authentication services. E.g. we might have an ldap context that is only used for
|
||||
// synchronizing
|
||||
if (!(authenticationService instanceof ActivateableBean)
|
||||
|| ((ActivateableBean) authenticationService).isActive())
|
||||
{
|
||||
|
||||
return authenticationService;
|
||||
}
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e)
|
||||
{
|
||||
@@ -107,7 +116,15 @@ public class SubsystemChainingAuthenticationService extends AbstractChainingAuth
|
||||
ApplicationContext context = this.applicationContextManager.getApplicationContext(instance);
|
||||
try
|
||||
{
|
||||
result.add((AuthenticationService) context.getBean(sourceBeanName));
|
||||
AuthenticationService authenticationService = (AuthenticationService) context.getBean(sourceBeanName);
|
||||
// Only add active authentication components. E.g. we might have an ldap context that is only used for
|
||||
// synchronizing
|
||||
if (!(authenticationService instanceof ActivateableBean)
|
||||
|| ((ActivateableBean) authenticationService).isActive())
|
||||
{
|
||||
|
||||
result.add(authenticationService);
|
||||
}
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e)
|
||||
{
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
<description>Alfresco User Model</description>
|
||||
<author>Alfresco</author>
|
||||
<published>2005-08-16</published>
|
||||
<version>0.1</version>
|
||||
<published>2009-06-04</published>
|
||||
<version>0.2</version>
|
||||
|
||||
<imports>
|
||||
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
<constraints>
|
||||
<constraint name="usr:userNameConstraint" type="org.alfresco.repo.dictionary.constraint.UserNameConstraint" />
|
||||
<constraint name="usr:authorityNameConstraint" type="org.alfresco.repo.dictionary.constraint.AuthorityNameConstraint" />
|
||||
</constraints>
|
||||
|
||||
<types>
|
||||
@@ -75,42 +74,6 @@
|
||||
</properties>
|
||||
</type>
|
||||
|
||||
<type name="usr:authorityContainer">
|
||||
<title>Alfresco Authority Type</title>
|
||||
<parent>usr:authority</parent>
|
||||
<properties>
|
||||
<!-- The tokenisation set here is ignored - it is fixed for this type -->
|
||||
<!-- This is so you can not break group lookup -->
|
||||
<property name="usr:authorityName">
|
||||
<type>d:text</type>
|
||||
<constraints>
|
||||
<constraint ref="usr:authorityNameConstraint" />
|
||||
</constraints>
|
||||
</property>
|
||||
<property name="usr:members">
|
||||
<type>d:text</type>
|
||||
<multiple>true</multiple>
|
||||
</property>
|
||||
<property name="usr:authorityDisplayName">
|
||||
<type>d:text</type>
|
||||
</property>
|
||||
</properties>
|
||||
<associations>
|
||||
<child-association name="usr:member">
|
||||
<source>
|
||||
<mandatory>false</mandatory>
|
||||
<many>true</many>
|
||||
</source>
|
||||
<target>
|
||||
<class>usr:authority</class>
|
||||
<mandatory>false</mandatory>
|
||||
<many>true</many>
|
||||
</target>
|
||||
<duplicate>false</duplicate>
|
||||
</child-association>
|
||||
</associations>
|
||||
</type>
|
||||
|
||||
</types>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user