仅用用户名单点登录
1. 问题描述
对于用户已有系统中想实现对FineReport的单点登录,一般用户需要在已有的登录界面中将用户名和密码传入到报表的认证地址进行认证,有些情况下,由于各种原因,只能传用户名给报表服务器,不能传密码过来验证,针对于这种情况,这里提供一个仅通过用户名来单点登录的方案;或者需要传一个加密后的密码过来验证,也可以通过同样的方式来实现单点登录。
2. 示例仅用用户名登录
提供一个用来做登录操作的jsp,通过传用户名给oaauth.jsp来实现单点登录到报表工程.
2.1 编写jsp文件
oaauth.jsp文件代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page
	import="com.fr.fs.base.entity.User,com.fr.fs.base.entity.UserInfo,com.fr.fs.control.UserControl,
com.fr.fs.privilege.auth.FSAuthentication,com.fr.fs.privilege.base.FServicePrivilegeLoader,
com.fr.fs.privilege.entity.DaoFSAuthentication,com.fr.privilege.session.PrivilegeInfoSessionMananger"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	 
	// 获取传过来的fr_username值
	String username = request.getParameter("fr_username");
	System.out.println(username);
	//如果用户名为空,跳转到登录页面
	if(username == null){
		response.sendRedirect("/WebReport/ReportServer?op=fs");
		return;
	}
	try {
		User U = UserControl.getInstance().getByUserName(username);
		//如果报表工程里没有对应传过来的用户名对应的用户信息,跳转到登录页面
		if (U == null) {
			//改成自己的登录界面
			response.sendRedirect("/WebReport/ReportServer?op=fs");
			return;
		}
		
		FSAuthentication authentication = new DaoFSAuthentication(new UserInfo(U.getId(), U.getUsername(), U.getPassword()));
		long userid = authentication.getUserInfo().getId();
		PrivilegeInfoSessionMananger.login(new FServicePrivilegeLoader(username, UserControl.getInstance().getAllSRoleNames(userid), UserControl.getInstance().getUserDP(userid)), session, response);
		session.setAttribute("fr_fs_auth_key", authentication);
		UserControl.getInstance().login(userid);
		//登录后跳转到决策平台地址,可以根据需要设置是否跳转及跳转的地址
		response.sendRedirect("/WebReport/ReportServer?op=fs");
		return;
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
2.2 使用jsp文件做登录
将oaauth.jsp文件保存到%FR_HOME%/WebReport 目录下,访问这个jsp文件并传用户名:http://localhost:8075/WebReport/oaauth.jsp?fr_username=Anna 即可实现单点登录。
注:报表工程里必须要有对应的用户名(可以没有密码)才可以登录成功。
3.示例用户名和加密后密码登录
提供一个用来做登录操作的jsp,通过传用户名和加密后的密码给oaauth.jsp来实现单点登录到报表工程.
3.1 编写jsp文件
oaauth.jsp文件代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page
	import="com.fr.fs.base.entity.User,com.fr.fs.base.entity.UserInfo,com.fr.fs.control.UserControl,
com.fr.fs.privilege.auth.FSAuthentication,com.fr.fs.privilege.base.FServicePrivilegeLoader,
com.fr.fs.privilege.entity.DaoFSAuthentication,com.fr.privilege.session.PrivilegeInfoSessionMananger"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	 
	// 获取传过来的fr_username值
	String username = request.getParameter("fr_username");
	System.out.println(username);
	//获取传过来的密码(密文/明文)
	String password = request.getParameter("fr_password");
	
	//TODO 解密密码
	// password = decode(password);
	//如果用户名为空,跳转到登录页面
	if(username == null){
		response.sendRedirect("/WebReport/ReportServer?op=fs");
		return;
	}
	try {
		//通过用户名,密码获取用户对象
		User U = UserControl.getInstance().getUser(username,password);
		
		//如果报表工程里没有对应传过来的用户名对应的用户信息,跳转到登录页面
		if (U == null) {
			//改成自己的登录界面
			response.sendRedirect("/WebReport/ReportServer?op=fs");
			return;
		}
		FSAuthentication authentication = new DaoFSAuthentication(new UserInfo(U.getId(), username, username));
		long userid = authentication.getUserInfo().getId();
		PrivilegeInfoSessionMananger.login(new FServicePrivilegeLoader(username, UserControl.getInstance().getAllSRoleNames(userid), UserControl.getInstance().getUserDP(userid)), session, response);
		session.setAttribute("fr_fs_auth_key", authentication);
		UserControl.getInstance().login(userid);
		//登录后跳转到决策平台地址,可以根据需要设置是否跳转及跳转的地址
		response.sendRedirect("/WebReport/ReportServer?op=fs");
		return;
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
3.2 使用jsp文件做登录
将oaauth.jsp文件保存到%FR_HOME%/WebReport 目录下,访问这个jsp文件并传用户名:http://localhost:8075/WebReport/oaauth.jsp?fr_username=Anna 即可实现单点登录。
注:如果加密后的密码里有加号("+"),直接获取的时候会识别为空格(" "),可以通过在加密后把加号("+")替换成下划线("_"),然后在jsp里获取到密文的密码后再把下划线("_")替换成加号("+"),然后再解密,即可正常登录。
注:报表工程里必须要有对应的用户名和密码才可以登录成功。
附件列表
       主题: 部署集成
      
	 
             
        
 
            
              
  
    
