use of org.springframework.web.context.request.RequestAttributes in project onebusaway-application-modules by camsys.
the class TextmarksSessionInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
processGoogleAnalytics();
ActionContext context = invocation.getInvocationContext();
Map<String, Object> parameters = context.getParameters();
Object phoneNumber = parameters.get(_phoneNumberParameterName);
if (phoneNumber == null)
return invocation.invoke();
if (phoneNumber instanceof String[]) {
String[] values = (String[]) phoneNumber;
if (values.length == 0)
return invocation.invoke();
phoneNumber = values[0];
}
String sessionId = phoneNumber.toString();
Map<String, Object> persistentSession = _sessionManager.getContext(sessionId);
Map<String, Object> originalSession = context.getSession();
context.setSession(persistentSession);
XWorkRequestAttributes attributes = new XWorkRequestAttributes(context, sessionId);
RequestAttributes originalAttributes = RequestContextHolder.getRequestAttributes();
RequestContextHolder.setRequestAttributes(attributes);
Object action = invocation.getAction();
if (action instanceof SessionAware)
((SessionAware) action).setSession(persistentSession);
try {
return invocation.invoke();
} finally {
RequestContextHolder.setRequestAttributes(originalAttributes);
context.setSession(originalSession);
}
}
use of org.springframework.web.context.request.RequestAttributes in project onebusaway-application-modules by camsys.
the class TwilioInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();
Map<String, Object> parameters = context.getParameters();
/* Stringify parameters for debugging output */
String paramString = "";
for (Entry<String, Object> entry : parameters.entrySet()) {
paramString += entry.getKey() + "=";
Object val = entry.getValue();
if (val instanceof String[]) {
paramString += Arrays.toString((String[]) val);
} else {
paramString += val.toString();
}
paramString += ", ";
}
int idx = paramString.lastIndexOf(',');
if (idx >= 0) {
paramString = paramString.substring(0, idx);
}
_log.debug("in with params={" + paramString + "} and session=" + context.getSession());
Object phoneNumber = parameters.get(_phoneNumberParameterName);
if (phoneNumber == null) {
return invocation.invoke();
}
if (phoneNumber instanceof String[]) {
String[] values = (String[]) phoneNumber;
if (values.length == 0)
return invocation.invoke();
phoneNumber = values[0];
}
String sessionId = phoneNumber.toString();
// Strip off leading '+', if any
sessionId = sessionId.replaceFirst("\\+", "");
Map<String, Object> persistentSession = _sessionManager.getContext(sessionId);
_log.debug("remapping sesssionId " + sessionId + " to " + persistentSession);
Map<String, Object> originalSession = context.getSession();
context.setSession(persistentSession);
XWorkRequestAttributes attributes = new XWorkRequestAttributes(context, sessionId);
RequestAttributes originalAttributes = RequestContextHolder.getRequestAttributes();
RequestContextHolder.setRequestAttributes(attributes);
Object action = invocation.getAction();
if (action instanceof SessionAware)
((SessionAware) action).setSession(persistentSession);
try {
return invocation.invoke();
} finally {
RequestContextHolder.setRequestAttributes(originalAttributes);
context.setSession(originalSession);
}
}
use of org.springframework.web.context.request.RequestAttributes in project onebusaway-application-modules by camsys.
the class DefaultSearchLocationServiceImpl method getDefaultSearchLocationForCurrentUser.
@Override
public DefaultSearchLocation getDefaultSearchLocationForCurrentUser() {
UserBean user = _currentUserService.getCurrentUser();
if (user != null && user.hasDefaultLocation()) {
return new DefaultSearchLocation(user.getDefaultLocationName(), user.getDefaultLocationLat(), user.getDefaultLocationLon(), false);
}
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
DefaultSearchLocation location = (DefaultSearchLocation) attributes.getAttribute(KEY_DEFAULT_SEARCH_LOCATION_FOR_SESSSION, RequestAttributes.SCOPE_SESSION);
return location;
}
use of org.springframework.web.context.request.RequestAttributes in project onebusaway-application-modules by camsys.
the class CustomAgiEntryPoint method onActionTearDown.
@Override
protected void onActionTearDown() {
super.onActionTearDown();
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
RequestContextHolder.resetRequestAttributes();
if (attributes instanceof XWorkRequestAttributes)
((XWorkRequestAttributes) attributes).requestCompleted();
}
use of org.springframework.web.context.request.RequestAttributes in project flytecnologia-api by jullierme.
the class FlyTokenUserDetails method getCurrentUsername.
public static String getCurrentUsername() {
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication = securityContext.getAuthentication();
if (authentication != null) {
if (authentication.getPrincipal() instanceof String)
return (String) authentication.getPrincipal();
if (authentication.getPrincipal() instanceof UserDetails)
return ((UserDetails) authentication.getPrincipal()).getUsername();
}
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
return (String) requestAttributes.getAttribute("username", RequestAttributes.SCOPE_REQUEST);
}
Aggregations