Java Code Examples for com.opensymphony.xwork2.ActionInvocation#invoke()

The following examples show how to use com.opensymphony.xwork2.ActionInvocation#invoke() . 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: AuthenticationInterceptor.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation)
		throws Exception {
	System.out.println("inside auth interceptor");
	Map<String, Object> sessionAttributes = actionInvocation.getInvocationContext().getSession();
	
	User user = (User) sessionAttributes.get("USER");
	
	if(user == null){
		return Action.LOGIN;
	}else{
		Action action = (Action) actionInvocation.getAction();
		if(action instanceof UserAware){
			((UserAware) action).setUser(user);
		}
		return actionInvocation.invoke();
	}
}
 
Example 2
Source File: ConfigInterceptor.java    From S-mall-ssh with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {

    HttpServletRequest request = (HttpServletRequest) actionInvocation.getInvocationContext().get(StrutsStatics.HTTP_REQUEST);
    Object action = actionInvocation.getAction();
    Map<String,String> config = configService.map();
    //配置首页SEO参数
    if(action.getClass().getSimpleName().equals("ShowAction")&&actionInvocation.getProxy().getMethod().equals("home")){
        String indexTitle = config.get("index_title");
        String indexKeyword = config.get("index_keyword");
        String indexDescription = config.get("index_description");
        request.setAttribute("SEOTitle",indexTitle);
        request.setAttribute("keywords",indexKeyword);
        request.setAttribute("description",indexDescription);
    }
    request.setAttribute("website_name",config.get("website_name"));
    request.setAttribute("productImgDir",config.get("path_product_img"));
    request.setAttribute("categoryImgDir",config.get("path_category_img"));
    return  actionInvocation.invoke();

}
 
Example 3
Source File: AbstractPreResultListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public final String intercept( ActionInvocation actionInvocation ) throws Exception
{
    actionInvocation.addPreResultListener( this );

    executePreResultListener = true;

    try
    {
        return actionInvocation.invoke();
    }
    catch ( Exception e )
    {
        executePreResultListener = false;
        throw e;
    }
}
 
Example 4
Source File: QueryParamInspectInterceptor.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
	Annotation[] actionMethodAnnotations = null;
	Method[] methods = actionInvocation.getAction().getClass().getMethods();
	for (Method method : methods) {
		if (actionInvocation.getProxy().getMethod().equals(method.getName())) {
			actionMethodAnnotations = method.getAnnotations();
		}
	}		
	if (actionMethodAnnotations!=null && actionMethodAnnotations.length>0) {
		try {
			this.log(actionInvocation, actionMethodAnnotations);
		} catch (ServiceException e) {
			e.printStackTrace();
		}
	}		
	return actionInvocation.invoke();
}
 
Example 5
Source File: LoginInterceptor.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String intercept( ActionInvocation invocation )
    throws Exception
{
    Boolean jli = (Boolean) ServletActionContext.getRequest().getSession()
        .getAttribute( LoginInterceptor.JLI_SESSION_VARIABLE );

    if ( jli != null )
    {
        log.debug( "JLI marker is present. Running " + actions.size() + " JLI actions." );

        for ( Action a : actions )
        {
            a.execute();
        }

        ServletActionContext.getRequest().getSession().removeAttribute( LoginInterceptor.JLI_SESSION_VARIABLE );
    }

    return invocation.invoke();
}
 
Example 6
Source File: XWorkPortalMenuInterceptor.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String intercept( ActionInvocation invocation )
    throws Exception
{
    Map<String, MenuState> menuStateMap = new HashMap<>( 1 );

    MenuState menuState = menuStateManager.getMenuState();

    if ( menuState == null )
    {
        menuState = MenuState.VISIBLE;
    }

    menuStateMap.put( KEY_MENU_STATE, menuState );

    invocation.getStack().push( menuStateMap );

    return invocation.invoke();
}
 
Example 7
Source File: StrutsInterceptor.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * Intercepte une exécution d'action struts.
 * @param invocation ActionInvocation
 * @return String
 * @throws Exception e
 */
@Override
public String intercept(ActionInvocation invocation) throws Exception { // NOPMD
	// cette méthode est appelée par struts
	if (DISABLED || !STRUTS_COUNTER.isDisplayed()) {
		return invocation.invoke();
	}
	boolean systemError = false;
	try {
		// Requested action name.
		final String actionName = getRequestName(invocation);

		STRUTS_COUNTER.bindContextIncludingCpu(actionName);
		return invocation.invoke();
	} catch (final Error e) {
		// on catche Error pour avoir les erreurs systèmes
		// mais pas Exception qui sont fonctionnelles en général
		systemError = true;
		throw e;
	} finally {
		// on enregistre la requête dans les statistiques
		STRUTS_COUNTER.addRequestForCurrentContext(systemError);
	}
}
 
Example 8
Source File: ForfeitInterceptor.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
@Override
public String intercept(ActionInvocation invocation) throws Exception {
	
	 Map sessionMap = ServletActionContext.getContext().getSession();
	 
	 Object obj = sessionMap.get("admin");
	 if(obj!=null && obj instanceof Admin){
		 Admin admin = (Admin) obj;
		 Authorization authorization = admin.getAuthorization();
		 if(authorization.getForfeitSet()==1 || authorization.getSuperSet()==1){
			 return invocation.invoke(); 
		 }
	 }
	return "nopass";
}
 
Example 9
Source File: LoginedCheckInterceptor.java    From scada with MIT License 5 votes vote down vote up
@Override
public String intercept(ActionInvocation invocation) throws Exception {
	//ȡ�������URL
       String url = ServletActionContext.getRequest().getRequestURL().toString();
       HttpServletResponse response=ServletActionContext.getResponse();
       response.setHeader("Pragma","No-cache");          
       response.setHeader("Cache-Control","no-cache");   
       response.setHeader("Cache-Control", "no-store");   
       response.setDateHeader("Expires",0);
       User user = null;
       //�Ե�¼��ע������ֱ�ӷ���,��������
       if (url.indexOf("loginAction_loginValidate")!=-1 || url.indexOf("loginAction_safeExit")!=-1 ){
           return invocation.invoke();
       }
       else{
           //��֤Session�Ƿ����
           if(!ServletActionContext.getRequest().isRequestedSessionIdValid()){
               //session����,ת��session������ʾҳ,������ת����¼ҳ��
               return "tologin";
           }
           else{
               user = (User)ServletActionContext.getRequest().getSession().getAttribute("global_user");
               //��֤�Ƿ��Ѿ���¼
               if (user==null){
                   //��δ��¼,��ת����¼ҳ��
                   return "tologin";
               }else{                    
                   return invocation.invoke();
                               
               }                
           }            
       }
}
 
Example 10
Source File: CheckInterceptor.java    From OnlineAuction with Apache License 2.0 5 votes vote down vote up
public String intercept(ActionInvocation arg0) throws Exception {
	Map<String, Object> session = arg0.getInvocationContext().getSession();
	Users u = (Users) session.get("user");
	if(u != null)
		return arg0.invoke();
	else 
		return "login";
}
 
Example 11
Source File: UserLoginInterceptor.java    From hrms with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: RedirectMessageInterceptor.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String doIntercept(ActionInvocation invocation) throws Exception {
	Object action = invocation.getAction();
	if (action instanceof ValidationAware) {
		before(invocation, (ValidationAware) action);
	}

	String result = invocation.invoke();

	if (action instanceof ValidationAware) {
		after(invocation, (ValidationAware) action);
	}
	return result;
}
 
Example 13
Source File: JsonOutermostBracketsInterceptor.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: AuthInterceptor.java    From S-mall-ssh with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    //获取访问页面的权限
    //获取方法上的注解
    Object action =actionInvocation.getAction();
    String methodName=actionInvocation.getProxy().getMethod();
    Auth authInMethod=action.getClass().getMethod(methodName).getAnnotation(Auth.class);
    //获取类上的注解
    Auth authInClass = action.getClass().getAnnotation(Auth.class);
    //获取Enum方法的ordinal,根据大小来确定该页面权限
    int pageRate = authInClass==null?0:authInClass.value().ordinal();
    pageRate = authInMethod == null?pageRate:authInMethod.value().ordinal();


    //获取用户的权限
    int userRate = 0;
    User user = (User) ActionContext.getContext().getSession().get("user");
    if(user!=null){
        userRate = user.getGroup().ordinal();
    }

    //顺带注入user
    if(user!=null && action instanceof SetUser){
        action.getClass().getMethod("setUser",User.class).invoke(action,user);
    }

    //根据权限决定是否放行
    if(pageRate>userRate){
        if(userRate == 0) {
            ServletActionContext.getResponse().sendRedirect("/login");
            return null;
        }
        return "/noAuth";
    }
    return  actionInvocation.invoke();
}
 
Example 15
Source File: CategoryNamesBelowSearchInterceptor.java    From S-mall-ssh with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    ServletContext servletContext= (ServletContext) actionInvocation.getInvocationContext().get(StrutsStatics.SERVLET_CONTEXT);
    Long oldTime = (Long)servletContext.getAttribute("csTimeOut");
    if(oldTime == null || System.currentTimeMillis()>oldTime) {
        servletContext.setAttribute("cs", categoryService.list("desc", "recommend", "max", 7));
        //1分钟内,全站用户只统一获取一次
        servletContext.setAttribute("csTimeOut", System.currentTimeMillis() + 60 * 1000);
    }
    return  actionInvocation.invoke();
}
 
Example 16
Source File: XWorkPortalModuleInterceptor.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String intercept( ActionInvocation actionInvocation )
    throws Exception
{
    String contextPath = ContextUtils.getContextPath( ServletActionContext.getRequest() );
    
    Map<String, Object> handle = new HashMap<>( 2 );

    handle.put( KEY_MENU_MODULES, moduleManager.getAccessibleMenuModulesAndApps( contextPath ) );

    actionInvocation.getStack().push( handle );

    return actionInvocation.invoke();
}
 
Example 17
Source File: SyslogInterceptor.java    From hrms with Apache License 2.0 4 votes vote down vote up
@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 18
Source File: XWorkPortalParamsInterceptor.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public String intercept( ActionInvocation actionInvocation )
    throws Exception
{
    ActionConfig actionConfig = actionInvocation.getProxy().getConfig();

    final Map<String, String> staticParams = actionConfig.getParams();

    if ( staticParams != null )
    {
        // ---------------------------------------------------------------------
        // Push the specified static parameters onto the value stack
        // ---------------------------------------------------------------------

        Map<String, Object> matches = new HashMap<>();

        for ( Map.Entry<String, String> entry : staticParams.entrySet() )
        {
            if ( standardParams.contains( entry.getKey() ) )
            {
                matches.put( entry.getKey(), entry.getValue() );
            }
            else if ( commaSeparatedParams.contains( entry.getKey() ) )
            {
                String[] values = entry.getValue().split( "," );

                for ( int i = 0; i < values.length; i++ )
                {
                    values[i] = values[i].trim();
                }

                matches.put( entry.getKey(), values );
            }
        }

        actionInvocation.getStack().push( matches );
    }

    // TODO: move this to its own systemInfoInterceptor?
    Map<String, Object> systemInfo = new HashMap<>();

    String revision = systemService.getSystemInfo().getRevision();

    if ( StringUtils.isEmpty( revision ) )
    {
        revision = "__dev__";
    }

    systemInfo.put( "buildRevision", revision );
    actionInvocation.getStack().push( systemInfo );

    return actionInvocation.invoke();
}
 
Example 19
Source File: ControllerAuthorityCheckInterceptor.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
	String actionName = actionInvocation.getProxy().getActionName();
	String url = actionName + Constants._S2_ACTION_EXTENSION;		
	Subject subject = SecurityUtils.getSubject();
	/*
	if ( !Constants.getSystem().equals(Constants.getMainSystem()) ) {
		SecurityUtils.setSecurityManager( (DefaultSecurityManager)AppContext.getBean("securityManager") );
		subject = SecurityUtils.getSubject();			
	}
	*/
	if (subject.hasRole(Constants.SUPER_ROLE_ALL) || subject.hasRole(Constants.SUPER_ROLE_ADMIN)) {
		SysEventLogSupport.log( (String)subject.getPrincipal(), Constants.getSystem(), url, true );
		return actionInvocation.invoke();
	}		
	Annotation[] annotations = actionInvocation.getAction().getClass().getAnnotations();
	Annotation[] actionMethodAnnotations = null;
	Method[] methods = actionInvocation.getAction().getClass().getMethods();
	for (Method method : methods) {
		if (actionInvocation.getProxy().getMethod().equals(method.getName())) {
			actionMethodAnnotations = method.getAnnotations();
		}
	}		
	if (this.isControllerAuthority(annotations, actionMethodAnnotations, subject)) {
		SysEventLogSupport.log( (String)subject.getPrincipal(), Constants.getSystem(), url, true );
		return actionInvocation.invoke();
	}		
	if (subject.isPermitted(url) || subject.isPermitted("/"+url)) {
		SysEventLogSupport.log( (String)subject.getPrincipal(), Constants.getSystem(), url, true );
		return actionInvocation.invoke();
	}
	logger.warn("[decline] user=" + subject.getPrincipal() + " url=" + url);
	String isDojoxContentPane = ServletActionContext.getRequest().getParameter(Constants.IS_DOJOX_CONTENT_PANE_XHR_LOAD);
	if (YesNo.YES.equals(isDojoxContentPane)) { // dojox.layout.ContentPane 它的 X-Requested-With 是 XMLHttpRequest
		SysEventLogSupport.log( (String)subject.getPrincipal(), Constants.getSystem(), url, false );
		return Constants._S2_RESULT_NO_AUTHORITH;
	}
	String header = ServletActionContext.getRequest().getHeader("X-Requested-With");
	if ("XMLHttpRequest".equalsIgnoreCase(header)) {
		PrintWriter printWriter = ServletActionContext.getResponse().getWriter();
		printWriter.print(Constants.NO_AUTHZ_JSON_DATA);
           printWriter.flush();
           printWriter.close();
           SysEventLogSupport.log( (String)subject.getPrincipal(), Constants.getSystem(), url, false );
		return null;
	}
	SysEventLogSupport.log( (String)subject.getPrincipal(), Constants.getSystem(), url, false );
	return Constants._S2_RESULT_NO_AUTHORITH;
}
 
Example 20
Source File: BaseInterceptorMadMax.java    From entando-core with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
   * Invokes the next step in processing this ActionInvocation. 
* @param invocation the execution state of the Action
   * @return The code of the execution result.
* @throws Exception in case of error
   */
  protected String invoke(ActionInvocation invocation) throws Exception {
      return invocation.invoke();
  }