r255 - in trunk: chorem-entities/src/main/java/org/chorem chorem-entities/src/main/xmi chorem-webmotion/src/main/java/org/chorem/webmotion chorem-webmotion/src/main/java/org/chorem/webmotion/actions chorem-webmotion/src/main/java/org/chorem/webmotion/filters chorem-webmotion/src/main/java/org/chorem/webmotion/injector chorem-webmotion/src/main/resources chorem-webmotion/src/main/webapp/WEB-INF/jsp
Author: bpoussin Date: 2012-08-24 01:36:55 +0200 (Fri, 24 Aug 2012) New Revision: 255 Url: http://chorem.org/repositories/revision/chorem/255 Log: - grosse refonte pour supporter plusieurs domaines sur une instance (1 base par domaine) - ajout de l'authentification Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremAction.java 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/ChoremMain.java trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java trunk/chorem-entities/src/main/xmi/chorem-model.properties trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/ChoremClientFilter.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/DecoratorFilter.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/injector/InjectorListener.java trunk/chorem-webmotion/src/main/resources/mapping trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremAction.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremAction.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremAction.java 2012-08-23 23:36:55 UTC (rev 255) @@ -39,18 +39,23 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(ChoremAction.class); + ApplicationConfig config; + + public ChoremAction(ApplicationConfig config) { + this.config = config; + } + /** * Remove all data in database, used with caution */ - static public void clean() { + public void clean() { System.out.println("Cleaning database ..."); - ChoremClient proxy = ChoremClient.getClient(); + ChoremClient proxy = ChoremClient.getClient(config); proxy.clear(); System.out.println("... clean done"); } - static public void configInfo() { - ApplicationConfig config = ChoremConfig.getConfig(); + public void configInfo() { config.printConfig(); } Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremClient.java 2012-08-23 23:36:55 UTC (rev 255) @@ -25,14 +25,15 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUtils; - import org.chorem.entities.Attachment; +import org.chorem.entities.ChoremUser; +import org.chorem.entities.Company; +import org.chorem.entities.CompanyImpl; import org.chorem.entities.Configuration; import org.chorem.entities.ConfigurationImpl; import org.chorem.entities.ContactDetails; - +import org.chorem.entities.Employee; 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; @@ -53,55 +54,81 @@ protected ChoremClient(ApplicationConfig config, WikittyService ws) { super(config, ws); } - + /** - * Returns new ChoremClient instance with specified security token + * Returns new ChoremClient instance for the specified domain * - * @param token can be null, if no authorisation token already exist (no login done) + * @param domain le domain qui permet de trouve la base de donnees * @return */ - static public ChoremClient getClient(String token) { - ApplicationConfig config = ChoremConfig.getConfig(); - WikittyService ws = getWikittyService(config); - ChoremClient result = new ChoremClient(config, ws); - result.setSecurityToken(token); - + static public ChoremClient getClient(String domain) { + ApplicationConfig config = ChoremConfig.getConfig(domain); + ChoremClient result = getClient(config); + return result; } /** - * Return new ChoremClient instance with authentication done with login and - * password found in application configuration. If no login found - * ChoremClient returned doesn't have authentication. + * Returns new ChoremClient instance for the specified domain * + * @param config la configuration a utiliser * @return */ - static public ChoremClient getClient() { - ApplicationConfig config = ChoremConfig.getConfig(); - String login = config.getOption(ChoremConfigOption.CHOREM_LOGIN.key); - String password = config.getOption(ChoremConfigOption.CHOREM_PASSWORD.key); + static public ChoremClient getClient(ApplicationConfig config) { + WikittyService ws = getWikittyService(config); + ChoremClient result = new ChoremClient(config, ws); - ChoremClient result = getClient(login, password); - return result; } - /** - * return new ChoremClient instance with authentication done with - * login and password in argument, only if login is not null and not blank - * - * @param login login used for authentication - * @param password password used for authentication - */ - static public ChoremClient getClient(String login, String password) { - ChoremClient result = getClient(null); +// /** +// * Returns new ChoremClient instance with specified security token +// * +// * @param token can be null, if no authorisation token already exist (no login done) +// * @return +// */ +// static public ChoremClient getClient(String token) { +// ApplicationConfig config = ChoremConfig.getConfig(); +// WikittyService ws = getWikittyService(config); +// ChoremClient result = new ChoremClient(config, ws); +// result.setSecurityToken(token); +// +// return result; +// } +// +// /** +// * Return new ChoremClient instance with authentication done with login and +// * password found in application configuration. If no login found +// * ChoremClient returned doesn't have authentication. +// * +// * @return +// */ +// static public ChoremClient getClient() { +// ApplicationConfig config = ChoremConfig.getConfig(); +// String login = config.getOption(ChoremConfigOption.CHOREM_LOGIN.key); +// String password = config.getOption(ChoremConfigOption.CHOREM_PASSWORD.key); +// +// ChoremClient result = getClient(login, password); +// +// return result; +// } +// +// /** +// * return new ChoremClient instance with authentication done with +// * login and password in argument, only if login is not null and not blank +// * +// * @param login login used for authentication +// * @param password password used for authentication +// */ +// static public ChoremClient getClient(String login, String password) { +// ChoremClient result = getClient(null); +// +// if (StringUtils.isNotBlank(login)) { +// result.login(login, password); +// } +// return result; +// } - if (StringUtils.isNotBlank(login)) { - result.login(login, password); - } - return result; - } - /** * Returns WikittyService to use. This WikittyService is singleton. * @@ -175,11 +202,11 @@ * @param wikittyId * @return the list of attachments */ - static public List<Attachment> getAttachments(String wikittyId) { + public List<Attachment> getAttachments(String wikittyId) { WikittyQuery criteria = new WikittyQueryMaker() .eq(Attachment.FQ_FIELD_ATTACHMENT_TARGET, wikittyId).end(); - WikittyQueryResult<Attachment> result = getClient(null) - .findAllByQuery(Attachment.class, criteria); + WikittyQueryResult<Attachment> result = + findAllByQuery(Attachment.class, criteria); List<Attachment> attachments = result.getAll(); return attachments; } @@ -190,16 +217,20 @@ * @param wikittyId * @return the list of contact details */ - static public List<ContactDetails> getContactDetails(String wikittyId) { + public List<ContactDetails> getContactDetails(String wikittyId) { WikittyQuery criteria = new WikittyQueryMaker() .eq(ContactDetails.FQ_FIELD_CONTACTDETAILS_TARGET, wikittyId).end(); - WikittyQueryResult<ContactDetails> result = getClient(null) - .findAllByQuery(ContactDetails.class, criteria); + WikittyQueryResult<ContactDetails> result = + findAllByQuery(ContactDetails.class, criteria); List<ContactDetails> contactDetails = result.getAll(); return contactDetails; } protected String configId; + /** + * Retourne la configuration générale pour l'application + * @return + */ public Configuration getConfiguration() { if (configId == null) { configId = findByQuery(new WikittyQueryMaker().exteq(Configuration.EXT_CONFIGURATION).end()); @@ -221,4 +252,60 @@ return config; } + /** + * Retourne la comparny par defaut pour l'utilisateur loggue, si par d'utilisateur + * alors on prend la company defini dans la configuration general. S'il n'y + * a aucune company, on en cree une nouvelle (non stocke) pour que tout + * fonctionne bien. Cette company n'existant pas reellement les recherches + * l'utilisant ne renvoie pas de resultat + * @return on retourne la company par defaut, ou company factice si aucun + * defaut n'existe + */ + public Company getDefaultCompany() { + String companyId = null; + ChoremUser user = getUser(ChoremUser.class); + + // on regarde si l'utilisateur a configurer sa societe par defaut + if (user != null) { + companyId = user.getDefaultCompany(); + } + + // on regarde si l'utilateur a une societe (au moins, on la prend au hasard :)) + WikittyQuery q = new WikittyQueryMaker() + .select(Employee.FQ_FIELD_EMPLOYEE_COMPANY) + .eq(Employee.FQ_FIELD_EMPLOYEE_PERSON, user) + .end(); + companyId = findByQuery(q); + + // on a toujours pas de societe, on utilise celle de la config de l'application + if (companyId == null) { + companyId = getConfiguration().getDefaultCompany(); + } + + Company result = null; + if (companyId == null) { + // on a trouve aucun societe on fini par en cree une victive qui ne doit pas etre persiste + result = new CompanyImpl(); + result.setName("No Company"); + } else { + // on restore la societe trouvee + result = restore(Company.class, companyId); + } + return result; + } + + /** + * Retourne toutes les companies possible pour l'utilisateur loggue + * @return + */ + public List<Company> getUserCompanies() { + String userId = getUser().getWikittyId(); + // on recupere toutes les companies pour lequel le user est salarie + WikittyQuery q = new WikittyQueryMaker() + .select(Employee.FQ_FIELD_EMPLOYEE_COMPANY) + .eq(Employee.FQ_FIELD_EMPLOYEE_PERSON, userId) + .end(); + WikittyQueryResult<Company> result = findAllByQuery(Company.class, q); + return result.getAll(); + } } Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremConfig.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremConfig.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremConfig.java 2012-08-23 23:36:55 UTC (rev 255) @@ -23,6 +23,7 @@ package org.chorem; import org.apache.commons.lang.UnhandledException; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.ApplicationConfig; @@ -46,22 +47,37 @@ public ChoremConfig() { } - public static ApplicationConfig getConfig(String... args) { + /** + * Get config for specified domain, if domain is null, configuration domain + * is used + * @param domain + * @param args + * @return + */ + public static ApplicationConfig getConfig(String domain, String... args) { if (config == null) { synchronized (ChoremConfig.class) { if (config == null) { try { - config = new ApplicationConfig(ChoremConfigOption.CONFIG_FILE.getDefaultValue()); + config = new ApplicationConfig( + ChoremConfigOption.CONFIG_FILE.getDefaultValue()); // Load wikitty options - config.loadDefaultOptions(WikittyConfigOption.class); + config.loadDefaultOptions(WikittyConfigOption.values()); // Load chorem options - config.loadDefaultOptions(ChoremConfigOption.class); + config.loadDefaultOptions(ChoremConfigOption.values()); // Load chorem action - config.loadActions(ChoremConfigAction.class); + config.loadActions(ChoremConfigAction.values()); + // set domain before parse command line but after load default + if (StringUtils.isNotBlank(domain)) { + config.setOption( + ChoremConfigOption.CHOREM_DOMAIN.getKey(), + domain); + } + // Parse args config.parse(args); Modified: trunk/chorem-entities/src/main/java/org/chorem/ChoremConfigOption.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremConfigOption.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremConfigOption.java 2012-08-23 23:36:55 UTC (rev 255) @@ -22,9 +22,10 @@ */ package org.chorem; -import static org.nuiton.i18n.I18n._; import org.nuiton.util.ApplicationConfig; +import static org.nuiton.i18n.I18n._; + /** * Chorem option definition. * @@ -37,13 +38,18 @@ CHOREM_EXTENSION_SEARCH_EXCLUSION( "chorem.extension.search.exclusion", _("Liste des extensions qui ne doivent pas apparaitre dans les resultats"), - "Configuration,Interval,WikittyTreeNode", + "Configuration,Interval,WikittyTreeNode,WikittyToken,WikittyUser", String.class, false, false), CHOREM_AUTHENTICATION( "chorem.authentication", _("If true authentication is used to acces page (default: false)"), "false", Boolean.class, false, false), + CHOREM_DOMAIN( + "chorem.domain", + _("Domain qui permet de trouver la base de donnees a utiliser"), + "default", + String.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/ChoremMain.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ChoremMain.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-entities/src/main/java/org/chorem/ChoremMain.java 2012-08-23 23:36:55 UTC (rev 255) @@ -44,7 +44,7 @@ System.out.println(String.format("Launching ChoremMain ... (args: %s)", Arrays.toString(args))); // getConfig do all: parse and doAllAction // String[] forceArgs = "--clean -ic /tmp/chorem-company.csv -ip /tmp/chorem-person.csv -ie /tmp/chorem-employee.csv --import-contract-type /tmp/chorem-contracttype.csv --import-contract /tmp/chorem-contract.csv --commit".split(" "); - ApplicationConfig config = ChoremConfig.getConfig(args); + ApplicationConfig config = ChoremConfig.getConfig(null, args); System.exit(0); } Modified: trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java =================================================================== --- trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-entities/src/main/java/org/chorem/ImportChoremTopia.java 2012-08-23 23:36:55 UTC (rev 255) @@ -38,6 +38,7 @@ import org.chorem.entities.EmployeeImpl; import org.chorem.entities.InvoiceImpl; import org.chorem.entities.PersonImpl; +import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ApplicationConfig.Action.Step; import org.nuiton.wikitty.entities.BusinessEntityImpl; @@ -107,7 +108,10 @@ // a ne pas stocker dans wikitty protected Map<String, String> contractType = new HashMap<String, String>(); - public ImportChoremTopia() { + protected ApplicationConfig config; + + public ImportChoremTopia(ApplicationConfig config) { + this.config = config; } /** @@ -138,7 +142,9 @@ } /** - * Commit all imported data. Step number must be the last + * Commit all imported data. Step number must be the last. + * @param domain le domain permettant de trouver la base de donnees dans + * lequel le commit doit etre fait */ @Step(99) public void commit() { @@ -149,7 +155,7 @@ data.addAll(employees.values()); data.addAll(contacts); - ChoremClient proxy = ChoremClient.getClient(); + ChoremClient proxy = ChoremClient.getClient(config); data = proxy.store(data); System.out.println(String.format("%s Commited data", data.size())); } Modified: trunk/chorem-entities/src/main/xmi/chorem-model.properties =================================================================== --- trunk/chorem-entities/src/main/xmi/chorem-model.properties 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-entities/src/main/xmi/chorem-model.properties 2012-08-23 23:36:55 UTC (rev 255) @@ -37,9 +37,9 @@ # # 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 +org.chorem.entities.ChoremUser.class.tagvalue.version=1.0 +org.chorem.entities.ChoremUser.class.tagvalue.toString=%WikittyUser.login|nologin$s +org.chorem.entities.ChoremUser.class.tagvalue.sortOrder=WikittyUser.login # # Configuration # Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/ChoremWebMotionUtil.java 2012-08-23 23:36:55 UTC (rev 255) @@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.ChoremClient; import org.chorem.ChoremConfig; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; @@ -22,8 +23,6 @@ /** 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; @@ -39,33 +38,40 @@ return result; } - static public String getSecurityToken(Call call) { - String result = getSecurityToken(call.getContext().getRequest()); + static public ApplicationConfig getConfig(HttpContext context) { + String domain = getDomain(context); + ApplicationConfig result = ChoremConfig.getConfig(domain); return result; } - static public String getSecurityToken(HttpContext context) { - String result = getSecurityToken(context.getRequest()); + static public ChoremClient getClient(Call call) { + ChoremClient result = getClient(call.getContext().getRequest()); return result; } - static public String getSecurityToken(HttpServletRequest request) { - String domain = getDomain(request); - String result = (String)request.getSession().getAttribute(domain + "." + SECURITY_TOKEN); + static public ChoremClient getClient(HttpContext context) { + ChoremClient result = getClient(context.getRequest()); return result; } - static public void setSecurityToken(HttpContext context, String token) { - setSecurityToken(context.getRequest(), token); - } - - static public void setSecurityToken(HttpServletRequest request, String token) { + /** + * Recupere le ChoremClient pour cette utilisateur dans sa session. S'il n'a + * pas encore de ChoremClient l'objet est cree et pousser dans la session. + * Ce ChoremClient n'est pas encore authentifier (pas de token de securite) + * @param request + * @return + */ + static public ChoremClient getClient(HttpServletRequest request) { String domain = getDomain(request); - request.getSession().setAttribute(domain + "." + SECURITY_TOKEN, token); - } + ChoremClient result = (ChoremClient)request.getSession().getAttribute( + domain + "." + ChoremClient.class.getName()); + if (result == null) { + result = ChoremClient.getClient(domain); + request.getSession().setAttribute(domain + "." + ChoremClient.class.getName(), result); + } - static public ApplicationConfig getConfig(HttpContext context) { - ApplicationConfig result = ChoremConfig.getConfig(); return result; } + + } Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/GenericAction.java 2012-08-23 23:36:55 UTC (rev 255) @@ -23,6 +23,20 @@ package org.chorem.webmotion.actions; import com.google.common.collect.LinkedHashMultimap; +import java.io.ByteArrayInputStream; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; @@ -33,6 +47,7 @@ import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.UploadFile; +import org.debux.webmotion.server.mapping.Config; import org.debux.webmotion.server.render.Render; import org.nuiton.wikitty.entities.Element; import org.nuiton.wikitty.entities.ElementField; @@ -45,23 +60,6 @@ import org.nuiton.wikitty.query.WikittyQueryParser; import org.nuiton.wikitty.query.WikittyQueryResult; -import java.io.ByteArrayInputStream; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.ServletContext; -import org.debux.webmotion.server.mapping.Config; - /** * * @author poussin @@ -75,6 +73,11 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(GenericAction.class); + public Render logout(HttpSession session) { + session.invalidate(); + return renderURL("/"); + } + // FIXME poussin 20120418 cette methode est-elle vraiment utilise ? // si oui searchJson ne peut-elle pas la remplacer ? public Render searchFieldJson(ChoremClient client, String query) { Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/AuthenticationFilter.java 2012-08-23 23:36:55 UTC (rev 255) @@ -23,14 +23,13 @@ package org.chorem.webmotion.filters; +import org.apache.commons.lang3.StringUtils; 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.WebMotionFilter; import org.debux.webmotion.server.call.HttpContext; import org.debux.webmotion.server.render.Render; import org.nuiton.util.ApplicationConfig; @@ -54,10 +53,19 @@ /** 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, + public Render check(HttpContext context, String choremLogin, String choremPassword) { - String token = ChoremWebMotionUtil.getSecurityToken(context); - log.debug("SecurityTocken: " + StringUtils.isNotBlank(token)); + Render result = null; + + // injection de ChoremWebMotionUtil dans la session + ChoremClient client = ChoremWebMotionUtil.getClient(context); + + String token = client.getSecurityToken(); + if (log.isDebugEnabled()) { + // on affiche pas le token, car ca creerait un trou de securite + // on indique donc juste s'il y en a un + 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 @@ -72,21 +80,33 @@ .exteq(WikittyUser.EXT_WIKITTYUSER).end(); String userId = client.findByQuery(q); if (userId != null) { - return renderView("login.jsp"); + result = 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()); + String url = context.getUrl(); + String query = context.getRequest().getQueryString(); + if (StringUtils.isNotBlank(query)) { + url = StringUtils.join(url, "?", query); + } + + + result = renderURL(url); } catch (SecurityException eee) { context.addErrorMessage("message", "bad login or password"); - return renderView("login.jsp"); + result = renderView("login.jsp"); } } } - doProcess(); - return null; + + if (result == null) { + doProcess(); + return null; + } else { + return result; + } } } Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/ChoremClientFilter.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/ChoremClientFilter.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/ChoremClientFilter.java 2012-08-23 23:36:55 UTC (rev 255) @@ -26,52 +26,32 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.ChoremClient; +import org.chorem.webmotion.ChoremWebMotionUtil; import org.debux.webmotion.server.WebMotionFilter; -import org.debux.webmotion.server.WebMotionUtils; -import org.debux.webmotion.server.call.Executor; -import org.debux.webmotion.server.mapping.Mapping; +import org.debux.webmotion.server.call.HttpContext; -import java.lang.reflect.Method; -import java.util.Map; - /** - * Inject dans les parametres des actions le client wikitty a utiliser pour les - * actions (ChoremClient) + * Inject le ChoremClient dans la request pour permettre au JSP de facilement + * l'utiliser. Cela est necessaire car celui en session + * est enregistrer avec le domain, ce qui empeche la recuperation dans + * les jsp pour l'utiliser. * * @author poussin * @version $Revision$ * * Last update: $Date$ * by : $Author$ - * - * @deprecated filter has been replaced by {@link org.chorem.webmotion.injector.InjectorListener} */ public class ChoremClientFilter extends WebMotionFilter { /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(ChoremClientFilter.class); - public void inject(Mapping mapping, String token) { - ChoremClient client = ChoremClient.getClient(token); - - Executor executor = contextable.getCall().getExecutor(); - if (executor != null) { - Method executorMethod = executor.getMethod(); - String[] parameterNames = WebMotionUtils.getParameterNames(mapping, executorMethod); - Class<?>[] parameterTypes = executorMethod.getParameterTypes(); - Map<String, Object> parameters = executor.getParameters(); - - for (int i=0; i<parameterNames.length; i++) { - Class<?> clazz = parameterTypes[i]; - if (ChoremClient.class.isAssignableFrom(clazz)) { - String name = parameterNames[i]; - if (parameters.get(name) == null) { - parameters.put(name, client); - } - } - } - } - + public void inject(HttpContext context) { + // recuperation du client courant + ChoremClient client = ChoremWebMotionUtil.getClient(context); + // ajout dans la request + context.getRequest().setAttribute("client", client); doProcess(); } } Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/DecoratorFilter.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/DecoratorFilter.java 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/filters/DecoratorFilter.java 2012-08-23 23:36:55 UTC (rev 255) @@ -33,10 +33,10 @@ * le fichier view par defaut ou le nom du slot principale * <p> * parametre possible - * <li> view: le nom du fichier jsp a utiliser comme decorateur (defaut: decorator.jsp) - * <li> main: le nom du slot utilise pour mettre le contenu principal (defaut: slotContent) + * <li> wmDecoratorView: le nom du fichier jsp a utiliser comme decorateur (defaut: decorator.jsp) + * <li> wmDecoratorMain: le nom du slot utilise pour mettre le contenu principal (defaut: slotContent) * - * Si dans la requete on trouve un attribut "__nodecorator__" qui vaut true alors + * Si dans la requete on trouve un attribut "wmDecoratorNo" qui vaut true alors * on ne fait pas la decoration. * * @author poussin 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-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/injector/InjectorListener.java 2012-08-23 23:36:55 UTC (rev 255) @@ -52,9 +52,8 @@ @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); + ChoremClient client = ChoremWebMotionUtil.getClient(call); return client; } return null; Modified: trunk/chorem-webmotion/src/main/resources/mapping =================================================================== --- trunk/chorem-webmotion/src/main/resources/mapping 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/resources/mapping 2012-08-23 23:36:55 UTC (rev 255) @@ -5,14 +5,21 @@ server.listener.class=org.chorem.webmotion.injector.InjectorListener [filters] -#* /* ChoremClientFilter.inject -#GET /wikitty/{extension}/view/{id} DecoratorFilter.decorate slotEntityFooter={extension}Footer.jsp +* /* ChoremClientFilter.inject +#GET /wikitty/{extension}/view/* DecoratorFilter.decorate slotEntityFooter={extension}Footer.jsp * /wikitty-json/* DecoratorFilter.decorate wmDecoratorNo=true * /fragment/* DecoratorFilter.decorate wmDecoratorNo=true -GET /* DecoratorFilter.decorate -GET /* AuthenticationFilter.check +GET /* DecoratorFilter.decorate +* /* AuthenticationFilter.check +##### +#/!\# +##### il y a un bug si on met le DecoratorFilter en POST avec les formulaires +##### enctype="multipart/form-data", il faut donc que tous les form post +##### fasse un redirect en GET apres leur action, sinon on a pas de decorateur +##### le symptome de l'erreur est qu'il n'y a aucun parametre qui nous arrive :( [actions] +* /logout action:GenericAction.logout * / view:index.jsp * /wikitty/{extension}/search action:GenericAction.search * /wikitty/{extension}/view/{id} action:GenericAction.view Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/decorator.jsp 2012-08-23 23:36:55 UTC (rev 255) @@ -22,6 +22,7 @@ --%> <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="/WEB-INF/wikitty.tld" prefix="w"%> <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html> @@ -190,8 +191,13 @@ <input type="text" class="search-query" placeholder="Search" name="query" value="${param.query}"/> </form> </div> - + <c:if test="${client.user != null}"> + <w:display wikitty="${client.user}"/> + <w:display wikitty="${client.defaultCompany}"/> + <a href="<c:url value='/logout'/>">Logout</a> + </c:if> + </div> </div> </div> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp 2012-08-23 11:06:17 UTC (rev 254) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/login.jsp 2012-08-23 23:36:55 UTC (rev 255) @@ -26,7 +26,8 @@ Bienvenue sur Chorem, l'outil de gestion d'entreprise. -<form> +<%-- En post pour eviter d'avoir le mot de passe dans l'url --%> +<form method="POST"> <input type="text" name="choremLogin" placeholder="login"/> <input type="password" name="choremPassword" placeholder="password"/> <input type="submit"/>
participants (1)
-
bpoussin@users.chorem.org