added virtual groups management

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@125711 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-03-18 11:19:10 +00:00
parent 59a3786158
commit 321512e876
5 changed files with 154 additions and 31 deletions

View File

@ -9,8 +9,10 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementNameExcepti
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
/** /**
@ -86,12 +88,19 @@ public interface GroupManager {
GCubeGroup getGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault; GCubeGroup getGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault;
/** /**
* Virtual Groups are handled as Custom attributes in Liferay Sites table * Virtual Groups are handled as Custom attributes in Liferay Sites table
* @param groupId the LR groupId * @param actualGroupId the LR groupId
* @return the virtual group list available
* @throws GroupRetrievalFault
*/
List<VirtualGroup> getVirtualGroups() throws VirtualGroupNotExistingException;
/**
* Virtual Groups are handled as Custom attributes in Liferay Sites table
* @param actualGroupId the LR groupId
* @return the virtual group name associated to this group * @return the virtual group name associated to this group
* @throws GroupRetrievalFault * @throws GroupRetrievalFault
*/ */
String getVirtualGroupName(long groupId) throws GroupRetrievalFault; VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException;
/** /*
* *
* @param scope the infrastructure scope e.g. /gcube/devsec * @param scope the infrastructure scope e.g. /gcube/devsec
* @return the LR groupId, -1 otherwise * @return the LR groupId, -1 otherwise

View File

@ -2,15 +2,8 @@ package org.gcube.vomanagement.usermanagement.exception;
import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.PortalException;
@SuppressWarnings("serial")
public class GroupRetrievalFault extends Exception{ public class GroupRetrievalFault extends Exception{
/**
*
*/
private static final long serialVersionUID = -5809619725100397844L;
public GroupRetrievalFault(String errorMsg, String orgId ){ public GroupRetrievalFault(String errorMsg, String orgId ){
System.out.println(errorMsg + orgId); System.out.println(errorMsg + orgId);

View File

@ -0,0 +1,14 @@
package org.gcube.vomanagement.usermanagement.exception;
import com.liferay.portal.kernel.exception.PortalException;
@SuppressWarnings("serial")
public class VirtualGroupNotExistingException extends Exception {
public VirtualGroupNotExistingException(String errorMsg, PortalException e){
System.out.println(errorMsg);
e.printStackTrace();
}
public VirtualGroupNotExistingException(String errorMsg){
System.out.println(errorMsg);
}
}

View File

@ -2,6 +2,7 @@ package org.gcube.vomanagement.usermanagement.impl;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -14,8 +15,10 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementNameExcepti
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
import org.gcube.vomanagement.usermanagement.util.ManagementUtils; import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,6 +42,8 @@ import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.RoleServiceUtil; import com.liferay.portal.service.RoleServiceUtil;
import com.liferay.portal.service.ServiceContext; import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
public class LiferayGroupManager implements GroupManager { public class LiferayGroupManager implements GroupManager {
/** /**
@ -109,29 +114,64 @@ public class LiferayGroupManager implements GroupManager {
} }
return group; return group;
} }
/**
public String getVirtualGroupName(long groupId) throws GroupRetrievalFault { * {@inheritDoc}
try { */
_log.debug("Setting Thread Permission"); @Override
long userId = LiferayUserManager.getAdmin().getUserId(); public VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException {
PrincipalThreadLocal.setName(userId); VirtualGroup toReturn = new VirtualGroup();
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId)); try {
PermissionThreadLocal.setPermissionChecker(permissionChecker); _log.debug("Setting Thread Permission");
Group site = GroupLocalServiceUtil.getGroup(groupId); long userId = LiferayUserManager.getAdmin().getUserId();
if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) { PrincipalThreadLocal.setName(userId);
_log.warn(String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName())); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId));
return null; PermissionThreadLocal.setPermissionChecker(permissionChecker);
} else { Group site = GroupLocalServiceUtil.getGroup(actualGroupId);
String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) {
if (values != null) String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
return values[0]; _log.warn(warningMessage);
else return ""; throw new VirtualGroupNotExistingException(warningMessage);
} else {
String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
if (values != null) {
String[] splits = values[0].split("\\|");
toReturn.setName(splits[0]);
toReturn.setDescription(splits[1]);
} }
} catch (Exception e) {
e.printStackTrace();
return "Exception ";
} }
} catch (Exception e) {
e.printStackTrace();
} }
return null;
}
/**
* {@inheritDoc}
*/
@Override
public List<VirtualGroup> getVirtualGroups() throws VirtualGroupNotExistingException {
ExpandoBridge expandoBridge = null;
List<VirtualGroup> toReturn = new ArrayList<VirtualGroup>();
try {
expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(ManagementUtils.getCompany().getCompanyId(), Group.class.getName());
String[] groups = (String[]) expandoBridge.getAttributeDefault(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
List<String> virtualGroups = Arrays.asList(groups);
for (String vg : virtualGroups) {
String[] splits = vg.split("\\|");
String gName = splits[0];
String gDescription = splits[1];
toReturn.add(new VirtualGroup(gName, gDescription));
}
} catch (PortalException e) {
throw new VirtualGroupNotExistingException("", e);
} catch (SystemException e) {
e.printStackTrace();
}
return toReturn;
}
/**
* {@inheritDoc}
*/
@Override @Override
public GCubeGroup createRootVO(String rootVOName, String description) throws UserManagementNameException, UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault, UserManagementPortalException { public GCubeGroup createRootVO(String rootVOName, String description) throws UserManagementNameException, UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault, UserManagementPortalException {
Group group = null; Group group = null;
@ -147,6 +187,9 @@ public class LiferayGroupManager implements GroupManager {
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public GCubeGroup createVO(String virtualOrgName, long rootVOGroupId, String description) throws UserManagementNameException, public GCubeGroup createVO(String virtualOrgName, long rootVOGroupId, String description) throws UserManagementNameException,
UserManagementSystemException, UserRetrievalFault, UserManagementSystemException, UserRetrievalFault,
@ -163,6 +206,9 @@ public class LiferayGroupManager implements GroupManager {
} }
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public GCubeGroup createVRE(String virtualResearchEnvName, long virtualOrgGroupId, String description) throws UserManagementNameException, public GCubeGroup createVRE(String virtualResearchEnvName, long virtualOrgGroupId, String description) throws UserManagementNameException,
UserManagementSystemException, UserRetrievalFault, UserManagementSystemException, UserRetrievalFault,

View File

@ -0,0 +1,61 @@
package org.gcube.vomanagement.usermanagement.model;
import java.io.Serializable;
/**
*
* @author Massimiliano Assante, CNR-ISTI
* Virtual Groups are another way to group VREs indipendently from the scope,
* they are modeled as Custom attributes in Liferay Sites table wtih
*/
@SuppressWarnings("serial")
public class VirtualGroup implements Serializable{
private String name;
private String description;
public VirtualGroup() {}
public VirtualGroup(String name, String description) {
super();
this.name = name;
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "VirtualGroup [name=" + name + ", description=" + description
+ "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VirtualGroup other = (VirtualGroup) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}