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

The following examples show how to use com.opensymphony.xwork2.ActionInvocation#getAction() . 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: 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 2
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 3
Source File: CustomTokenInterceptor.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected String handleInvalidToken(ActionInvocation invocation) throws Exception {
    Object action = invocation.getAction();
    String errorMessage = this.getCustomMessage(invocation, "struts.messages.invalid.token",
            "The form has already been processed or no token was supplied, please try again.");
    String message = this.getCustomMessage(invocation, "struts.messages.invalid.token.message",
            "Stop double-submission of forms.");
    if (action instanceof ValidationAware) {
        if (null == this.getTypeMessages() || this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_NONE_MESSAGE)) {
            //nothing to do
        } else if (this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_ACTION_ERROR_MESSAGE)) {
            ((ValidationAware) action).addActionError(errorMessage);
        } else if (this.getTypeMessages().equalsIgnoreCase(TYPE_RETURN_ACTION_MESSAGE)) {
            ((ValidationAware) action).addActionMessage(message);
        } else {
            LOG.warn("Invalid message type : {}", this.getTypeMessages());
        }
    } else {
        LOG.warn(errorMessage);
    }
    return INVALID_TOKEN_CODE;
}
 
Example 4
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 5
Source File: CustomImageBytesResult.java    From aliada-tool with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(final ActionInvocation invocation) throws Exception {
	
	ImageAction action = (ImageAction) invocation.getAction();
	HttpServletResponse response = ServletActionContext.getResponse();

	response.setContentType(action.getCustomContentType());
	response.getOutputStream().write(action.getCustomImageInBytes());
	response.getOutputStream().flush();
	
}
 
Example 6
Source File: RedirectMessageInterceptor.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String doIntercept(ActionInvocation invocation) throws Exception {
	Object action = invocation.getAction();
	if (action instanceof ValidationAware) {
		this.before(invocation, (ValidationAware) action);
	}
	String result = invocation.invoke();
	if (action instanceof ValidationAware) {
		after(invocation, (ValidationAware) action);
	}
	return result;
}
 
Example 7
Source File: CustomTokenInterceptor.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String getCustomMessage(ActionInvocation invocation, String key, String defaultText) {
    Object action = invocation.getAction();
    if (action instanceof TextProvider) {
        return ((TextProvider) action).getText(key, defaultText);
    }
    return textProvider.getText(key, defaultText);
}
 
Example 8
Source File: ActionLoggerInterceptor.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionLogRecord actionRecord = null;
    String result = null;
    try {
        actionRecord = this.buildActionRecord(invocation);
        result = invocation.invoke();
        List<ActivityStreamInfo> asiList = null;
        Object actionObject = invocation.getAction();
        if (actionObject instanceof BaseAction) {
            BaseAction action = (BaseAction) actionObject;
            asiList = action.getActivityStreamInfos();
        }
        this.includeActionProperties(actionRecord, actionObject);
        if (null == asiList || asiList.isEmpty()) {
            this.getActionLoggerManager().addActionRecord(actionRecord);
        } else {
            for (ActivityStreamInfo asi : asiList) {
                ActionLogRecord clone = this.createClone(actionRecord);
                clone.setActivityStreamInfo(asi);
                this.getActionLoggerManager().addActionRecord(clone);
            }
        }
    } catch (Throwable t) {
        _logger.error("error in intercept", t);
    }
    return result;
}
 
Example 9
Source File: InterceptorMadMax.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected String invoke(ActionInvocation invocation) throws Exception {
	Object action = invocation.getAction();
	if (action instanceof BaseAction) {
		Set<String> requiredPermissions = super.extractAllRequiredPermissions();
		((BaseAction) action).setRequiredPermissions(requiredPermissions);
	}
	HttpSession session = ServletActionContext.getRequest().getSession();
	UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
	_logger.debug("Action invoked '{}' on namespace '{}' from user '{}'", invocation.getProxy().getActionName(), invocation.getProxy().getNamespace(), currentUser.getUsername());
	return super.invoke(invocation);
}
 
Example 10
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;
}