BusinessObject Enterprise SDK应用开发(下)
在一般的BO项目开发中,为了更快速的进行项目的周期性的开发,通常使用这样的开发方式:
登录CMS认证,认证完毕,获得TOKEN(所谓的TOKEN就是一个凭证,类似唐僧的通关文碟,有了这个东西,只要带着它,可以畅行无阻),在后面的开发中,都是通过OpenDocument的方式来直接使用InfoView中的功能,在打开报表时,带着这个TOKEN,就不需要在Cms中再次认证(报表文件的数据源的证证,可以在CMS中设置)。
本文主要讲述认证的过程,先介绍这个过程中使用的几个类:
com.crystaldecisions.sdk.framework.CrystalEnterprise 用于获取很多可用对象,包括本文中的ISessionMgr
com.crystaldecisions.sdk.framework.ISessionMgr 会话管理器
com.crystaldecisions.sdk.framework.IEnterpriseSession企业级会话
登录使用的安全协议(Security protocols):
com.crystaldecisions.sdk.plugin.authentication.enterprise.IsecEnterprise 企业级
com.crystaldecisions.sdk.plugin.authentication.ldap.IsecLDAP LDAP方式
com.crystaldecisions.sdk.plugin.authentication.secwinnt.IsecWinNT window系统登录
com.crystaldecisions.sdk.plugin.authentication.secwinad.IsecWinAD window动态目录
下面的例子展示如何认证:
<%@ page contentType="text/html; charset=GBK" language="java"%>
<%@ page import="com.crystaldecisions.sdk.framework.ISessionMgr"%>
<%@ page import="com.crystaldecisions.sdk.framework.CrystalEnterprise"%>
<%@ page import="com.crystaldecisions.sdk.framework.IEnterpriseSession"%>
<%@ page import="com.crystaldecisions.sdk.occa.security.ILogonTokenMgr"%>
try {
<%@ page import="com.crystaldecisions.sdk.framework.ISessionMgr"%>
<%@ page import="com.crystaldecisions.sdk.framework.CrystalEnterprise"%>
<%@ page import="com.crystaldecisions.sdk.framework.IEnterpriseSession"%>
<%@ page import="com.crystaldecisions.sdk.occa.security.ILogonTokenMgr"%>
try {
//CMS服务器名,也可以是IP地址
String cms = "10.16.11.83:6400";
String cms = "10.16.11.83:6400";
//认证的安全类型,类型是以上几种,如果是SAP,则类型字符为secSAPR3
String authentication = "secEnterprise";
//用户名,如果是SAP系统方式登录,格式为bwp~888/eiacext1
String username ="username";
String username ="username";
String password = "password";//密码
//登录并获得TOKEN,并命名用OpenDocument方式打开一个文件
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
IEnterpriseSession enterpriseSession = sessionMgr.logon( username, password, cms + ":6400", authentication);
ILogonTokenMgr mgr = enterpriseSession.getLogonTokenMgr();
String defaultToken = mgr.getDefaultToken();
IEnterpriseSession enterpriseSession = sessionMgr.logon( username, password, cms + ":6400", authentication);
ILogonTokenMgr mgr = enterpriseSession.getLogonTokenMgr();
String defaultToken = mgr.getDefaultToken();
session.setAttribute("token",defaultToken);
String url = "http://10.16.11.83:8080/OpenDocument/opendoc/openDocument.jsp?iDocID=8797&sType=rpt&token="+defaultToken;
response.sendRedirect(url);
}catch(SDKException ex){
throw new Error("A error has occured :"+ex.getLocalizedMessage());
}
String url = "http://10.16.11.83:8080/OpenDocument/opendoc/openDocument.jsp?iDocID=8797&sType=rpt&token="+defaultToken;
response.sendRedirect(url);
}catch(SDKException ex){
throw new Error("A error has occured :"+ex.getLocalizedMessage());
}
其中winNT的方式WEB中不支持,可以通过ISessionMgr.getInstalledAuthIDs的方法或者登录安全方式字符串,分别为:
secEnterprise
secWinAD
secLDAP
secSAPR3