Now gcube's user, group and role managers are used to get related names and context is URL encoded as per Keycloak's needs
This commit is contained in:
parent
5a58818701
commit
7f5ea195d6
|
@ -5,7 +5,11 @@ import java.net.UnknownHostException;
|
|||
import java.util.Map;
|
||||
|
||||
import org.gcube.event.publisher.Event;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
|
@ -18,6 +22,8 @@ public class PortalEvent extends Event {
|
|||
|
||||
protected static final Log log = LogFactoryUtil.getLog(PortalEvent.class);
|
||||
|
||||
protected static final UserManager USER_MANAGER = new LiferayUserManager();
|
||||
|
||||
private static String rootVOName;
|
||||
|
||||
public static final String TYPE = "portal";
|
||||
|
@ -67,7 +73,12 @@ public class PortalEvent extends Event {
|
|||
}
|
||||
|
||||
protected static String getUserIdentifier(User user) {
|
||||
return user.getScreenName();
|
||||
try {
|
||||
return USER_MANAGER.getUserById(user.getUserId()).getUsername();
|
||||
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot get username for user: " + user, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
package org.gcube.portal.event.publisher.lr62.model;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
|
@ -17,6 +26,9 @@ public class PortalModelListenerEvent<T extends BaseModel<T>> extends PortalEven
|
|||
|
||||
public static final String MODELCLASSNAME_ENTRY = "model-class-name";
|
||||
|
||||
protected static final GroupManager GROUP_MANAGER = new LiferayGroupManager();
|
||||
protected static final RoleManager ROLE_MANAGER = new LiferayRoleManager();
|
||||
|
||||
public PortalModelListenerEvent(String name, T baseModel) {
|
||||
super(name);
|
||||
setModelClassName(baseModel.getModelClassName());
|
||||
|
@ -47,7 +59,12 @@ public class PortalModelListenerEvent<T extends BaseModel<T>> extends PortalEven
|
|||
}
|
||||
|
||||
protected static String getGroupIdentifier(Group group) throws PortalException, SystemException {
|
||||
return group.getDescriptiveName();
|
||||
try {
|
||||
return URLEncoder.encode(GROUP_MANAGER.getInfrastructureScope(group.getGroupId()), "UTF-8");
|
||||
} catch (UnsupportedEncodingException | UserManagementSystemException | GroupRetrievalFault e) {
|
||||
log.error("Cannot get URL encoded infrastrucure scope for group: " + group, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRole(Role role) throws PortalException, SystemException {
|
||||
|
@ -55,7 +72,12 @@ public class PortalModelListenerEvent<T extends BaseModel<T>> extends PortalEven
|
|||
}
|
||||
|
||||
protected static String getRoleIdentifier(Role role) throws PortalException, SystemException {
|
||||
return role.getDescriptiveName();
|
||||
try {
|
||||
return ROLE_MANAGER.getRole(role.getRoleId()).getRoleName();
|
||||
} catch (UserManagementSystemException | RoleRetrievalFault e) {
|
||||
log.error("Cannot get gCube role for role: " + role, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setModelClassName(String group) {
|
||||
|
|
Loading…
Reference in New Issue