Index: lams_central/build.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_central/build.xml,v
diff -u -r1.42 -r1.43
--- lams_central/build.xml 9 Dec 2008 05:40:33 -0000 1.42
+++ lams_central/build.xml 28 Jan 2009 00:10:32 -0000 1.43
@@ -252,6 +252,7 @@
+
+
+
@@ -24,6 +29,9 @@
+
+
+
Index: lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java,v
diff -u -r1.30 -r1.31
--- lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java 25 Nov 2008 00:59:52 -0000 1.30
+++ lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java 28 Jan 2009 00:10:32 -0000 1.31
@@ -24,6 +24,7 @@
package org.lamsfoundation.lams.web;
import java.io.IOException;
+import java.net.URLEncoder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -49,14 +50,11 @@
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
-
/**
- * this is an action where all lams client environments launch.
- * initial configuration of the individual environment setting is done here.
+ * this is an action where all lams client environments launch. initial
+ * configuration of the individual environment setting is done here.
*
- * @struts:action path="/home"
- * validate="false"
- * parameter="method"
+ * @struts:action path="/home" validate="false" parameter="method"
* @struts:action-forward name="sysadmin" path="/sysadmin.jsp"
* @struts:action-forward name="learner" path="/learner.jsp"
* @struts:action-forward name="author" path="/author.jsp"
@@ -66,260 +64,278 @@
* @struts:action-forward name="message" path=".message"
* @struts:action-forward name="passwordChange" path=".passwordChange"
* @struts:action-forward name="index" path="/index.jsp"
- *
+ *
*/
public class HomeAction extends DispatchAction {
-
- private static Logger log = Logger.getLogger(HomeAction.class);
-
- private static IUserManagementService service;
- private static ILessonService lessonService;
-
- private IUserManagementService getService(){
- if(service==null){
- WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext());
- service = (IUserManagementService) ctx.getBean("userManagementService");
- }
- return service;
+
+ private static Logger log = Logger.getLogger(HomeAction.class);
+
+ private static IUserManagementService service;
+ private static ILessonService lessonService;
+
+ private IUserManagementService getService() {
+ if (service == null) {
+ WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet()
+ .getServletContext());
+ service = (IUserManagementService) ctx.getBean("userManagementService");
}
+ return service;
+ }
- private ILessonService getLessonService(){
- if(lessonService==null){
- WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext());
- lessonService = (ILessonService) ctx.getBean("lessonService");
- }
- return lessonService;
+ private ILessonService getLessonService() {
+ if (lessonService == null) {
+ WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet()
+ .getServletContext());
+ lessonService = (ILessonService) ctx.getBean("lessonService");
}
+ return lessonService;
+ }
- private UserDTO getUser() {
- HttpSession ss = SessionManager.getSession();
- return (UserDTO) ss.getAttribute(AttributeNames.USER);
+ private UserDTO getUser() {
+ HttpSession ss = SessionManager.getSession();
+ return (UserDTO) ss.getAttribute(AttributeNames.USER);
+ }
+
+ private User getRealUser(UserDTO dto) {
+ return getService().getUserByLogin(dto.getLogin());
+ }
+
+ /**
+ * request for sysadmin environment
+ */
+ public ActionForward sysadmin(ActionMapping mapping, ActionForm form, HttpServletRequest req,
+ HttpServletResponse res) throws IOException, ServletException {
+
+ try {
+ log.debug("request sysadmin");
+ int orgId = new Integer(req.getParameter("orgId")).intValue();
+ UserDTO user = getUser();
+ if (user == null) {
+ log.error("admin: User missing from session. ");
+ return mapping.findForward("error");
+ } else if (getService().isUserInRole(user.getUserID(), orgId, Role.SYSADMIN)) {
+ log.debug("user is sysadmin");
+ return mapping.findForward("sysadmin");
+ } else {
+ log.error("User " + user.getLogin()
+ + " tried to get sysadmin screen but isn't sysadmin in organisation: " + orgId);
+ return displayMessage(mapping, req, "error.authorisation");
+ }
+
+ } catch (Exception e) {
+ log.error("Failed to load sysadmin", e);
+ return mapping.findForward("error");
}
-
- private User getRealUser(UserDTO dto) {
- return getService().getUserByLogin(dto.getLogin());
- }
+ }
- /**
- * request for sysadmin environment
- */
- public ActionForward sysadmin(ActionMapping mapping, ActionForm form,
- HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
+ /**
+ * request for learner environment
+ */
+ public ActionForward learner(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException {
- try {
- log.debug("request sysadmin");
- int orgId = new Integer(req.getParameter("orgId")).intValue();
- UserDTO user = getUser();
- if ( user == null ) {
- log.error("admin: User missing from session. ");
- return mapping.findForward("error");
- } else if ( getService().isUserInRole(user.getUserID(),orgId,Role.SYSADMIN)) {
- log.debug("user is sysadmin");
- return mapping.findForward("sysadmin");
- } else {
- log.error("User "+user.getLogin()+" tried to get sysadmin screen but isn't sysadmin in organisation: "+orgId);
- return displayMessage(mapping, req, "error.authorisation");
- }
-
- } catch (Exception e) {
- log.error("Failed to load sysadmin",e);
- return mapping.findForward("error");
+ try {
+ log.debug("request learner");
+
+ Long lessonId = WebUtil.readLongParam(req, AttributeNames.PARAM_LESSON_ID);
+ String mode = WebUtil.readStrParam(req, AttributeNames.PARAM_MODE, true);
+
+ UserDTO user = getUser();
+ if (user == null) {
+ log.error("learner: User missing from session. ");
+ return mapping.findForward("error");
+ } else {
+ Lesson lesson = lessonId != null ? getLessonService().getLesson(lessonId) : null;
+ if (lesson == null || !lesson.isLessonStarted()) {
+ return displayMessage(mapping, req, "message.lesson.not.started.cannot.participate");
}
- }
-
- /**
- * request for learner environment
- */
- public ActionForward learner(ActionMapping mapping, ActionForm form,
- HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
- try {
- log.debug("request learner");
-
- Long lessonId = WebUtil.readLongParam(req, AttributeNames.PARAM_LESSON_ID);
- String mode = WebUtil.readStrParam(req, AttributeNames.PARAM_MODE, true);
-
- UserDTO user = getUser();
- if ( user == null ) {
- log.error("learner: User missing from session. ");
- return mapping.findForward("error");
- } else {
- Lesson lesson = lessonId != null ? getLessonService().getLesson(lessonId) : null;
- if ( lesson == null || ! lesson.isLessonStarted()) {
- return displayMessage(mapping, req, "message.lesson.not.started.cannot.participate");
- }
-
- if ( lesson.getLessonClass() == null || ! lesson.getLessonClass().getLearners().contains(getRealUser(user)) ) {
- log.error("learner: User "+user.getLogin()+" is not a learner in the requested lesson. Cannot access the lesson.");
- return displayMessage(mapping, req, "error.authorisation");
- }
-
- if(mode != null)
- req.setAttribute(AttributeNames.PARAM_MODE, mode);
-
- req.setAttribute(AttributeNames.PARAM_EXPORT_PORTFOLIO_ENABLED, lesson.getLearnerExportAvailable() != null ? lesson.getLearnerExportAvailable(): Boolean.TRUE);
- req.setAttribute(AttributeNames.PARAM_PRESENCE_ENABLED, lesson.getLearnerPresenceAvailable());
- req.setAttribute(AttributeNames.PARAM_PRESENCE_IM_ENABLED, lesson.getLearnerImAvailable());
- req.setAttribute(AttributeNames.PARAM_TITLE, lesson.getLessonName());
- req.setAttribute(AttributeNames.PARAM_CREATE_DATE_TIME, lesson.getCreateDateTime());
- String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
- req.setAttribute("serverUrl", serverUrl);
- String presenceUrl = Configuration.get(ConfigurationKeys.XMPP_DOMAIN);
- req.setAttribute("presenceUrl", presenceUrl);
- req.setAttribute(AttributeNames.PARAM_LESSON_ID,lessonId);
- return mapping.findForward("learner");
- }
-
- } catch (Exception e) {
- log.error("Failed to load learner",e);
- return mapping.findForward("error");
+ if (lesson.getLessonClass() == null
+ || !lesson.getLessonClass().getLearners().contains(getRealUser(user))) {
+ log.error("learner: User " + user.getLogin()
+ + " is not a learner in the requested lesson. Cannot access the lesson.");
+ return displayMessage(mapping, req, "error.authorisation");
}
+
+ if (mode != null)
+ req.setAttribute(AttributeNames.PARAM_MODE, mode);
+
+ req.setAttribute(AttributeNames.PARAM_EXPORT_PORTFOLIO_ENABLED,
+ lesson.getLearnerExportAvailable() != null ? lesson.getLearnerExportAvailable() : Boolean.TRUE);
+ req.setAttribute(AttributeNames.PARAM_PRESENCE_ENABLED, lesson.getLearnerPresenceAvailable());
+ req.setAttribute(AttributeNames.PARAM_PRESENCE_IM_ENABLED, lesson.getLearnerImAvailable());
+ req.setAttribute(AttributeNames.PARAM_TITLE, lesson.getLessonName());
+ req.setAttribute(AttributeNames.PARAM_CREATE_DATE_TIME, lesson.getCreateDateTime());
+ String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
+ req.setAttribute("serverUrl", serverUrl);
+ String presenceUrl = Configuration.get(ConfigurationKeys.XMPP_DOMAIN);
+ req.setAttribute("presenceUrl", presenceUrl);
+ req.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId);
+ return mapping.findForward("learner");
+ }
+
+ } catch (Exception e) {
+ log.error("Failed to load learner", e);
+ return mapping.findForward("error");
}
-
-
- /**
- * request for author environment
- */
- public ActionForward author(ActionMapping mapping, ActionForm form,
- HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
+ }
- try {
- log.debug("request author");
- UserDTO user = getUser();
- if ( user == null ) {
- log.error("admin: User missing from session. ");
- return mapping.findForward("error");
- } else {
- Long learningDesignID = null;
- String layout = null;
- String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
- req.setAttribute("serverUrl", serverUrl);
-
- String requestSrc = req.getParameter("requestSrc");
- String notifyCloseURL = req.getParameter("notifyCloseURL");
- String customCSV = req.getParameter(AttributeNames.PARAM_CUSTOM_CSV);
- String extLmsId = req.getParameter(AttributeNames.PARAM_EXT_LMS_ID);
-
- if(req.getParameter("learningDesignID") != null)
- learningDesignID = WebUtil.readLongParam(req, "learningDesignID");
-
- if(req.getParameter("layout") != null)
- layout = WebUtil.readStrParam(req, "layout");
-
- if(layout != null)
- req.setAttribute("layout", layout);
-
- if(req.getParameter("learningDesignID") != null)
- learningDesignID = WebUtil.readLongParam(req, "learningDesignID");
-
- if(learningDesignID != null)
- req.setAttribute("learningDesignID", learningDesignID);
-
- req.setAttribute("requestSrc", requestSrc);
- req.setAttribute("notifyCloseURL", notifyCloseURL);
- req.setAttribute(AttributeNames.PARAM_CUSTOM_CSV, customCSV);
- req.setAttribute(AttributeNames.PARAM_EXT_LMS_ID, extLmsId);
-
- return mapping.findForward("author");
- }
-
- } catch (Exception e) {
- log.error("Failed to load author",e);
- return mapping.findForward("error");
+ /**
+ * request for author environment
+ */
+ public ActionForward author(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException {
+
+ try {
+ log.debug("request author");
+ UserDTO user = getUser();
+ if (user == null) {
+ log.error("admin: User missing from session. ");
+ return mapping.findForward("error");
+ } else {
+ Long learningDesignID = null;
+ String layout = null;
+ String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
+ req.setAttribute("serverUrl", serverUrl);
+
+ String requestSrc = req.getParameter("requestSrc");
+ String notifyCloseURL = req.getParameter("notifyCloseURL");
+ String customCSV = req.getParameter(AttributeNames.PARAM_CUSTOM_CSV);
+ String extLmsId = req.getParameter(AttributeNames.PARAM_EXT_LMS_ID);
+
+ if (req.getParameter("learningDesignID") != null)
+ learningDesignID = WebUtil.readLongParam(req, "learningDesignID");
+
+ if (req.getParameter("layout") != null)
+ layout = WebUtil.readStrParam(req, "layout");
+
+ if (layout != null)
+ req.setAttribute("layout", layout);
+
+ if (req.getParameter("learningDesignID") != null)
+ learningDesignID = WebUtil.readLongParam(req, "learningDesignID");
+
+ if (learningDesignID != null)
+ req.setAttribute("learningDesignID", learningDesignID);
+
+ req.setAttribute("requestSrc", requestSrc);
+ req.setAttribute("notifyCloseURL", notifyCloseURL);
+ req.setAttribute(AttributeNames.PARAM_CUSTOM_CSV, customCSV);
+ req.setAttribute(AttributeNames.PARAM_EXT_LMS_ID, extLmsId);
+
+ return mapping.findForward("author");
+ }
+
+ } catch (Exception e) {
+ log.error("Failed to load author", e);
+ return mapping.findForward("error");
+ }
+ }
+
+ /**
+ * request for monitor environment
+ */
+ public ActionForward monitorLesson(ActionMapping mapping, ActionForm form, HttpServletRequest req,
+ HttpServletResponse res) throws IOException, ServletException {
+
+ try {
+ log.debug("request monitorLesson");
+ Long lessonId = WebUtil.readLongParam(req, AttributeNames.PARAM_LESSON_ID);
+ UserDTO user = getUser();
+ if (user == null) {
+ log.error("admin: User missing from session. ");
+ return mapping.findForward("error");
+ } else {
+ Lesson lesson = lessonId != null ? getLessonService().getLesson(lessonId) : null;
+ if (lesson == null) {
+ log.error("monitorLesson: Lesson " + lessonId + " does not exist. Unable to monitor lesson");
+ return mapping.findForward("error");
}
+
+ if (lesson.getLessonClass() == null || !lesson.getLessonClass().isStaffMember(getRealUser(user))) {
+ log.error("learner: User " + user.getLogin()
+ + " is not a learner in the requested lesson. Cannot access the lesson.");
+ return displayMessage(mapping, req, "error.authorisation");
+ }
+
+ log.debug("user is staff");
+ String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
+ req.setAttribute("serverUrl", serverUrl);
+ req.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId);
+ return mapping.findForward("monitorLesson");
+ }
+ } catch (Exception e) {
+ log.error("Failed to load monitor lesson", e);
+ return mapping.findForward("error");
}
-
-
- /**
- * request for monitor environment
- */
- public ActionForward monitorLesson(ActionMapping mapping, ActionForm form,
- HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
+ }
- try {
- log.debug("request monitorLesson");
- Long lessonId = WebUtil.readLongParam(req, AttributeNames.PARAM_LESSON_ID);
- UserDTO user = getUser();
- if ( user == null ) {
- log.error("admin: User missing from session. ");
- return mapping.findForward("error");
- } else {
- Lesson lesson = lessonId != null ? getLessonService().getLesson(lessonId) : null;
- if ( lesson == null ) {
- log.error("monitorLesson: Lesson "+lessonId+" does not exist. Unable to monitor lesson");
- return mapping.findForward("error");
- }
-
- if ( lesson.getLessonClass() == null || ! lesson.getLessonClass().isStaffMember(getRealUser(user)) ) {
- log.error("learner: User "+user.getLogin()+" is not a learner in the requested lesson. Cannot access the lesson.");
- return displayMessage(mapping, req, "error.authorisation");
- }
+ /**
+ * request for add lesson wizard
+ */
+ public ActionForward addLesson(ActionMapping mapping, ActionForm form, HttpServletRequest req,
+ HttpServletResponse res) throws IOException, ServletException {
- log.debug("user is staff");
- String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
- req.setAttribute("serverUrl", serverUrl);
- req.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId);
- return mapping.findForward("monitorLesson");
- }
- } catch (Exception e) {
- log.error("Failed to load monitor lesson",e);
- return mapping.findForward("error");
+ try {
+ log.debug("request addLesson");
+ Integer courseId = WebUtil.readIntParam(req, AttributeNames.PARAM_COURSE_ID, false);
+ Integer classId = WebUtil.readIntParam(req, AttributeNames.PARAM_CLASS_ID, true);
+ UserDTO user = getUser();
+ if (user == null) {
+ log.error("admin: User missing from session. ");
+ return mapping.findForward("error");
+ } else {
+ Integer orgId = classId != null ? classId : courseId;
+ if (getService().isUserInRole(user.getUserID(), orgId, Role.MONITOR)
+ || getService().isUserInRole(user.getUserID(), orgId, Role.GROUP_MANAGER)) {
+ log.debug("user is staff");
+ String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
+ req.setAttribute("serverUrl", serverUrl);
+ req.setAttribute(AttributeNames.PARAM_COURSE_ID, courseId);
+ req.setAttribute(AttributeNames.PARAM_CLASS_ID, classId);
+ return mapping.findForward("addLesson");
+ } else {
+ log.error("User " + user.getLogin()
+ + " tried to get staff screen but isn't staff in organisation: " + orgId);
+ return displayMessage(mapping, req, "error.authorisation");
}
+ }
+
+ } catch (Exception e) {
+ log.error("Failed to load add lesson", e);
+ return mapping.findForward("error");
}
+ }
- /**
- * request for add lesson wizard
- */
- public ActionForward addLesson(ActionMapping mapping, ActionForm form,
- HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
+ public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException {
- try {
- log.debug("request addLesson");
- Integer courseId = WebUtil.readIntParam(req, AttributeNames.PARAM_COURSE_ID, false);
- Integer classId = WebUtil.readIntParam(req, AttributeNames.PARAM_CLASS_ID, true);
- UserDTO user = getUser();
- if ( user == null ) {
- log.error("admin: User missing from session. ");
- return mapping.findForward("error");
- } else {
- Integer orgId = classId != null ? classId : courseId;
- if (getService().isUserInRole(user.getUserID(), orgId, Role.MONITOR)||getService().isUserInRole(user.getUserID(), orgId, Role.GROUP_MANAGER)) {
- log.debug("user is staff");
- String serverUrl = Configuration.get(ConfigurationKeys.SERVER_URL);
- req.setAttribute("serverUrl", serverUrl);
- req.setAttribute(AttributeNames.PARAM_COURSE_ID, courseId);
- req.setAttribute(AttributeNames.PARAM_CLASS_ID, classId);
- return mapping.findForward("addLesson");
- } else {
- log.error("User "+ user.getLogin() + " tried to get staff screen but isn't staff in organisation: " + orgId);
- return displayMessage(mapping, req, "error.authorisation");
- }
- }
+ UserDTO userDTO = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER);
+ if (userDTO.getLoggedIntoLamsCommunity() != null && userDTO.getLoggedIntoLamsCommunity()) {
+ log.debug("Need to log out user from lamscoomunity");
+ req.getSession().invalidate();
- } catch (Exception e) {
- log.error("Failed to load add lesson",e);
- return mapping.findForward("error");
- }
+ //clear system shared session.
+ SessionManager.getSession().invalidate();
+
+ // redirect to lamscommunity logout servlet to log out.
+ String url = "http://lamscommunity.org/register/logout?return_url=";
+ url += URLEncoder.encode(Configuration.get(ConfigurationKeys.SERVER_URL), "UTF8");
+ res.sendRedirect(url);
+ return null;
+
+ } else {
+ req.getSession().invalidate();
+
+ //clear system shared session.
+ SessionManager.getSession().invalidate();
+
+ return mapping.findForward("index");
}
-
- public ActionForward logout(ActionMapping mapping, ActionForm form,
- HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
- req.getSession().invalidate();
-
- //clear system shared session.
- SessionManager.getSession().invalidate();
-
- return mapping.findForward("index");
- }
-
- private ActionForward displayMessage(ActionMapping mapping, HttpServletRequest req, String messageKey) {
- req.setAttribute("messageKey", messageKey);
- return mapping.findForward("message");
- }
+ }
+
+ private ActionForward displayMessage(ActionMapping mapping, HttpServletRequest req, String messageKey) {
+ req.setAttribute("messageKey", messageKey);
+ return mapping.findForward("message");
+ }
}
\ No newline at end of file
Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java,v
diff -u -r1.46 -r1.47
--- lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java 26 Jan 2009 18:32:29 -0000 1.46
+++ lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java 28 Jan 2009 00:10:32 -0000 1.47
@@ -35,6 +35,7 @@
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.lamsfoundation.lams.authoring.service.IAuthoringService;
+import org.lamsfoundation.lams.config.Registration;
import org.lamsfoundation.lams.index.IndexLinkBean;
import org.lamsfoundation.lams.learningdesign.service.IExportToolContentService;
import org.lamsfoundation.lams.usermanagement.Role;
@@ -70,13 +71,15 @@
* @struts.action-forward name="passwordChanged" path=".passwordChangeOk"
* @struts.action-forward name="portrait" path="/portrait.do"
* @struts.action-forward name="lessons" path="/profile.do?method=lessons"
+ * @struts.action-forward name="planner" path="/pedagogicalPlanner.do"
*/
public class IndexAction extends Action {
private static Logger log = Logger.getLogger(IndexAction.class);
private static IUserManagementService userManagementService;
private static IExportToolContentService exportService;
private static IAuthoringService authoringService;
+ private static Configuration configurationService;
@Override
@SuppressWarnings("unchecked")
@@ -125,6 +128,11 @@
}
}
+ Registration reg = Configuration.getRegistration();
+ if (reg != null) {
+ request.setAttribute("lamsCommunityEnabled", reg.isEnableLamsCommunityIntegration());
+ }
+
List collapsedOrgDTOs = getUserManagementService().getActiveCourseIdsByUser(loggedInUser.getUserId(),
request.isUserInRole(Role.SYSADMIN));
request.setAttribute("collapsedOrgDTOs", collapsedOrgDTOs);
@@ -135,7 +143,7 @@
private void setHeaderLinks(HttpServletRequest request) {
List headerLinks = new ArrayList();
if (request.isUserInRole(Role.AUTHOR) || request.isUserInRole(Role.AUTHOR_ADMIN)) {
- headerLinks.add(new IndexLinkBean("index.planner", "javascript:openPedagogicalPlanner()"));
+ headerLinks.add(new IndexLinkBean("index.planner", "index.do?tab=planner"));
headerLinks.add(new IndexLinkBean("index.author", "javascript:openAuthor()"));
}
headerLinks.add(new IndexLinkBean("index.myprofile", "index.do?tab=profile"));
Index: lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java,v
diff -u -r1.16 -r1.17
--- lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java 31 Oct 2008 00:57:30 -0000 1.16
+++ lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java 28 Jan 2009 00:10:32 -0000 1.17
@@ -198,6 +198,10 @@
userForm.set("localeId", locale.getLocaleId());
request.setAttribute("locales", locales);
request.setAttribute("tab", "profile");
+
+ boolean hasLamsCommunityToken = requestor.getLamsCommunityToken() != null;
+ request.setAttribute("hasLamsCommunityToken", hasLamsCommunityToken);
+
return mapping.findForward("edit");
}
Index: lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveAction.java,v
diff -u -r1.11 -r1.12
--- lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveAction.java 23 Jan 2009 01:36:33 -0000 1.11
+++ lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveAction.java 28 Jan 2009 00:10:32 -0000 1.12
@@ -40,6 +40,7 @@
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
+import org.hibernate.Hibernate;
import org.lamsfoundation.lams.usermanagement.SupportedLocale;
import org.lamsfoundation.lams.usermanagement.User;
import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
@@ -113,6 +114,13 @@
SupportedLocale locale = (SupportedLocale) getService().findById(SupportedLocale.class,
(Integer) userForm.get("localeId"));
requestor.setLocale(locale);
+
+ if (userForm.get("disableLamsCommunityUsername") != null
+ && (Boolean) userForm.get("disableLamsCommunityUsername")) {
+ requestor.setLamsCommunityToken(null);
+ requestor.setLamsCommunityUsername(null);
+ }
+
getService().save(requestor);
log.debug("profile edited: " + requestor);
Index: lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginAction.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginAction.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginAction.java 28 Jan 2009 00:10:32 -0000 1.1
@@ -0,0 +1,266 @@
+/****************************************************************
+ * Copyright (C) 2008 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id: LamsCommunityLoginAction.java,v 1.1 2009/01/28 00:10:32 lfoxton Exp $ */
+package org.lamsfoundation.lams.web.lamscommunity;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URLEncoder;
+import java.util.Date;
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.lamsfoundation.lams.config.Registration;
+import org.lamsfoundation.lams.usermanagement.User;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
+import org.lamsfoundation.lams.util.Configuration;
+import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.web.action.LamsDispatchAction;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * Action to login to lamscommunity when the user reaches the main page
+ *
+ * Steps:
+ *
+ * 1) If the user has previously logged in and has a lamscommunity login token
+ * saved, then it will immediately log them in through the lamscommunity sso
+ * servlet, otherwise it will take them to a authentication page where the user
+ * will enter their lamscommunity username and password
+ *
+ * 2) Once the username and password has been entered, a request will be sent to
+ * lams community with the username/password which lams community will
+ * authenticate and return a valid user token for this user, which can be used
+ * to login as in step one for thence forward.
+ *
+ *
+ * @author lfoxton
+ *
+ * @struts.action name="lamsCommunityLoginForm" path="/lamsCommunityLogin"
+ * scope="request" validate="false" parameter="dispatch"
+ *
+ * @struts.action-forward name="lamsCommunityLogin"
+ * path="/lamscommunity/lamscommunityLogin.jsp"
+ *
+ */
+public class LamsCommunityLoginAction extends LamsDispatchAction {
+
+ private IUserManagementService service;
+
+ private static final String ATTR_ERROR_MESSAGE = "errorMessage";
+ private static final String ATTR_LC_USERNAME = "lcUsername";
+
+ /**
+ * Default action response
+ * Checks whether the user has a lamscommunity token, if so logs them in
+ * immediately, otherwise forward to lamsCommunityLogin.jsp that
+ * prompts for login and password
+ */
+ public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+
+ User user = getUser(request);
+ if (user.getLamsCommunityToken() == null || user.getLamsCommunityToken().equals("")) {
+ // Authenticate the user manually
+ return mapping.findForward("lamsCommunityLogin");
+ } else {
+ // log the user into lamscommunity directly using the user token
+ loginToLamsCommunity(mapping, form, request, response);
+ }
+
+ return null;
+ }
+
+ public ActionForward getLCUserLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ return mapping.findForward("lamsCommunityLogin");
+ }
+
+ /**
+ * Authenticates the user with lamscommunity
+ * If the username/password is successfull a user token from the lams
+ * community is saved for the user which will be used henceforth to do the
+ * login request.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws Exception
+ */
+ public ActionForward authenticate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+
+ LamsCommunityLoginForm loginForm = (LamsCommunityLoginForm) form;
+
+ //configurationService = getConfiguration();
+ Registration reg = Configuration.getRegistration();
+
+ String responseString = null;
+ if(reg != null && reg.getServerID() != null && reg.getServerKey() != null)
+ {
+ responseString = lamsCommunityAuth(loginForm.getLcUserName(), loginForm.getLcPassword(), reg.getServerID(), reg.getServerKey());
+ }
+ else
+ {
+ throw new Exception("Attempt to authenticate in lams community without registration");
+ }
+
+ if (responseString != null) {
+ String[] result = responseString.split(",");
+ if (result[0].equals("success")) {
+ // Save the lams community user token to the user table
+ User user = getUser(request);
+ user.setLamsCommunityUsername(loginForm.getLcUserName());
+ user.setLamsCommunityToken(result[1]);
+ getService().save(user);
+
+ // then login
+ return loginToLamsCommunity(mapping, form, request, response);
+ } else {
+ if (result.length == 2) {
+ // login failed known reason
+ request.setAttribute(ATTR_ERROR_MESSAGE, result[1]);
+ } else {
+ // login failed unknown reason
+ request.setAttribute(ATTR_ERROR_MESSAGE, "lamscommunity.login.failed");
+ }
+ return mapping.findForward("lamsCommunityLogin");
+ }
+ } else {
+ // login failed, did not recieve response from lamscommunity
+ request.setAttribute(ATTR_ERROR_MESSAGE, "lamscommunity.no.result");
+ return mapping.findForward("lamsCommunityLogin");
+ }
+ }
+
+ /**
+ * Handles the call to lamscommunity to authenticate the user
+ * An encrypted message is sent to the lamscommunity with the user's
+ * credetials and lamscommunity returns a token if the authentication was
+ * successful
+ *
+ * @param userName
+ * @param lcPassword
+ * @param serverID
+ * @param serverKey
+ * @return
+ * @throws Exception
+ */
+ public String lamsCommunityAuth(String userName, String lcPassword, String serverID, String serverKey) throws Exception {
+
+ String timestamp = "" + new Date().getTime();
+
+ // encrypt the user data
+ String encryption = LamsCommunityUtil.encryptAuthenticationInfo(timestamp, userName, lcPassword, serverID, serverKey);
+
+ // Create the requst parameters
+ HashMap params = new HashMap();
+ params.put(LamsCommunityUtil.PARAM_HASH, URLEncoder.encode(encryption, "UTF8"));
+ params.put(LamsCommunityUtil.PARAM_SERVER_ID, URLEncoder.encode(serverID, "UTF8"));
+
+ // send the request to lamscommunity
+ InputStream is = WebUtil.getResponseInputStreamFromExternalServer(LamsCommunityUtil.LAMS_COMMUNITY_AUTH_URL, params);
+ BufferedReader isReader = new BufferedReader(new InputStreamReader(is));
+ String str = isReader.readLine();
+ return str;
+ }
+
+ /**
+ * Logs the user into lams community directly using the user token which
+ * was saved in the authentication action
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws Exception
+ */
+ public ActionForward loginToLamsCommunity(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+
+ User user = getUser(request);
+
+ // check that the server is registered with lamscommunity
+ Registration reg = Configuration.getRegistration();
+ String serverID;
+ String serverKey;
+ if(reg != null && reg.getServerID() != null && reg.getServerKey() != null)
+ {
+ serverID = reg.getServerID();
+ serverKey = reg.getServerKey();
+ }
+ else
+ {
+ throw new Exception("Attempt to authenticate in lams community without registration");
+ }
+
+ // Update the user session, set the logged into lamscommunity flag
+ UserDTO userDTO = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER);
+ userDTO.setLoggedIntoLamsCommunity(true);
+ HttpSession sharedsession = SessionManager.getSession();
+ sharedsession.setAttribute(AttributeNames.USER, userDTO);
+
+
+ String timestamp = "" + new Date().getTime();
+ String hash = LamsCommunityUtil.createAuthenticationHash(timestamp, user.getLamsCommunityUsername(), user.getLamsCommunityToken(), serverID, serverKey);
+
+ // Refirect the user to the lamscommunity sso url
+ String url = LamsCommunityUtil.LAMS_COMMUNITY_SSO_URL + "?";
+ url += LamsCommunityUtil.PARAM_LC_USERNAME + "=" + URLEncoder.encode(user.getLamsCommunityUsername(), "UTF8");
+ url += "&" + LamsCommunityUtil.PARAM_HASH + "=" + hash;
+ url += "&" + LamsCommunityUtil.PARAM_SERVER_ID + "=" + serverID;
+ url += "&" + LamsCommunityUtil.PARAM_TIMESTAMP + "=" + timestamp;
+
+ log.debug("Redirecting to lamscommunity url: " + url);
+
+ response.sendRedirect(url);
+ return null;
+ }
+
+ private User getUser(HttpServletRequest request) {
+ return (User) getService().getUserByLogin(request.getRemoteUser());
+ }
+
+ private IUserManagementService getService() {
+ if (service == null) {
+ WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet()
+ .getServletContext());
+ service = (IUserManagementService) ctx.getBean("userManagementService");
+ }
+ return service;
+ }
+}
Index: lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginForm.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginForm.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginForm.java 28 Jan 2009 00:10:32 -0000 1.1
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Copyright (C) 2008 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id: LamsCommunityLoginForm.java,v 1.1 2009/01/28 00:10:32 lfoxton Exp $ */
+package org.lamsfoundation.lams.web.lamscommunity;
+
+import org.apache.struts.action.ActionForm;
+
+/**
+ *
+ * @author lfoxton
+ *
+ * @struts.form name="lamsCommunityLoginForm" include-pk="true" include-all="true"
+ */
+public class LamsCommunityLoginForm extends ActionForm {
+
+ public static final long serialVersionUID = 82738272773582375L;
+
+ public String lcUserName;
+ public String lcPassword;
+ public String lcConfirmPassword;
+ public String dispatch;
+
+ public LamsCommunityLoginForm() {}
+
+ public String getLcUserName() {
+ return lcUserName;
+ }
+
+ public void setLcUserName(String lcUserName) {
+ this.lcUserName = lcUserName;
+ }
+
+ public String getLcPassword() {
+ return lcPassword;
+ }
+
+ public void setLcPassword(String lcPassword) {
+ this.lcPassword = lcPassword;
+ }
+
+ public String getDispatch() {
+ return dispatch;
+ }
+
+ public void setDispatch(String dispatch) {
+ this.dispatch = dispatch;
+ }
+
+ public String getLcConfirmPassword() {
+ return lcConfirmPassword;
+ }
+
+ public void setLcConfirmPassword(String lcConfirmPassword) {
+ this.lcConfirmPassword = lcConfirmPassword;
+ }
+}
+
\ No newline at end of file
Index: lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityUtil.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityUtil.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityUtil.java 28 Jan 2009 00:10:32 -0000 1.1
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Copyright (C) 2008 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id: LamsCommunityUtil.java,v 1.1 2009/01/28 00:10:32 lfoxton Exp $ */
+package org.lamsfoundation.lams.web.lamscommunity;
+
+import java.net.URLEncoder;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import org.lamsfoundation.lams.util.HashUtil;
+
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+public class LamsCommunityUtil {
+
+
+ public static final String LAMS_COMMUNITY_URL = "http://lamscommunity.org";
+ public static final String LAMS_COMMUNITY_SSO_URL = "http://lamscommunity.org/lams/x/sso";
+ public static final String LAMS_COMMUNITY_AUTH_URL = "http://lamscommunity.org/lams/x/auth";
+
+
+
+ public static final String PARAM_HASH = "hs";
+ public static final String PARAM_SERVER_ID = "sid";
+ public static final String PARAM_TIMESTAMP = "ts";
+ public static final String PARAM_LC_USERNAME = "un";
+ public static final String PARAM_LC_PASSWORD = "ps";
+ public static final String PARAM_LC_USER_TOKEN = "tk";
+
+
+ public static String createAuthenticationHash(String timestamp, String username, String password, String serverId, String serverKey) {
+ String hash = "";
+ if (serverId != null && serverKey != null) {
+ hash = hash(timestamp + username + serverId + password + serverKey);
+ }
+ return hash;
+ }
+
+ public static String hash(String string)
+ {
+ return HashUtil.sha1(string);
+ }
+
+ public static String encryptAuthenticationInfo(String timestamp, String username, String password, String serverId,
+ String serverKey) throws Exception{
+ String hash = "";
+ if (serverId != null && serverKey != null) {
+ hash = encrypt(timestamp +","+ username +","+ URLEncoder.encode(password, "UTF8"), serverKey);
+ }
+ return hash;
+ }
+
+ public static String encrypt(String text, String password) throws Exception{
+
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+
+ //setup key
+ byte[] keyBytes = new byte[16];
+ byte[] b = password.getBytes("UTF-8");
+ int len = b.length;
+ if (len > keyBytes.length)
+ len = keyBytes.length;
+ System.arraycopy(b, 0, keyBytes, 0, len);
+
+ SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
+
+ //the below may make this less secure, hard code byte array the IV in both java and .net clients
+ IvParameterSpec ivSpec = new IvParameterSpec(keyBytes);
+
+ cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
+ byte[] results = cipher.doFinal(text.getBytes("UTF-8"));
+ BASE64Encoder encoder = new BASE64Encoder();
+ return encoder.encode(results);
+ }
+
+
+}
Index: lams_central/web/editprofile.jsp
===================================================================
RCS file: /usr/local/cvsroot/lams_central/web/editprofile.jsp,v
diff -u -r1.13 -r1.14
--- lams_central/web/editprofile.jsp 5 Mar 2008 07:33:03 -0000 1.13
+++ lams_central/web/editprofile.jsp 28 Jan 2009 00:11:26 -0000 1.14
@@ -30,11 +30,13 @@
<%= AuthenticationMethod.DB %>
+
+
- : |
- |
+ : |
+ |
: |
@@ -125,9 +127,20 @@
-
+
+
+
+
+
+
+ : |
+
+
+ |
+
+
-
+
Index: lams_central/web/index.jsp
===================================================================
RCS file: /usr/local/cvsroot/lams_central/web/index.jsp,v
diff -u -r1.28 -r1.29
--- lams_central/web/index.jsp 19 Oct 2007 02:32:38 -0000 1.28
+++ lams_central/web/index.jsp 28 Jan 2009 00:11:38 -0000 1.29
@@ -4,6 +4,7 @@
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="tags-lams" prefix="lams" %>
<%@ taglib uri="tags-fmt" prefix="fmt" %>
+<%@ taglib uri="tags-core" prefix="c"%>
@@ -22,4 +23,13 @@