Index: lams_central/src/java/org/lamsfoundation/lams/security/UniversalLoginModule.java =================================================================== diff -u -ra575014b02a693b4686e958f883e3eb00f9b0861 -r0240d8e22e9a8027666408290fbb8eec4b3c1421 --- lams_central/src/java/org/lamsfoundation/lams/security/UniversalLoginModule.java (.../UniversalLoginModule.java) (revision a575014b02a693b4686e958f883e3eb00f9b0861) +++ lams_central/src/java/org/lamsfoundation/lams/security/UniversalLoginModule.java (.../UniversalLoginModule.java) (revision 0240d8e22e9a8027666408290fbb8eec4b3c1421) @@ -24,8 +24,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; -import java.util.HashMap; -import java.util.Map; import java.util.*; import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; @@ -34,6 +32,8 @@ import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.WebApplicationContext; import org.lamsfoundation.lams.usermanagement.service.UserManagementService; +import org.lamsfoundation.lams.web.SharedSession; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.HttpSessionManager; import org.lamsfoundation.lams.usermanagement.*; @@ -147,6 +147,11 @@ log.debug("Unexpected authentication type!"); return false; } + //if login is valid, register userDTO into session. + if(isValid){ + SharedSession sharedSess = SharedSession.getInstance(HttpSessionManager.getInstance().getServletContext()); + sharedSess.setAttribute(AttributeNames.USER,user.getUserDTO()); + } } catch (Exception e) { e.printStackTrace(); log.debug("===> exception: " + e); Index: lams_central/src/java/org/lamsfoundation/lams/web/SharedSession.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/SharedSession.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/SharedSession.java (revision 0240d8e22e9a8027666408290fbb8eec4b3c1421) @@ -0,0 +1,85 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ +package org.lamsfoundation.lams.web; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; + +import org.apache.log4j.Logger; +/** + * + * @author Steve.Ni + * + * $version$ + */ +public class SharedSession { + + private static Logger log = Logger.getLogger(SharedSession.class); + private ServletContext context; + private static final String SHARE_SESSION_NAME = "name"; + private SharedSession(ServletContext context){ + this.context = context; + } + /** + * Set value with the given sessionId into whole system scope HttpSession. + * + * @param sessionId + * @param value + */ + public void setAttribute(String sessionId, Object value){ + Object map = context.getAttribute(SHARE_SESSION_NAME); + if(map == null || !(map instanceof HashMap)) + map = new HashMap(); + + Map sessionMap = (Map) map; + sessionMap.put(sessionId,value); + context.setAttribute(SHARE_SESSION_NAME,sessionMap); + } + /** + * Get value by the given sessionId from whole system scope HttpSession. + * @param sessionId + * @return + */ + public Object getAttribute(String sessionId){ + Object map = context.getAttribute(SHARE_SESSION_NAME); + if(map == null || !(map instanceof HashMap)) + return null; + + Map sessionMap = (Map) map; + return sessionMap.get(sessionId); + + } + /** + * Get SharedSession instance by given SevletContext + * @param context + * @return + */ + public static SharedSession getInstance(ServletContext context){ + SharedSession ss = new SharedSession(context.getContext("/lams")); + if(ss.context == null){ + log.error("Failed in retrieving lams core context."); + return null; + } + return ss; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java =================================================================== diff -u -ra575014b02a693b4686e958f883e3eb00f9b0861 -r0240d8e22e9a8027666408290fbb8eec4b3c1421 --- lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java (.../AttributeNames.java) (revision a575014b02a693b4686e958f883e3eb00f9b0861) +++ lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java (.../AttributeNames.java) (revision 0240d8e22e9a8027666408290fbb8eec4b3c1421) @@ -36,4 +36,6 @@ public static final String ADMIN_USER = "user"; public static final String ADMIN_ERR_MSG = "errormsg"; + public static final String USER= "user"; + }