Index: lams_common/.classpath =================================================================== RCS file: /usr/local/cvsroot/lams_common/.classpath,v diff -u -r1.15 -r1.15.8.1 --- lams_common/.classpath 30 Oct 2008 03:48:30 -0000 1.15 +++ lams_common/.classpath 13 May 2009 10:05:21 -0000 1.15.8.1 @@ -5,11 +5,17 @@ - - - - + + + + + + + + + + Index: lams_common/db/sql/insert_lams_unix_config_data.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/db/sql/insert_lams_unix_config_data.sql,v diff -u -r1.43.2.3 -r1.43.2.3.2.1 --- lams_common/db/sql/insert_lams_unix_config_data.sql 7 May 2009 06:54:34 -0000 1.43.2.3 +++ lams_common/db/sql/insert_lams_unix_config_data.sql 13 May 2009 10:05:21 -0000 1.43.2.3.2.1 @@ -14,7 +14,7 @@ values ('DumpDir','/var/opt/lams/dump', 'config.dump.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) -values ('EARDir','/usr/local/jboss-4.0.2/server/default/deploy/lams.ear/', 'config.ear.dir', 'config.header.system', 'STRING', 1); +values ('EARDir','/usr/local/jboss-5/server/default/deploy/lams.ear/', 'config.ear.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) values ('SMTPServer','', 'config.smtp.server', 'config.header.email', 'STRING', 0); Index: lams_common/db/sql/insert_lams_windows_config_data.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/db/sql/insert_lams_windows_config_data.sql,v diff -u -r1.35.4.3 -r1.35.4.3.2.1 --- lams_common/db/sql/insert_lams_windows_config_data.sql 7 May 2009 06:54:34 -0000 1.35.4.3 +++ lams_common/db/sql/insert_lams_windows_config_data.sql 13 May 2009 10:05:21 -0000 1.35.4.3.2.1 @@ -14,7 +14,7 @@ values ('DumpDir','C:/lams/dump', 'config.dump.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) -values ('EARDir','D:/jboss-4.0.2/server/default/deploy/lams.ear', 'config.ear.dir', 'config.header.system', 'STRING', 1); +values ('EARDir','D:/jboss-5/server/default/deploy/lams.ear', 'config.ear.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) values ('SMTPServer','', 'config.smtp.server', 'config.header.email', 'STRING', 0); Index: lams_common/db/sql/insert_rams_unix_config_data.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/db/sql/Attic/insert_rams_unix_config_data.sql,v diff -u -r1.20.6.1 -r1.20.6.1.2.1 --- lams_common/db/sql/insert_rams_unix_config_data.sql 20 Apr 2009 00:31:27 -0000 1.20.6.1 +++ lams_common/db/sql/insert_rams_unix_config_data.sql 13 May 2009 10:05:21 -0000 1.20.6.1.2.1 @@ -14,7 +14,7 @@ values ('DumpDir','/var/opt/rams/dump', 'config.dump.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) -values ('EARDir','/usr/local/jboss-4.0.2/server/default/deploy/rams.ear', 'config.ear.dir', 'config.header.system', 'STRING', 1); +values ('EARDir','/usr/local/jboss-5/server/default/deploy/rams.ear', 'config.ear.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) values ('SMTPServer','', 'config.smtp.server', 'config.header.email', 'STRING', 0); Index: lams_common/db/sql/insert_rams_windows_config_data.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/db/sql/Attic/insert_rams_windows_config_data.sql,v diff -u -r1.17.6.1 -r1.17.6.1.2.1 --- lams_common/db/sql/insert_rams_windows_config_data.sql 20 Apr 2009 00:31:28 -0000 1.17.6.1 +++ lams_common/db/sql/insert_rams_windows_config_data.sql 13 May 2009 10:05:21 -0000 1.17.6.1.2.1 @@ -14,7 +14,7 @@ values ('DumpDir','C:/rams/dump', 'config.dump.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) -values ('EARDir','C:/jboss-4.0.2/server/default/deploy/rams.ear', 'config.ear.dir', 'config.header.system', 'STRING', 1); +values ('EARDir','C:/jboss-5/server/default/deploy/rams.ear', 'config.ear.dir', 'config.header.system', 'STRING', 1); insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) values ('SMTPServer','', 'config.smtp.server', 'config.header.email', 'STRING', 0); Index: lams_common/src/java/org/lamsfoundation/lams/applicationContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/applicationContext.xml,v diff -u -r1.7 -r1.7.4.1 --- lams_common/src/java/org/lamsfoundation/lams/applicationContext.xml 26 Mar 2009 10:00:34 -0000 1.7 +++ lams_common/src/java/org/lamsfoundation/lams/applicationContext.xml 13 May 2009 10:05:21 -0000 1.7.4.1 @@ -20,8 +20,19 @@ 20 1800 50 - org.jboss.hibernate.cache.DeployedTreeCacheProvider - jboss.cache:service=TreeCache + org.hibernate.cache.jbc2.SharedJBossCacheRegionFactory + Index: lams_common/src/java/org/lamsfoundation/lams/beanRefContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/beanRefContext.xml,v diff -u -r1.5.2.1 -r1.5.2.1.2.1 --- lams_common/src/java/org/lamsfoundation/lams/beanRefContext.xml 22 Apr 2009 06:39:05 -0000 1.5.2.1 +++ lams_common/src/java/org/lamsfoundation/lams/beanRefContext.xml 13 May 2009 10:05:21 -0000 1.5.2.1.2.1 @@ -28,9 +28,16 @@ classpath*:org/lamsfoundation/lams/tool/**/*pplicationContext.xml collects all application context files from all deployed lams tools. + [IMPORTANT!!!! + UPDATE: JBoss 5.1.0.CR1 still has bugs when it comes ot Ant-style pattern resolution, like the one above. + The pattern had to be change to explicit list of tools, until a good solution is found. + This means that the list of deployed tools is fixed and any changes done to it will cause deployment errors. + ] + If new application context file is used in development and its beans need to be added to shared context, just add it to the end (or wherever it is suitable) of the list. --> + @@ -40,7 +47,32 @@ /org/lamsfoundation/lams/contentrepository/applicationContext.xml /org/lamsfoundation/lams/lesson/lessonApplicationContext.xml /org/lamsfoundation/lams/learning/learningApplicationContext.xml - classpath*:org/lamsfoundation/lams/tool/**/*pplicationContext.xml + + + /org/lamsfoundation/lams/tool/mc/mcApplicationContext.xml + /org/lamsfoundation/lams/tool/forum/forumApplicationContext.xml + /org/lamsfoundation/lams/tool/noticeboard/nbApplicationContext.xml + /org/lamsfoundation/lams/tool/gmap/gmapApplicationContext.xml + /org/lamsfoundation/lams/tool/imageGallery/imageGalleryApplicationContext.xml + /org/lamsfoundation/lams/tool/qa/qaApplicationContext.xml + /org/lamsfoundation/lams/tool/rsrc/rsrcApplicationContext.xml + /org/lamsfoundation/lams/tool/dimdim/dimdimApplicationContext.xml + /org/lamsfoundation/lams/tool/notebook/notebookApplicationContext.xml + /org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml + /org/lamsfoundation/lams/tool/daco/dacoApplicationContext.xml + /org/lamsfoundation/lams/tool/scribe/scribeApplicationContext.xml + /org/lamsfoundation/lams/tool/spreadsheet/spreadsheetApplicationContext.xml + /org/lamsfoundation/lams/tool/survey/surveyApplicationContext.xml + /org/lamsfoundation/lams/tool/taskList/taskListApplicationContext.xml + /org/lamsfoundation/lams/tool/vote/voteApplicationContext.xml + /org/lamsfoundation/lams/tool/wiki/wikiApplicationContext.xml + /org/lamsfoundation/lams/tool/chat/chatApplicationContext.xml + /org/lamsfoundation/lams/authoring/authoringApplicationContext.xml /org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml /org/lamsfoundation/lams/workspace/workspaceApplicationContext.xml Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/commonContext.xml,v diff -u -r1.79.2.2 -r1.79.2.2.2.1 --- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml 20 Apr 2009 04:13:32 -0000 1.79.2.2 +++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml 13 May 2009 10:05:21 -0000 1.79.2.2.2.1 @@ -42,8 +42,8 @@ classpath:org/lamsfoundation/lams/learningdesign/Activity.hbm.xml classpath:org/lamsfoundation/lams/learningdesign/BranchActivityEntry.hbm.xml classpath:org/lamsfoundation/lams/learningdesign/BranchCondition.hbm.xml - classpath:org/lamsfoundation/lams/learningdesign/Group.hbm.xml - classpath:org/lamsfoundation/lams/learningdesign/GroupUser.hbm.xml + classpath:org/lamsfoundation/lams/learningdesign/Group.hbm.xml + classpath:org/lamsfoundation/lams/learningdesign/GroupUser.hbm.xml classpath:org/lamsfoundation/lams/learningdesign/Grouping.hbm.xml classpath:org/lamsfoundation/lams/learningdesign/LearningDesign.hbm.xml classpath:org/lamsfoundation/lams/learningdesign/Competence.hbm.xml @@ -100,12 +100,203 @@ classpath:org/lamsfoundation/lams/contentrepository/CrWorkspace.hbm.xml classpath:org/lamsfoundation/lams/contentrepository/CrWorkspaceCredential.hbm.xml - - + + + classpath:org/lamsfoundation/lams/tool/BasicToolVO.hbm.xml + classpath:org/lamsfoundation/lams/tool/SystemTool.hbm.xml + classpath:org/lamsfoundation/lams/tool/Tool.hbm.xml + classpath:org/lamsfoundation/lams/tool/ToolContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/ToolImportSupport.hbm.xml + classpath:org/lamsfoundation/lams/tool/ToolSession.hbm.xml + + classpath:org/lamsfoundation/lams/tool/forum/persistence/Attachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/Forum.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/ForumCondition.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/ForumReport.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/ForumToolSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/ForumUser.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/Message.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/MessageSeq.hbm.xml + classpath:org/lamsfoundation/lams/tool/forum/persistence/Timestamp.hbm.xml + + classpath:org/lamsfoundation/lams/tool/noticeboard/NoticeboardAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/noticeboard/NoticeboardSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/noticeboard/NoticeboardUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/mc/McContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/mc/McOptsContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/mc/McQueContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/mc/McQueUsr.hbm.xml + classpath:org/lamsfoundation/lams/tool/mc/McSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/mc/McUploadedFile.hbm.xml + classpath:org/lamsfoundation/lams/tool/mc/McUsrAttempt.hbm.xml + + classpath:org/lamsfoundation/lams/tool/wiki/model/Wiki.hbm.xml + classpath:org/lamsfoundation/lams/tool/wiki/model/WikiAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/wiki/model/WikiPage.hbm.xml + classpath:org/lamsfoundation/lams/tool/wiki/model/WikiPageContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/wiki/model/WikiSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/wiki/model/WikiUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/vote/VoteContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/vote/VoteQueContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/vote/VoteQueUsr.hbm.xml + classpath:org/lamsfoundation/lams/tool/vote/VoteSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/vote/VoteUploadedFile.hbm.xml + classpath:org/lamsfoundation/lams/tool/vote/VoteUsrAttempt.hbm.xml + + + + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskList.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListCondition.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListItem.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListItemAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListItemComment.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListItemVisitLog.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/taskList/model/TaskListUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/survey/model/Survey.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyAnswer.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyCondition.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyOption.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyQuestion.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveySession.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/spreadsheet/model/Spreadsheet.hbm.xml + classpath:org/lamsfoundation/lams/tool/spreadsheet/model/SpreadsheetAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/spreadsheet/model/SpreadsheetMark.hbm.xml + classpath:org/lamsfoundation/lams/tool/spreadsheet/model/SpreadsheetSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/spreadsheet/model/SpreadsheetUser.hbm.xml + classpath:org/lamsfoundation/lams/tool/spreadsheet/model/UserModifiedSpreadsheet.hbm.xml + + classpath:org/lamsfoundation/lams/tool/scribe/model/Scribe.hbm.xml + classpath:org/lamsfoundation/lams/tool/scribe/model/ScribeAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/scribe/model/ScribeHeading.hbm.xml + classpath:org/lamsfoundation/lams/tool/scribe/model/ScribeReportEntry.hbm.xml + classpath:org/lamsfoundation/lams/tool/scribe/model/ScribeSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/scribe/model/ScribeUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/sbmt/InstructionFiles.hbm.xml + classpath:org/lamsfoundation/lams/tool/sbmt/SubmissionDetails.hbm.xml + classpath:org/lamsfoundation/lams/tool/sbmt/SubmitFilesContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/sbmt/SubmitFilesReport.hbm.xml + classpath:org/lamsfoundation/lams/tool/sbmt/SubmitFilesSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/sbmt/SubmitUser.hbm.xml + + + + classpath:org/lamsfoundation/lams/tool/notebook/model/Notebook.hbm.xml + classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookCondition.hbm.xml + classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/rsrc/model/Resource.hbm.xml + classpath:org/lamsfoundation/lams/tool/rsrc/model/ResourceAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/rsrc/model/ResourceItem.hbm.xml + classpath:org/lamsfoundation/lams/tool/rsrc/model/ResourceItemInstruction.hbm.xml + classpath:org/lamsfoundation/lams/tool/rsrc/model/ResourceItemVisitLog.hbm.xml + classpath:org/lamsfoundation/lams/tool/rsrc/model/ResourceSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/rsrc/model/ResourceUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/qa/QaCondition.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaConfigItem.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaQueContent.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaQueUsr.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaUploadedFile.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaUsrResp.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaWizardCategory.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaWizardCognitiveSkill.hbm.xml + classpath:org/lamsfoundation/lams/tool/qa/QaWizardQuestion.hbm.xml + + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageComment.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageGallery.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryConfigItem.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryItem.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryItemVisitLog.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageGallerySession.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryUser.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageRating.hbm.xml + classpath:org/lamsfoundation/lams/tool/imageGallery/model/ImageVote.hbm.xml + + + classpath:org/lamsfoundation/lams/tool/gmap/model/Gmap.hbm.xml + classpath:org/lamsfoundation/lams/tool/gmap/model/GmapAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/gmap/model/GmapConfigItem.hbm.xml + classpath:org/lamsfoundation/lams/tool/gmap/model/GmapMarker.hbm.xml + classpath:org/lamsfoundation/lams/tool/gmap/model/GmapSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/gmap/model/GmapUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/dimdim/model/Dimdim.hbm.xml + classpath:org/lamsfoundation/lams/tool/dimdim/model/DimdimAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/dimdim/model/DimdimConfig.hbm.xml + classpath:org/lamsfoundation/lams/tool/dimdim/model/DimdimSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/dimdim/model/DimdimUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/daco/model/Daco.hbm.xml + classpath:org/lamsfoundation/lams/tool/daco/model/DacoAnswer.hbm.xml + classpath:org/lamsfoundation/lams/tool/daco/model/DacoAnswerOption.hbm.xml + classpath:org/lamsfoundation/lams/tool/daco/model/DacoAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/daco/model/DacoQuestion.hbm.xml + classpath:org/lamsfoundation/lams/tool/daco/model/DacoSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/daco/model/DacoUser.hbm.xml + + classpath:org/lamsfoundation/lams/tool/chat/model/Chat.hbm.xml + classpath:org/lamsfoundation/lams/tool/chat/model/ChatAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/chat/model/ChatCondition.hbm.xml + classpath:org/lamsfoundation/lams/tool/chat/model/ChatMessage.hbm.xml + classpath:org/lamsfoundation/lams/tool/chat/model/ChatSession.hbm.xml + classpath:org/lamsfoundation/lams/tool/chat/model/ChatUser.hbm.xml + @@ -241,14 +432,40 @@ - + + + + + + + + + + + + + + + + true + + + + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + + + + @@ -288,33 +505,6 @@ - - - - - - - - - - - - - - - - true - - - - PROPAGATION_REQUIRED - PROPAGATION_REQUIRED - PROPAGATION_REQUIRED - PROPAGATION_REQUIRED - - - - @@ -415,7 +605,7 @@ - + - * If necessary, gets it via the MBean. If gets via MBean, then - * also sets up the cache listener at the same time, if required. */ - private TreeCacheMBean getCache() { - if ( treeCache == null ) { - - try { - if ( cacheObjectName == null ) - cacheObjectName = DEFAULT_CACHE_OBJECT_NAME; - MBeanServer server=MBeanServerLocator.locate(); - treeCache = (TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class, cacheObjectName, server); - - if ( Configuration.getAsBoolean(ConfigurationKeys.USE_CACHE_DEBUG_LISTENER) ) { - if ( listener != null ) - treeCache.removeTreeCacheListener(listener); - listener = new CacheDebugListener(); - treeCache.addTreeCacheListener(listener); - log.info("Added tree cache listener."); - } - } catch (Exception e) { - log.error("Unable to access the JBOSS cache mbean "+cacheObjectName+". Cache not available.",e); - } + protected Logger log = Logger.getLogger(CacheManager.class); + private String DEFAULT_CACHE_OBJECT_NAME = "jboss.cache:service=TreeCache"; + + /* Spring configured variables */ + private String cacheObjectName = null; + + /* + * There is one cache across the whole system, so it should be safe to use a static cache bean. Do not use this + * attribute directly - always get it via getCache(). + */ + private Cache cache = null; + private Object listener = null; + + /** + * Get the tree cache. + *

+ * If necessary, gets it via the MBean. If gets via MBean, then also sets up the cache listener at the same time, if + * required. + */ + private Cache getCache() { + if (cache == null) { + + try { + if (cacheObjectName == null) { + cacheObjectName = DEFAULT_CACHE_OBJECT_NAME; } - return treeCache; + /* + * When migrating to JBoss 5, the way the Cache is accessed had to be changed. Also, currently Cache is + * not exposed by JMX, so it is also unavailable for Cache Manager. Trying to retrieve it causes an + * error. This will be fixed in the future. + */ + MBeanServer server = JMXUtil.getMBeanServer(); + CacheJmxWrapperMBean wrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler.newProxyInstance( + server, ObjectName.getInstance(cacheObjectName), CacheJmxWrapperMBean.class, false); + cache = wrapper.getCache(); + + // cache = (Cache) server.getObjectInstance(ObjectName.getInstance(cacheObjectName)); + // cache = (Cache) server.createMBean(Cache.class.getName(), ); + + if (Configuration.getAsBoolean(ConfigurationKeys.USE_CACHE_DEBUG_LISTENER)) { + if (listener != null) { + cache.removeCacheListener(listener); + } + listener = new CacheDebugListener(); + cache.addCacheListener(listener); + log.info("Added tree cache listener."); + } + } catch (Exception e) { + log.error("Unable to access the JBOSS cache mbean " + cacheObjectName + ". Cache not available.", e); + } } - - /** Get the String[] version of the objects class name. */ - public String[] getPartsFromClass(Class clasz) { - return clasz.getName().split("\\."); + return cache; + } + + /** Get the String[] version of the objects class name. */ + public String[] getPartsFromClass(Class clasz) { + return clasz.getName().split("\\."); + } + + /** + * Get the Fqn for this object, based on the class name. The Fqn is used as the part of the key to the cached + * object. + */ + private Fqn getFqn(Class clasz) { + return Fqn.fromElements(getPartsFromClass(clasz)); + } + + /** + * Get the Fqn for this object, based on classNameParts. The Fqn is used as the part of the key to the cached + * object. + */ + private Fqn getFqn(String[] classNameParts) { + return Fqn.fromElements(classNameParts); + } + + /* + * (non-Javadoc) + * + * @see org.lamsfoundation.lams.cache.ICacheManager#getItem(java.lang.String[], java.lang.Object) + */ + public Object getItem(String[] classNameParts, Object key) { + if (key == null || classNameParts == null) { + return null; } - /** Get the Fqn for this object, based on the class name. The Fqn is used as the part of the key to the cached object. */ - private Fqn getFqn(Class clasz) { - return new Fqn(getPartsFromClass(clasz)); + return getItem(getFqn(classNameParts), key); + } + + /* + * (non-Javadoc) + * + * @see org.lamsfoundation.lams.cache.ICacheManager#getItem(java.lang.Class, java.lang.Object) + */ + public Object getItem(Class clasz, Object key) { + if (key == null || clasz == null) { + return null; } - - /** Get the Fqn for this object, based on classNameParts. The Fqn is used as the part of the key to the cached object. */ - private Fqn getFqn(String[] classNameParts) { - return new Fqn(classNameParts); - } - /* (non-Javadoc) - * @see org.lamsfoundation.lams.cache.ICacheManager#getItem(java.lang.String[], java.lang.Object) - */ - public Object getItem(String[] classNameParts, Object key){ - if ( key == null || classNameParts == null ) - return null; + return getItem(getFqn(clasz), key); + } - return getItem(getFqn(classNameParts),key); + /** Does the "real" get from the cache. Key and fqn must not be null or an exception may be thrown. */ + private Object getItem(Fqn fqn, Object key) { + Cache cache = getCache(); + if (cache == null) { + log.warn("Unable to get item with fqn " + fqn + " key " + key + " as we can't get the JBOSS Cache mbean."); + return null; } - - /* (non-Javadoc) - * @see org.lamsfoundation.lams.cache.ICacheManager#getItem(java.lang.Class, java.lang.Object) - */ - public Object getItem(Class clasz, Object key) { - if ( key == null || clasz == null ) - return null; - return getItem(getFqn(clasz), key); + Object obj = null; + try { + obj = cache.get(fqn, key); + if (obj != null) { + log.debug("Retrieved object from cache fqn " + fqn + " key " + key); + } + } catch (CacheException e) { + log.error("JBOSS Cache exception occured getting object from cache. fqn " + fqn + " key " + key, e); } - - /** Does the "real" get from the cache. Key and fqn must not be null or an exception may be thrown. */ - private Object getItem(Fqn fqn, Object key) { - TreeCacheMBean cache = getCache(); - if (cache==null) { - log.warn("Unable to get item with fqn "+fqn+" key "+key+" as we can't get the JBOSS Cache mbean."); - return null; - } - - Object obj = null; - try { - obj = (Object) cache.get(fqn, key); - if ( obj != null ) { - log.debug("Retrieved object from cache fqn "+fqn+" key "+key); - } - } catch (CacheException e) { - log.error("JBOSS Cache exception occured getting object from cache. fqn "+fqn+" key "+key, e); - } - return obj; + return obj; + } + + /* + * (non-Javadoc) + * + * @see org.lamsfoundation.lams.cache.ICacheManager#addItem(java.lang.String[], java.lang.Object, java.lang.Object) + */ + public void addItem(String[] classNameParts, Object key, Object item) { + if (item != null && key != null && classNameParts != null) { + addItem(getFqn(classNameParts), key, item); } + } - /* (non-Javadoc) - * @see org.lamsfoundation.lams.cache.ICacheManager#addItem(java.lang.String[], java.lang.Object, java.lang.Object) - */ - public void addItem(String[] classNameParts, Object key, Object item){ - if ( item != null && key != null && classNameParts != null ) - addItem(getFqn(classNameParts), key, item); + /* + * (non-Javadoc) + * + * @see org.lamsfoundation.lams.cache.ICacheManager#addItem(java.lang.Class, java.lang.Object, java.lang.Object) + */ + public void addItem(Class clasz, Object key, Object item) { + if (item != null && key != null && clasz != null) { + addItem(getFqn(clasz), key, item); } - - /* (non-Javadoc) - * @see org.lamsfoundation.lams.cache.ICacheManager#addItem(java.lang.Class, java.lang.Object, java.lang.Object) - */ - public void addItem(Class clasz, Object key, Object item){ - if ( item != null && key != null && clasz != null ) - addItem(getFqn(clasz),key,item); - } + } - /** Does the "real" put in the cache. Key, fqn and item must not be null or an exception may be thrown. */ - private void addItem(Fqn fqn, Object key, Object item){ - TreeCacheMBean cache = getCache(); - if (cache==null) { - log.warn("Unable to get cache item with fqn "+fqn+" key "+key+" as we can't get the JBOSS Cache mbean."); - return; - } - - try { - cache.put(fqn, key, item); - } catch (CacheException e) { - log.error("JBOSS Cache exception occured putting object in cache. fqn "+fqn+" key "+key,e); - } + /** Does the "real" put in the cache. Key, fqn and item must not be null or an exception may be thrown. */ + private void addItem(Fqn fqn, Object key, Object item) { + Cache cache = getCache(); + if (cache == null) { + log.warn("Unable to get cache item with fqn " + fqn + " key " + key + + " as we can't get the JBOSS Cache mbean."); + return; } - public Map getCachedItems() { - TreeCacheMBean cache = getCache(); - Map allChildNames = new TreeMap(); - if (cache==null) { - log.warn("Unable to get cache items as we can't get the JBOSS Cache mbean."); - } else { - addChildren("/", cache, allChildNames); - } - return allChildNames; + try { + cache.put(fqn, key, item); + } catch (CacheException e) { + log.error("JBOSS Cache exception occured putting object in cache. fqn " + fqn + " key " + key, e); } + } - /* Recursively add all the child nodes to the map. This is where the format of FQNs is important - - * this code will hardcode in "/" between each step. */ - private void addChildren(String node, TreeCacheMBean cache, Map allChildNames ) { - try { - Set childNames = cache.getChildrenNames(node); - if ( childNames != null ) { - allChildNames.put(node, childNames); - Iterator iter = childNames.iterator(); - while ( iter.hasNext() ) { - String childNode = (String) iter.next(); - if ( node.endsWith("/") ) { - addChildren(node+childNode,cache,allChildNames); - } else { - addChildren(node+"/"+childNode,cache,allChildNames); - } - } - } - } catch (CacheException e) { - log.error("JBOSS Cache exception occured getting child names from cache",e); - } + public Map getCachedItems() { + Cache cache = getCache(); + Map allChildNames = new TreeMap(); + if (cache == null) { + log.warn("Unable to get cache items as we can't get the JBOSS Cache mbean."); + } else { + addChildren("/", cache, allChildNames); } + return allChildNames; + } - /** Clear all the nodes in the cache with the given key. - * Works on nodes starting with /org, /com and /net */ - public void clearCache(String node) { - TreeCacheMBean cache = getCache(); - if (cache==null) { - log.warn("Unable to clear cache node "+node+" as we can't get the JBOSS Cache mbean."); - } else { - try { - cache.remove(node); - } catch (CacheException e) { - log.error("JBOSS Cache exception occured getting child names from cache",e); - } + /* + * Recursively add all the child nodes to the map. This is where the format of FQNs is important - this code will + * hardcode in "/" between each step. + */ + private void addChildren(String node, Cache cache, Map allChildNames) { + try { + Set childNames = cache.getChildrenNames(node); + if (childNames != null) { + allChildNames.put(node, childNames); + Iterator iter = childNames.iterator(); + while (iter.hasNext()) { + String childNode = (String) iter.next(); + if (node.endsWith("/")) { + addChildren(node + childNode, cache, allChildNames); + } else { + addChildren(node + "/" + childNode, cache, allChildNames); + } } + } + } catch (CacheException e) { + log.error("JBOSS Cache exception occured getting child names from cache", e); } - - /** Remove a particular item from the cache. */ - public void removeItem(String[] classNameParts, Object key) { - TreeCacheMBean cache = getCache(); - if (cache==null) { - log.warn("Unable to remove cache item "+classNameParts+":"+key+"as we can't get the JBOSS Cache mbean."); - } else { - try { - cache.remove(getFqn(classNameParts), key); - } catch (CacheException e) { - log.error("JBOSS Cache exception occured getting child names from cache",e); - } - } - } + } - /* **** Spring initialisation methods */ - - public String getCacheObjectName() { - return cacheObjectName; + /** + * Clear all the nodes in the cache with the given key. Works on nodes starting with /org, /com and /net + */ + public void clearCache(String node) { + Cache cache = getCache(); + + if (cache == null) { + log.warn("Unable to clear cache node " + node + " as we can't get the JBOSS Cache mbean."); + } else { + try { + cache.removeNode(node); + } catch (CacheException e) { + log.error("JBOSS Cache exception occured getting child names from cache", e); + } } + } - public void setCacheObjectName(String cacheObjectName) { - this.cacheObjectName = cacheObjectName; + /** Remove a particular item from the cache. */ + public void removeItem(String[] classNameParts, Object key) { + Cache cache = getCache(); + if (cache == null) { + log.warn("Unable to remove cache item " + classNameParts + ":" + key + + "as we can't get the JBOSS Cache mbean."); + } else { + try { + cache.remove(getFqn(classNameParts), key); + } catch (CacheException e) { + log.error("JBOSS Cache exception occured getting child names from cache", e); + } } - + } + + /* **** Spring initialisation methods */ + + public String getCacheObjectName() { + return cacheObjectName; + } + + public void setCacheObjectName(String cacheObjectName) { + this.cacheObjectName = cacheObjectName; + } + } Index: lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java,v diff -u -r1.1 -r1.1.8.1 --- lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java 25 Aug 2008 08:15:43 -0000 1.1 +++ lams_common/src/java/org/lamsfoundation/lams/events/dao/hibernate/EventDAOHibernate.java 13 May 2009 10:05:21 -0000 1.1.8.1 @@ -9,34 +9,34 @@ class EventDAOHibernate extends HibernateDaoSupport implements EventDAO { - protected static final String GET_EVENT_QUERY = "FROM " + Event.class.getName() - + " AS e WHERE e.scope=? AND e.name=? AND e.eventSessionId=? AND e.failTime IS NULL"; + protected static final String GET_EVENT_QUERY = "FROM " + Event.class.getName() + + " AS e WHERE e.scope=? AND e.name=? AND e.eventSessionId=? AND e.failTime IS NULL"; - protected static final String GET_EVENTS_TO_RESEND_QUERY = "SELECT DISTINCT e FROM " + Event.class.getName() - + " AS e LEFT JOIN FETCH e.subscriptions WHERE e.failTime IS NOT NULL OR " - + "(e.subscriptions.periodicity > 0 AND (NOW()- e.subscriptions.lastOperationTime >= e.subscriptions.periodicity))"; + protected static final String GET_EVENTS_TO_RESEND_QUERY = "SELECT DISTINCT e FROM " + Event.class.getName() + + " AS e LEFT JOIN FETCH e.subscriptions AS s WHERE e.failTime IS NOT NULL OR " + + "(s.periodicity > 0 AND (NOW()- s.lastOperationTime >= s.periodicity))"; - public Event getEvent(String scope, String name, Long sessionId) throws InvalidParameterException { - List events = getHibernateTemplate().find(EventDAOHibernate.GET_EVENT_QUERY, - new Object[] { scope, name, sessionId }); - if (events.size() > 1) { - throw new InvalidParameterException("Two events with the same parameters exist in the database."); - } - if (events.size() == 0) { - return null; - } - return events.get(0); + public Event getEvent(String scope, String name, Long sessionId) throws InvalidParameterException { + List events = getHibernateTemplate().find(EventDAOHibernate.GET_EVENT_QUERY, + new Object[] { scope, name, sessionId }); + if (events.size() > 1) { + throw new InvalidParameterException("Two events with the same parameters exist in the database."); } - - public List getEventsToResend() { - return getHibernateTemplate().find(EventDAOHibernate.GET_EVENTS_TO_RESEND_QUERY); + if (events.size() == 0) { + return null; } + return events.get(0); + } - public void deleteEvent(Event event) { - getHibernateTemplate().delete(event); - } + public List getEventsToResend() { + return getHibernateTemplate().find(EventDAOHibernate.GET_EVENTS_TO_RESEND_QUERY); + } - public void saveEvent(Event event) { - getHibernateTemplate().saveOrUpdate(event); - } + public void deleteEvent(Event event) { + getHibernateTemplate().delete(event); + } + + public void saveEvent(Event event) { + getHibernateTemplate().saveOrUpdate(event); + } } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupUser.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupUser.java,v diff -u -r1.1.2.1 -r1.1.2.1.2.1 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupUser.java 16 Apr 2009 06:46:26 -0000 1.1.2.1 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupUser.java 13 May 2009 10:05:21 -0000 1.1.2.1.2.1 @@ -18,38 +18,41 @@ * * http://www.gnu.org/licenses/gpl.txt * **************************************************************** - */ - -/* $Id$ */ -package org.lamsfoundation.lams.learningdesign; + */ +/* $Id$ */ +package org.lamsfoundation.lams.learningdesign; + +import java.io.Serializable; + import org.lamsfoundation.lams.usermanagement.User; - + /** * A persistence bean for group/user mappings + * * @author lfoxton - * + * * @hibernate.class table="lams_user_group" */ -public class GroupUser { +public class GroupUser implements Serializable { - private Group group; private User user; - - public GroupUser() {} + public GroupUser() { + } + /** * @hibernate.many-to-one not-null="true" lazy="false" * @hibernate.column name="group_id" * */ public Group getGroup() { - return group; + return group; } public void setGroup(Group group) { - this.group = group; + this.group = group; } /** @@ -58,11 +61,10 @@ * */ public User getUser() { - return user; + return user; } public void setUser(User user) { - this.user = user; + this.user = user; } } - \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/web/session/SessionManager.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/web/session/SessionManager.java,v diff -u -r1.12 -r1.12.8.1 --- lams_common/src/java/org/lamsfoundation/lams/web/session/SessionManager.java 4 Oct 2007 03:19:43 -0000 1.12 +++ lams_common/src/java/org/lamsfoundation/lams/web/session/SessionManager.java 13 May 2009 10:05:22 -0000 1.12.8.1 @@ -23,7 +23,6 @@ /* $$Id$$ */ package org.lamsfoundation.lams.web.session; - import java.util.Enumeration; import java.util.Iterator; import java.util.Map; @@ -39,468 +38,516 @@ import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionContext; -import org.hibernate.id.UUIDHexGenerator; - import org.apache.log4j.Logger; +import org.hibernate.id.UUIDHexGenerator; import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; + /** * * @author Steve.Ni * * @version $Revision$ */ -public class SessionManager{ +public class SessionManager { - private static final Logger log = Logger.getLogger(SessionManager.class); - - //singleton - private static SessionManager sessionMgr; - //KEY: sessionId, each session will have an identified id. VALUE: SessionImpl instance, which contains - //true session key/value pairs. - private Map sessionContainer = new ConcurrentReaderHashMap(); - //Save current session id - private ThreadLocal currentSessionIdContainer = new ThreadLocal(); - - //The system monitoring thread instance - private Monitor monitor; - //The sleep time in seconds period to monitoring the thread. - //This attribute could be set in spring context.xml. - private short monitorPeriod = 20; - + private static final Logger log = Logger.getLogger(SessionManager.class); + + // singleton + private static SessionManager sessionMgr; + // KEY: sessionId, each session will have an identified id. VALUE: SessionImpl instance, which contains + // true session key/value pairs. + private Map sessionContainer = new ConcurrentReaderHashMap(); + // Save current session id + private ThreadLocal currentSessionIdContainer = new ThreadLocal(); + + // The system monitoring thread instance + private Monitor monitor; + // The sleep time in seconds period to monitoring the thread. + // This attribute could be set in spring context.xml. + private short monitorPeriod = 20; + + /** + * Get the singleton instance of this class. + * + * @return + */ + private static SessionManager getInstance() { + if (SessionManager.sessionMgr == null) { + SessionManager.log.error("init SessionManager failed"); + } + + return SessionManager.sessionMgr; + } + + /** + * Get system level HttpSession by current session id. + * + * @return HttpSession instanceof org.lamsfoundation.lams.systemsession.SessionManager#SessionImpl + */ + public static HttpSession getSession() { + String sessionId = (String) getInstance().currentSessionIdContainer.get(); + return getSession(sessionId); + } + + /** + * Get system session by given session id. + * + * @param sessionId + * @return system session. Return an null if the given sessionid can not map to an existed session. + */ + public static HttpSession getSession(String sessionId) { + if (sessionId == null) { + SessionManager.log.debug("Failed on finding current system session with null sessionId"); + return null; + } + return (HttpSession) getInstance().sessionContainer.get(sessionId); + + } + + static void createSession(String sessionId) { + // initialize a new one + HttpSession session = getInstance().new SessionImpl(sessionId); + getInstance().sessionContainer.put(sessionId, session); + } + + /** + * Return SessionVisitor of currentSessionId. An internal method, only + * available in package. + * + * @return + */ + static SessionVisitor getSessionVisitor() { + return (SessionVisitor) getSession(); + } + + /** + * An internal method, only available in package. + * + * @param currentSessionId + */ + static void setCurrentSessionId(String currentSessionId) { + getInstance().currentSessionIdContainer.set(currentSessionId); + } + + /** + * This class initialize method called by Spring framework. + */ + public void init() { + if (SessionManager.sessionMgr == null) { + // only start once + SessionManager.sessionMgr = this; + if (monitorPeriod > 0) { + monitor = new Monitor(); + monitor.start(); + } + } + } + + /** + * This class destroy method called by Spring framework. + */ + public void destroy() { + if (monitor != null) { + SessionManager.sessionMgr = null; + monitor.stop(); + monitor = null; + } + + } + + public short getMonitorPeriod() { + return monitorPeriod; + } + + public void setMonitorPeriod(short monitorPeriod) { + this.monitorPeriod = monitorPeriod; + } + + /** + * Start a session for current ServletRequest and SerlvetResponse. If session does not exist, then create a new + * session. If it exists, just using current session. + * + * + * @param req + * @param res + */ + public static void startSession(ServletRequest req, ServletResponse res) { + Cookie cookie = findCookie((HttpServletRequest) req, SystemSessionFilter.SSO_SESSION_COOKIE); + + String currentSessionId = null; + if (cookie != null) { + currentSessionId = cookie.getValue(); + Object obj = getSession(currentSessionId); + // if cookie exist, but session does not. This usually menas seesion expired. + // then delete the cookie first and set it null in order to create a new one + if (obj == null) { + createSession(currentSessionId); + /* + * After changing cookie name to JSESSIONID, left cookie lifecycle management to Server + * LDEV-2071: SSO session cookie is used to indicate shared session, as there were + * problems with JBoss JSESSIONID cookie management. For each WAR a new cookie was + * created by the server itself. Setting path and domain to "/" in createCookie() did + * not help - the cookie was not found by tool modules and a new was created by the + * server, resulting in a new session. + * + * removeCookie((HttpServletResponse) res,SystemSessionFilter.SYS_SESSION_COOKIE); + * cookie = null; + * + */ + + } + } + // can not be in else! + if (cookie == null) { + // TODO remove this debugging - only put in to diagnose Ozgur's session problem + if (SessionManager.log.isDebugEnabled()) { + SessionManager.log.debug("SessionManager: SSO cookie does not exist, generating a new session"); + } + // create new session and set it into cookie + currentSessionId = (String) new UUIDHexGenerator().generate(null, null); + createSession(currentSessionId); + cookie = createCookie((HttpServletResponse) res, SystemSessionFilter.SSO_SESSION_COOKIE, currentSessionId); + } + + setCurrentSessionId(currentSessionId); + // reset session last access time + SessionVisitor sessionVisitor = getSessionVisitor(); + sessionVisitor.accessed(); + } + + /** + * This method will reset current session id, so programs can not use getSession() to get current + * session after this method is called. + */ + public static void endSession() { + setCurrentSessionId(null); + } + + /** + * Find a cookie by given cookie name from request. + * + * @param req + * @param name + * The cookie name + * @return The cookie of this name in the request, or null if not found. + */ + private static Cookie findCookie(HttpServletRequest req, String name) { + Cookie[] cookies = req.getCookies(); + if (cookies != null) { + for (int i = 0; i < cookies.length; i++) { + if (cookies[i].getName().equals(name)) { + return cookies[i]; + } + } + } + + return null; + } + + /** + * Remove cookie by given name from request + * + * @param res + * @param name + * @return the removed cookies + */ + private static Cookie removeCookie(HttpServletResponse res, String name) { + Cookie cookie = new Cookie(name, ""); + cookie.setPath("/"); + cookie.setMaxAge(0); + res.addCookie(cookie); + + return cookie; + } + + /** + * Create a new cookie for request. + * + * @param res + * @param name + * cookie name + * @param value + * cookie value + * @return the created cookie. + */ + private static Cookie createCookie(HttpServletResponse res, String name, String value) { + Cookie cookie = new Cookie(name, value); + cookie.setPath("/"); + cookie.setMaxAge(-1); + res.addCookie(cookie); + + return cookie; + } + + // ************************************************************************ + // SYSTEM SESSION MONITOR CLASS + // ************************************************************************ + class Monitor implements Runnable { + private static final String THREAD_NAME = "LAMS SYSTEM SESSION MONITOR"; + private Thread monitoringThread; + private boolean stopSign = false; + + public void start() { + monitoringThread = new Thread(this, Monitor.THREAD_NAME); + stopSign = false; + monitoringThread.start(); + } + + public void run() { + while (!stopSign) { + try { + // check whether session is expired + Iterator iter = sessionContainer.values().iterator(); + while (iter.hasNext()) { + SessionImpl session = (SessionImpl) iter.next(); + if (session.getMaxInactiveInterval() > 0) { + if (System.currentTimeMillis() - session.getLastAccessedTime() + - session.getMaxInactiveInterval() * 1000L > 0) { + session.invalidate(); + } + } + } + } catch (Throwable e) { + SessionManager.log.warn("Monitor thread exception: " + e); + } + if (!stopSign) { + try { + Thread.sleep(monitorPeriod * 1000L); + } catch (Exception e) { + // do nothing + } + } + } + } + + public void stop() { + + if (monitoringThread != null) { + stopSign = true; + monitoringThread.interrupt(); + try { + monitoringThread.join(); + } catch (InterruptedException ignore) { + SessionManager.log.error("Exception when interruptting Session Monitoring Thread"); + } + monitoringThread = null; + } + } + } + + // ************************************************************************ + // SYSTEM SESSION IMPLEMENTAION CLASS + // ************************************************************************ + class SessionImpl implements HttpSession, SessionVisitor { + + private String sessionId; + private long createTime; + private long accessTime; + private int timeout; + + private Map valueMap; + + public SessionImpl(String sessionId) { + this.sessionId = sessionId; + createTime = System.currentTimeMillis(); + accessTime = createTime; + timeout = Configuration.getAsInt(ConfigurationKeys.INACTIVE_TIME); + valueMap = new ConcurrentReaderHashMap(); + } + /** - * Get the singleton instance of this class. - * @return + * {@inheritDoc} */ - private static SessionManager getInstance(){ - if(sessionMgr == null) - log.error("init SessionManager failed"); - - return sessionMgr; + public long getCreationTime() { + return createTime; } + /** - * Get system level HttpSession by current session id. - * @return HttpSession instanceof org.lamsfoundation.lams.systemsession.SessionManager#SessionImpl + * {@inheritDoc} */ - public static HttpSession getSession(){ - String sessionId = (String) getInstance().currentSessionIdContainer.get(); - return getSession(sessionId); + public String getId() { + return sessionId; } + /** - * Get system session by given session id. - * @param sessionId - * @return system session. Return an null if the given sessionid can not map to an existed session. + * {@inheritDoc} */ - public static HttpSession getSession(String sessionId){ - if(sessionId == null){ - log.debug("Failed on finding current system session with null sessionId"); - return null; - } - return (HttpSession) getInstance().sessionContainer.get(sessionId); - + public long getLastAccessedTime() { + return accessTime; } - - static void createSession(String sessionId){ - //initialize a new one - HttpSession session = getInstance().new SessionImpl(sessionId); - getInstance().sessionContainer.put(sessionId,session); + + /** + * {@inheritDoc} + */ + public void setMaxInactiveInterval(int timeout) { + this.timeout = timeout; } - + /** - * Return SessionVisitor of currentSessionId. - * An internal method, only available in package. - * @return + * {@inheritDoc} */ - static SessionVisitor getSessionVisitor() { - return (SessionVisitor)getSession(); + public int getMaxInactiveInterval() { + return timeout; } + /** - * An internal method, only available in package. - * @param currentSessionId + * {@inheritDoc} */ - static void setCurrentSessionId(String currentSessionId) { - getInstance().currentSessionIdContainer.set(currentSessionId); + public Object getAttribute(String name) { + return valueMap.get(name); } + /** - * This class initialize method called by Spring framework. + * {@inheritDoc} */ - public void init(){ - if(sessionMgr == null){ - //only start once - sessionMgr = this; - if (monitorPeriod > 0){ - monitor = new Monitor(); - monitor.start(); - } + public Enumeration getAttributeNames() { + + return new Enumeration() { + Iterator iter = valueMap.keySet().iterator(); + + public boolean hasMoreElements() { + return iter.hasNext(); } + + public Object nextElement() { + return iter.next(); + } + + }; } + /** - * This class destroy method called by Spring framework. + * {@inheritDoc} */ - public void destroy(){ - if(monitor != null){ - sessionMgr = null; - monitor.stop(); - monitor = null; - } - + public void setAttribute(String name, Object value) { + if (value == null) { + removeAttribute(name); + } + + Object old = valueMap.put(name, value); + + fireBound(name, value); + + if (old != null) { + fireUnbound(name, old); + } } - - public short getMonitorPeriod() { - return monitorPeriod; + + /** + * {@inheritDoc} + */ + public void removeAttribute(String name) { + Object value = valueMap.remove(name); + if (value != null) { + fireUnbound(name, value); + } } - public void setMonitorPeriod(short monitorPeriod) { - this.monitorPeriod = monitorPeriod; - } /** - * Start a session for current ServletRequest and SerlvetResponse. - * If session does not exist, then create a new session. If it exists, just using current session. - * - * @param req - * @param res + * {@inheritDoc} */ - public static void startSession(ServletRequest req, ServletResponse res) { - Cookie ssoCookie = findCookie((HttpServletRequest) req,SystemSessionFilter.SSO_SESSION_COOKIE); - if(ssoCookie == null){ - log.debug("==>Couldn't find the sso cookie"); - String value = (String) new UUIDHexGenerator().generate(null,null); - ssoCookie = createCookie((HttpServletResponse) res,SystemSessionFilter.SSO_SESSION_COOKIE,value); - log.debug("==>Created one - "+ssoCookie.getValue()); - } - Cookie cookie = findCookie((HttpServletRequest) req,SystemSessionFilter.SYS_SESSION_COOKIE); - String currentSessionId = null; - if(cookie != null){ - currentSessionId = cookie.getValue(); - Object obj = getSession(currentSessionId); - //if cookie exist, but session does not. This usually menas seesion expired. - //then delete the cookie first and set it null in order to create a new one - if(obj == null){ - createSession(currentSessionId); - //After changing cookie name to JSESSIONID, left cookie lifecycle management to Server -// removeCookie((HttpServletResponse) res,SystemSessionFilter.SYS_SESSION_COOKIE); -// cookie = null; - } - } - //can not be in else! - if(cookie == null){ - // TODO remove this debugging - only put in to diagnose Ozgur's session problem - if ( log.isDebugEnabled() ) { - log.debug("SessionManager: cookie is null, generating a new session"); - } - //create new session and set it into cookie - currentSessionId = (String) new UUIDHexGenerator().generate(null,null); - createSession(currentSessionId); - cookie = createCookie((HttpServletResponse) res,SystemSessionFilter.SYS_SESSION_COOKIE,currentSessionId); - } - - setCurrentSessionId(currentSessionId); - //reset session last access time - SessionVisitor sessionVisitor = getSessionVisitor(); - sessionVisitor.accessed(); + public void invalidate() { + + Iterator iter = valueMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry) iter.next(); + fireUnbound((String) entry.getKey(), entry.getValue()); + } + valueMap.clear(); } + /** - * This method will reset current session id, so programs can not use getSession() to get current - * session after this method is called. + * Notice: This method always return false {@inheritDoc} */ - public static void endSession() { - setCurrentSessionId(null); + public boolean isNew() { + return false; } /** - * Find a cookie by given cookie name from request. - * - * @param req - * @param name The cookie name - * @return The cookie of this name in the request, or null if not found. + * {@inheritDoc} */ - private static Cookie findCookie(HttpServletRequest req, String name) - { - Cookie[] cookies = req.getCookies(); - if (cookies != null) { - for (int i = 0; i < cookies.length; i++) { - if (cookies[i].getName().equals(name)) { - return cookies[i]; - } - } - } - - return null; + public void putValue(String name, Object value) { + setAttribute(name, value); } + /** - * Remove cookie by given name from request - * @param res - * @param name - * @return the removed cookies + * {@inheritDoc} */ - private static Cookie removeCookie(HttpServletResponse res, String name){ - Cookie cookie = new Cookie(name, ""); - cookie.setPath("/"); - cookie.setMaxAge(0); - res.addCookie(cookie); - - return cookie; + public void removeValue(String name) { + removeAttribute(name); } + /** - * Create a new cookie for request. - * @param res - * @param name cookie name - * @param value cookie value - * @return the created cookie. + * {@inheritDoc} */ - private static Cookie createCookie(HttpServletResponse res, String name, String value){ - Cookie cookie = new Cookie(name, value); - cookie.setPath("/"); - cookie.setMaxAge(-1); - res.addCookie(cookie); - - return cookie; + public Object getValue(String name) { + return getAttribute(name); } - //************************************************************************ - // SYSTEM SESSION MONITOR CLASS - //************************************************************************ - class Monitor implements Runnable{ - private static final String THREAD_NAME = "LAMS SYSTEM SESSION MONITOR"; - private Thread monitoringThread; - private boolean stopSign = false; - public void start(){ - monitoringThread = new Thread(this,THREAD_NAME); - stopSign = false; - monitoringThread.start(); - } - public void run() { - while (!stopSign) { - try { - //check whether session is expired - Iterator iter = sessionContainer.values().iterator(); - while(iter.hasNext()) { - SessionImpl session = (SessionImpl) iter.next(); - if(session.getMaxInactiveInterval() > 0){ - if ((System.currentTimeMillis() - session.getLastAccessedTime() - - session.getMaxInactiveInterval() * 1000L) > 0) - session.invalidate(); - } - } - } catch (Throwable e) { - log.warn("Monitor thread exception: " + e); - } - if (!stopSign) { - try { - Thread.sleep(monitorPeriod * 1000L); - } catch (Exception e) { - // do nothing - } - } - } - } - - public void stop(){ - - if (monitoringThread != null){ - stopSign = true; - monitoringThread.interrupt(); - try{ - monitoringThread.join(); - }catch (InterruptedException ignore){ - log.error("Exception when interruptting Session Monitoring Thread"); - } - monitoringThread = null; - } - } + /** + * {@inheritDoc} + */ + public String[] getValueNames() { + return (String[]) valueMap.keySet().toArray(new String[valueMap.size()]); } - //************************************************************************ - // SYSTEM SESSION IMPLEMENTAION CLASS - //************************************************************************ - class SessionImpl implements HttpSession,SessionVisitor { - private String sessionId; - private long createTime; - private long accessTime; - private int timeout; - - private Map valueMap; - - public SessionImpl(String sessionId){ - this.sessionId = sessionId; - createTime = System.currentTimeMillis(); - accessTime = createTime; - timeout = Configuration.getAsInt(ConfigurationKeys.INACTIVE_TIME); - valueMap = new ConcurrentReaderHashMap(); - } - /** - * {@inheritDoc} - */ - public long getCreationTime() { - return createTime; - } - /** - * {@inheritDoc} - */ - public String getId() { - return sessionId; - } - /** - * {@inheritDoc} - */ - public long getLastAccessedTime() { - return accessTime; - } - /** - * {@inheritDoc} - */ - public void setMaxInactiveInterval(int timeout) { - this.timeout = timeout; - } - /** - * {@inheritDoc} - */ - public int getMaxInactiveInterval() { - return timeout; - } + /** + * {@inheritDoc} + */ + public HttpSessionContext getSessionContext() { + return new HttpSessionContext() { - /** - * {@inheritDoc} - */ - public Object getAttribute(String name) { - return valueMap.get(name); + public HttpSession getSession(String sessionId) { + return SessionImpl.this; } - /** - * {@inheritDoc} - */ - public Enumeration getAttributeNames() { - - return new Enumeration(){ - Iterator iter = valueMap.keySet().iterator(); - public boolean hasMoreElements() { - return iter.hasNext(); - } - public Object nextElement() { - return iter.next(); - } - - }; - } - /** - * {@inheritDoc} - */ - public void setAttribute(String name, Object value) { - if(value == null) - removeAttribute(name); - - Object old = valueMap.put(name, value); + public Enumeration getIds() { + return new Enumeration() { + public boolean hasMoreElements() { + return false; + } - fireBound(name, value); - - if (old != null){ - fireUnbound(name, old); + public Object nextElement() { + return null; } + }; } - /** - * {@inheritDoc} - */ - public void removeAttribute(String name) { - Object value = valueMap.remove(name); - if(value != null) - fireUnbound(name, value); - } - /** - * {@inheritDoc} - */ - public void invalidate() { - - Iterator iter = valueMap.entrySet().iterator(); - while(iter.hasNext()){ - Map.Entry entry = (Map.Entry) iter.next(); - fireUnbound((String) entry.getKey(),entry.getValue()); - } - valueMap.clear(); - } - /** - * Notice: This method always return false - * {@inheritDoc} - */ - public boolean isNew() { - return false; - } - - /** - * {@inheritDoc} - */ - public void putValue(String name, Object value) { - setAttribute(name,value); - } - /** - * {@inheritDoc} - */ - public void removeValue(String name) { - removeAttribute(name); - } - /** - * {@inheritDoc} - */ - public Object getValue(String name) { - return getAttribute(name); - } - /** - * {@inheritDoc} - */ - public String[] getValueNames() { - return (String[])valueMap.keySet().toArray(new String[valueMap.size()]); - } - /** - * {@inheritDoc} - */ - public HttpSessionContext getSessionContext() { - return new HttpSessionContext(){ - public HttpSession getSession(String sessionId) { - return SessionImpl.this; - } + }; + } - public Enumeration getIds() { - return new Enumeration(){ - public boolean hasMoreElements() { - return false; - } - public Object nextElement() { - return null; - } - }; - } - - }; - } - /** - * Notice: This method always return null. - * {@inheritDoc} - */ - public ServletContext getServletContext() { - return null; - } - //********************************************************** - // SessionVisitor method - public void accessed() { - accessTime = System.currentTimeMillis(); - } - //********************************************************** - // private method - private void fireUnbound(String name, Object value) { - if(value instanceof HttpSessionBindingListener){ - HttpSessionBindingEvent event = new HttpSessionBindingEvent(this,name,value); - ((HttpSessionBindingListener)value).valueUnbound(event); - } - } - private void fireBound(String name, Object value) { - if(value instanceof HttpSessionBindingListener){ - HttpSessionBindingEvent event = new HttpSessionBindingEvent(this,name,value); - ((HttpSessionBindingListener)value).valueBound(event); - } - } + /** + * Notice: This method always return null. {@inheritDoc} + */ + public ServletContext getServletContext() { + return null; + } + // ********************************************************** + // SessionVisitor method + public void accessed() { + accessTime = System.currentTimeMillis(); } + // ********************************************************** + // private method + private void fireUnbound(String name, Object value) { + if (value instanceof HttpSessionBindingListener) { + HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, name, value); + ((HttpSessionBindingListener) value).valueUnbound(event); + } + } + + private void fireBound(String name, Object value) { + if (value instanceof HttpSessionBindingListener) { + HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, name, value); + ((HttpSessionBindingListener) value).valueBound(event); + } + } + + } + } Index: lams_common/src/java/org/lamsfoundation/lams/web/session/SystemSessionFilter.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/web/session/SystemSessionFilter.java,v diff -u -r1.11 -r1.11.18.1 --- lams_common/src/java/org/lamsfoundation/lams/web/session/SystemSessionFilter.java 11 Oct 2006 05:05:12 -0000 1.11 +++ lams_common/src/java/org/lamsfoundation/lams/web/session/SystemSessionFilter.java 13 May 2009 10:05:21 -0000 1.11.18.1 @@ -34,47 +34,50 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - /** * - * @author Steve.Ni - * Create and manage system wide (across multiple webapps in JBOSS) session. - * - *

- * NOTICE: This filter must set before org.lamsfoundation.lams.web.filter.LocaleFilter - * in web.xml because LocaleFilter need get value from SystemSession . - * + * @author Steve.Ni Create and manage system wide (across multiple webapps in JBOSS) session. + * + *

+ * NOTICE: This filter must set before org.lamsfoundation.lams.web.filter.LocaleFilter in web.xml + * because LocaleFilter need get value from SystemSession . + * * @version $Revision$ */ public class SystemSessionFilter implements Filter { - - //The session name to trace shared session - public static final String SYS_SESSION_COOKIE = "JSESSIONID"; - - public static final String SSO_SESSION_COOKIE = "JSESSIONIDSSO"; - public void init(FilterConfig config) throws ServletException { - } + /* + * The session name to trace shared session LDEV-2071: Removed because JBoss 5 uses this cookie differently. It is + * not shared among LAMS WARs like JSESSIONIDSSO. Setting path and domain parameters to root "/" does not help. + * JSESSIONIDSSO is used instead, as it is the same for all WARs and makes a good shared session indicator. public + * + * static final String SYS_SESSION_COOKIE = "JSESSIONID"; + */ - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) - throws IOException, ServletException { + public static final String SSO_SESSION_COOKIE = "JSESSIONIDSSO"; - // Skip non-http request/response - if (!((req instanceof HttpServletRequest) && (res instanceof HttpServletResponse))){ - chain.doFilter(req, res); - return; - } - - SessionManager.startSession(req, res); - - //do following part of chain - chain.doFilter(req,res); - - SessionManager.endSession(); - - } + public void init(FilterConfig config) throws ServletException { + } - public void destroy() { - //do nothing + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, + ServletException { + + // Skip non-http request/response + if (!(req instanceof HttpServletRequest && res instanceof HttpServletResponse)) { + chain.doFilter(req, res); + return; } + + SessionManager.startSession(req, res); + + // do following part of chain + chain.doFilter(req, res); + + SessionManager.endSession(); + + } + + public void destroy() { + // do nothing + } } Index: lams_contentrepository/.classpath =================================================================== RCS file: /usr/local/cvsroot/lams_contentrepository/.classpath,v diff -u -r1.15 -r1.15.8.1 --- lams_contentrepository/.classpath 30 Oct 2008 03:48:30 -0000 1.15 +++ lams_contentrepository/.classpath 13 May 2009 10:01:37 -0000 1.15.8.1 @@ -5,9 +5,12 @@ - - - + + + + + + - + Index: lams_contentrepository/conf/xdoclet/web-settings.xml =================================================================== RCS file: /usr/local/cvsroot/lams_contentrepository/conf/xdoclet/web-settings.xml,v diff -u -r1.2 -r1.2.4.1 --- lams_contentrepository/conf/xdoclet/web-settings.xml 26 Mar 2009 10:00:35 -0000 1.2 +++ lams_contentrepository/conf/xdoclet/web-settings.xml 13 May 2009 10:01:37 -0000 1.2.4.1 @@ -1,10 +1,14 @@ + + contextClass + org.jboss.spring.factory.VFSXmlWebApplicationContext + contextConfigLocation locatorFactorySelector - classpath*:/org/lamsfoundation/lams/**/beanRefContext.xml + classpath:/org/lamsfoundation/lams/beanRefContext.xml parentContextKey Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/CredentialDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/CredentialDAO.java,v diff -u -r1.6 -r1.6.10.1 --- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/CredentialDAO.java 17 Sep 2006 06:16:10 -0000 1.6 +++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/CredentialDAO.java 13 May 2009 10:01:37 -0000 1.6.10.1 @@ -21,7 +21,7 @@ * **************************************************************** */ -/* $$Id$$ */ +/* $$Id$$ */ package org.lamsfoundation.lams.contentrepository.dao.hibernate; import java.sql.Connection; @@ -40,135 +40,131 @@ import org.lamsfoundation.lams.contentrepository.dao.ICredentialDAO; import org.lamsfoundation.lams.dao.hibernate.BaseDAO; - /** - * + * * Implements the credentials lookup using Hibernate. * * @author Fiona Malikoff - * + * */ public class CredentialDAO extends BaseDAO implements ICredentialDAO { - - protected Logger log = Logger.getLogger(CredentialDAO.class); - /** - * Checks whether a user can login to this workspace. The - * Credential must include the password. - */ - public boolean checkCredential(ICredentials credential, IWorkspace workspace) - throws RepositoryRuntimeException { - if ( log.isDebugEnabled() ) - log.debug("Checking credential "+credential+" for workspace "+workspace); + protected Logger log = Logger.getLogger(CredentialDAO.class); - if ( credential == null || workspace == null || workspace.getWorkspaceId() == null ) - return false; - - return checkCredentialInternal(credential, workspace); + /** + * Checks whether a user can login to this workspace. The Credential must include the password. + */ + public boolean checkCredential(ICredentials credential, IWorkspace workspace) throws RepositoryRuntimeException { + if (log.isDebugEnabled()) { + log.debug("Checking credential " + credential + " for workspace " + workspace); } - /** - * Checks whether a user can login to the repository. The - * Credential must include the password. - */ - public boolean checkCredential(ICredentials credential) - throws RepositoryRuntimeException { - if ( log.isDebugEnabled() ) - log.debug("Checking credential "+credential); + if (credential == null || workspace == null || workspace.getWorkspaceId() == null) { + return false; + } - if ( credential == null ) - return false; - - return checkCredentialInternal(credential, null); + return checkCredentialInternal(credential, workspace); + } + + /** + * Checks whether a user can login to the repository. The Credential must include the password. + */ + public boolean checkCredential(ICredentials credential) throws RepositoryRuntimeException { + if (log.isDebugEnabled()) { + log.debug("Checking credential " + credential); } - - /** - * Checks whether a user can login to the repository. The - * Credential must include the password. - * - * If workspace defined then checks workspace, otherwise just checks password - */ - public boolean checkCredentialInternal(ICredentials credential, IWorkspace workspace) - throws RepositoryRuntimeException { - // given the input credential, is there a credential matching - // in the database? why go to so much trouble in this code? I'm trying - // to avoid converting the char[] to a string. - // There will be better ways to do this, but this will do for starters - // until I get more familiar with Spring. - - boolean credentialMatched = false; - - Session hibernateSession = getSession(); - Connection conn = null; - PreparedStatement ps = null; - try { - conn = hibernateSession.connection(); - - StringBuffer buf = new StringBuffer(200); - buf.append("select count(*) num from lams_cr_credential c"); - if ( workspace != null ) { - buf.append(", lams_cr_workspace_credential wc "); - } - buf.append(" where c.name = \""); - buf.append(credential.getName()); - buf.append("\" and c.password = \""); - buf.append(credential.getPassword()); - buf.append("\""); - if ( workspace != null ) { - buf.append(" and wc.credential_id = c.credential_id "); - buf.append(" and wc.workspace_id = "); - buf.append(workspace.getWorkspaceId()); - } - - ps = conn.prepareStatement(buf.toString()); - ps.execute(); - ResultSet rs = ps.getResultSet(); - if ( rs.next() ) { - int val = rs.getInt("num"); - if ( val > 0 ) { - credentialMatched = true; - if ( val > 1 ) { - log.warn("More than one credential found for workspace " - +workspace.getWorkspaceId() - +" credential name " - +credential.getName()); - } - } - } - - } catch (HibernateException e) { - log.error("Hibernate exception occured during login. ",e); - throw new RepositoryRuntimeException("Unable to login due to internal error.", e); - } catch (SQLException se) { - log.error("SQL exception occured during login. ",se); - throw new RepositoryRuntimeException("Unable to login due to internal error.", se); - } finally { - if ( ps != null ) { - try { - ps.close(); - } catch (SQLException se2) { - log.error("SQL exception occured during login, while closing statement. ",se2); - throw new RepositoryRuntimeException("Unable to login due to internal error.", se2); - } - } + if (credential == null) { + return false; + } + + return checkCredentialInternal(credential, null); + } + + /** + * Checks whether a user can login to the repository. The Credential must include the password. + * + * If workspace defined then checks workspace, otherwise just checks password + */ + public boolean checkCredentialInternal(ICredentials credential, IWorkspace workspace) + throws RepositoryRuntimeException { + + // given the input credential, is there a credential matching + // in the database? why go to so much trouble in this code? I'm trying + // to avoid converting the char[] to a string. + // There will be better ways to do this, but this will do for starters + // until I get more familiar with Spring. + + boolean credentialMatched = false; + + Session hibernateSession = getSession(); + Connection conn = null; + PreparedStatement ps = null; + try { + conn = hibernateSession.connection(); + + StringBuffer buf = new StringBuffer(200); + buf.append("select count(*) num from lams_cr_credential c"); + if (workspace != null) { + buf.append(", lams_cr_workspace_credential wc "); + } + buf.append(" where c.name = \""); + buf.append(credential.getName()); + buf.append("\" and c.password = \""); + buf.append(credential.getPassword()); + buf.append("\""); + if (workspace != null) { + buf.append(" and wc.credential_id = c.credential_id "); + buf.append(" and wc.workspace_id = "); + buf.append(workspace.getWorkspaceId()); + } + + ps = conn.prepareStatement(buf.toString()); + ps.execute(); + ResultSet rs = ps.getResultSet(); + if (rs.next()) { + long val = rs.getLong("num"); + if (val > 0) { + credentialMatched = true; + if (val > 1) { + log.warn("More than one credential found for workspace " + workspace.getWorkspaceId() + + " credential name " + credential.getName()); + } } + } - return credentialMatched; + } catch (HibernateException e) { + log.error("Hibernate exception occured during login. ", e); + throw new RepositoryRuntimeException("Unable to login due to internal error.", e); + } catch (SQLException se) { + log.error("SQL exception occured during login. ", se); + throw new RepositoryRuntimeException("Unable to login due to internal error.", se); + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException se2) { + log.error("SQL exception occured during login, while closing statement. ", se2); + throw new RepositoryRuntimeException("Unable to login due to internal error.", se2); + } + } } - public CrCredential findByName(String name) { + return credentialMatched; + } - log.debug("Getting credential for name "+name); - - String queryString = "from CrCredential as c where c.name = ?"; - List credentials = getHibernateTemplate().find(queryString,name); - - if(credentials.size() == 0){ - log.debug("No credentials found"); - return null; - }else{ - return (CrCredential)credentials.get(0); - } + public CrCredential findByName(String name) { + + log.debug("Getting credential for name " + name); + + String queryString = "from CrCredential as c where c.name = ?"; + List credentials = getHibernateTemplate().find(queryString, name); + + if (credentials.size() == 0) { + log.debug("No credentials found"); + return null; + } else { + return (CrCredential) credentials.get(0); } + } }