⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rolesinterceptor.java

📁 struts 2 核心包 的源码 有错误是难免的
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   RolesInterceptor.java

package org.apache.struts2.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;

public class RolesInterceptor extends AbstractInterceptor
{

	private List allowedRoles;
	private List disallowedRoles;

	public RolesInterceptor()
	{
		allowedRoles = new ArrayList();
		disallowedRoles = new ArrayList();
	}

	public void setAllowedRoles(String roles)
	{
		allowedRoles = stringToList(roles);
	}

	public void setDisallowedRoles(String roles)
	{
		disallowedRoles = stringToList(roles);
	}

	public String intercept(ActionInvocation invocation)
		throws Exception
	{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		String result = null;
		if (!isAllowed(request, invocation.getAction()))
			result = handleRejection(invocation, response);
		else
			result = invocation.invoke();
		return result;
	}

	protected List stringToList(String val)
	{
		if (val != null)
		{
			String list[] = val.split("[ ]*,[ ]*");
			return Arrays.asList(list);
		} else
		{
			return Collections.EMPTY_LIST;
		}
	}

	protected boolean isAllowed(HttpServletRequest request, Object action)
	{
label0:
		{
			if (allowedRoles.size() > 0)
			{
				boolean result = false;
				Iterator i$ = allowedRoles.iterator();
				do
				{
					if (!i$.hasNext())
						break;
					String role = (String)i$.next();
					if (request.isUserInRole(role))
						result = true;
				} while (true);
				return result;
			}
			if (disallowedRoles.size() <= 0)
				break label0;
			Iterator i$ = disallowedRoles.iterator();
			String role;
			do
			{
				if (!i$.hasNext())
					break label0;
				role = (String)i$.next();
			} while (!request.isUserInRole(role));
			return false;
		}
		return true;
	}

	protected String handleRejection(ActionInvocation invocation, HttpServletResponse response)
		throws Exception
	{
		response.sendError(403);
		return null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -