Java Code Examples for com.opensymphony.xwork2.ActionInvocation#getInvocationContext()
The following examples show how to use
com.opensymphony.xwork2.ActionInvocation#getInvocationContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserLoginInterceptor.java From bamboobsc with Apache License 2.0 | 6 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { ActionContext actionContext=actionInvocation.getInvocationContext(); Map<String, Object> session=actionContext.getSession(); this.accountObj = (AccountObj)session.get(Constants.SESS_ACCOUNT); Map<String, String> dataMap = UserCurrentCookie.getCurrentData( (HttpServletRequest)actionContext.get(StrutsStatics.HTTP_REQUEST) ); String currentId = StringUtils.defaultString( dataMap.get("currentId") ); String accountId = StringUtils.defaultString( dataMap.get("account") ); if (accountObj!=null && !StringUtils.isBlank(accountObj.getAccount()) ) { if ( StringUtils.isBlank(currentId) ) { currentId = "NULL"; } String sessSysCurrentId = (String)session.get(Constants.SESS_SYSCURRENT_ID); if ( !currentId.equals(sessSysCurrentId) ) { logger.warn( "currentId: " + currentId + " not equals session variable currentId: " + sessSysCurrentId ); return this.redirectLogin(actionInvocation, session, currentId, accountId); } if (uSessLogHelper.countByCurrent(accountObj.getAccount(), currentId)<1) { return this.redirectLogin(actionInvocation, session, currentId, accountId); } return actionInvocation.invoke(); } return this.redirectLogin(actionInvocation, session, currentId, accountId); }
Example 2
Source File: ActionInfoSupportInterceptor.java From bamboobsc with Apache License 2.0 | 6 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { /* ActionInvocation ai=(ActionInvocation)ActionContext.getContext().get(ActionContext.ACTION_INVOCATION); String action=ai.getProxy().getActionName(); String namespace=ai.getProxy().getNamespace(); */ HttpServletRequest request=ServletActionContext.getRequest(); ActionContext context=actionInvocation.getInvocationContext(); String action=actionInvocation.getProxy().getActionName(); String namespace=actionInvocation.getProxy().getNamespace(); String remoteAddr=request.getRemoteAddr(); String referer=request.getHeader("referer"); context.getSession().put(Constants.SESS_PAGE_INFO_ACTION_ByInterceptor, action); context.getSession().put(Constants.SESS_PAGE_INFO_NAMESPACE_ByInterceptor, namespace); context.getSession().put(Constants.SESS_PAGE_INFO_RemoteAddr_ByInterceptor, remoteAddr); context.getSession().put(Constants.SESS_PAGE_INFO_Referer_ByInterceptor, referer); return actionInvocation.invoke(); }
Example 3
Source File: LogonInterceptor.java From aliada-tool with GNU General Public License v3.0 | 6 votes |
/** * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation) * @param invocation * The ActionInvocation to set. * @return Returns the result of the invocation. * @throws Exception for the invoke method */ public String intercept(final ActionInvocation invocation) throws Exception { final ActionContext context = invocation.getInvocationContext(); HttpServletRequest request = (HttpServletRequest) context .get(HTTP_REQUEST); HttpSession session = request.getSession(true); // Is there a "user" object stored in the user's HttpSession? Object user = session.getAttribute(USER_HANDLE); if (user == null) { // The user has not logged in yet. // Is the user attempting to log in right now? String loginAttempt = request.getParameter(LOGIN_ATTEMPT); /* The user is attempting to log in. */ if (!StringUtils.isBlank(loginAttempt)) { return invocation.invoke(); } return "logon"; } else { return invocation.invoke(); } }
Example 4
Source File: JsonOutermostBracketsInterceptor.java From bamboobsc with Apache License 2.0 | 5 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { ActionContext context=actionInvocation.getInvocationContext(); HttpServletResponse response=(HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE); response.setCharacterEncoding("utf8"); response.setContentType("text/html"); PrintWriter writer=response.getWriter(); writer.print("["); writer.flush(); String forward=actionInvocation.invoke(); writer.print("]"); writer.flush(); return forward; }
Example 5
Source File: NoCacheHeaderInterceptor.java From bamboobsc with Apache License 2.0 | 5 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { ActionContext context=actionInvocation.getInvocationContext(); HttpServletResponse response=(HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE); if (response!=null ) { response.setHeader("Cache-control", "no-cache, no-store"); response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "0"); } return actionInvocation.invoke(); }
Example 6
Source File: UserLoginInterceptor.java From hrms with Apache License 2.0 | 5 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { ActionContext actionContext = actionInvocation.getInvocationContext(); Object user = actionContext.getSession().get("user"); if(user != null){ return actionInvocation.invoke(); } else{ actionContext.put("loginMessage", "您尚未登陆,请先登陆"); return Action.LOGIN; } }
Example 7
Source File: GuiFragmentResult.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Execute this result, using the specified fragment. * @param code The code of the fragment * @param invocation The invocation */ @Override public void doExecute(String code, ActionInvocation invocation) throws Exception { if (null == code) { code = conditionalParse(this._code, invocation); } if (null == code) { this.executeDispatcherResult(invocation); return; } ActionContext ctx = invocation.getInvocationContext(); HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST); IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, req); try { GuiFragment guiFragment = guiFragmentManager.getGuiFragment(code); String output = (null != guiFragment) ? guiFragment.getCurrentGui() : null; if (StringUtils.isBlank(output)) { _logger.info("The fragment '{}' is not available - Action '{}' - Namespace '{}'", code, invocation.getProxy().getActionName(), invocation.getProxy().getNamespace()); boolean execution = this.executeDispatcherResult(invocation); if (!execution) { output = "The fragment '" + code + "' is not available"; } else { return; } } RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX); ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER); Writer writer = this.getWriter(); Template template = new Template(code, new StringReader(output), ebc.getConfiguration()); template.process(ebc.getTemplateModel(), writer); } catch (Throwable t) { _logger.error("Error processing GuiFragment result!", t); throw new RuntimeException("Error processing GuiFragment result!", t); } }
Example 8
Source File: UserLoginInterceptor.java From bamboobsc with Apache License 2.0 | 4 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { ActionContext actionContext=actionInvocation.getInvocationContext(); Map<String, Object> session=actionContext.getSession(); this.accountObj = (AccountObj)session.get(Constants.SESS_ACCOUNT); boolean getUserCurrentCookieFail = false; // 有 sysCurrentId 的 cookie, 但用這個cookie資料count tb_sys_usess 又與 core-web 的資料不符 /* * String contextPath = ServletActionContext.getServletContext().getContextPath(); * if (!contextPath.endsWith( ApplicationSiteUtils.getContextPathFromMap(Constants.getMainSystem()) ) ) { */ if ( !Constants.getSystem().equals(Constants.getMainSystem()) ) { /** * 1. 先用admin登入 * 2. 登出admin 改用 tester登入 * 這樣的話 gsbsc-web 的 http-session 還是admin , 所以非core-web 要檢查當前CURRENT cookie 中的帳戶是否與 gsbsc-web 一樣 * 要是不同的話就讓這個 http-session 失效掉 */ this.invalidCurrentSessionForDifferentAccount(actionContext); if (accountObj==null) { getUserCurrentCookie(actionContext); if (accountObj==null && UserCurrentCookie.foundCurrent( (HttpServletRequest)actionContext.get(StrutsStatics.HTTP_REQUEST) ) ) { // 有 sysCurrentId 的 cookie, 但用這個cookie資料count tb_sys_usess 又與 core-web 的資料不符 getUserCurrentCookieFail = true; } } } if (accountObj!=null && !StringUtils.isBlank(accountObj.getAccount()) ) { Map<String, String> dataMap = UserCurrentCookie.getCurrentData( (HttpServletRequest)actionContext.get(StrutsStatics.HTTP_REQUEST) ); String currentId = StringUtils.defaultString( dataMap.get("currentId") ); if ( StringUtils.isBlank(currentId) ) { currentId = "NULL"; } if (uSessLogHelper.countByCurrent(accountObj.getAccount(), currentId)<1) { return this.redirectLogin(session, getUserCurrentCookieFail); } boolean isUnknownSession = false; SecurityUtils.setSecurityManager( (DefaultSecurityManager)AppContext.getBean("securityManager") ); Subject subject = SecurityUtils.getSubject(); try { if (subject.isAuthenticated() && !accountObj.getAccount().equals(subject.getPrincipal()) ) { subject.logout(); } } catch (ExpiredSessionException ese) { logger.warn( ese.getMessage().toString() ); return this.redirectLogin(session, getUserCurrentCookieFail); } catch (UnknownSessionException ue) { logger.warn( ue.getMessage().toString() ); isUnknownSession = true; } /** * core-web 有 session了, 但gsbsc-web 沒有session, 所以產生gsbsc-web 的 http session * 或是 apache shiro session 失效 expires */ if ( !subject.isAuthenticated() || isUnknownSession ) { GreenStepBaseUsernamePasswordToken token = new GreenStepBaseUsernamePasswordToken(); //token.setRememberMe(true); token.setRememberMe(false); token.setCaptcha(""); token.setUsername(accountObj.getAccount()); token.setPassword( ((AccountVO)accountObj).getPassword().toCharArray() ); try { subject.login(token); } catch (UnknownAccountException uae) { logger.warn( uae.getMessage().toString() ); subject = new Subject.Builder().buildSubject(); subject.login(token); } catch (UnknownSessionException use) { logger.warn( use.getMessage().toString() ); subject = new Subject.Builder().buildSubject(); /* Serializable sessionId = subject.getSession().getId(); System.out.println("SESSION_ID=" + sessionId); subject = new Subject.Builder( (DefaultSecurityManager)AppContext.getBean("securityManager") ) .sessionId(sessionId) .buildSubject(); */ subject.login(token); } UserAccountHttpSessionSupport.create(actionContext, accountObj); } return actionInvocation.invoke(); } return this.redirectLogin(session, getUserCurrentCookieFail); }
Example 9
Source File: SyslogInterceptor.java From hrms with Apache License 2.0 | 4 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { Syslog syslog = new Syslog(); ActionContext actionContext = actionInvocation.getInvocationContext(); HttpServletRequest request = (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST); String accessIp = getIpAddr(request); syslog.setAccessIp(accessIp); StringBuffer url = request.getRequestURL(); int slash = url.lastIndexOf("/"); String linkUrl = url.substring(slash+1); int point = linkUrl.lastIndexOf("."); if (point>0) { linkUrl = linkUrl.substring(0,point); } int bottomLine = linkUrl.lastIndexOf("_"); String result; String userId; String actionId = "1"; String actionStr = linkUrl.substring(linkUrl.lastIndexOf("_")+1); if(actionStr.equals("add")) { actionId = "2"; } else if (actionStr.equals("update")) { actionId = "3"; }else if (actionStr.equals("delete")) { actionId = "4"; } if(linkUrl.equals("user_login")) { syslog.setAction("登入"); result = actionInvocation.invoke(); userId = actionContext.getSession().get("userId").toString(); }else { userId = actionContext.getSession().get("userId").toString(); if(linkUrl.equals("user_loginOut")) { syslog.setAction("退出"); }else { if (actionId != null && actionId.trim() != "") { Action action = (Action) actionService.findById(Integer.valueOf(actionId)); if (action!=null) { syslog.setAction(action.getAction()); } } } result = actionInvocation.invoke(); } if (bottomLine>0) { linkUrl = linkUrl.substring(0,bottomLine); } if (userId != null && actionId != null && !actionId.equals("1")) { syslog.setDate(new Date()); Module module = moduleService.getModuleByLinkUrl(linkUrl); syslog.setModule(module); if (result.equals("error")) { syslog.setType("错误"); } else if((result.equals("input"))){ syslog.setType("警告"); } else { syslog.setType("信息"); } syslog.setUser(userService.findById(Integer.valueOf(userId))); if (result.equals("success") || result.equals("error") || result.equals("input")) { syslogService.save(syslog); } return result; } return "login"; }
Example 10
Source File: PermissionInterceptor.java From hrms with Apache License 2.0 | 4 votes |
@Override public String intercept(ActionInvocation actionInvocation) throws Exception { ActionContext actionContext = actionInvocation.getInvocationContext(); HttpServletRequest request = (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST); String userId = actionContext.getSession().get("userId").toString(); String contextPath = request.getContextPath(); StringBuffer url = request.getRequestURL(); int contextPathPost = url.lastIndexOf(contextPath); int contextPathLength = contextPath.length(); String linkUrl = url.substring(contextPathPost + contextPathLength + 1); String actionId = ""; int bottomLine = linkUrl.lastIndexOf("_"); String action = linkUrl.substring(bottomLine+1); if(bottomLine < 0 || action.equals("my")) { actionId = "1"; } else if(action.equals("add")) { actionId = "2"; } else if (action.equals("update")) { actionId = "3"; }else if (action.equals("delete")) { actionId = "4"; } else if (action.equals("approverList") || action.equals("transactorList")) { actionId = "5"; } else { actionId = "6"; } if (bottomLine>0) { linkUrl = linkUrl.substring(0,bottomLine); } Module module = moduleService.getModuleByLinkUrl(linkUrl); if (userId != null && module!=null) { String moduleId = module.getModuleId().toString(); if (userPermissionService.checkPermission(userId, moduleId,actionId)) { return actionInvocation.invoke(); } } if (module==null) { return actionInvocation.invoke(); } actionContext.put("permissionMessage", "你没有该权限,请先登陆"); return Action.NONE; }
Example 11
Source File: LogInterceptor.java From csustRepo with MIT License | 4 votes |
@SuppressWarnings("unchecked") public String intercept(ActionInvocation invocation) throws Exception { ActionContext actionContext=invocation.getInvocationContext(); HttpServletRequest request=(HttpServletRequest) actionContext.get(ServletActionContext.HTTP_REQUEST); String actionName=actionContext.getName(); String description=null; String type=null; //取出并遍历所有的permission对象,如果有含有actionName一样的则把对应的操作保存到description for (RepPermission permission : list) { if(permission.getActionname().equals(actionName)){ description=permission.getName(); } } //根据actionName里面包含的关键字判断操作的类型 String actionNameLowerCase=actionName.toLowerCase(); if(actionNameLowerCase.contains("add")){ type="新增"; }else if (actionNameLowerCase.contains("delete")) { type="删除"; }else if (actionNameLowerCase.contains("update") ||actionNameLowerCase.contains("lock") ||actionNameLowerCase.contains("pass") ||actionNameLowerCase.contains("modify")) { type="修改"; }else if(actionNameLowerCase.contains("login")){ type="登录"; description="登录后台"; }else if (actionNameLowerCase.contains("logout")) { type="登出"; description="登出后台"; } //创建RepLog对象来报错日志信息 RepLog log=new RepLog(); log.setOperationtime(new Date()); log.setOperationip(request.getRemoteAddr()); //执行action并获取执行完成的结果 String result=invocation.invoke(); String resultLowerCase=null; if(result!=null){ resultLowerCase=result.toLowerCase(); } //根据resultCode判断是否执行成功,不成功的话则什么也 不做 if(resultLowerCase==null ||resultLowerCase.equals("faild") ||resultLowerCase.equals("add") ||resultLowerCase.equals("edit") ||resultLowerCase.equals("modify") ||resultLowerCase.equals("login") ){ /* * 成功的话根据 * description是否为空(即是否是有对应permission的action) * type是否为空(既是否是含有增删改登陆登出的关键字)判断访问的action是否有必要记录。 */ }else if(description!=null&&type!=null){ RepAdmin admin=(RepAdmin) actionContext.getSession().get(RepAdmin.ADMIN); log.setRepAdmin(admin); log.setDescription(description); log.setOperationtype(type); log.setOperator(admin.getUsername()); logService.add(log); Integer id=log.getId(); List<Integer> ids=logService.findByhql( "select l.id from RepLog l where l.id<?", 0, id-800000); logService.deleteAll(ids); } // logService.remove(); return result; }