From: idfx Date: Sun, 7 Sep 2003 16:55:00 +0000 (+0000) Subject: next steps in itegrating struts and hibernate. login and logout ist now possible... X-Git-Tag: BEFORE_MERGE_1_1~63 X-Git-Url: http://erislabs.net/gitweb/?p=mir.git;a=commitdiff_plain;h=e39d9dd259ebe069d3aaa71b0661d290fd218ecb next steps in itegrating struts and hibernate. login and logout ist now possible. first steps to convert the message administration. access to the admin by server/mir/admin/index.do . --- diff --git a/etc/struts-config-admin.xml b/etc/struts-config-admin.xml new file mode 100755 index 00000000..426513e3 --- /dev/null +++ b/etc/struts-config-admin.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etc/struts-config.xml b/etc/struts-config.xml deleted file mode 100755 index 4b946194..00000000 --- a/etc/struts-config.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/etc/web.xml b/etc/web.xml index db47a25b..b028d4ff 100755 --- a/etc/web.xml +++ b/etc/web.xml @@ -1,84 +1,75 @@ + Mir CMS + + Mir + Mir + + Config + etc/config.properties + + + + OpenMir + OpenMir + + Config + etc/config.properties + + + presentation + Presentation mir.core.ui.servlet.TemplateServlet - - presentation - *.shtml - - + action + Action org.apache.struts.action.ActionServlet - config - /WEB-INF/etc/struts-config.xml + config + /WEB-INF/etc/struts-config.xml - 1 - - - - - Mir - - - Mir - - - Config - etc/config.properties + config/admin + /WEB-INF/etc/struts-config-admin.xml - - - - - - OpenMir - - - OpenMir - - - Config - etc/config.properties + debug + 3 - - - - - - Mir - - - /Mir - - + + detail + 3 + + 1 + + + + presentation + *.shtml + + + + action + *.do + - - Mir - - - /servlet/Mir - + Mir + /servlet/Mir OpenMir - /OpenMir - - - OpenMir /servlet/OpenMir @@ -86,11 +77,21 @@ authentication mir.core.ui.filter.AuthenticationFilter - - + + authentication presentation + + + authentication + action + + + + index.shtml + + mp3 diff --git a/source/mir/core/model/IMedia.java b/source/mir/core/model/IMedia.java index eeb6ff1f..6865d1ed 100755 --- a/source/mir/core/model/IMedia.java +++ b/source/mir/core/model/IMedia.java @@ -31,13 +31,12 @@ */ package mir.core.model; -import java.util.Date; import java.util.Set; /** * IMedia * @author idefix - * @version $Id: IMedia.java,v 1.2 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: IMedia.java,v 1.3 2003/09/07 16:55:00 idfx Exp $ */ public interface IMedia { public abstract java.lang.Integer getId(); diff --git a/source/mir/core/service/storage/CommentService.java b/source/mir/core/service/storage/CommentService.java index 780bc06c..2075efd7 100755 --- a/source/mir/core/service/storage/CommentService.java +++ b/source/mir/core/service/storage/CommentService.java @@ -32,14 +32,13 @@ package mir.core.service.storage; import mir.core.model.Comment; -import net.sf.hibernate.Hibernate; import net.sf.hibernate.HibernateException; import net.sf.hibernate.SessionFactory; /** * CommentService * @author idefix - * @version $Id: CommentService.java,v 1.2 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: CommentService.java,v 1.3 2003/09/07 16:55:00 idfx Exp $ */ public class CommentService extends StorageService { diff --git a/source/mir/core/service/storage/StorageService.java b/source/mir/core/service/storage/StorageService.java index 6a21d947..e8ced3cc 100755 --- a/source/mir/core/service/storage/StorageService.java +++ b/source/mir/core/service/storage/StorageService.java @@ -34,9 +34,9 @@ package mir.core.service.storage; import java.util.List; -import mir.core.model.IImage; +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; import net.sf.hibernate.Criteria; -import net.sf.hibernate.Hibernate; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; @@ -47,21 +47,36 @@ import net.sf.hibernate.expression.Expression; * * StorageService * @author idefix - * @version $Id: StorageService.java,v 1.3 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: StorageService.java,v 1.4 2003/09/07 16:55:00 idfx Exp $ */ public abstract class StorageService { private Class objectClass; private SessionHolder sessionHolder; + protected MirPropertiesConfiguration _configuration; public StorageService(Class objectClass, SessionFactory factory){ this.objectClass = objectClass; sessionHolder = new SessionHolder(factory); + try { + _configuration = MirPropertiesConfiguration.instance(); + } catch (PropertiesConfigExc e) { + throw new multex.Failure("could not get the config", e); + } } public List list(int offset, int limit){ return list(offset, limit, null); } + public List list(int offset){ + int limit = _configuration.getInt("ServletModule.Default.ListSize"); + return list(offset, limit, null); + } + + public List list(int offset, Expression expression){ + int limit = _configuration.getInt("ServletModule.Default.ListSize"); + return list(offset, limit, expression); + } public List list(int offset, int limit, Expression expression){ try { Session session = sessionHolder.currentSession(); diff --git a/source/mir/core/service/storage/UserService.java b/source/mir/core/service/storage/UserService.java index 51f43869..f1c92233 100755 --- a/source/mir/core/service/storage/UserService.java +++ b/source/mir/core/service/storage/UserService.java @@ -42,7 +42,7 @@ import net.sf.hibernate.expression.Expression; /** * UserService * @author idefix - * @version $Id: UserService.java,v 1.2 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: UserService.java,v 1.3 2003/09/07 16:55:00 idfx Exp $ */ public class UserService extends StorageService { @@ -64,6 +64,9 @@ public class UserService extends StorageService { Expression.eq("isAdmin", new Boolean(true)) ) ); + if(list.size() == 0){ + return null; + } return (MirUser)list.get(0); } @@ -73,5 +76,4 @@ public class UserService extends StorageService { protected void initializeLazyCollections(Object returnObject) throws HibernateException { //do nothing } - } diff --git a/source/mir/core/test/Test.java b/source/mir/core/test/Test.java index f94670d1..33cccc11 100755 --- a/source/mir/core/test/Test.java +++ b/source/mir/core/test/Test.java @@ -34,13 +34,9 @@ package mir.core.test; import java.util.Iterator; import java.util.List; -import org.apache.log4j.BasicConfigurator; - import mir.core.model.Audio; import mir.core.model.Content; -import mir.core.model.IContent; import mir.core.model.IImage; -import mir.core.model.Image; import mir.core.model.Media; import mir.core.model.Topic; import mir.core.model.UploadedMedia; @@ -56,7 +52,7 @@ import net.sf.hibernate.cfg.Configuration; /** * Test - * @version $Id: Test.java,v 1.6 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: Test.java,v 1.7 2003/09/07 16:55:00 idfx Exp $ * @author idefix */ public class Test { diff --git a/source/mir/core/ui/action/AuthenticationAction.java b/source/mir/core/ui/action/AuthenticationAction.java deleted file mode 100755 index 7a1bb2fd..00000000 --- a/source/mir/core/ui/action/AuthenticationAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * AuthenticationAction.java created on 05.09.2003 - * - * Copyright (C) 2001, 2002, 2003 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir 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 Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ -package mir.core.ui.action; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.struts.action.Action; -import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionForward; -import org.apache.struts.action.ActionMapping; - -/** - * AuthenticationAction - * @author idefix - * @version $Id: AuthenticationAction.java,v 1.1 2003/09/05 20:23:59 idfx Exp $ - */ -public class AuthenticationAction extends Action { - - - /** - * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) - */ - public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, - HttpServletRequest request, HttpServletResponse response) - throws Exception { - // TODO Auto-generated method stub - return actionMapping.findForward("success"); - } - -} diff --git a/source/mir/core/ui/action/admin/AuthenticationAction.java b/source/mir/core/ui/action/admin/AuthenticationAction.java new file mode 100755 index 00000000..55f60226 --- /dev/null +++ b/source/mir/core/ui/action/admin/AuthenticationAction.java @@ -0,0 +1,216 @@ +/* + * AuthenticationAction.java created on 05.09.2003 + * + * Copyright (C) 2001, 2002, 2003 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir 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 Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mir.core.ui.action.admin; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.core.model.MirUser; +import mir.core.service.storage.UserService; +import mir.core.ui.servlet.ServletConstants; +import mir.util.StringRoutines; +import mircoders.global.MirGlobal; +import multex.Failure; +import net.sf.hibernate.SessionFactory; + +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.DynaActionForm; +import org.apache.struts.action.RedirectingActionForward; +import org.apache.struts.util.MessageResources; + +/** + * AuthenticationAction + * @author idefix + * @version $Id: AuthenticationAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $ + */ +public class AuthenticationAction extends Action { + private MirPropertiesConfiguration _configuration; + + public AuthenticationAction(){ + try { + _configuration = MirPropertiesConfiguration.instance(); + } catch (PropertiesConfigExc e) { + throw new Failure("could not load config", e); + } + } + + /** + * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + + String param = actionMapping.getParameter(); + if(param.equals("logon")){ + return logon(actionMapping, actionForm, request, response); + } + if(param.equals("logoff")){ + return logoff(actionMapping, actionForm, request, response); + } + return null; + } + + private ActionForward logon(ActionMapping actionMapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + + //retrieve the form input data + DynaActionForm form = (DynaActionForm)actionForm; + String login = (String) form.get("login"); + String password = (String) form.get("password"); + + if((login == null || login.trim().length() == 0) + && (password == null || password.trim().length() == 0)){ + //no input --> error + return actionMapping.findForward("failed"); + } + + //access to persitence layer + ServletContext context = this.getServlet().getServletContext(); + UserService userService = + new UserService((SessionFactory)context + .getAttribute(ServletConstants.SESSION_FACTORY)); + setLoginLanguages(context); + + //try to retrieve user for the given values + MirUser mirUser = userService.loadUser(login, password); + if(mirUser == null){ + //not existent user --> error + return actionMapping.findForward("failed"); + } + + //add user to the session context + HttpSession session = request.getSession(); + session.setAttribute(ServletConstants.USER, mirUser); + + //check if we have to redirect the user + String requestUri = + (String) session.getAttribute(ServletConstants.REDIRECT_ACTION); + + if(requestUri != null && requestUri.indexOf("index") == -1 + && requestUri.indexOf("logon") == -1){ + + // we have to redirect the user + requestUri = requestUri.substring(requestUri.lastIndexOf("/")); + + //retrieve the correct action name + String queryString = + (String) session.getAttribute(ServletConstants.REDIRECT_QUERY_STRING); + if(queryString != null){ + requestUri = requestUri + "?" +queryString; + } + + //construct a redirect + RedirectingActionForward actionForward = + new RedirectingActionForward(requestUri); + + //return the redirect + return actionForward; + } + + //normal redirect to the startpage + return actionMapping.findForward("success"); + } + + private ActionForward logoff(ActionMapping actionMapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + + //kill session + HttpSession session = request.getSession(); + session.setAttribute(ServletConstants.USER, null); + session.invalidate(); + + //return to the logon form + return actionMapping.findForward("index"); + } + + private void setLoginLanguages(ServletContext context) throws ServletException { + List loginLanguages = + (List) context.getAttribute(ServletConstants.LOGIN_LANGUAGES); + try { + if (loginLanguages == null) { + MessageResources messageResources = + MessageResources.getMessageResources("bundles.adminlocal"); + MessageResources messageResources2 = + MessageResources.getMessageResources("bundles.admin"); + + List languages = + StringRoutines.splitString( + MirGlobal.config().getString("Mir.Login.Languages", "en"), ";"); + + loginLanguages = new ArrayList(); + Iterator i = languages.iterator(); + while (i.hasNext()) { + String code = (String) i.next(); + Locale locale = new Locale(code, ""); + String name = messageResources.getMessage(locale, "languagename"); + + if (name == null) { + name = messageResources2.getMessage(locale, "languagename"); + } + + if (name == null) { + name = code; + } + + Map record = new HashMap(); + record.put("name", name); + record.put("code", code); + loginLanguages.add(record); + } + context.setAttribute(ServletConstants.LOGIN_LANGUAGES, + loginLanguages); + context.setAttribute(ServletConstants.DEFAULT_LANGUAGE, + _configuration.getString("Mir.Login.DefaultLanguage")); + } + } catch (Throwable t) { + throw new ServletException(t.getMessage()); + } + } +} diff --git a/source/mir/core/ui/action/admin/MessageAction.java b/source/mir/core/ui/action/admin/MessageAction.java new file mode 100755 index 00000000..4c9f2ec7 --- /dev/null +++ b/source/mir/core/ui/action/admin/MessageAction.java @@ -0,0 +1,121 @@ +/* + * AuthenticationAction.java created on 05.09.2003 + * + * Copyright (C) 2001, 2002, 2003 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir 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 Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mir.core.ui.action.admin; + +import java.util.List; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.core.service.storage.MessageService; +import mir.core.ui.servlet.ServletConstants; + +import multex.Failure; + +import net.sf.hibernate.SessionFactory; + +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +/** + * AuthenticationAction + * @author idefix + * @version $Id: MessageAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $ + */ +public class MessageAction extends Action { + private MirPropertiesConfiguration _configuration; + + public MessageAction(){ + try { + _configuration = MirPropertiesConfiguration.instance(); + } catch (PropertiesConfigExc e) { + throw new Failure("could not load config", e); + } + } + + /** + * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + + String param = actionMapping.getParameter(); + if(param.equals("list")){ + return list(actionMapping, actionForm, request, response); + } + return null; + } + + private ActionForward list(ActionMapping actionMapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + //retrieve parameters + String offsetString = request.getParameter(ServletConstants.OFFSET); + int offset = 0; + if(offsetString != null){ + offset = new Integer(offsetString).intValue(); + } + + //access to persistence + ServletContext context = getServlet().getServletContext(); + MessageService messageService = + new MessageService((SessionFactory)context + .getAttribute(ServletConstants.SESSION_FACTORY)); + + //retrieve entities + List messages = messageService.list(offset); + + //configure the data to send to view + int listSize = _configuration.getInt("ServletModule.Default.ListSize"); + Integer lastOffset; + if(offset-listSize < 0){ + lastOffset = new Integer(0); + } else { + lastOffset = new Integer(offset-listSize); + } + request.setAttribute(ServletConstants.LAST_OFFSET, lastOffset); + request.setAttribute(ServletConstants.NEXT_OFFSET, + new Integer(offset + listSize)); + request.setAttribute(ServletConstants.OFFSET, + new Integer(offset)); + request.setAttribute("messages", messages); + + //show the view + return actionMapping.findForward("success"); + } +} diff --git a/source/mir/core/ui/action/admin/StartpageAction.java b/source/mir/core/ui/action/admin/StartpageAction.java new file mode 100755 index 00000000..d4f59ac0 --- /dev/null +++ b/source/mir/core/ui/action/admin/StartpageAction.java @@ -0,0 +1,83 @@ +/* + * AuthenticationAction.java created on 05.09.2003 + * + * Copyright (C) 2001, 2002, 2003 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir 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 Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mir.core.ui.action.admin; + +import java.util.List; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import mir.core.service.storage.MessageService; +import mir.core.ui.servlet.ServletConstants; +import net.sf.hibernate.SessionFactory; + +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +/** + * AuthenticationAction + * @author idefix + * @version $Id: StartpageAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $ + */ +public class StartpageAction extends Action { + + /** + * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + + String param = actionMapping.getParameter(); + if(param.equals("index")){ + return index(actionMapping, actionForm, request, response); + } + return null; + } + + private ActionForward index(ActionMapping actionMapping, ActionForm actionForm, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + + ServletContext context = this.getServlet().getServletContext(); + MessageService messageService = + new MessageService((SessionFactory)context + .getAttribute(ServletConstants.SESSION_FACTORY)); + List messages = messageService.list(0); + + request.setAttribute("messages", messages); + return actionMapping.findForward("success"); + } +} diff --git a/source/mir/core/ui/filter/AuthenticationFilter.java b/source/mir/core/ui/filter/AuthenticationFilter.java index f83eea5e..7102f105 100755 --- a/source/mir/core/ui/filter/AuthenticationFilter.java +++ b/source/mir/core/ui/filter/AuthenticationFilter.java @@ -48,10 +48,11 @@ import mir.core.ui.servlet.*; /** * AuthenticationFilter * @author idefix - * @version $Id: AuthenticationFilter.java,v 1.1 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: AuthenticationFilter.java,v 1.2 2003/09/07 16:55:00 idfx Exp $ */ public class AuthenticationFilter implements Filter { private FilterConfig _filterConfig; + /** * */ @@ -62,27 +63,42 @@ public class AuthenticationFilter implements Filter { /** * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */ - public void init(final FilterConfig filterConfig) throws ServletException { + public void init(final FilterConfig filterConfig) + throws ServletException { _filterConfig = filterConfig; } /** * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */ - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) + public void doFilter(ServletRequest servletRequest, + ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + HttpServletRequest request = (HttpServletRequest)servletRequest; String requestUri = request.getRequestURI(); - System.out.println(requestUri); - System.out.println(request.getContextPath()); - if(requestUri != null && requestUri.startsWith(request.getContextPath() + "/admin")){ + + if(requestUri != null + && requestUri.startsWith(request.getContextPath() + "/admin") + && requestUri.indexOf("logon") == -1){ //check if authenticated, only if in admin-module HttpSession httpSession = request.getSession(); - MirUser mirUser = (MirUser)httpSession.getAttribute(ServletConstants.USER); + MirUser mirUser = + (MirUser)httpSession.getAttribute(ServletConstants.USER); + if(mirUser == null){ - servletRequest.getRequestDispatcher("/admin/login.shtml").forward(servletRequest, servletResponse); - } - } + //user is not authorized to access + //set redirect attributes that the user comes to place he wants to be + httpSession.setAttribute(ServletConstants.REDIRECT_ACTION, requestUri); + httpSession.setAttribute(ServletConstants.REDIRECT_QUERY_STRING, + request.getQueryString()); + + //send user to logon-page + servletRequest.getRequestDispatcher("/admin/logon.do") + .forward(servletRequest, servletResponse); + } + } + filterChain.doFilter(servletRequest, servletResponse); } @@ -90,6 +106,7 @@ public class AuthenticationFilter implements Filter { * @see javax.servlet.Filter#destroy() */ public void destroy() { + _filterConfig = null; } } diff --git a/source/mir/core/ui/plugin/ConfigurationPlugin.java b/source/mir/core/ui/plugin/ConfigurationPlugin.java new file mode 100755 index 00000000..4acf3683 --- /dev/null +++ b/source/mir/core/ui/plugin/ConfigurationPlugin.java @@ -0,0 +1,77 @@ +/* + * ConfigurationPlugin.java + * + * Copyright (C) 2001, 2002, 2003 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir 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 Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mir.core.ui.plugin; + +import javax.servlet.ServletException; + +import mir.config.MirPropertiesConfiguration; +import mircoders.global.MirGlobal; + +import org.apache.struts.action.ActionServlet; +import org.apache.struts.action.PlugIn; +import org.apache.struts.config.ModuleConfig; + +/** + * ConfigurationPlugin + * @version $Id: ConfigurationPlugin.java,v 1.1 2003/09/07 16:55:00 idfx Exp $ + * @author idefix + */ +public class ConfigurationPlugin implements PlugIn { + + /** + * @see org.apache.struts.action.PlugIn#destroy() + */ + public void destroy() { + } + + /** + * @see org.apache.struts.action.PlugIn#init(org.apache.struts.action.ActionServlet, org.apache.struts.config.ModuleConfig) + */ + public void init(ActionServlet actionServlet, ModuleConfig config) + throws ServletException { + MirPropertiesConfiguration.setContext(actionServlet.getServletContext()); + try { + MirPropertiesConfiguration.instance(); + } + catch (Throwable t) { + throw new ServletException("can't read configuration: " + t.toString()); + } + + try { + MirGlobal.localizer(); + } + catch (Throwable t) { + throw new ServletException("can't get localizer: " + t.toString()); + } + } + +} diff --git a/source/mir/core/ui/servlet/ServletConstants.java b/source/mir/core/ui/servlet/ServletConstants.java index 215f5c3b..726e46b3 100755 --- a/source/mir/core/ui/servlet/ServletConstants.java +++ b/source/mir/core/ui/servlet/ServletConstants.java @@ -35,9 +35,23 @@ package mir.core.ui.servlet; * ServletConstants
* Some constant string values needed as keys to store values in the servlet context. * @author idefix - * @version $Id: ServletConstants.java,v 1.1 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: ServletConstants.java,v 1.2 2003/09/07 16:55:00 idfx Exp $ */ public interface ServletConstants { + public static final String REDIRECT_ACTION = "redirect action"; + + public static final String REDIRECT_QUERY_STRING = "redirect query string"; + + public static final String NEXT_OFFSET = "nextoffset"; + + public static final String LAST_OFFSET = "lastoffset"; + + public static final String OFFSET = "offset"; + + public static final String DEFAULT_LANGUAGE = "defaultlanguage"; + + public static final String LOGIN_LANGUAGES = "languages"; + public static final String SESSION_FACTORY = "session factory"; public static final String USER = "user"; diff --git a/source/mir/core/ui/servlet/TemplateServlet.java b/source/mir/core/ui/servlet/TemplateServlet.java index 06711cc3..2c70b2c6 100755 --- a/source/mir/core/ui/servlet/TemplateServlet.java +++ b/source/mir/core/ui/servlet/TemplateServlet.java @@ -33,10 +33,13 @@ package mir.core.ui.servlet; import java.io.IOException; import java.io.PrintWriter; +import java.util.Date; import java.util.Enumeration; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Vector; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -47,9 +50,16 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; import mir.servlet.ServletModuleExc; +import mir.util.GeneratorDateTimeFunctions; +import mir.util.GeneratorExpressionFunctions; +import mir.util.GeneratorHTMLFunctions; +import mir.util.GeneratorIntegerFunctions; +import mir.util.GeneratorListFunctions; +import mir.util.GeneratorRegularExpressionFunctions; +import mir.util.GeneratorStringFunctions; import mir.util.ResourceBundleGeneratorFunction; +import mir.util.StringRoutines; import mircoders.servlet.ServletHelper; import org.apache.struts.util.MessageResources; @@ -57,7 +67,7 @@ import org.apache.struts.util.MessageResources; /** * TemplateServlet * @author idefix - * @version $Id: TemplateServlet.java,v 1.1 2003/09/05 20:23:59 idfx Exp $ + * @version $Id: TemplateServlet.java,v 1.2 2003/09/07 16:55:00 idfx Exp $ */ public class TemplateServlet extends HttpServlet { @@ -68,6 +78,8 @@ public class TemplateServlet extends HttpServlet { super(); } + + /** * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @@ -91,47 +103,106 @@ public class TemplateServlet extends HttpServlet { */ protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - PrintWriter printWriter = response.getWriter(); - Map requestData = new HashMap(); - Enumeration keys = request.getAttributeNames(); - while(keys.hasMoreElements()){ - final String key = (String)keys.nextElement(); - requestData.put(key, request.getAttribute(key)); - } - Map sessionData = new HashMap(); - HttpSession httpSession = request.getSession(); - keys = httpSession.getAttributeNames(); - while(keys.hasMoreElements()){ - final String key = (String)keys.nextElement(); - sessionData.put(key, httpSession.getAttribute(key)); - } - Map applicationData = new HashMap(); - ServletContext servletContext = getServletContext(); - keys = servletContext.getAttributeNames(); - while(keys.hasMoreElements()){ - final String key = (String)keys.nextElement(); - applicationData.put(key, servletContext.getAttribute(key)); - } - Map templateData = new HashMap(); - templateData.put("request", requestData); - templateData.put("session", sessionData); - templateData.put("application", applicationData); try { - templateData.put("config", MirPropertiesConfiguration.instance().allSettings()); - } catch (PropertiesConfigExc e) { - throw new ServletException(e); - } - - String templateName = generateTemplateString(request); - - Locale[] locales = new Locale[2]; - locales[0] = request.getLocale(); - locales[1] = request.getLocale(); + Map requestData = new HashMap(); + Enumeration keys = request.getAttributeNames(); + while(keys.hasMoreElements()){ + final String key = (String)keys.nextElement(); + requestData.put(key, request.getAttribute(key)); + } + requestData.putAll(request.getParameterMap()); + + Map sessionData = new HashMap(); + HttpSession httpSession = request.getSession(); + keys = httpSession.getAttributeNames(); + while(keys.hasMoreElements()){ + final String key = (String)keys.nextElement(); + sessionData.put(key, httpSession.getAttribute(key)); + } + + Map applicationData = new HashMap(); + ServletContext servletContext = getServletContext(); + keys = servletContext.getAttributeNames(); + while(keys.hasMoreElements()){ + final String key = (String)keys.nextElement(); + applicationData.put(key, servletContext.getAttribute(key)); + } + + Map utilityMap = new HashMap(); + utilityMap.put("compressWhitespace", + new freemarker.template.utility.CompressWhitespace()); + utilityMap.put("encodeHTML", + new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction()); + utilityMap.put("encodeXML", + new GeneratorHTMLFunctions.encodeXMLGeneratorFunction()); + utilityMap.put("encodeURI", + new GeneratorHTMLFunctions.encodeURIGeneratorFunction()); + utilityMap.put("subString", + new GeneratorStringFunctions.subStringFunction()); + utilityMap.put("subList", + new GeneratorListFunctions.subListFunction()); + utilityMap.put("isOdd", + new GeneratorIntegerFunctions.isOddFunction()); + utilityMap.put("increment", + new GeneratorIntegerFunctions.incrementFunction()); + utilityMap.put("evaluate", + new GeneratorExpressionFunctions.evaluateExpressionFunction()); + utilityMap.put("constructString", + new GeneratorStringFunctions.constructStructuredStringFunction()); + utilityMap.put("escapeJDBCString", + new GeneratorStringFunctions.jdbcStringEscapeFunction()); + utilityMap.put("regexpreplace", + new GeneratorRegularExpressionFunctions.regularExpressionReplaceFunction()); + utilityMap.put("datetime", + new GeneratorDateTimeFunctions.DateTimeFunctions( + MirPropertiesConfiguration.instance().getString("Mir.DefaultTimezone"))); + utilityMap.put("encodeLink", + new GeneratorHTMLFunctions.encodeLinksGeneratorFunction(response)); + + Map configData = MirPropertiesConfiguration.instance().allSettings(); + configData.put("docRoot", request.getContextPath()); + configData.put("now", new Date()); + + //administeroperations + List administerOperations = new Vector(); + String settings[] = MirPropertiesConfiguration.instance().getStringArray("Mir.Localizer.Admin.AdministerOperations"); + if (settings!=null) { + for (int i = 0; i < settings.length; i++) { + String setting = settings[i].trim(); + + if (setting.length() > 0) { + List parts = StringRoutines.splitString(setting, ":"); + if (parts.size() != 2) { +// logger.error("config error: " + settings[i] + ", 2 parts expected"); + } + else { + Map entry = new HashMap(); + entry.put("name", (String) parts.get(0)); + entry.put("url", (String) parts.get(1)); + administerOperations.add(entry); + } + } + } + } + + Map templateData = new HashMap(); + templateData.put("request", requestData); + templateData.put("session", sessionData); + templateData.put("application", applicationData); + templateData.put("utility", utilityMap); + templateData.put("config", configData); + templateData.put("administeroperations", administerOperations); + + String templateName = generateTemplateString(request); + + Locale[] locales = new Locale[2]; + locales[0] = request.getLocale(); + locales[1] = request.getLocale(); - try { //write the servlet + PrintWriter printWriter = response.getWriter(); generateResponse(printWriter, templateData, templateName, locales); - } catch (ServletModuleExc e) { + } catch (Throwable e) { throw new ServletException(e); } } @@ -139,7 +210,7 @@ public class TemplateServlet extends HttpServlet { private String generateTemplateString(HttpServletRequest request){ String returnString = request.getServletPath(); returnString = returnString.substring(0, returnString.indexOf(".")); - return returnString + ".template"; + return returnString + ".tmpl"; } private void generateResponse(PrintWriter printWriter, Map map, @@ -148,19 +219,23 @@ public class TemplateServlet extends HttpServlet { if(templateString.startsWith("/admin")){ map.put( "lang", new ResourceBundleGeneratorFunction( locales, - new MessageResources[] { MessageResources.getMessageResources("bundles.admin"), - MessageResources.getMessageResources("bundles.adminlocal")})); + new MessageResources[] { + MessageResources.getMessageResources("bundles.admin"), + MessageResources.getMessageResources("bundles.adminlocal") + })); - templateString = templateString.substring(6); + templateString = templateString.substring(templateString.lastIndexOf('/')); ServletHelper.generateResponse(printWriter, map, templateString); } if(templateString.startsWith("/open")){ map.put( "lang", - new ResourceBundleGeneratorFunction( locales, - new MessageResources[] { MessageResources.getMessageResources("bundles.open"), - MessageResources.getMessageResources("bundles.open")})); + new ResourceBundleGeneratorFunction( locales, + new MessageResources[] { + MessageResources.getMessageResources("bundles.open"), + MessageResources.getMessageResources("bundles.open") + })); - templateString = templateString.substring(5); + templateString = templateString.substring(templateString.lastIndexOf('/')); ServletHelper.generateOpenPostingResponse(printWriter, map, templateString); } } @@ -177,5 +252,12 @@ public class TemplateServlet extends HttpServlet { */ public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); + MirPropertiesConfiguration.setContext(servletConfig.getServletContext()); + try { + MirPropertiesConfiguration.instance(); + } + catch (Throwable t) { + throw new ServletException("can't read configuration: " + t.toString()); + } } } diff --git a/source/mir/util/GeneratorHTMLFunctions.java b/source/mir/util/GeneratorHTMLFunctions.java index 661ff56a..511f0b2f 100755 --- a/source/mir/util/GeneratorHTMLFunctions.java +++ b/source/mir/util/GeneratorHTMLFunctions.java @@ -30,7 +30,7 @@ package mir.util; import java.util.List; -import java.io.*; +import javax.servlet.http.HttpServletResponse; import mir.generator.Generator; import mir.generator.GeneratorExc; @@ -94,4 +94,25 @@ public class GeneratorHTMLFunctions { } }; } + + public static class encodeLinksGeneratorFunction implements Generator.GeneratorFunction { + private HttpServletResponse _response; + public encodeLinksGeneratorFunction(HttpServletResponse response){ + _response = response; + } + public Object perform(List aParameters) throws GeneratorExc { + try { + if (aParameters.size()!=1) + throw new GeneratorExc("encodeHTMLGeneratorFunction: only 1 parameter expected"); + + return _response.encodeURL((String)aParameters.get(0)); + } + catch (GeneratorExc e) { + throw e; + } + catch (Throwable t) { + throw new GeneratorFailure("encodeHTMLGeneratorFunction: " + t.getMessage(), t); + } + }; + } }