`

liferay portal 在cas整合

 
阅读更多

创建java类

/*
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License.  You may obtain a
 * copy of the License at the following location:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.jasig.cas.adaptors.jdbc;

import org.jasig.cas.authentication.handler.AuthenticationException;
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;
import org.springframework.dao.IncorrectResultSizeDataAccessException;

import com.liferay.portal.PwdEncryptorException;
import com.liferay.portal.security.pwd.BCryptPasswordEncryptor;
import com.liferay.portal.security.pwd.CompositePasswordEncryptor;
import com.liferay.portal.security.pwd.CryptPasswordEncryptor;
import com.liferay.portal.security.pwd.DefaultPasswordEncryptor;
import com.liferay.portal.security.pwd.NullPasswordEncryptor;
import com.liferay.portal.security.pwd.PBKDF2PasswordEncryptor;
import com.liferay.portal.security.pwd.PasswordEncryptor;
import com.liferay.portal.security.pwd.SSHAPasswordEncryptor;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotNull;

/**
 * Class that if provided a query that returns a password (parameter of query
 * must be username) will compare that password to a translated version of the
 * password provided by the user. If they match, then authentication succeeds.
 * Default password translator is plaintext translator.
 * 
 * @author Scott Battaglia
 * @author Dmitriy Kopylenko
 * @version $Revision$ $Date$
 * @since 3.0
 */
public class LiferayQueryDatabaseAuthenticationHandler extends AbstractJdbcUsernamePasswordAuthenticationHandler {

    private static CompositePasswordEncryptor compositePasswordEncryptor = new CompositePasswordEncryptor();

    public LiferayQueryDatabaseAuthenticationHandler() {
        super();
        compositePasswordEncryptor.setDefaultPasswordEncryptor(new DefaultPasswordEncryptor());
        List<PasswordEncryptor> passwordEncryptors = new ArrayList<PasswordEncryptor>();
        passwordEncryptors.add(new BCryptPasswordEncryptor());
        passwordEncryptors.add(new CryptPasswordEncryptor());
        passwordEncryptors.add(new NullPasswordEncryptor());
        passwordEncryptors.add(new PBKDF2PasswordEncryptor());
        passwordEncryptors.add(new SSHAPasswordEncryptor());
        compositePasswordEncryptor.setPasswordEncryptors(passwordEncryptors);
    }

    @NotNull
    private String sql;

    protected final boolean authenticateUsernamePasswordInternal(final UsernamePasswordCredentials credentials) throws AuthenticationException {
        final String username = getPrincipalNameTransformer().transform(credentials.getUsername());

        try {
            final String dbPassword = getJdbcTemplate().queryForObject(this.sql, String.class, username);
            final String encryptedPassword = compositePasswordEncryptor.encrypt("PBKDF2WITHHMACSHA1/160/128000", credentials.getPassword(), dbPassword);
            return dbPassword.equals(encryptedPassword);
        } catch (final IncorrectResultSizeDataAccessException e) {
            // this means the username was not found.
            return false;
        } catch (PwdEncryptorException e) {
            return false;
		}
    }

    /**
     * @param sql The sql to set.
     */
    public void setSql(final String sql) {
        this.sql = sql;
    }
}

修改\cas\WEB-INF 目录下的deployerConfigContext.xml文件部分如下:

		<property name="authenticationHandlers">
			<list>
				<!--
					| This is the authentication handler that authenticates services by means of callback via SSL, thereby validating
					| a server side SSL certificate.
					+-->
				<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
					p:httpClient-ref="httpClient" />
				<!--
					| This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS 
					| into production.  The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials
					| where the username equals the password.  You will need to replace this with an AuthenticationHandler that implements your
					| local authentication strategy.  You might accomplish this by coding a new such handler and declaring
					| edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules.
					+-->
				<!--
				<bean 
					class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />
					-->
				
				<bean class="org.jasig.cas.adaptors.jdbc.LiferayQueryDatabaseAuthenticationHandler"> 
					<property name="sql" value="select password_ from user_ where screenName=?" />
					<property name="dataSource" ref="dataSource" />
					<!-- <property name="passwordEncoder" ref="myPasswordEncoder" /> -->
				</bean>
			</list>
		</property>
	</bean>

	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/liferay_portal" />
		<property name="username" value="root" />
		<property name="password" value="passw0rd" />
	</bean>

缺少几个jar包,添加到lib目录下:

 

portal-impl-6.2.5.jar 

portal-service-6.2.5.jar 

cas-server-support-jdbc-4.2.4.jar 

MySQL-connector-java-5.1.36-bin.jar

 

最后在Liferay中配置CAS连接信息。

分享到:
评论

相关推荐

    liferay portal开发大全

    **Liferay Portal 开发大全** Liferay Portal 是一个开源的企业级门户平台,广泛用于构建复杂的Web应用程序和企业内部...在实际工作中,不断探索和学习Liferay的新特性和最佳实践,将有助于提升开发效率和产品质量。

    liferay portal 开发实例

    在这个开发实例中,我们将深入探讨四个Liferay Portal MVC(Model-View-Controller)应用的实践案例,这些实例可以帮助开发者更好地理解如何在Liferay环境中进行portlet开发。 首先,让我们了解MVC模式在Liferay中...

    liferay portal 6 使用文档

    Liferay Portal 6的部署相对灵活,既可以在本地服务器上运行,也可以在云平台上部署。对于大规模的企业,还可以选择分布式部署,以提高系统的响应速度和处理能力。在维护方面,Liferay提供了详细的文档和社区支持,...

    Liferay Portal 内容管理

    在Liferay Portal中,文档管理主要通过【Document Library】Portlet实现。用户可以方便地上传文档,如在文件夹内点击【Add Document】,选择本地文件上传。值得注意的是,上传的文档大小通常有3000KB的限制。文档...

    liferay portal 开发指南

    本文档旨在指导开发者如何进行 Portlet 的开发并部署在 Liferay Portal 上。 #### 二、Portlet 开发与 Servlet 开发对比 1. **Portlet 开发**: - **标准性**:遵循 JSR-168 规范,使得 Portlet 可以跨平台部署。...

    Liferay Portal Systems Development

    4. 技术集成:Liferay支持与多种技术的集成,这意味着它可以作为企业级应用的中心平台,整合广告、搜索引擎优化、BPM等多个方面,以满足复杂的业务需求。 5. 开源社区贡献:Jonas X. Yuan作为开源社区的贡献者,...

    Using Liferay Portal 6.1

    Using Liferay Portal 6.1

    Liferay Portal文档

    - **Portal服务器**:是提供用户界面、整合各种应用和服务的平台,Liferay Portal就是这样的一个服务器,它能够聚合来自不同源的信息并提供统一的访问入口。 - **Portlet容器**:是portal服务器的一部分,负责管理...

    Liferay Portal 二次开发指南

    ### Liferay Portal 二次开发指南 #### 一、Liferay Portal 架构解析 ##### 1.1 Portal规范 Liferay Portal遵循了两种主要的门户规范:JSR 168 和 WSRP (Web Services for Remote Portlets)。JSR 168是一个Java...

    liferay Portal 求助

    这个求助主题可能涉及到在使用Liferay Portal过程中遇到的问题,或者是寻求关于如何更有效地利用其特性和功能的建议。 首先,我们要理解Liferay Portal的核心特性。它提供了强大的身份管理和权限控制,使得不同角色...

    搭建liferay portal的开发环境.doc

    3. **整合Liferay目录**:从`liferayPortal/tomcat`目录中,将`liferay`目录剪切至项目根目录,替换原有目录,确保结构一致。 4. **导入源码**:解压`liferay-portal-src-4.0.0.zip`,将`portal-ejb/src`目录下的`...

    liferay-portal-sql-6.1.1-ce-ga2-20120731132656558

    1. **安装脚本**:通常在安装或更新Liferay Portal时,会有一系列的SQL脚本用于创建必要的数据库结构,包括表、视图、存储过程等。 2. **升级脚本**:随着Liferay版本的升级,这些脚本可能用于将现有数据库从一个...

    liferay_Portal的安装与简单应用.docx

    在Eclipse中,选择“Help” &gt; “Install New Software...”,然后添加Liferay IDE的URL,如Helios release stable或nightly URL,进行插件安装。 通过上述介绍,我们可以看到Liferay Portal不仅是一个强大的企业...

    Liferay Portal Liferay IDE

    Liferay Portal Liferay IDE

    Liferay_Portal_6.1源码导入到eclipse

    "Liferay Portal 6.1 源码导入到 Eclipse" Liferay Portal 是一个基于 Java 的开源门户平台,提供了丰富的功能和插件,可以满足企业级门户网站的需求。将 Liferay Portal 6.1 源码导入到 Eclipse,以便更好地理解和...

    liferay portal介绍

    关于liferay portal介绍的ppt

    liferay portal 设置文件

    liferay是一个现成的,即开即用的,功能完备的门户网站Liferay Portal,是一个完美的桌面协同办公组合,完全为企业和机构设计

    Liferay Portal 数据库介绍

    在Liferay Portal 中,可以通过不同的portlet来修改页面的布局和Page Settings 等。例如: * 对社区的页面进行修改:选择【Communities】portlet,选择某个社区,点击【Actions】,选择【Configure Pages】,即可...

    Liferay Portal performance

    Liferay Portal 被 Gartner 命名为领导者,在 Gartner 魔力象限 (MQ) 中因其功能完整性和投资回报率而受到认可,它是领先的开源企业门户解决方案。Liferay Portal 企业版 (EE) 是 Liferay Portal 的商业支持版本,...

    liferay-portal详解

    liferay-portal详解 Liferay Portal 是一个基于 Java 的开源门户平台,提供了一个灵活的框架来构建企业门户和 web 应用程序。本文档将从架构解析、portal 规范、portlet 容器、portlet 生命周期、liferay portal ...

Global site tag (gtag.js) - Google Analytics