`
cn_arthurs
  • 浏览: 330027 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JForum与web应用整合

阅读更多

参考文章:http://www.lifevv.com/java/doc/20080305224358885.html

创建了一个CookieUserSSO

package net.jforum.sso;

import javax.servlet.http.Cookie;

import net.jforum.ControllerUtils;
import net.jforum.context.RequestContext;
import net.jforum.entities.UserSession;
import net.jforum.util.preferences.ConfigKeys;
import net.jforum.util.preferences.SystemGlobals;

import org.apache.log4j.Logger;

/**
 * jforum 与 web 项目整合的的处理类
 * @author Rafael Steil
 * @version $Id: $
 */
public class CookieUserSSO implements SSO{
	static final Logger logger = Logger.getLogger(CookieUserSSO.class.getName());
	
	public String authenticateUser(RequestContext request) {
		// login cookie set by my web LOGIN application
//		Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_USER));//这种写法会获取null,不解啊
		Cookie cookieNameUser = ControllerUtils.getCookie("jforumSSOCookieNameUser");
		String username = null;

		if (cookieNameUser != null) {
		username = cookieNameUser.getValue();
		}
		System.out.println(cookieNameUser+" ======== "+username+" ==========");
		return username; // return username for jforum
		// jforum will use this name to regist database or set in HttpSession

	}

	public boolean isSessionValid(UserSession userSession,
			RequestContext request) {
		Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals
				.getValue(ConfigKeys.COOKIE_NAME_USER)); // user cookie
				String remoteUser = null;

				if (cookieNameUser != null) {
				remoteUser = cookieNameUser.getValue(); // jforum username
				}

				if (remoteUser == null
				&& userSession.getUserId() != SystemGlobals
				.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
				// user has since logged out
				return false;
				} else if (remoteUser != null
				&& userSession.getUserId() == SystemGlobals
				.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
				// anonymous user has logged in
				return false;
				} else if (remoteUser != null
				&& !remoteUser.equals(userSession.getUsername())) {
				// not the same user (cookie and session)
				return false;
				}
				return true; // myapp user and forum user the same. valid user.

	}

}



修改systemglobals.properties文件中的SSO片段

#############################
# SSO / User authentication
#############################
# Auhentication type: use one of the following options
#
# sso: SSO based authentication. The called class will be the one
#	specified by the key "sso.implementation", whic must be an implementation
# 	of net.jforum.sso.SSO
#
# default: Non-SSO authentication, which relies on the key 
#	"login.authenticator" to validate users. For more information, please see
#	net.jforum.sso.LoginAuthenticator and the default implementation.

#authentication.type = default
authentication.type = sso

# The above key will be used when "authentication.type" is set to "default"
# Can be any implementation of net.jforum.sso.LoginAuthenticator
#
# For LDAP authentication, set the value to net.jforum.sso.LDAPAuthenticator. Also,
# see the LDAP section below
login.authenticator = net.jforum.sso.DefaultLoginAuthenticator

# When using authentication.type = default, you may choose to disable
# the automatic login feature, which will prevents users to get 
# automatic logged in when they come back to the forum
auto.login.enabled = true

# The above key will be be used then "authentication.type" is set to "sso"
# The default implementation (used here) only checks if request.getRemoteUser()
# is not null. This may be enough for many situations.

#sso.implementation = net.jforum.sso.RemoteUserSSO
sso.implementation = net.jforum.sso.CookieUserSSO
#cookie.name.user = jforumSSOCookieNameUser这里不需要重写cookie.name.user了,因为在下面还有一个这个属性,直接修改就可以了

# Special attributes used when creating a new user
# Only if auhentication.type = sso
# The attribute name to search in the session for the password.
sso.password.attribute = password

# Same as above
sso.email.attribute = email

# The default email to use if sso.email.attribute is empty
sso.default.email = sso@user

# The default password to use if sso.password.attribute is empty
sso.default.password = sso 

# Optional redirect for SSO
#
# If a value is set, the user will be redirected to the defined
# URL, using the following logic:
#
# ${sso.redirect}?returnUrl=${forum.link} + 
#
# The value MUST start with the protocol (http:// or https://)
#
sso.redirect = http://localhost:8082/jforum


然后,在web项目的登陆处理中加入cookie的设置

//与jforum整合代码,设置cookic
			Cookie cookie = new Cookie("jforumSSOCookieNameUser", username);
		    cookie.setMaxAge(-1);
		    cookie.setPath("/");
		    response.addCookie(cookie);



退出处理类中,加入

Cookie cookie = new Cookie("jforumSSOCookieNameUser", "");
	    cookie.setMaxAge(0); // delete the cookie.
	    cookie.setPath("/");
	    response.addCookie(cookie);



然后发布就ok了

 

分享到:
评论

相关推荐

    jforum与web项目的整合(通过Cookie实现SSO)

    标题 "jforum与web项目的整合(通过Cookie实现SSO)" 涉及的是将开源的JForum论坛系统与其他Web应用程序进行集成,并利用Cookie技术实现单点登录(Single Sign-On,简称SSO)。SSO允许用户在一个应用系统中登录后,...

    jforum+ckeditor整合案例

    - 在JForum的Web应用目录下,找到`js`或`scripts`文件夹,创建一个新文件夹,如`ckeditor`,并将CKEditor的JavaScript和CSS文件复制到这里。 - 根据JForum的目录结构,可能还需要将CKEditor的图片和其他资源文件...

    chx 学习jForum笔记十八 jForum与ms sqlserver

    《jForum与MS SQLServer整合学习笔记》 jForum是一款基于Java的开源论坛系统,它以其高度可定制性、灵活性和强大的功能深受开发者喜爱。在本文中,我们将深入探讨如何将jForum与Microsoft SQL Server(简称MS SQL...

    jforum3.0所需要的jar包

    2. **Servlet和JSP相关jar**:由于jForum是Web应用,因此需要Servlet和JSP相关的jar包,如servlet-api.jar、jsp-api.jar。它们提供了与Web服务器交互的接口,使jForum能够处理HTTP请求,并通过JSP技术生成动态网页...

    jforum-2.1.8.zip

    《JForum 2.1.8 Web工程深度解析与应用指南》 JForum是一个功能强大的、基于Java的开源讨论论坛系统,它提供了丰富的社区管理工具和用户交互功能,深受开发者和社区管理员的喜爱。本篇文章将深入探讨JForum 2.1.8...

    JForum3 完整项目

    **JForum3 完整项目详解** JForum3 是一个基于Java开发的开源论坛系统,提供了丰富的社区交流功能。...通过深入了解JForum3的架构和实现,开发者可以提升在Web应用开发、数据库管理、安全实践等方面的能力。

    JForum_SSO_-_JForum单点登陆原理与配置

    在与其他Web应用集成时,为了提供无缝的用户体验,通常需要实现单点登录(SSO,Single Sign On)。SSO允许用户在一个系统登录后,无需再次认证即可访问其他关联的系统,提升了用户体验。 JForum的SSO机制主要依赖于...

    jforum安装部署指南

    本指南将详细介绍如何安装与部署jForum,并针对一些常见配置进行说明。 #### 二、环境准备 1. **Java环境**:确保已安装Java Development Kit (JDK) 并正确配置JAVA_HOME环境变量。 2. **Web容器**:如Apache ...

    jforum3源代码

    本文将深入探讨JForum3的源代码,帮助开发者了解其内部工作原理,提升对Web应用程序开发的理解。 1. **框架与技术栈** JForum3基于Java编程语言,利用Spring框架进行依赖注入和控制反转,提高了代码的可测试性和...

    jforum说明文档 源码解析 单点登录 jforum缓存

    Jforum提供了与CAS的接口,方便用户在多应用环境中无缝切换。 **Jforum-ppt文件** 在提供的压缩包中,`Jforum-ppt`可能包含关于Jforum的详细讲解或演示材料,如开发教程、架构解析、功能介绍等。通过阅读这些PPT,...

    jforum3.0项目需要的jar包

    3. **Servlet容器**:由于JForum是一个Web应用程序,它依赖于Servlet容器来运行。你需要在你的Web服务器中配置Servlet容器,例如Tomcat中的`webapps`目录。 4. **Maven或Gradle构建工具**:JForum 3.0 可能使用...

    Jforum2.19

    通过深入研究Jforum的源代码,开发者可以了解到Java Web应用的开发模式,包括MVC架构、ORM框架的使用(如Hibernate)、国际化处理、权限控制等方面的知识。同时,这也是学习和理解Web论坛系统设计与实现的一个宝贵...

    java开源论坛jforum

    Java开源论坛JForum是一款基于Java开发的讨论区平台,它为开发者提供了一个高效、功能...通过对JForum的源码学习,开发者可以掌握更多关于Web应用设计和实现的实用技巧,对于个人技术成长和职业发展都有着积极的影响。

    jforum2.1.8

    5. **部署应用**:将WAR文件部署到Web服务器的应用目录下,启动服务器完成部署。 6. **初始化数据**:访问安装URL,按照向导完成论坛的初始化设置,如管理员账户、默认板块等。 7. **运行论坛**:安装完成后,通过...

    jforum-2.5.0安装包+安装方式.rar

    这个压缩包“jforum-2.5.0安装包+安装方式.rar”包含了JForum 2.5.0版本的安装文件和相关的安装指南,主要文件为“jforum-2.5.0.war”,这是一个Web应用的归档文件,可以直接部署在支持Servlet和JSP的Web服务器上。...

    jforum2论坛源码

    1. **Java Web开发**:jforum2是一个基于Java的Web应用,利用Servlet和JSP(JavaServer Pages)技术构建,遵循MVC(Model-View-Controller)设计模式。开发者可以通过学习其源码来了解如何在Java环境中开发Web应用。...

    Jforum论坛数据库架构

    数据库架构是任何Web应用程序的核心部分,对于Jforum论坛而言也不例外。一个良好的数据库架构设计能够确保论坛的数据高效、稳定且易于扩展。本文将深入探讨Jforum论坛的数据库架构,分析其设计原则、主要数据表结构...

    jforum 源码

    **正文** JForum是一款基于Java...通过对JForum源码的深度学习,开发者不仅可以掌握FreeMarker的使用,还能了解一个完整的Web应用是如何设计和实现的,对于提升Java Web开发技能和理解大型项目结构有着极大的帮助。

    Jforum二次开发成果

    1.2 开发工具选择:Eclipse是一款强大的Java集成开发环境,它提供丰富的插件支持,对于Jforum这样的Web应用开发来说,是理想的选择。通过安装相关的Struts和Hibernate插件,可以在Eclipse中实现无缝的开发体验。 二...

Global site tag (gtag.js) - Google Analytics