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