Skip to content

Commit d8d3a10

Browse files
committed
[KNOWAGE-9621] prevent users from executing documents with an expired license
1 parent 4db7691 commit d8d3a10

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

knowage-core/src/main/java/it/eng/knowage/security/ProductProfiler.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ public static boolean canExecuteDocument(BIObject biObj) {
8484
}
8585
}
8686

87+
public static boolean canExecuteDocumentByLicenseExpiredOrAbsent(BIObject biObj) {
88+
if (isCommunity) {
89+
return true;
90+
} else {
91+
boolean toReturn = false;
92+
try {
93+
Method canExecuteDocumentByLicenseExpiredOrAbsentMethod = productProfilerEE.getMethod("canExecuteDocumentByLicenseExpiredOrAbsent", BIObject.class);
94+
toReturn = (boolean) canExecuteDocumentByLicenseExpiredOrAbsentMethod.invoke(productProfilerEE, biObj);
95+
} catch (Exception e) {
96+
logger.error("Error while filtering engines by product: ", e);
97+
}
98+
return toReturn;
99+
}
100+
101+
}
102+
87103
public static boolean canCreateDataset(String type, UserProfile profile) {
88104
if (isCommunity) {
89105
return true;

knowage-core/src/main/java/it/eng/spagobi/api/v3/DocumentExecutionResource.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,20 @@ public JSONObject getDocumentTemplates(@PathParam("id") Integer id) throws JSONE
9090
LOGGER.error(message);
9191
throw new SpagoBIRuntimeException(message);
9292
}
93-
String userId = (String) userProfile.getUserAttribute("user_id");
94-
byte[] temp = null;
95-
JSONObject jsonTemplate = null;
93+
94+
byte[] temp;
95+
JSONObject jsonTemplate;
9696

9797
try {
9898
IBIObjectDAO documentDao = DAOFactory.getBIObjectDAO();
9999
BIObject document = documentDao.loadBIObjectById(id);
100100

101+
if (!ProductProfiler.canExecuteDocumentByLicenseExpiredOrAbsent(document)) {
102+
String message = "This document cannot be executed within the current product";
103+
LOGGER.error(message);
104+
throw new SpagoBIRuntimeException(message);
105+
}
106+
101107
if (!ObjectsAccessVerifier.canExec(document, userProfile)) {
102108
String message = "User cannot exec the document";
103109
LOGGER.error(message);

0 commit comments

Comments
 (0)