2022-10-11 15:00:39 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.server.mongoservice;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accessidentity.GcubeIdentity;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accessidentity.IAMClientIdentity;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accessidentity.UserIdentity;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class GeoportalServiceIdentityProxy.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Sep 23, 2021
|
|
|
|
*/
|
|
|
|
public class GeoportalServiceIdentityProxy {
|
|
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalServiceIdentityProxy.class);
|
|
|
|
|
|
|
|
private GcubeIdentity gCubeIdentity;
|
2022-10-27 15:09:07 +02:00
|
|
|
|
|
|
|
private boolean isUser = false;
|
|
|
|
|
|
|
|
private boolean isIAMClient = false;
|
2022-10-11 15:00:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new concessioni mongo service proxy.
|
|
|
|
*
|
|
|
|
* @param request the request
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public GeoportalServiceIdentityProxy(HttpServletRequest request) throws Exception {
|
|
|
|
SessionUtil.getCurrentContext(request, true);
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
String username = null;
|
|
|
|
try {
|
|
|
|
username = pContext.getCurrentUser(request).getUsername();
|
|
|
|
if (username == null || username.isEmpty())
|
|
|
|
throw new Exception("Invalid username");
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.info("Username not detected in session");
|
|
|
|
username = null; // to be sure that is null and not empty string
|
|
|
|
}
|
|
|
|
if (username != null) {
|
2022-10-27 15:09:07 +02:00
|
|
|
isUser = true;
|
2022-10-11 15:00:39 +02:00
|
|
|
LOG.info("User detected, using its identity");
|
|
|
|
gCubeIdentity = new UserIdentity();
|
|
|
|
} else {
|
2022-10-27 15:09:07 +02:00
|
|
|
isIAMClient = true;
|
2022-10-11 15:00:39 +02:00
|
|
|
LOG.info("User not detected, using IAM Client identity");
|
|
|
|
gCubeIdentity = new IAMClientIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
gCubeIdentity.setIdentity(request);
|
|
|
|
}
|
2022-10-27 15:09:07 +02:00
|
|
|
|
|
|
|
public boolean isUser() {
|
|
|
|
return isUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isIAMClient() {
|
|
|
|
return isIAMClient;
|
|
|
|
}
|
2022-10-11 15:00:39 +02:00
|
|
|
}
|