Ported to Liferay 6.2 API
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/ldap-export-servlet@129867 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
48ca69e423
commit
2c01090876
|
@ -1,5 +1,10 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
<Changeset component="org.gcube.portal.ldap-export-servlet.1-0-0" date="2015-12-11">
|
<Changeset component="org.gcube.portal.ldap-export-servlet.1-1-0"
|
||||||
|
date="2016-07-04">
|
||||||
|
<Change>Updated to use Liferay 6.2 API</Change>
|
||||||
|
</Changeset>
|
||||||
|
<Changeset component="org.gcube.portal.ldap-export-servlet.1-0-0"
|
||||||
|
date="2015-12-11">
|
||||||
<Change>First Release</Change>
|
<Change>First Release</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
</ReleaseNotes>
|
</ReleaseNotes>
|
||||||
|
|
|
@ -38,10 +38,5 @@
|
||||||
<source>target/${build.finalName}.war</source>
|
<source>target/${build.finalName}.war</source>
|
||||||
<outputDirectory>/${artifactId}</outputDirectory>
|
<outputDirectory>/${artifactId}</outputDirectory>
|
||||||
</file>
|
</file>
|
||||||
<file>
|
|
||||||
<source>${distroDirectory}/svnpath.txt</source>
|
|
||||||
<outputDirectory>/${artifactId}</outputDirectory>
|
|
||||||
<filtered>true</filtered>
|
|
||||||
</file>
|
|
||||||
</files>
|
</files>
|
||||||
</assembly>
|
</assembly>
|
|
@ -6,7 +6,7 @@
|
||||||
<Description>${description}</Description>
|
<Description>${description}</Description>
|
||||||
<Class>Portal</Class>
|
<Class>Portal</Class>
|
||||||
<Name>${artifactId}</Name>
|
<Name>${artifactId}</Name>
|
||||||
<Version>1.0.0</Version>
|
<Version>${version}</Version>
|
||||||
<Packages>
|
<Packages>
|
||||||
<Software>
|
<Software>
|
||||||
<Name>${artifactId}</Name>
|
<Name>${artifactId}</Name>
|
||||||
|
|
9
pom.xml
9
pom.xml
|
@ -11,13 +11,13 @@
|
||||||
<groupId>org.gcube.portal</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
<artifactId>ldap-export-servlet</artifactId>
|
<artifactId>ldap-export-servlet</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
<name>ldap-export-servlet Maven Webapp</name>
|
<name>ldap-export-servlet Maven Webapp</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<description>This component read periodically exports users and their groups in LDAP</description>
|
<description>This component read periodically exports users and their groups in LDAP</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java-version>1.7</java-version>
|
<java-version>1.7</java-version>
|
||||||
<liferay-version>6.0.6</liferay-version>
|
<liferay-version>6.2.5</liferay-version>
|
||||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||||
<distroDirectory>distro</distroDirectory>
|
<distroDirectory>distro</distroDirectory>
|
||||||
|
@ -51,6 +51,11 @@
|
||||||
<artifactId>custom-portal-handler</artifactId>
|
<artifactId>custom-portal-handler</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.dvos</groupId>
|
||||||
|
<artifactId>usermanagement-core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources.discovery</groupId>
|
<groupId>org.gcube.resources.discovery</groupId>
|
||||||
<artifactId>ic-client</artifactId>
|
<artifactId>ic-client</artifactId>
|
||||||
|
|
|
@ -18,16 +18,15 @@ import javax.naming.directory.SearchControls;
|
||||||
import javax.naming.directory.SearchResult;
|
import javax.naming.directory.SearchResult;
|
||||||
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
|
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
|
||||||
import com.liferay.portal.kernel.exception.PortalException;
|
|
||||||
import com.liferay.portal.kernel.exception.SystemException;
|
import com.liferay.portal.kernel.exception.SystemException;
|
||||||
import com.liferay.portal.model.Organization;
|
|
||||||
import com.liferay.portal.model.User;
|
import com.liferay.portal.model.User;
|
||||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
public class LDAPSync implements Runnable {
|
public class LDAPSync implements Runnable {
|
||||||
|
@ -56,22 +55,15 @@ public class LDAPSync implements Runnable {
|
||||||
*
|
*
|
||||||
* @return the Liferay mapped as Root Organization
|
* @return the Liferay mapped as Root Organization
|
||||||
*/
|
*/
|
||||||
private Organization getRootVO() {
|
private GCubeGroup getRootVO() {
|
||||||
String rootVoName = PortalContext.getConfiguration().getInfrastructureName();
|
|
||||||
_log.debug("Root organization name found: " + rootVoName);
|
|
||||||
|
|
||||||
//start of iteration of the actual groups
|
|
||||||
List<Organization> organizations;
|
|
||||||
try {
|
try {
|
||||||
organizations = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount());
|
GroupManager gm = new LiferayGroupManager();
|
||||||
for (Organization organization : organizations) {
|
String rootVoName = gm.getRootVOName();
|
||||||
if (organization.getName().equals(rootVoName)) {
|
_log.debug("Root organization name found: " + rootVoName);
|
||||||
return organization;
|
return gm.getGroup(gm.getGroupIdFromInfrastructureScope("/"+rootVoName));
|
||||||
}
|
}
|
||||||
}
|
catch (Exception e) {
|
||||||
}
|
_log.error("There were problems retrieving root VO group", e);
|
||||||
catch (SystemException e) {
|
|
||||||
_log.error("There were problems retrieving root organization", e);
|
|
||||||
}
|
}
|
||||||
_log.error("Could not find any root organization");
|
_log.error("Could not find any root organization");
|
||||||
return null;
|
return null;
|
||||||
|
@ -91,7 +83,7 @@ public class LDAPSync implements Runnable {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
_log.debug("Reading Portal Organizations ...");
|
_log.debug("Reading Portal Organizations ...");
|
||||||
Organization rootVO = getRootVO();
|
GCubeGroup rootVO = getRootVO();
|
||||||
|
|
||||||
_log.debug("Initializing LDAP exporter ...");
|
_log.debug("Initializing LDAP exporter ...");
|
||||||
|
|
||||||
|
@ -163,18 +155,18 @@ public class LDAPSync implements Runnable {
|
||||||
* @throws NamingException
|
* @throws NamingException
|
||||||
* @throws SystemException
|
* @throws SystemException
|
||||||
*/
|
*/
|
||||||
private void updateGroups(DirContext ctx, Organization root) throws NamingException, SystemException {
|
private void updateGroups(DirContext ctx, GCubeGroup root) throws NamingException, SystemException {
|
||||||
String subCtx = getOrgSubContext(root.getName());
|
String subCtx = getOrgSubContext(root.getGroupName());
|
||||||
if (!checkIfLDAPOrganizationalUnitExists(ctx, subCtx))
|
if (!checkIfLDAPOrganizationalUnitExists(ctx, subCtx))
|
||||||
createOrganizationalUnit(ctx, subCtx);
|
createOrganizationalUnit(ctx, subCtx);
|
||||||
for (Organization org : root.getSuborganizations()) {
|
for (GCubeGroup vo : root.getChildren()) {
|
||||||
String orgSubCtx = "ou="+org.getName()+","+subCtx;
|
String orgSubCtx = "ou="+vo.getGroupName()+","+subCtx;
|
||||||
if (!checkIfLDAPOrganizationalUnitExists(ctx, orgSubCtx))
|
if (!checkIfLDAPOrganizationalUnitExists(ctx, orgSubCtx))
|
||||||
createOrganizationalUnit(ctx, orgSubCtx);
|
createOrganizationalUnit(ctx, orgSubCtx);
|
||||||
for (Organization vre : org.getSuborganizations()) {
|
for (GCubeGroup vre : vo.getChildren()) {
|
||||||
String vreSubCtx = "cn="+vre.getName()+","+orgSubCtx;
|
String vreSubCtx = "cn="+vre.getGroupName()+","+orgSubCtx;
|
||||||
if (!checkIfLDAPGroupExists(ctx, vreSubCtx))
|
if (!checkIfLDAPGroupExists(ctx, vreSubCtx))
|
||||||
createGroupVRE(ctx, vreSubCtx, vre.getName());
|
createGroupVRE(ctx, vreSubCtx, vre.getGroupName());
|
||||||
//update the list of users in such VRE
|
//update the list of users in such VRE
|
||||||
updateUsersInGroup(ctx, vreSubCtx, vre);
|
updateUsersInGroup(ctx, vreSubCtx, vre);
|
||||||
}
|
}
|
||||||
|
@ -188,8 +180,8 @@ public class LDAPSync implements Runnable {
|
||||||
* @throws NamingException
|
* @throws NamingException
|
||||||
* @throws SystemException
|
* @throws SystemException
|
||||||
*/
|
*/
|
||||||
private void updateUsersInGroup(DirContext ctx, String vreSubCtx, Organization vre) throws NamingException, SystemException {
|
private void updateUsersInGroup(DirContext ctx, String vreSubCtx, GCubeGroup vre) throws NamingException, SystemException {
|
||||||
List<User> users = UserLocalServiceUtil.getOrganizationUsers(vre.getOrganizationId());
|
List<User> users = UserLocalServiceUtil.getGroupUsers(vre.getGroupId());
|
||||||
for (User userObj : users) {
|
for (User userObj : users) {
|
||||||
String user = userObj.getScreenName();
|
String user = userObj.getScreenName();
|
||||||
try {
|
try {
|
||||||
|
@ -211,7 +203,7 @@ public class LDAPSync implements Runnable {
|
||||||
private void exportSingleUsers(DirContext ctx, Properties env, List<User> users) throws NamingException {
|
private void exportSingleUsers(DirContext ctx, Properties env, List<User> users) throws NamingException {
|
||||||
for (User user : users) {
|
for (User user : users) {
|
||||||
updateUserInLDAP(user.getScreenName(), user.getFirstName(), user.getLastName(), user.getFullName(), user.getEmailAddress(), "{SHA}"+user.getPassword(), ctx, filter);
|
updateUserInLDAP(user.getScreenName(), user.getFirstName(), user.getLastName(), user.getFullName(), user.getEmailAddress(), "{SHA}"+user.getPassword(), ctx, filter);
|
||||||
//_log.debug("Updated " + user.getScreenName());
|
_log.debug("Updated " + user.getScreenName());
|
||||||
}
|
}
|
||||||
_log.debug("LDAP Users Sync cycle done");
|
_log.debug("LDAP Users Sync cycle done");
|
||||||
if (! users.isEmpty())
|
if (! users.isEmpty())
|
||||||
|
@ -407,14 +399,12 @@ public class LDAPSync implements Runnable {
|
||||||
private List<User> getAllLiferayUsers() {
|
private List<User> getAllLiferayUsers() {
|
||||||
String infraName = PortalContext.getConfiguration().getInfrastructureName();
|
String infraName = PortalContext.getConfiguration().getInfrastructureName();
|
||||||
_log.info("TRY Reading non chached users belonging to: /" + infraName);
|
_log.info("TRY Reading non chached users belonging to: /" + infraName);
|
||||||
|
|
||||||
List<User> toReturn = new ArrayList<User>();
|
List<User> toReturn = new ArrayList<User>();
|
||||||
Organization rootInfra;
|
|
||||||
try {
|
try {
|
||||||
CacheRegistryUtil.clear(); //needed to avoid cache use by liferay API
|
CacheRegistryUtil.clear(); //needed to avoid cache use by liferay API
|
||||||
rootInfra = OrganizationLocalServiceUtil.getOrganization(OrganizationsUtil.getCompany().getCompanyId(), infraName);
|
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope("/" + infraName);
|
||||||
toReturn = UserLocalServiceUtil.getOrganizationUsers(rootInfra.getOrganizationId());
|
toReturn = UserLocalServiceUtil.getGroupUsers(groupId);
|
||||||
} catch (PortalException | SystemException e) {
|
} catch (Exception e) {
|
||||||
_log.error("Error during LDAP Sync, could not retrieve users from LR DB: " + e.getMessage());
|
_log.error("Error during LDAP Sync, could not retrieve users from LR DB: " + e.getMessage());
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<!DOCTYPE web-app PUBLIC
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
"http://java.sun.com/dtd/web-app_2_3.dtd" >
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||||
<web-app>
|
version="3.0">
|
||||||
<display-name>LDAP Export servlet</display-name>
|
<display-name>LDAP Export servlet</display-name>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
|
Reference in New Issue