Author: bpoussin Date: 2012-08-23 13:06:17 +0200 (Thu, 23 Aug 2012) New Revision: 254 Url: http://chorem.org/repositories/revision/chorem/254 Log: modif extension WikittyTreeNode pour une meilleur presentation debut d'implantation d'une authentification (si la config le demande) Added: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java trunk/chorem-entities/src/main/java/org/chorem/ChoremConfig.java trunk/chorem-entities/src/main/java/org/chorem/ChoremConfigOption.java trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java trunk/chorem-entities/src/main/xmi/chorem-model.properties trunk/chorem-entities/src/main/xmi/chorem-model.zargo trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/injector/InjectorListener.java trunk/chorem-webmotion/src/main/resources/mapping Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2012-08-22 14:11:15 UTC (rev 253) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2012-08-23 11:06:17 UTC (rev 254) @@ -32,9 +32,11 @@ import org.chorem.entities.ContactDetails; import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.VersionUtil; import org.nuiton.wikitty.WikittyClient; import org.nuiton.wikitty.WikittyService; import org.nuiton.wikitty.WikittyServiceFactory; +import org.nuiton.wikitty.WikittyUtil; import org.nuiton.wikitty.entities.WikittyExtension; import org.nuiton.wikitty.query.WikittyQuery; import org.nuiton.wikitty.query.WikittyQueryMaker; @@ -115,11 +117,11 @@ // register last entity versions in database List<WikittyExtension> exts = new ArrayList<WikittyExtension>(); - exts.addAll(org.chorem.entities.ConfigurationAbstract.extensions); + exts.addAll(org.chorem.entities.AttachmentAbstract.extensions); exts.addAll(org.chorem.entities.CategoryAbstract.extensions); - exts.addAll(org.chorem.entities.AttachmentAbstract.extensions); - exts.addAll(org.chorem.entities.NoteAbstract.extensions); + exts.addAll(org.chorem.entities.ChoremUserAbstract.extensions); exts.addAll(org.chorem.entities.CompanyAbstract.extensions); + exts.addAll(org.chorem.entities.ConfigurationAbstract.extensions); exts.addAll(org.chorem.entities.ContactDetailsAbstract.extensions); exts.addAll(org.chorem.entities.EmployeeAbstract.extensions); exts.addAll(org.chorem.entities.EvaluationAbstract.extensions); @@ -129,6 +131,7 @@ exts.addAll(org.chorem.entities.InvoiceableAbstract.extensions); exts.addAll(org.chorem.entities.InvoiceAbstract.extensions); exts.addAll(org.chorem.entities.MissionAbstract.extensions); + exts.addAll(org.chorem.entities.NoteAbstract.extensions); exts.addAll(org.chorem.entities.PersonAbstract.extensions); exts.addAll(org.chorem.entities.PersonSkillAbstract.extensions); exts.addAll(org.chorem.entities.ProjectAbstract.extensions); @@ -140,13 +143,25 @@ exts.addAll(org.chorem.entities.VacationAbstract.extensions); exts.addAll(org.chorem.entities.WorkerAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyAuthorisationAbstract.extensions); exts.addAll(org.nuiton.wikitty.entities.WikittyGroupAbstract.extensions); - exts.addAll(org.nuiton.wikitty.entities.WikittyUserAbstract.extensions); - exts.addAll(org.nuiton.wikitty.entities.WikittyTreeNodeAbstract.extensions); exts.addAll(org.nuiton.wikitty.entities.WikittyHookAbstract.extensions); - exts.addAll(org.nuiton.wikitty.entities.WikittyAuthorisationAbstract.extensions); exts.addAll(org.nuiton.wikitty.entities.WikittyLabelAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyTreeNodeAbstract.extensions); + exts.addAll(org.nuiton.wikitty.entities.WikittyUserAbstract.extensions); + // Ajout de TAG value specifique au objet deja genere dans Wikitty +//org.chorem.entities.WikittyTreeNode.attribute.name.tagvalue.help=Le nom pour cette catégorie (ex: dépense, Salaire, ...) +//org.chorem.entities.WikittyTreeNode.attribute.attachment.tagvalue.visible=false +//org.chorem.entities.WikittyTreeNode.attribute.parent.tagvalue.help=La catégorie Parente de celle-ci (ex: dépense pour Loyer) +//org.chorem.entities.WikittyTreeNode.attribute.parent.tagvalue.allowed=Category + WikittyExtension e = org.nuiton.wikitty.entities.WikittyTreeNodeAbstract.extensionWikittyTreeNode; + e.setVersion(WikittyUtil.incrementMajorRevision(e.getVersion())); // toujours faire attention d'etre a +1 par rapport a l'objet genere + e.getFieldType("name").addTagValue("help", "Le nom pour cette catégorie (ex: dépense, Salaire, ...)"); + e.getFieldType("attachment").addTagValue("visible", "false"); + e.getFieldType("parent").addTagValue("help", "La catégorie Parente de celle-ci (ex: dépense pour Loyer)"); + e.getFieldType("parent").addTagValue("allowed", "Category"); + ws.storeExtension(null, exts); } } Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremConfig.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremConfig.java 2012-08-22 14:11:15 UTC (rev 253) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremConfig.java 2012-08-23 11:06:17 UTC (rev 254) @@ -38,7 +38,7 @@ static protected ApplicationConfig config = null; - /** + /** * constructeur public seulement pour pouvoir mettre une variable de ce * type dans BowBaseAction et acceder facilement au donnees dans les jsp * en ognl Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremConfigOption.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremConfigOption.java 2012-08-22 14:11:15 UTC (rev 253) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremConfigOption.java 2012-08-23 11:06:17 UTC (rev 254) @@ -20,22 +20,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -/* - * Copyright (c) 2011 poussin. All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ package org.chorem; import static org.nuiton.i18n.I18n._; @@ -53,8 +37,13 @@ CHOREM_EXTENSION_SEARCH_EXCLUSION( "chorem.extension.search.exclusion", _("Liste des extensions qui ne doivent pas apparaitre dans les resultats"), - "Configuration,Interval", + "Configuration,Interval,WikittyTreeNode", String.class, false, false), + CHOREM_AUTHENTICATION( + "chorem.authentication", + _("If true authentication is used to acces page (default: false)"), + "false", + Boolean.class, false, false), CHOREM_LOGIN( "chorem.admin.login", _("Login as default login for action on command line"), Modified: trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java 2012-08-22 14:11:15 UTC (rev 253) +++ trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java 2012-08-23 11:06:17 UTC (rev 254) @@ -36,6 +36,7 @@ import org.chorem.entities.CompanyImpl; import org.chorem.entities.ContactDetailsImpl; import org.chorem.entities.EmployeeImpl; +import org.chorem.entities.InvoiceImpl; import org.chorem.entities.PersonImpl; import org.nuiton.util.ApplicationConfig.Action.Step; import org.nuiton.wikitty.entities.BusinessEntityImpl; @@ -49,6 +50,8 @@ * \copy contracttype to '/tmp/chorem-contracttype.csv' delimiter ';' CSV HEADER * \copy contract to '/tmp/chorem-contract.csv' delimiter ';' CSV HEADER * + * pour bill + * \copy (SELECT subcategory.name AS category, number, issuedate, hopedate, realdate, value, company.name AS company from bill LEFT OUTER JOIN subcategory ON bill.subcategory=subcategory.topiaid LEFT OUTER JOIN task ON bill.task=task.topiaid LEFT OUTER JOIN contact ON bill.contact=contact.topiaid LEFT OUTER JOIN company ON contact.company=company.topiaid order by company.name) TO '/tmp/bill.csv' delimiter ';' CSV HEADER * </pre> * * @author poussin @@ -91,10 +94,15 @@ monthduration, basepay, othercost, employee, contracttype } + enum BILL_HEADER { + category,number,issuedate,hopedate,realdate,value,company + } + protected List<ContactDetailsImpl> contacts = new LinkedList<ContactDetailsImpl>(); protected Map<String, CompanyImpl> companies = new HashMap<String, CompanyImpl>(); protected Map<String, PersonImpl> persons = new HashMap<String, PersonImpl>(); protected Map<String, EmployeeImpl> employees = new HashMap<String, EmployeeImpl>(); + protected Map<String, InvoiceImpl> invoices = new HashMap<String, InvoiceImpl>(); // a ne pas stocker dans wikitty protected Map<String, String> contractType = new HashMap<String, String>(); Modified: trunk/chorem-entities/src/main/xmi/chorem-model.properties =================================================================== --- trunk/chorem-entities/src/main/xmi/chorem-model.properties 2012-08-22 14:11:15 UTC (rev 253) +++ trunk/chorem-entities/src/main/xmi/chorem-model.properties 2012-08-23 11:06:17 UTC (rev 254) @@ -35,6 +35,12 @@ org.chorem.entities.Attachment.attribute.content.tagvalue.help=Le fichier \u00e0 importer org.chorem.entities.Attachment.attribute.contentUrl.tagvalue.help=Si on ne souhaite pas importer le fichier, on peut indiquer ici sont URL (ex: http://commun.codelutin.home/Clients/...) # +# ChoremUser +# +org.chorem.entities.Attachment.class.tagvalue.version=1.0 +org.chorem.entities.Attachment.class.tagvalue.toString=%WikittyUser.login|nologin$s +org.chorem.entities.Attachment.class.tagvalue.sortOrder=WikittyUser.login +# # Configuration # org.chorem.entities.Configuration.class.tagvalue.version=3.0 Modified: trunk/chorem-entities/src/main/xmi/chorem-model.zargo =================================================================== (Binary files differ) Added: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java (rev 0) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java 2012-08-23 11:06:17 UTC (rev 254) @@ -0,0 +1,71 @@ +package org.chorem.webmotion; + + +import javax.servlet.http.HttpServletRequest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.ChoremConfig; +import org.debux.webmotion.server.call.Call; +import org.debux.webmotion.server.call.HttpContext; +import org.nuiton.util.ApplicationConfig; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ChoremWebMotionUtil { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ChoremWebMotionUtil.class); + + static final private String SECURITY_TOKEN = "SecurityTocken"; + + static public String getDomain(Call call) { + String result = getDomain(call.getContext().getRequest()); + return result; + } + + static public String getDomain(HttpContext context) { + String result = getDomain(context.getRequest()); + return result; + } + + static public String getDomain(HttpServletRequest request) { + String result = request.getServerName(); + return result; + } + + static public String getSecurityToken(Call call) { + String result = getSecurityToken(call.getContext().getRequest()); + return result; + } + + static public String getSecurityToken(HttpContext context) { + String result = getSecurityToken(context.getRequest()); + return result; + } + + static public String getSecurityToken(HttpServletRequest request) { + String domain = getDomain(request); + String result = (String)request.getSession().getAttribute(domain + "." + SECURITY_TOKEN); + return result; + } + + static public void setSecurityToken(HttpContext context, String token) { + setSecurityToken(context.getRequest(), token); + } + + static public void setSecurityToken(HttpServletRequest request, String token) { + String domain = getDomain(request); + request.getSession().setAttribute(domain + "." + SECURITY_TOKEN, token); + } + + static public ApplicationConfig getConfig(HttpContext context) { + ApplicationConfig result = ChoremConfig.getConfig(); + return result; + } +} Added: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java (rev 0) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java 2012-08-23 11:06:17 UTC (rev 254) @@ -0,0 +1,92 @@ +/* + * #%L + * Chorem webmotion + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2011 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.webmotion.filters; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.ChoremClient; +import org.debux.webmotion.server.WebMotionFilter; +import javax.servlet.http.HttpSession; +import org.apache.commons.lang3.StringUtils; +import org.chorem.ChoremConfigOption; +import org.chorem.webmotion.ChoremWebMotionUtil; +import org.debux.webmotion.server.call.HttpContext; +import org.debux.webmotion.server.render.Render; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.wikitty.entities.WikittyUser; +import org.nuiton.wikitty.query.WikittyQuery; +import org.nuiton.wikitty.query.WikittyQueryMaker; + +/** + * Inject dans les parametres des actions le client wikitty a utiliser pour les + * actions (ChoremClient) + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + * + */ +public class AuthenticationFilter extends WebMotionFilter { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(AuthenticationFilter.class); + + public Render check(ChoremClient client, HttpContext context, + String choremLogin, String choremPassword) { + String token = ChoremWebMotionUtil.getSecurityToken(context); + log.debug("SecurityTocken: " + StringUtils.isNotBlank(token)); + if (token == null) { + if (StringUtils.isBlank(choremLogin)) { + // avant de mettre la page de login, on verifie s'il le faut vraiment + ApplicationConfig config = ChoremWebMotionUtil.getConfig(context); + boolean authActivate = + config.getOptionAsBoolean(ChoremConfigOption.CHOREM_AUTHENTICATION.getKey()); + if (authActivate) { + // la configuration demande une authentification, mais s'il + // n'y a aucun WikittyUser, on ne le fait pas pour permettre + // la creation du 1er user + WikittyQuery q = new WikittyQueryMaker() + .exteq(WikittyUser.EXT_WIKITTYUSER).end(); + String userId = client.findByQuery(q); + if (userId != null) { + return renderView("login.jsp"); + } + } + } else { + // phase d'authentification, l'utilisateur a soumis le formulaire de login + try { + client.login(choremLogin, choremPassword); + ChoremWebMotionUtil.setSecurityToken(context, client.getSecurityToken()); + } catch (SecurityException eee) { + context.addErrorMessage("message", "bad login or password"); + return renderView("login.jsp"); + } + } + } + doProcess(); + return null; + } +} Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/injector/InjectorListener.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/injector/InjectorListener.java 2012-08-22 14:11:15 UTC (rev 253) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/injector/InjectorListener.java 2012-08-23 11:06:17 UTC (rev 254) @@ -36,6 +36,7 @@ import org.apache.commons.beanutils.ConversionException; import org.apache.commons.beanutils.Converter; import org.apache.commons.lang3.StringUtils; +import org.chorem.webmotion.ChoremWebMotionUtil; import org.nuiton.wikitty.WikittyUtil; /** @@ -45,20 +46,15 @@ @Override public void onStart(ServerContext context) { - - // FIXME poussin 20120815 il y a un probleme avec l'injection du ChoremClient. - // a terme, il doit y avoir un ChoremClient instancier pour chaque requete, - // car chaque requete est faite par un utilisateur different (token different) - - // Get Client - String token = ""; - final ChoremClient client = ChoremClient.getClient(null); - + // Declare injector context.addInjector(new Injector() { @Override public Object getValue(Mapping mapping, Call call, Class<?> type, Type generic) { if (ChoremClient.class.isAssignableFrom(type)) { + String token = ChoremWebMotionUtil.getSecurityToken(call); + // Get Client + ChoremClient client = ChoremClient.getClient(token); return client; } return null; Modified: trunk/chorem-webmotion/src/main/resources/mapping =================================================================== --- trunk/chorem-webmotion/src/main/resources/mapping 2012-08-22 14:11:15 UTC (rev 253) +++ trunk/chorem-webmotion/src/main/resources/mapping 2012-08-23 11:06:17 UTC (rev 254) @@ -10,6 +10,7 @@ * /wikitty-json/* DecoratorFilter.decorate wmDecoratorNo=true * /fragment/* DecoratorFilter.decorate wmDecoratorNo=true GET /* DecoratorFilter.decorate +GET /* AuthenticationFilter.check [actions] * / view:index.jsp Added: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp (rev 0) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp 2012-08-23 11:06:17 UTC (rev 254) @@ -0,0 +1,33 @@ +<%-- + #%L + Chorem webmotion + $Id:$ + $HeadURL:$ + %% + Copyright (C) 2011 - 2012 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + +<h1>Chorem</h1> + +Bienvenue sur Chorem, l'outil de gestion d'entreprise. + +<form> + <input type="text" name="choremLogin" placeholder="login"/> + <input type="password" name="choremPassword" placeholder="password"/> + <input type="submit"/> +</form> \ No newline at end of file