利用OFBiz实现Single Sign On单点登录

1 、 ofbiz 单点登录介绍
ofbiz 点单登录是集成了 CAS SSO , LDAP 使用的,具体的 CAS 与 LDAP 怎么应用,在这里不做介绍。

2 、 ofbiz 点单登录文档
ofbiz 12 版本中,有英文的简单的 ofbiz 单点登录的问题。

路径在: apache-ofbiz-12.04.01\framework\documents\SingleSignOn.xml

3 、 ofbiz 单点登录目录
ofbiz   单点登录集成的目录在: apache-ofbiz-12.04.01\specialpurpose\ldap

在使用单点登录时需要把这个目录的应用加载到 component.xml 中。

4 、 ofbiz 点单登录原始应用

ofbiz 原始的单点登录建立在 CAS 与 LDAP 安装及配置好的前提下。

每一个 web 应用程序 , 您需要使用 LDAP( 单点登录 ) 功能 , 您需要更改事件的一些安全请求映射 org.ofbiz.ldap.LdapLoginWorker 类。

< request-map uri = "login" >

        < security https = "false" auth = "false" />

        < event type = "java" path = "org.ofbiz.ldap.LdapLoginWorker" invoke = "login" />

        < response name = "success" type = "view" value = "main" />

        < response name = "requirePasswordChange" type = "view" value = "requirePasswordChange" />

        < response name = "error" type = "view" value = "login" />

    </ request-map >

< request-map uri = "logout" >

        < security https = "false" auth = "false" />

        < event type = "java" path = "org.ofbiz.ldap.LdapLoginWorker " invoke = "logout" />

        < response name = "success" type = "request-redirect" value = "main" />

        < response name = "error" type = "view" value = "main" />

    </ request-map >

5 、 ofbiz ldap.xml 文件配置
进入这个文件,我相信搞过 ofbiz 的人都能开的明白。

在这我想说一下,安全配置的问题。

如果您不想用 ssl   https 这种模式情况下, https://localhost:8443/cas 这种方式改成 http://localhost:8080/cas 这种连接就可以了,这样 CAS 就不再有签名的问题,当然您也需要配置 CAS 不使用证书验证的方式。

6 、 ofbiz 单点登录流程


7 、 ofbiz SSO 改造应用
1 、 CAS 用户数据在 ofbiz 表中管理

新增加一个实体,名称为 SsoUserLogin , 数据和 UserLogin 数据同步,密码可以用先用明文或者通过 CAS 加密后的密文

2 、去掉 LDAP 验证

为了更方便简单的单点登录的管理与应用,决定去掉 LDAP 。

在 OFBizCasAuthenticationHandler.java 中去掉:

//             SearchResult result = getLdapSearchResult( username ,password, rootElement, false);

//             if (result != null) {

//                 return login(request, response, username , password, rootElement, result);

//             }

这个事获取 ldap 验证及基于 ldap 的登录

改成:

LocalDispatcher dispatcher =(LocalDispatcher) request.getAttribute( "dispatcher" );

            Delegator delegator =dispatcher.getDelegator();

            GenericValue userTryToLogin= delegator.findOne( "SsoUserLogin" , false , "userLoginId" , username);

            String currentPas =userTryToLogin.getString( "currentPassword" );

            HttpSessionsession = request.getSession();

            session.setAttribute( "USERNAME" ,username);

            if (currentPas!= null && currentPas!= "" ){

               session.setAttribute( "PASSWORD" ,currentPas);

            } else {

               session.setAttribute( "PASSWORD" ,password);

            }

这样修改是为了使用 ofbiz 最原始的登录方式。

在 LdapLoginWorker.java 修改:

//             boolean useOFBizLoginWhenFail =Boolean.getBoolean(UtilXml.childElementValue(rootElement,"UseOFBizLoginWhenLDAPFail", "false"));

            //boolean useOFBizLoginWhenFail =Boolean.getBoolean(UtilXml.childElementValue(rootElement,"UseOFBizLoginWhenLDAPFail", "true"));

//           if(useOFBizLoginWhenFail) {

            if ( true ) {

                return LoginWorker. login (request,response);

            }

使用 ofbiz 原始方式登录

登出是一样的节凑。。。。。

猜你喜欢

转载自784838898.iteye.com/blog/2355790
今日推荐