<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="org.jasig.cas.client.authentication.AttributePrincipal" %>
<%@ page import="org.jasig.cas.client.util.AssertionHolder"%>
<%@ page import="com.gaowj.business.comp.BusinessManager" %>
<%@ page import="com.gaowj.business.SystemOpeBusiness" %>
<%@ page import="com.gaowj.business.util.Java_tool" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Map" %>
<%
//解决在IE的frame/iframe环境下，跨域单点登录后，无法重定向的问题
response.setHeader("P3P","CP=CAO PSA OUR");
%>
<%
AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal();
Map<String, Object> attributes = principal.getAttributes();
String userID = attributes.get("userid").toString();
String userName = attributes.get("USER_NAME").toString();
System.out.println("-----1"+userID);
System.out.println("-----2"+userName);
System.out.println("-----3"+attributes.get("UNIT_ID"));
if(userID!=null){
  String username = userID;
  Java_tool jt = new Java_tool();
  SystemOpeBusiness systemOpeBusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
  
  Map query = new HashMap();
  query.put("EMID", username);
  Map<String,Object> userInfoI = systemOpeBusiness.listLoginUserInfo(query).get(0);
  Map<String,Object> sessionUser = new HashMap<String,Object>();
  String u_all_m  = systemOpeBusiness.getUserAllModule(userInfoI.get("CODE").toString());
  sessionUser.put("CODE",userInfoI.get("CODE"));
  sessionUser.put("EMID",userInfoI.get("EMID"));
  sessionUser.put("EMSEX",userInfoI.get("EMSEX"));
  sessionUser.put("EMDEPARTNAME",userInfoI.get("EMDEPARTNAME"));
  sessionUser.put("EMDEPART",userInfoI.get("EMDEPART"));
  sessionUser.put("EMNAME",userInfoI.get("EMNAME"));
  sessionUser.put("BEFORETIME",userInfoI.get("BEFORETIME"));
                	    
  sessionUser.put("SESSIONID", request.getSession().getId());
  sessionUser.put("CURRENTTIME", jt.now_datetime());
  sessionUser.put("LOGINIP", request.getRemoteAddr());
  sessionUser.put("SERVERIP", request.getLocalAddr());
  sessionUser.put("QUANXIAN",u_all_m);
  request.getSession().setAttribute("userInfo", sessionUser);
  //增加登陆日志
  Map<String,Object> log = new HashMap<String,Object>();
  log.put("CODE", sessionUser.get("CODE"));log.put("EMNAME", sessionUser.get("EMNAME"));log.put("EMIP", sessionUser.get("LOGINIP"));
  log.put("OPENAME", "登陆");log.put("OPETIME", jt.String3date((String)sessionUser.get("CURRENTTIME")));log.put("TYPE", userInfoI.get("TYPE"));
  log.put("OPETYPE", "B/S登陆");
  systemOpeBusiness.insert_log(log);
}
    String strRedirecturl = request.getParameter("redirectUrl");
	if(strRedirecturl != null && strRedirecturl.length() > 0) {
		response.sendRedirect(strRedirecturl);
	}else{
		response.sendRedirect("index.jsp");
	}
   response.getWriter().println("123");
%>