2024年6月11日发(作者:)

Cognos 第三方认证Custom java provider这种认证是通过 java 接口实现的通过

java 类校验数据库中的用户来通过验证这种验证方式可以节省项目成本提高服务

效率在 Cognos 安装目录下的 sdk 文件夹下有具体的 java 代码如:////Copyright c

2007 Cognos Incorporated. All Rights Reserved.//Cognos and the Cognos logo are

trademarks of Cognos Incorporated.//package authenticationimport port

putStreamimport import tiesimport

authentication.//import

tyConfiguratorimport

_Headerimport

_Header2import

_paceAuthenticationProvider2import

_paceConfigurationimport

_import

_Resultimport

_hExpressionimport

_hFilterimport

_hStepimport

_mport

_esultimport

_RecoverableExceptionimport

_splayObjectimport

_EchoDisplayObjectimport

_verableExceptionimport

_coverableExceptionimport

_Axispublic class

JDBCSample extends Namespace implements INamespaceAuthenticationProvider2

private String connectionString// private static LogWriter lw tant//

public static Log myLogger /

__er.I

NamespaceConfiguration / public void initINamespaceConfiguration

theNamespaceConfiguration throws UnrecoverableException

eNamespaceConfiguration e ault

playName //

uotxxxxxxxxxxxxx:quot try // // Read our configuration from this

Cognos 8 installs // configuration directory. // String configPath

tallLocation quot/configurationquot// File nsConfig

new FileconfigPath quotJDBC_Config_quot//

tiesquot// Properties nsProperties new Properties// FileInputStream input

new FileInputStreamnsConfig// put// String server

pertyquotserverquot// String databaseName

pertyquotdatabaseNamequot// connectionString

MS_nectionStringserver// databaseName//

MS_bConnectionconnectionString

ureconfigPath quot/tiesquot//

ureconfigPath quot/tiesquot catch Exception

e throw new UnrecoverableExceptionquotConfiguration Errorquot quotProvider

initialization failure. Reason: quot ng /

_

_Header2 / public IVisa logonIBiBusHeader2

theAuthRequest throws UserRecoverableException SystemRecoverableException

UnrecoverableException // uotstep1quot//

ogquot1111111111quot JDBCVisa visa null String username null String

password null username

stedEnvVarValuequotREMOTE_USERquot if username null

try visa new JDBCVisa is username0 catch UnrecoverableException ex

UserRecoverableException e new UserRecoverableException quot锟斤拷锟斤拷锟斤

拷锟斤拷锟斤拷没锟斤拷锟斤拷锟斤拷锟斤拷.quot quotquot

e .addDisplayObjectnewTextDisplayObjectquot锟矫伙拷锟斤

拷:quotquotCAMUsernamequot playObjectnew TextNoEchoDisplayObjectquot

锟斤拷锟斤拷:quot quotCAMPasswordquot throw e return visa // 1 - Look for

trusted credentials username

stedCredentialValuequotusernamequot password

stedCredentialValuequotpasswordquot if username null

ampamp password null // 2 - Look for credentials coming from SDK request

username dentialValuequotusernamequot password

dentialValuequotpasswordquot if username null ampamp

password null // 3 - Look for credentials in formfield username

mFieldValuequotCAMUsernamequot password

mFieldValuequotCAMPasswordquot if username null

password null UserRecoverableException e new UserRecoverableException

quotPlease type your credentials for quotThe provided credentials are

e .addDisplayObjectnew TextDisplayObjectquotUser ID:quot

quotCAMUsernamequot playObjectnew

TextNoEchoDisplayObjectquotPassword:quot quotCAMPasswordquot throw e try //

// Create a Visa for the new user. // visa new JDBCVisa// ogusername0//

og password0 is username0 password0// ogquotendquot

catch UnrecoverableException ex // Something went wrong probably because the users

credentials // are invalid. UserRecoverableException e new UserRecoverableException

quotThe provided credentials are invalid. Please type your credentials

ex .toString e .addDisplayObjectnew TextDisplayObjectquotUser

ID:quot quotCAMUsernamequot playObjectnew

TextNoEchoDisplayObjectquotPassword:quot quotCAMPasswordquot throw e return

visa /

_

_ _Header /

public void logoffIVisa theVisa IBiBusHeader theAuthRequest try // We can safely

assume that well get back the same Visa that we // issued. JDBCVisa visa JDBCVisa

theVisa y catch Throwable t /

_

_ _ / public

IQueryResult searchIVisa theVisa IQuery theQuery throws UnrecoverableException //

We can safely assume that well get back the same Visa that we // issued.//

ogquotsearchquot JDBCVisa visa JDBCVisa theVisa QueryResult result

new QueryResult try ISearchExpression expression rchExpression

String objectID ectID ISearchStep steps ps // It

doesnt make sense to have multiple steps for this provider // since the objects are not

hierarchical. if 1 throw new UnrecoverableException quotInternal

Errorquot quotInvalid search expression. Multiple steps is not supported for

StringBuffer sqlCondition new StringBuffer int searchType

s ISearchFilter filter dicate switch searchType case

: case dentOrSelf : case dent : if

objectID null if filter null sFilter filter ectthis // Add

current namespace if searchType return result else

QueryUtil .getSqlConditionfilter else if

Withquotu:quot ampamp ount .getObjectID if

filter null sFilterfilter // ogquotaaaaaaaaaaaaaaquot

ount// ogquotbbbbbbbbbbbbbbquot // Add current

user return result else if Withquotr:quot String sqlID

ing2 QueryUtil .getSqlConditionfilter if

gt 0 quot AND quot

//quotobjectID quot sqlID //by boc

quotobjectID rquot sqlID quotquot else if

Withquotu:quot String sqlID ing2

QueryUtil .getSqlConditionfilter if gt 0

quot AND quot //quotobjectID quot sqlID

//by quotobjectID uquot sqlID quotquot break default :

if objectID null //quotparentid is nullquot

quotparentid 0quot else String sqlID ing2

Conditionfilter if gt 0

quot AND quot // quotparentid quot sqlID

//by boc quotparentid quot sqlID quotquot break

ng ryOption perties

tProperties result this catch Throwable t tackTrace return

result 一、在 SecurityAuthentication 下 建 立 一 个 第 三 方 认 证 的 名 字 空

间 名 字 随 意 本 文 以QGYY_PORTAL 命名类型为 Custom java

providerNamespace ID:dbAuthJava class name:mple注意:这

里的 mple 是 包下的 authentication 下的

最后效果如下:修改 SecurityAuthenticationCognos 下的 allow

anonymous access 的值为 false二、ties 改一下连接信息放到

cognos/c8/configuration 下将 CAM_AAA_

这几个 jar 包放到 Cognos/c8/webapps/p2pd/WEB-INF/lib 下

三、在数据库中建立用户表的视图视图备份了数据库中的用户信息通过视图中的用

户来登录 Cognos 创建视图代码如下:用户试图CREATE OR REPLACE VIEW

KPI_USERUSER_ID USER_NAME USER_PASS USER_SIGNON_ID

USER_OSSIGNON_ID USER_ROLE_ID USER_DICRIPTIONASselect _id

user___password user__id

user_signon_iduser_ossignon_id user_role_id user_dicription from _ u order

by user_order组视图:CREATE OR REPLACE VIEW

KPI_USER_CLASSUSER_CLASS_ID USER_CLASS_NAME

USER_CLASS_DISCRIPTIONPARENT_USER_CLASS_ID USER_CLASS_LEVEL

USER_CLASS_ORG_IDASselect cognos_class_id user_class_idcognos_class_name

user_class_namecognos_class_descuser_class_discriptioncognos_class_parentid

parent_user_class_id user_class_leveluser_class_org_id from _class关系视

图CREATE OR REPLACE VIEW USER_ROLE_RELATIONUSER_CLASS_ID

USER_SIGNON_IDASselect _class_id user_class_id _ID

user_signon_id _cog.