2253: Accounting Manager - Top N Active Users
https://support.d4science.org/issues/2253 Added Debug Mode git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@128473 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
85564df0ab
commit
a12eee72fe
38
pom.xml
38
pom.xml
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
||||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||||
<distroDirectory>distro</distroDirectory>
|
<distroDirectory>distro</distroDirectory>
|
||||||
<configDirectory>config</configDirectory>
|
<configDirectory>config</configDirectory>
|
||||||
|
@ -77,9 +77,16 @@
|
||||||
<artifactId>accounting-lib</artifactId>
|
<artifactId>accounting-lib</artifactId>
|
||||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>common-authorization</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>authorization-client</artifactId>
|
<artifactId>authorization-client</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -174,6 +181,27 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Authorization -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>common-authorization</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>authorization-client</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- GCube Widgets -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
|
<artifactId>gcube-widgets</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- Social -->
|
<!-- Social -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.portal</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
|
@ -187,12 +215,6 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- GCube Widgets -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
|
||||||
<artifactId>gcube-widgets</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- WSLT dependencies <dependency> <groupId>org.gcube.portlets.widgets</groupId>
|
<!-- WSLT dependencies <dependency> <groupId>org.gcube.portlets.widgets</groupId>
|
||||||
|
@ -382,7 +404,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>maven-portal-bom</artifactId>
|
<artifactId>maven-portal-bom</artifactId>
|
||||||
<version>LATEST</version>
|
<version>2.6.0-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -9,6 +9,8 @@ import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService;
|
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService;
|
||||||
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller;
|
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller;
|
||||||
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerInterface;
|
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerInterface;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerTester;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
|
||||||
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
|
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
|
||||||
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
|
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
|
||||||
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
|
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
|
||||||
|
@ -59,7 +61,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
|
||||||
public UserInfo hello() throws AccountingManagerServiceException {
|
public UserInfo hello() throws AccountingManagerServiceException {
|
||||||
try {
|
try {
|
||||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
ASLSession aslSession = SessionUtil.getAslSession(session);
|
ASLSession aslSession = SessionUtil.getASLSession(session);
|
||||||
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
|
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
|
||||||
aslSession.getGroupId(), aslSession.getGroupName(),
|
aslSession.getGroupId(), aslSession.getGroupName(),
|
||||||
aslSession.getScope(), aslSession.getScopeName(),
|
aslSession.getScope(), aslSession.getScopeName(),
|
||||||
|
@ -87,8 +89,13 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
|
||||||
throws AccountingManagerServiceException {
|
throws AccountingManagerServiceException {
|
||||||
try {
|
try {
|
||||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
SessionUtil.getAslSession(session);
|
SessionUtil.getASLSession(session);
|
||||||
AccountingCallerInterface accountingCaller = new AccountingCaller();
|
AccountingCallerInterface accountingCaller;
|
||||||
|
if(Constants.DEBUG_MODE){
|
||||||
|
accountingCaller= new AccountingCallerTester();
|
||||||
|
} else {
|
||||||
|
accountingCaller= new AccountingCaller();
|
||||||
|
}
|
||||||
SeriesResponse seriesResponse = accountingCaller.getSeries(
|
SeriesResponse seriesResponse = accountingCaller.getSeries(
|
||||||
accountingType, seriesRequest);
|
accountingType, seriesRequest);
|
||||||
|
|
||||||
|
@ -114,9 +121,13 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
|
||||||
throws AccountingManagerServiceException {
|
throws AccountingManagerServiceException {
|
||||||
try {
|
try {
|
||||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
SessionUtil.getAslSession(session);
|
SessionUtil.getASLSession(session);
|
||||||
|
AccountingCallerInterface accountingCaller;
|
||||||
AccountingCallerInterface accountingCaller = new AccountingCaller();
|
if(Constants.DEBUG_MODE){
|
||||||
|
accountingCaller= new AccountingCallerTester();
|
||||||
|
} else {
|
||||||
|
accountingCaller= new AccountingCaller();
|
||||||
|
}
|
||||||
ArrayList<FilterKey> filterKeys = accountingCaller.getFilterKeys(accountingType);
|
ArrayList<FilterKey> filterKeys = accountingCaller.getFilterKeys(accountingType);
|
||||||
|
|
||||||
return filterKeys;
|
return filterKeys;
|
||||||
|
@ -142,9 +153,14 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
|
||||||
throws AccountingManagerServiceException {
|
throws AccountingManagerServiceException {
|
||||||
try {
|
try {
|
||||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
SessionUtil.getAslSession(session);
|
SessionUtil.getASLSession(session);
|
||||||
|
|
||||||
AccountingCallerInterface accountingCaller = new AccountingCaller();
|
AccountingCallerInterface accountingCaller;
|
||||||
|
if(Constants.DEBUG_MODE){
|
||||||
|
accountingCaller= new AccountingCallerTester();
|
||||||
|
} else {
|
||||||
|
accountingCaller= new AccountingCaller();
|
||||||
|
}
|
||||||
ArrayList<FilterValue> filterValues = accountingCaller.getFilterValues(filterValuesRequest);
|
ArrayList<FilterValue> filterValues = accountingCaller.getFilterValues(filterValuesRequest);
|
||||||
|
|
||||||
return filterValues;
|
return filterValues;
|
||||||
|
|
|
@ -3,11 +3,18 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.admin.accountingmanager.server;
|
package org.gcube.portlets.admin.accountingmanager.server;
|
||||||
|
|
||||||
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
import org.gcube.application.framework.core.session.SessionManager;
|
||||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
|
||||||
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
|
||||||
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException;
|
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -22,37 +29,59 @@ public class SessionUtil {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
||||||
|
|
||||||
public static ASLSession getAslSession(HttpSession httpSession)
|
public static ASLSession getASLSession(HttpSession httpSession)
|
||||||
throws AccountingManagerSessionExpiredException {
|
throws AccountingManagerServiceException {
|
||||||
String username = (String) httpSession
|
String username = (String) httpSession
|
||||||
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
||||||
ASLSession session;
|
ASLSession aslSession;
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
logger.warn("no user found in session, use test user");
|
if (Constants.DEBUG_MODE) {
|
||||||
throw new AccountingManagerSessionExpiredException("Session Expired!");
|
logger.info("no user found in session, use test user");
|
||||||
|
|
||||||
/*
|
|
||||||
// Remove comment for Test
|
|
||||||
username = Constants.DEFAULT_USER;
|
|
||||||
String scope = Constants.DEFAULT_SCOPE;
|
|
||||||
|
|
||||||
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username);
|
// Remove comment for Test
|
||||||
session = SessionManager.getInstance().getASLSession(
|
username = org.gcube.portlets.admin.accountingmanager.shared.Constants.DEFAULT_USER;
|
||||||
httpSession.getId(), username);
|
String scope = Constants.DEFAULT_SCOPE;
|
||||||
session.setScope(scope);
|
|
||||||
*/
|
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
|
||||||
|
username);
|
||||||
|
aslSession = SessionManager.getInstance().getASLSession(
|
||||||
|
httpSession.getId(), username);
|
||||||
|
aslSession.setScope(scope);
|
||||||
|
} else {
|
||||||
|
logger.info("No user found in session");
|
||||||
|
throw new AccountingManagerSessionExpiredException("Session Expired!");
|
||||||
|
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
session = SessionManager.getInstance().getASLSession(
|
aslSession = SessionManager.getInstance().getASLSession(
|
||||||
httpSession.getId(), username);
|
httpSession.getId(), username);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("SessionUtil: aslSession " + session.getUsername() + " "
|
logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " "
|
||||||
+ session.getScope());
|
+ aslSession.getScope());
|
||||||
|
|
||||||
return session;
|
|
||||||
|
|
||||||
|
return aslSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getToken(ASLSession aslSession) {
|
||||||
|
String token=null;
|
||||||
|
if (Constants.DEBUG_MODE) {
|
||||||
|
List<String> userRoles = new ArrayList<>();
|
||||||
|
userRoles.add(Constants.DEFAULT_ROLE);
|
||||||
|
/*if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
|
||||||
|
userRoles.add("VRE-Manager");*/
|
||||||
|
token = authorizationService().build().generate(
|
||||||
|
aslSession.getUsername(), userRoles);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
token = aslSession.getSecurityToken();
|
||||||
|
}
|
||||||
|
logger.info("received token: " + token);
|
||||||
|
return token;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,21 @@ package org.gcube.portlets.admin.accountingmanager.shared;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
public static final boolean DEBUG_MODE = false;
|
||||||
|
|
||||||
public static final String APPLICATION_ID = "org.gcube.portlets.admin.accountingmanager.server.portlet.AccountingManagerPortlet";
|
public static final String APPLICATION_ID = "org.gcube.portlets.admin.accountingmanager.server.portlet.AccountingManagerPortlet";
|
||||||
public static final String ACCOUNTING_MANAGER_ID = "AccountingManagerId";
|
public static final String ACCOUNTING_MANAGER_ID = "AccountingManagerId";
|
||||||
public static final String AM_LANG_COOKIE = "AMLangCookie";
|
public static final String AM_LANG_COOKIE = "AMLangCookie";
|
||||||
public static final String AM_LANG = "AMLang";
|
public static final String AM_LANG = "AMLang";
|
||||||
public final static String DEFAULT_USER = "giancarlo.panichi";
|
public static final String DEFAULT_USER = "giancarlo.panichi";
|
||||||
//public final static String DEFAULT_USER = "test.user";
|
//public final static String DEFAULT_USER = "test.user";
|
||||||
//public final static String DEFAULT_SCOPE = "/gcube/devNext";
|
//public final static String DEFAULT_SCOPE = "/gcube/devNext";
|
||||||
//public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
|
//public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
//public final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
|
//public final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
|
||||||
|
|
||||||
public final static String DEFAULT_SCOPE = "/gcube";
|
public static final String DEFAULT_SCOPE = "/gcube";
|
||||||
|
public static final String DEFAULT_ROLE = "OrganizationMember";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue