contextmanager.java

来自「web项目的sso单点登录」· Java 代码 · 共 41 行

JAVA
41
字号
package com.neusoft.sso;

import java.util.Set;

import javax.servlet.ServletContext;

/**************************************************
 * NAME : ContextManager.java
 * HISTORY
 * 2007-08-15 shanc  创建文件
 * 注意:这个类是个包访问权限的类,使用Sso组件的程序员,不建议了解该类的具体结构
 *************************************************/
class ContextManager { 
	static boolean hasUser(ServletContext context,String paraName){	
		//获取其他所有平台的context,并遍历其中的Set
		String[] otherNames = Global.getOthersNames();
		for(int i = 0;i<otherNames.length;i++){
			String otherName = otherNames[i];
			ServletContext otherC = context.getContext("/"+otherName);
			Set ssoUserSet = (Set)otherC.getAttribute(Global.SET_NAME);
			if(ssoUserSet.contains(paraName))//已在别的应用中登录
				return true;
		}
		return false;
	}
	
	static void clearContext(ServletContext context,String paraName){
		//获取自身平台的Set,并清除Set中的paraName
		Set selfUserSet = (Set)context.getAttribute(Global.SET_NAME);
		selfUserSet.remove(paraName);
		//获取其他所有平台的context,并清除Set中的paraName
		String[] otherNames = Global.getOthersNames();
		for(int i = 0;i<otherNames.length;i++){
			String otherName = otherNames[i];
			ServletContext otherC = context.getContext("/"+otherName);
			Set ssoUserSet = (Set)otherC.getAttribute(Global.SET_NAME);
			ssoUserSet.remove(paraName);
		}
	}
}

⌨️ 快捷键说明

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