Skip to content

Commit

Permalink
Merge f071c9d into 230a300
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Apr 21, 2020
2 parents 230a300 + f071c9d commit ee7e0fe
Show file tree
Hide file tree
Showing 179 changed files with 2,643 additions and 2,517 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,28 @@
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.logging.log4j.Logger;

import java.util.Map;

public class ChatAuthenticationInterceptor extends AbstractInterceptor {

private static final long serialVersionUID = 1L;
private static final Logger LOG = LogManager.getLogger(ChatAuthenticationInterceptor.class);
public static final String USER_SESSION_KEY = "chatUserSessionKey";
private static final long serialVersionUID = 1L;
private static final Logger LOG = LogManager.getLogger(ChatAuthenticationInterceptor.class);
public static final String USER_SESSION_KEY = "chatUserSessionKey";

public String intercept(ActionInvocation invocation) throws Exception {
public String intercept(ActionInvocation invocation) throws Exception {

LOG.debug("Authenticating chat user");
LOG.debug("Authenticating chat user");

SessionMap session = (SessionMap) ActionContext.getContext().get(ActionContext.SESSION);
User user = (User) session.get(USER_SESSION_KEY);
Map<String, Object> session = ActionContext.getContext().getSession();
User user = (User) session.get(USER_SESSION_KEY);

if (user == null) {
return Action.LOGIN;
}
return invocation.invoke();
}
if (user == null) {
return Action.LOGIN;
}
return invocation.invoke();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
* Authenticate showcase chat example, make sure everyone have a username.
*/
public class ChatInterceptor extends AbstractInterceptor {

private static final Logger LOG = LogManager.getLogger(ChatInterceptor.class);
private static final Logger LOG = LogManager.getLogger(ChatInterceptor.class);

private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;

public static final String CHAT_USER_SESSION_KEY = "ChatUserSessionKey";
public static final String CHAT_USER_SESSION_KEY = "ChatUserSessionKey";

public String intercept(ActionInvocation invocation) throws Exception {
HttpSession session = (HttpSession) ActionContext.getContext().get(ActionContext.SESSION);
User chatUser = (User) session.getAttribute(CHAT_USER_SESSION_KEY);
if (chatUser == null) {
LOG.debug("Chat user not logged in");
return Action.LOGIN;
}
return invocation.invoke();
}
public String intercept(ActionInvocation invocation) throws Exception {
Map<String, Object> session = ActionContext.getContext().getSession();
User chatUser = (User) session.get(CHAT_USER_SESSION_KEY);
if (chatUser == null) {
LOG.debug("Chat user not logged in");
return Action.LOGIN;
}
return invocation.invoke();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static LinkedList<String> getChainHistory() {
* @param invocation the DefaultActionInvocation calling the action call stack
*/
public void execute(ActionInvocation invocation) throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
ValueStack stack = invocation.getInvocationContext().getValueStack();
String finalNamespace = this.namespace != null
? TextParseUtil.translateVariables(namespace, stack)
: invocation.getProxy().getNamespace();
Expand All @@ -216,15 +216,16 @@ public void execute(ActionInvocation invocation) throws Exception {
throw new StrutsException("Infinite recursion detected: " + ActionChainResult.getChainHistory().toString());
}

if (ActionChainResult.getChainHistory().isEmpty() && invocation != null && invocation.getProxy() != null) {
if (ActionChainResult.getChainHistory().isEmpty() && invocation.getProxy() != null) {
addToHistory(finalNamespace, invocation.getProxy().getActionName(), invocation.getProxy().getMethod());
}
addToHistory(finalNamespace, finalActionName, finalMethodName);

HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.VALUE_STACK, ActionContext.getContext().getValueStack());
extraContext.put(ActionContext.PARAMETERS, ActionContext.getContext().getParameters());
extraContext.put(CHAIN_HISTORY, ActionChainResult.getChainHistory());
Map<String, Object> extraContext = ActionContext.of(new HashMap<>())
.withValueStack(invocation.getInvocationContext().getValueStack())
.withParameters(invocation.getInvocationContext().getParameters())
.with(CHAIN_HISTORY, ActionChainResult.getChainHistory())
.getContextMap();

LOG.debug("Chaining to action {}", finalActionName);

Expand Down

0 comments on commit ee7e0fe

Please sign in to comment.