Fixed PortalContext for get token
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@135047 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
975ee71103
commit
e09671daae
|
@ -20,6 +20,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceExcept
|
|||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -34,8 +35,7 @@ public class SessionUtil {
|
|||
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
||||
|
||||
public static ServiceCredentials getServiceCredentials(
|
||||
HttpServletRequest httpServletRequest)
|
||||
throws ServiceException {
|
||||
HttpServletRequest httpServletRequest) throws ServiceException {
|
||||
return getServiceCredentials(httpServletRequest, null);
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,8 @@ public class SessionUtil {
|
|||
String userName = null;
|
||||
String scope = null;
|
||||
String token = null;
|
||||
String groupId = null;
|
||||
String groupName = null;
|
||||
|
||||
if (Constants.DEBUG_MODE) {
|
||||
logger.info("No credential found in session, use test user!");
|
||||
|
@ -59,10 +61,20 @@ public class SessionUtil {
|
|||
} else {
|
||||
logger.info("Retrieving credential in session!");
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
boolean hasScopeGroupId = false;
|
||||
|
||||
if (scopeGroupId != null && !scopeGroupId.isEmpty()) {
|
||||
hasScopeGroupId = true;
|
||||
|
||||
} else {
|
||||
hasScopeGroupId = false;
|
||||
}
|
||||
|
||||
if (hasScopeGroupId) {
|
||||
scope = pContext.getCurrentScope(scopeGroupId);
|
||||
} else {
|
||||
scope = pContext.getCurrentScope(httpServletRequest);
|
||||
|
||||
}
|
||||
|
||||
if (scope == null || scope.isEmpty()) {
|
||||
|
@ -71,8 +83,16 @@ public class SessionUtil {
|
|||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
userName = pContext.getCurrentUser(httpServletRequest)
|
||||
.getUsername();
|
||||
GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest);
|
||||
|
||||
if (gCubeUser == null) {
|
||||
String error = "Error retrieving gCubeUser in scope " + scope
|
||||
+ ": " + gCubeUser;
|
||||
logger.error(error);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
userName = gCubeUser.getUsername();
|
||||
|
||||
if (userName == null || userName.isEmpty()) {
|
||||
String error = "Error retrieving username in scope " + scope
|
||||
|
@ -81,7 +101,7 @@ public class SessionUtil {
|
|||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
token = pContext.getCurrentUserToken(httpServletRequest);
|
||||
token = pContext.getCurrentUserToken(scope, httpServletRequest);
|
||||
|
||||
if (token == null || token.isEmpty()) {
|
||||
String error = "Error retrieving token for " + userName
|
||||
|
@ -90,21 +110,54 @@ public class SessionUtil {
|
|||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
String name = pContext.getCurrentUser(httpServletRequest)
|
||||
String name = gCubeUser
|
||||
.getFirstName();
|
||||
String lastName = pContext.getCurrentUser(httpServletRequest)
|
||||
String lastName = gCubeUser
|
||||
.getLastName();
|
||||
String fullName = pContext.getCurrentUser(httpServletRequest)
|
||||
String fullName = gCubeUser
|
||||
.getFullname();
|
||||
|
||||
String userAvatarURL = pContext.getCurrentUser(httpServletRequest)
|
||||
String userAvatarURL = gCubeUser
|
||||
.getUserAvatarURL();
|
||||
|
||||
String email = pContext.getCurrentUser(httpServletRequest)
|
||||
String email = gCubeUser
|
||||
.getEmail();
|
||||
String groupId = String.valueOf(pContext
|
||||
|
||||
|
||||
if (hasScopeGroupId) {
|
||||
|
||||
groupId = scopeGroupId;
|
||||
|
||||
long gId;
|
||||
|
||||
try {
|
||||
gId = Long.parseLong(scopeGroupId);
|
||||
} catch (Throwable e) {
|
||||
String error = "Error retrieving groupId: " + scopeGroupId;
|
||||
logger.error(error, e);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
GCubeGroup group;
|
||||
try {
|
||||
group = new LiferayGroupManager().getGroup(gId);
|
||||
} catch (Throwable e) {
|
||||
String error = "Error retrieving group: " + groupName;
|
||||
logger.error(error);
|
||||
throw new ServiceException(error);
|
||||
}
|
||||
|
||||
groupName = group.getGroupName();
|
||||
|
||||
} else {
|
||||
|
||||
groupId = String.valueOf(pContext
|
||||
.getCurrentGroupId(httpServletRequest));
|
||||
String groupName = pContext.getCurrentGroupName(httpServletRequest);
|
||||
|
||||
groupName = pContext.getCurrentGroupName(httpServletRequest);
|
||||
|
||||
}
|
||||
|
||||
|
||||
sCredentials = new ServiceCredentials(userName, fullName, name,
|
||||
lastName, email, scope, groupId, groupName, userAvatarURL,
|
||||
|
@ -154,8 +207,9 @@ public class SessionUtil {
|
|||
|
||||
if (Constants.DEBUG_MODE) {
|
||||
contexts.add(serviceCredentials.getScope());
|
||||
for(int i=0; i<50 ; i++){
|
||||
contexts.add("/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture"+i);
|
||||
for (int i = 0; i < 50; i++) {
|
||||
contexts.add("/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture"
|
||||
+ i);
|
||||
}
|
||||
} else {
|
||||
contexts.add(serviceCredentials.getScope());
|
||||
|
|
|
@ -186,11 +186,12 @@ public class CSVManager {
|
|||
logger.debug("Temp File: " + tempFile.toString());
|
||||
|
||||
// Create the CSVFormat object
|
||||
CSVFormat format = CSVFormat.RFC4180.withHeader()
|
||||
CSVFormat format = CSVFormat.RFC4180.withFirstRecordAsHeader()
|
||||
.withDelimiter(',');
|
||||
|
||||
PrintStream printStream = new PrintStream(tempFile.toFile());
|
||||
// CSV Write Example using CSVPrinter
|
||||
|
||||
CSVPrinter printer = new CSVPrinter(printStream, format);
|
||||
printer.printRecord(accountingDataModel.getHeader());
|
||||
for (AccountingDataRow row : accountingDataModel.getRows()) {
|
||||
|
|
Loading…
Reference in New Issue