Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

mvn -B clean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.Iterator;
import java.util.Set;

import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.util.ApsTenantApplicationUtils;
import jakarta.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
Expand Down Expand Up @@ -44,6 +46,9 @@ public abstract class BaseInterceptorMadMax extends AbstractInterceptor {
public String intercept(ActionInvocation invocation) throws Exception {
boolean isAuthorized = false;
try {
// ESB-805 - Adding logs for tenant
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - intercept - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));
HttpSession session = ServletActionContext.getRequest().getSession();
UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
IAuthorizationManager authManager = (IAuthorizationManager) ApsWebApplicationUtils.getBean(SystemConstants.AUTHORIZATION_SERVICE, ServletActionContext.getRequest());
Expand All @@ -60,7 +65,11 @@ public String intercept(ActionInvocation invocation) throws Exception {
}
}
if (isAuthorized) {
return this.invoke(invocation);
String result = this.invoke(invocation);
// ESB-805 - Adding logs for tenant
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - invoked - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));
return result;
}
} catch (Throwable t) {
_logger.error("Error occurred verifying authority of current user", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.Map;
import java.util.Map.Entry;

import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.util.ApsTenantApplicationUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

Expand Down Expand Up @@ -53,15 +55,25 @@ public String intercept(ActionInvocation invocation) throws Exception {
ActionLogRecord actionRecord = null;
String result = null;
try {
// ESB-805 - Adding logs for tenant
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - intercept - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));
actionRecord = this.buildActionRecord(invocation);
result = invocation.invoke();
// ESB-805 - Adding logs for tenant
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - invoked - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));

List<ActivityStreamInfo> asiList = null;
Object actionObject = invocation.getAction();
if (actionObject instanceof BaseAction) {
BaseAction action = (BaseAction) actionObject;
asiList = action.getActivityStreamInfos();
}
this.includeActionProperties(actionRecord, actionObject);
// CDP - ESB-805 - Adding logs for tenant
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - saving log - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));
if (null == asiList || asiList.isEmpty()) {
this.getActionLoggerManager().addActionRecord(actionRecord);
} else {
Expand All @@ -71,6 +83,9 @@ public String intercept(ActionInvocation invocation) throws Exception {
this.getActionLoggerManager().addActionRecord(clone);
}
}
ApsTenantApplicationUtils.removeTenant();
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - log saved - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));
} catch (Throwable t) {
_logger.error("error in intercept", t);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.entando.entando.apsadmin.system;

import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.util.ApsTenantApplicationUtils;
import org.apache.struts2.ActionInvocation;
import org.apache.struts2.interceptor.AbstractInterceptor;
Expand All @@ -11,11 +12,15 @@ public class MDCStrutsTenantInterceptor extends AbstractInterceptor {

@Override
public String intercept(ActionInvocation invocation) throws Exception {
try {
MDC.put(MDC_KEY_TENANT, ApsTenantApplicationUtils.getTenant().orElse(""));
return invocation.invoke();
} finally {
MDC.remove(MDC_KEY_TENANT);
}
//try {
// ESB-805 - Adding logs for tenant
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - intercept - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));
MDC.put(MDC_KEY_TENANT, ApsTenantApplicationUtils.getTenant().orElse(""));
return invocation.invoke();
//} finally {
// ESB-805 - Removed to preserve tenant
// MDC.remove(MDC_KEY_TENANT);
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.entando.entando.apsadmin.system;

import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.system.EntThreadLocal;
import com.agiletec.aps.util.ApsTenantApplicationUtils;
import org.apache.struts2.ActionInvocation;
Expand All @@ -25,7 +26,11 @@ public class MultitenancyStrutsInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {

try {
//try {
// ESB-805 - Adding logs for tenant
ApsSystemUtils.ApsDeepDebug.print("TENANT", String.format("%s - intercept - tenant %s",
this.getClass().getSimpleName(), ApsTenantApplicationUtils.getTenant().orElse("primary")));

EntThreadLocal.clear();

HttpServletRequest request = ServletActionContext.getRequest();
Expand All @@ -34,8 +39,9 @@ public String intercept(ActionInvocation invocation) throws Exception {

return invocation.invoke();

} finally {
ApsTenantApplicationUtils.removeTenant();
}
//} finally {
// ESB-805 - Removed to preserve tenant
// ApsTenantApplicationUtils.removeTenant();
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
package com.agiletec.aps.system;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.entando.entando.ent.util.EntLogging.EntLogger;
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import java.util.Enumeration;
import java.util.Optional;

/**
* Utility class for system logger
Expand Down Expand Up @@ -209,6 +211,13 @@ public static String getEnv(String name, String def) {
return (res != null) ? res : def;
}

public static Integer getEnv(String name, Integer defaultValue) {
return Optional.ofNullable(System.getenv(name))
.filter(StringUtils::isNotBlank)
.map(Integer::parseInt)
.orElse(defaultValue);
}

public static boolean getEnvFlag(String name, boolean def) {
String res = System.getenv(name);
return res != null ? Boolean.parseBoolean(res) : def;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
*/
public interface IKeyGeneratorDAO {

/**
* Incrementa la chiave presente nel db.
* @return La chiave incrementata.
*/
public int getNextUniqueKey();

/**
* Estrae la chiave presente nel db.
* Il metodo viene chiamato solo in fase di inizializzazione.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
*/
package com.agiletec.aps.system.services.keygenerator;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.*;

import org.entando.entando.ent.util.EntLogging.EntLogger;
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
Expand All @@ -30,7 +27,30 @@
public class KeyGeneratorDAO extends AbstractDAO implements IKeyGeneratorDAO {

private static final EntLogger _logger = EntLogFactory.getSanitizedLogger(KeyGeneratorDAO.class);


@Override
public int getNextUniqueKey() {
Connection conn = null;
int nextKey = 0;
Statement stat = null;
ResultSet res = null;
try {
conn = this.getConnection();
conn.setAutoCommit(false);
nextKey = this.getUniqueKey(conn) + 1;
this.updateKey(nextKey, conn);
conn.commit();
} catch (Throwable t) {
this.executeRollback(conn);
_logger.error("Error while getting the unique key", t);
throw new RuntimeException("Error while getting the unique key", t);
//processDaoException(e, "Error while getting the unique key", "getUniqueKey");
} finally {
closeConnection(conn);
}
return nextKey;
}

/**
* Estrae la chiave presente nel db.
* Il metodo viene chiamato solo in fase di inizializzazione.
Expand All @@ -39,21 +59,15 @@ public class KeyGeneratorDAO extends AbstractDAO implements IKeyGeneratorDAO {
public int getUniqueKey() {
Connection conn = null;
int currentKey = 0;
Statement stat = null;
ResultSet res = null;
try {
conn = this.getConnection();
stat = conn.createStatement();
res = stat.executeQuery(EXTRACT_KEY);
if (res.next()) {
currentKey = res.getInt(1);
}
currentKey = this.getUniqueKey(conn);
} catch (Throwable t) {
_logger.error("Error while getting the unique key", t);
throw new RuntimeException("Error while getting the unique key", t);
//processDaoException(e, "Error while getting the unique key", "getUniqueKey");
} finally {
closeDaoResources(res, stat, conn);
closeConnection(conn);
}
return currentKey;
}
Expand All @@ -64,21 +78,46 @@ public int getUniqueKey() {
*/
public synchronized void updateKey(int currentKey) {
Connection conn = null;
PreparedStatement stat = null;
try {
conn = this.getConnection();
conn.setAutoCommit(false);
stat = conn.prepareStatement(UPDATE_KEY);
stat.setInt(1, currentKey);
stat.executeUpdate();
conn.commit();
this.updateKey(currentKey, conn);
} catch (Throwable t) {
this.executeRollback(conn);
_logger.error("Error while updating a key", t);
throw new RuntimeException("Error while updating a key", t);
//processDaoException(e, "Error while updating a key", "getUpdateKey");
} finally {
closeDaoResources(null, stat, conn);
closeConnection(conn);
}
}

protected int getUniqueKey(Connection conn) throws SQLException {
int currentKey = 0;
Statement stat = null;
ResultSet res = null;
try {
stat = conn.createStatement();
res = stat.executeQuery(EXTRACT_KEY);
if (res.next()) {
currentKey = res.getInt(1);
}
} finally {
closeDaoResources(res, stat);
}
return currentKey;
}

/**
* Aggiorna la chiave univoca nel db.
* @param currentKey Il valore della chiave corrente.
*/
protected void updateKey(int currentKey, Connection conn) throws SQLException {
PreparedStatement stat = null;
try {
stat = conn.prepareStatement(UPDATE_KEY);
stat.setInt(1, currentKey);
stat.executeUpdate();
} finally {
closeDaoResources(null, stat);
}
}

Expand Down
Loading
Loading