Author: tchemit Date: 2011-11-04 15:01:05 +0100 (Fri, 04 Nov 2011) New Revision: 12 Url: http://forge.codelutin.com/repositories/revision/echobase/12 Log: login service + others Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/EchoBaseFieldValidatorSupport.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/LoginValidator.java trunk/echobase-ui/src/main/resources/echobase.properties trunk/echobase-ui/src/main/resources/fr/ trunk/echobase-ui/src/main/resources/fr/ifremer/ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/LoginAction-login-validation.xml trunk/echobase-ui/src/main/resources/validators.xml Removed: trunk/echobase-ui/web/ Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserImpl.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java trunk/echobase-ui/pom.xml trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/ApplicationListener.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java trunk/echobase-ui/src/main/resources/config/struts-user.xml trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties trunk/echobase-ui/src/main/resources/struts.xml Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2011-11-04 14:01:05 UTC (rev 12) @@ -108,6 +108,11 @@ return klass; } + public boolean isEmbedded() { + Class<?> driverClass = getDriverClass(); + return driverClass.getSimpleName().toLowerCase().contains("h2"); + } + /** * Creates a directory given the configuration given key. * Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserImpl.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserImpl.java 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserImpl.java 2011-11-04 14:01:05 UTC (rev 12) @@ -38,7 +38,7 @@ EchoBaseUserDTO dto = new EchoBaseUserDTOImpl(); dto.setAdmin(isAdmin()); dto.setEmail(getEmail()); - dto.setPassword(getPassword()); +// dto.setPassword(getPassword()); dto.setId(getTopiaId()); return dto; } @@ -47,7 +47,7 @@ public void fromDTO(EchoBaseUserDTO dto) { setAdmin(dto.isAdmin()); setEmail(dto.getEmail()); - setPassword(dto.getPassword()); +// setPassword(dto.getPassword()); } } Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java 2011-11-04 14:01:05 UTC (rev 12) @@ -1,18 +1,19 @@ package fr.ifremer.echobase.services; +import com.google.common.base.Preconditions; import fr.ifremer.echobase.EchoBaseTechnicalException; import fr.ifremer.echobase.entities.EchoBaseDAOHelper; import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.entities.EchoBaseUserDAO; import fr.ifremer.echobase.entities.EchoBaseUserDTO; +import org.apache.commons.lang3.StringUtils; import org.nuiton.topia.TopiaException; +import org.nuiton.util.StringUtil; import java.util.ArrayList; import java.util.List; -/** - * @author sletellier - */ +/** @author sletellier */ public class UserService extends AbstractEchoBaseService { public EchoBaseUserDAO getDAO() throws TopiaException { @@ -58,7 +59,13 @@ } user.fromDTO(userDTO); + String password = userDTO.getPassword(); + if (StringUtils.isNotEmpty(password)) { + user.setPassword(encodePassword(password)); + } dao.update(user); + + getTransaction().commitTransaction(); } catch (TopiaException eee) { throw new EchoBaseTechnicalException(eee); } @@ -74,4 +81,26 @@ throw new EchoBaseTechnicalException(eee); } } + + public EchoBaseUserDTO getUserByEmail(String email) { + Preconditions.checkNotNull(email); + try { + EchoBaseUserDAO dao = getDAO(); + EchoBaseUser user = dao.findByEmail(email); + return user.toDTO(); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(eee); + } + } + + public boolean checkPassword(EchoBaseUserDTO user, + String password) throws Exception { + String s = encodePassword(password); + return s.equals(user.getPassword()); + } + + public static String encodePassword(String password) { + String encodedPassword = StringUtil.encodeMD5(password); + return encodedPassword; + } } Modified: trunk/echobase-ui/pom.xml =================================================================== --- trunk/echobase-ui/pom.xml 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/pom.xml 2011-11-04 14:01:05 UTC (rev 12) @@ -43,11 +43,11 @@ <artifactId>nuiton-struts2</artifactId> </dependency> - <!--dependency> + <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-validator</artifactId> <scope>compile</scope> - </dependency--> + </dependency> <!-- struts 2 --> Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/ApplicationListener.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/ApplicationListener.java 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/ApplicationListener.java 2011-11-04 14:01:05 UTC (rev 12) @@ -25,24 +25,36 @@ import com.google.common.base.Supplier; import fr.ifremer.echobase.EchoBaseConfiguration; -import fr.ifremer.echobase.EchoBaseObjectFactory; +import fr.ifremer.echobase.EchoBaseTechnicalException; import fr.ifremer.echobase.EchoBaseTopiaRootContextSupplierFactory; +import fr.ifremer.echobase.entities.EchoBaseUserDTO; +import fr.ifremer.echobase.entities.EchoBaseUserDTOImpl; +import fr.ifremer.echobase.entities.EchoBaseUserImpl; +import fr.ifremer.echobase.services.EchoBaseServiceContext; +import fr.ifremer.echobase.services.EchoBaseServiceContextImpl; +import fr.ifremer.echobase.services.EchoBaseServiceFactory; +import fr.ifremer.echobase.services.UserService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import fr.ird.converter.FloatConverter; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.Converter; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.DefaultI18nInitializer; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaUtil; import org.nuiton.util.converter.ConverterUtil; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import java.util.Date; +import java.util.List; import java.util.Locale; +import java.util.Properties; /** * To listen start or end of the application. @@ -90,9 +102,6 @@ new EchoBaseTopiaRootContextSupplierFactory(); rootContextSupplier = factory.newDatabaseFromConfig(configuration); applicationContext.setRootContextSupplier(rootContextSupplier); - - // attach configuration to service factory - EchoBaseObjectFactory.setConfiguration(configuration); // register our not locale dependant converter Converter converter = ConverterUtil.getConverter(Float.class); @@ -101,161 +110,136 @@ } ConvertUtils.register(new FloatConverter(), Float.class); - // obtain a new service factory - EchoBaseObjectFactory serviceFactory = EchoBaseObjectFactory.newInstance(); - // init database (and create minimal admin user if required) - -// initInternalDatabase(serviceFactory, configuration); + try { + boolean schemaExist = isSchemaCreated(); + if (!schemaExist) { + + updateSchema(configuration); + } + + createAdminUser(configuration); + } catch (TopiaException e) { + throw new EchoBaseTechnicalException("Could not init db", e); + } } @Override public void contextDestroyed(ServletContextEvent sce) { + if (log.isInfoEnabled()) { log.info("Application is ending at " + new Date() + "..."); } - EchoBaseObjectFactory.destroy(); + if (rootContextSupplier != null) { + if (log.isInfoEnabled()) { + log.info("Shuting down RootContextSupplier..."); + } + TopiaContext rootContext = rootContextSupplier.get(); + if (!rootContext.isClosed()) { + try { + rootContext.closeContext(); + } catch (TopiaException te) { + if (log.isErrorEnabled()) { + log.error("Could not close rootContext", te); + } + } + } + } } -// /** -// * Init the internal database, says : -// * <ul> -// * <li>If no schema found or if asked to updateSchema using the -// * {@code updateSchema} configuration option is on.</li> -// * <li>If no user found is db, create a administrator user -// * {@code admin/admin}</li> -// * </ul> -// * -// * @param serviceFactory the service factory to use -// * @param configuration application configuration. -// */ -// protected void initInternalDatabase(EchoBaseObjectFactory serviceFactory, -// T3Configuration configuration) { -// -// DatabaseService databaseService = -// serviceFactory.newService(DatabaseService.class); -// -// try { -// boolean schemaNeedUpdate = !isInternalSchemaCreated(databaseService) || -// configuration.getOptionAsBoolean("updateSchema"); -// -// if (schemaNeedUpdate) { -// -// updateInternalSchema(databaseService); -// } -// } catch (Exception e) { -// throw new IllegalStateException("could not start db", e); -// } -// -// try { -// createAdminUser(serviceFactory, databaseService); -// -// } catch (Exception e) { -// throw new IllegalStateException( -// "could not create default admin user", e); -// } -// } + protected void updateSchema(EchoBaseConfiguration configuration) throws TopiaException { + if (log.isInfoEnabled()) { + log.info("Will create or update schema for db."); + } + // must create the schema -// /** -// * Updates the schema of the internal database. -// * -// * @param databaseService data service used to obtain transactions of db -// * @throws TopiaException if something was wrong while schema update -// */ -// protected void updateInternalSchema(DatabaseService databaseService) throws TopiaException { -// if (log.isInfoEnabled()) { -// log.info("Will create or update schema for db."); -// } -// // must create the schema -// -// Properties dbConf = -// databaseService.getInternalDatabaseConfiguration(); -// -// dbConf.put("hibernate.hbm2ddl.auto", "update"); -// -// // start a connexion to load schema -// TopiaContext tx = null; -// -// try { -// tx = databaseService.beginInternalTransaction(); -// -// } finally { -// -// // no more update of schema... -// dbConf.put("hibernate.hbm2ddl.auto", "none"); -// -// closeTransaction(tx); -// } -// } + Properties dbConf = configuration.getProperties(); -// /** -// * Creates the adminsitrator ({@code admin/admin}) on the internal -// * database. -// * -// * @param serviceFactory the service factory -// * @param databaseService the database service used to obtain transactions. -// * @throws Exception if could not create the user. -// */ -// protected void createAdminUser(T3ServiceFactory serviceFactory, -// DatabaseService databaseService) throws Exception { -// -// TopiaContext tx = databaseService.beginInternalTransaction(); -// try { -// UserService service = -// serviceFactory.newTransactionalService(UserService.class, tx); -// -// List<T3User> users = service.getUsers(); -// -// if (CollectionUtils.isEmpty(users)) { -// -// // no users in database create the admin user -// if (log.isInfoEnabled()) { -// log.info("No user in database, will create default " + -// "admin user (password admin)."); -// } -// -// T3User u = new T3UserImpl(); -// u.setLogin("admin"); -// u.setPassword("admin"); -// u.setAdmin(true); -// -// // store it in db -// service.createUser(u); -// -// } -// } finally { -// -// closeTransaction(tx); -// } -// } + dbConf.put("hibernate.hbm2ddl.auto", "update"); -// /** -// * Tests if the internal database schema created. -// * -// * @param databaseService the database to obtains transactions on internal -// * database -// * @return {@code true} if the schema is already created, {@code false} -// * otherwise -// * @throws TopiaException if something was wrong while requesting database -// */ -// protected boolean isInternalSchemaCreated(DatabaseService databaseService) throws TopiaException { -// -// TopiaContextImplementor tx = -// (TopiaContextImplementor) -// databaseService.beginInternalTransaction(); -// try { -// boolean schemaFound = TopiaUtil.isSchemaExist( -// tx.getHibernateConfiguration(), -// T3UserImpl.class.getName()); -// -// return schemaFound; -// -// } finally { -// closeTransaction(tx); -// } -// } + EchoBaseTopiaRootContextSupplierFactory factory = + new EchoBaseTopiaRootContextSupplierFactory(); + Supplier<TopiaContext> topiaContextSupplier = + factory.newDatabaseFromProperties(dbConf); + // start a connexion to load schema + TopiaContext tx = null; + + try { + tx = topiaContextSupplier.get().beginTransaction(); + + } finally { + + // no more update of schema... + dbConf.put("hibernate.hbm2ddl.auto", "none"); + + closeTransaction(tx); + } + } + /** + * Creates the adminsitrator ({@code admin/admin}) on the internal + * database. + * + * @param configuration + * @throws TopiaException if could not create the user. + */ + protected void createAdminUser(EchoBaseConfiguration configuration) throws TopiaException { + + EchoBaseServiceFactory serviceFactory = + new EchoBaseServiceFactory(); + TopiaContext transaction = rootContextSupplier.get().beginTransaction(); + + try { + EchoBaseServiceContext serviceContext = new EchoBaseServiceContextImpl( + transaction, + configuration, + serviceFactory + ); + + UserService service = serviceFactory.newService(UserService.class, serviceContext); + + List<EchoBaseUserDTO> users = service.getUsers(); + + if (CollectionUtils.isEmpty(users)) { + + // no users in database create the admin user + if (log.isInfoEnabled()) { + log.info("No user in database, will create default " + + "admin user (password admin)."); + } + + EchoBaseUserDTO userDTO = new EchoBaseUserDTOImpl(); + userDTO.setEmail("admin"); + userDTO.setPassword("admin"); + userDTO.setAdmin(true); + service.createOrUpdate(userDTO); + } + } finally { + transaction.closeContext(); + } + + } + + protected boolean isSchemaCreated() throws TopiaException { + + TopiaContextImplementor tx = + (TopiaContextImplementor) + rootContextSupplier.get(); + try { + boolean schemaFound = TopiaUtil.isSchemaExist( + tx.getHibernateConfiguration(), + EchoBaseUserImpl.class.getName() + ); + + return schemaFound; + + } finally { + closeTransaction(tx); + } + } + + /** * Try to close the given transaction. * * @param tx the transaction to close Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java 2011-11-04 14:01:05 UTC (rev 12) @@ -24,8 +24,6 @@ package fr.ifremer.echobase.ui.actions; -import fr.ifremer.echobase.services.ioc.InjectFromDAO; - /** * To go to the home page. * @@ -39,8 +37,7 @@ @Override public String execute() throws Exception { - injectOnly(InjectFromDAO.class); - + return SUCCESS; } Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java 2011-11-04 14:01:05 UTC (rev 12) @@ -25,7 +25,9 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.interceptor.I18nInterceptor; -import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.EchoBaseUserDTO; +import fr.ifremer.echobase.entities.EchoBaseUserImpl; +import fr.ifremer.echobase.services.UserService; import fr.ifremer.echobase.ui.EchoBaseSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,30 +48,29 @@ private static final long serialVersionUID = 1L; - protected boolean logging; + protected String email; - protected String login; - protected String password; protected String redirectAction; private transient Map<String, Object> session; - public boolean isLogging() { - return logging; - } + protected transient UserService userService; - public void setLogging(boolean logging) { - this.logging = logging; + public UserService getUserService() { + if (userService == null) { + userService = newService(UserService.class); + } + return userService; } - public String getLogin() { - return login; + public String getEmail() { + return email; } - public void setLogin(String login) { - this.login = login; + public void setEmail(String email) { + this.email = email; } public String getPassword() { @@ -90,13 +91,14 @@ public String doLogin() throws Exception { - // TODO Get user from userService - EchoBaseUser user = null; + EchoBaseUserDTO user = getUserService().getUserByEmail(email); EchoBaseSession userSession = getEchoBaseSession(); // user is authorized, keep it in his echoBaseSession - userSession.setEchoBaseUser(user); + EchoBaseUserImpl echoBaseUser = new EchoBaseUserImpl(); + echoBaseUser.fromDTO(user); + userSession.setEchoBaseUser(echoBaseUser); // add locale in echoBaseSession if required Object o = session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE); @@ -109,7 +111,7 @@ // redecode parameters if (log.isInfoEnabled()) { - log.info("success login for user " + login + + log.info("success login for user " + email + ", will redirect to " + redirectAction); } return "redirect"; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java 2011-11-04 14:01:05 UTC (rev 12) @@ -10,8 +10,10 @@ */ public class UserAction extends EchoBaseActionSupport { - protected UserService service; + private static final long serialVersionUID = 1L; + protected transient UserService service; + protected UserService getService() { if (service == null) { service = newService(UserService.class); @@ -19,7 +21,7 @@ return service; } - public List<EchoBaseUserDTO> userList() { + public List<EchoBaseUserDTO> getUserList() { return getService().getUsers(); } Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/EchoBaseFieldValidatorSupport.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/EchoBaseFieldValidatorSupport.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/EchoBaseFieldValidatorSupport.java 2011-11-04 14:01:05 UTC (rev 12) @@ -0,0 +1,62 @@ +/* + * #%L + * T3 :: Web + * + * $Id: T3BaseFieldValidatorSupport.java 623 2011-10-24 14:43:56Z chemit $ + * $HeadURL: https://svn.mpl.ird.fr/osiris/t3/trunk/t3-web/src/main/java/fr/ird/t3/web/va... $ + * %% + * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit + * %% + * 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 fr.ifremer.echobase.ui.validators; + +import org.nuiton.validator.xwork2.field.NuitonFieldValidatorSupport; + +import java.util.Arrays; + +/** + * Base T3 validator. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public abstract class EchoBaseFieldValidatorSupport extends NuitonFieldValidatorSupport { + + /** + * Add directly a field error with the given sentence wihtout any translation from the xml validator file. + * + * @param propertyName name of the property where to push the error + * @param error the error + */ + protected void addFieldError(String propertyName, String error) { + getValidatorContext().addFieldError(propertyName, error); + } + + /** + * Translate the given i18n key with his optional arguments. + * <p/> + * <strong>Note:</strong> This method name is fixed to be detected via the + * nuiton i18n system, do NOT change this method name. + * + * @param key the i18n key to translate + * @param args the optional arguments of the sentence + * @return the translated sentence + */ + protected String _(String key, Object... args) { + String text = getValidatorContext().getText(key, Arrays.asList(args)); + return text; + } +} Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/LoginValidator.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/LoginValidator.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/validators/LoginValidator.java 2011-11-04 14:01:05 UTC (rev 12) @@ -0,0 +1,79 @@ +/* + * #%L + * T3 :: Web + * + * $Id: LoginValidator.java 623 2011-10-24 14:43:56Z chemit $ + * $HeadURL: https://svn.mpl.ird.fr/osiris/t3/trunk/t3-web/src/main/java/fr/ird/t3/web/va... $ + * %% + * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit + * %% + * 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 fr.ifremer.echobase.ui.validators; + +import com.opensymphony.xwork2.validator.ValidationException; +import fr.ifremer.echobase.entities.EchoBaseUserDTO; +import fr.ifremer.echobase.services.UserService; + +/** + * Check user login. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class LoginValidator extends EchoBaseFieldValidatorSupport { + + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + + UserService userService = + (UserService) getFieldValue("userService", object); + + String login = (String) getFieldValue("login", object); + String password = (String) getFieldValue("password", object); + + if (log.isInfoEnabled()) { + log.info("try to log for user " + login); + } + + try { + // check in db that user is ok + EchoBaseUserDTO user = userService.getUserByEmail(login); + + if (user == null) { + + // user not found + addFieldError("login", _("t3.error.login.unknown")); + return; + } + + boolean passwordOk = userService.checkPassword(user, password); + + if (!passwordOk) { + addFieldError("password", _("t3.error.bad.password")); + } + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Could not validate login", e); + } + throw new ValidationException("Could not validate login : " + e.getMessage()); + } + } + + @Override + public String getValidatorType() { + return "login"; + } +} Modified: trunk/echobase-ui/src/main/resources/config/struts-user.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-user.xml 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/src/main/resources/config/struts-user.xml 2011-11-04 14:01:05 UTC (rev 12) @@ -30,21 +30,16 @@ <struts> - <package name="user" extends="default" namespace="/user"> + <package name="user" extends="loggued" namespace="/user"> - <!-- when a action has no context --> - <!--<action name="missingEchoBaseDatabase">--> - <!--<result name="success">/WEB-INF/jsp/missingEchoBaseDatabaseSelected.jsp</result>--> - <!--</action>--> - <!-- login action --> <action name="login" class="fr.ifremer.echobase.ui.actions.LoginAction" method="doLogin"> <result name="input">/WEB-INF/jsp/user/login.jsp</result> <result name="error">/WEB-INF/jsp/user/login.jsp</result> <result name="redirect" type="redirect">${redirectAction}</result> - <!--<interceptor-ref name="internalTransaction"/>--> - <interceptor-ref name="paramsPrepareParamsStack"/> + <interceptor-ref name="topiaTransaction"/> + <interceptor-ref name="basicStack"/> </action> <!-- logout action --> @@ -56,28 +51,27 @@ </result> <interceptor-ref name="checkUserLoggued"/> <interceptor-ref name="basicStack"/> - <interceptor-ref name="injectEchoBaseSession"/> </action> <!-- get lists of users --> <action name="userList" class="fr.ifremer.echobase.ui.actions.UserAction"> - <interceptor-ref name="internalBasicStackLoggued"/> + <interceptor-ref name="basicStackLoggued"/> <interceptor-ref name="checkUserIsAdmin"/> - <result name="input">/WEB-INF/jsp/admin/users.jsp</result> + <result name="input">/WEB-INF/jsp/user/users.jsp</result> </action> <!-- update or create (if not exist) user --> <action name="createOrUpdate" class="fr.ifremer.echobase.ui.actions.UserAction"> - <interceptor-ref name="internalBasicStackLoggued"/> + <interceptor-ref name="basicStackLoggued"/> <interceptor-ref name="checkUserIsAdmin"/> - <result name="input">/WEB-INF/jsp/admin/users.jsp</result> + <result name="input">/WEB-INF/jsp/user/users.jsp</result> </action> <!-- delete user --> <action name="delete" class="fr.ifremer.echobase.ui.actions.UserAction"> - <interceptor-ref name="internalBasicStackLoggued"/> + <interceptor-ref name="basicStackLoggued"/> <interceptor-ref name="checkUserIsAdmin"/> - <result name="input">/WEB-INF/jsp/admin/users.jsp</result> + <result name="input">/WEB-INF/jsp/user/users.jsp</result> </action> </package> Added: trunk/echobase-ui/src/main/resources/echobase.properties =================================================================== --- trunk/echobase-ui/src/main/resources/echobase.properties (rev 0) +++ trunk/echobase-ui/src/main/resources/echobase.properties 2011-11-04 14:01:05 UTC (rev 12) @@ -0,0 +1,8 @@ +hibernate.hbm2ddl.auto=none +hibernate.show_sql=false +hibernate.dialect=org.hibernate.dialect.H2Dialect + +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:file:${data.directory}/db/h2data +hibernate.connection.username=sa +hibernate.connection.password=sa \ No newline at end of file Added: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/LoginAction-login-validation.xml =================================================================== --- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/LoginAction-login-validation.xml (rev 0) +++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/LoginAction-login-validation.xml 2011-11-04 14:01:05 UTC (rev 12) @@ -0,0 +1,36 @@ +<!-- + #%L + T3 :: Web + + $Id: LoginAction-login-validation.xml 614 2011-10-22 00:49:05Z chemit $ + $HeadURL: https://svn.mpl.ird.fr/osiris/t3/trunk/t3-web/src/main/resources/fr/ird/t3/w... $ + %% + Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit + %% + 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% + --> +<!DOCTYPE validators PUBLIC + "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> +<validators> + + <field name="email"> + + <field-validator type="login"> + <message/> + </field-validator> + </field> + +</validators> Modified: trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties =================================================================== --- trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-04 14:01:05 UTC (rev 12) @@ -26,3 +26,5 @@ echobase.title.login=Connection echobase.title.users=Adminitration des utilisateurs echobase.user.gridTitle=Liste des utilisateurs +t3.error.bad.password= +t3.error.login.unknown= Modified: trunk/echobase-ui/src/main/resources/struts.xml =================================================================== --- trunk/echobase-ui/src/main/resources/struts.xml 2011-11-04 12:50:20 UTC (rev 11) +++ trunk/echobase-ui/src/main/resources/struts.xml 2011-11-04 14:01:05 UTC (rev 12) @@ -117,12 +117,6 @@ <interceptor-ref name="echoBaseParamsPrepareParamsStack"/> </interceptor-stack> - <interceptor-stack name="execAndwaitStackLoggued"> - <interceptor-ref name="loginAndActionContext"/> - <interceptor-ref name="echoBaseParamsPrepareParamsStack"/> - <interceptor-ref name="execAndWait"/> - </interceptor-stack> - </interceptors> <!-- must be authenticated to perform any actions --> Added: trunk/echobase-ui/src/main/resources/validators.xml =================================================================== --- trunk/echobase-ui/src/main/resources/validators.xml (rev 0) +++ trunk/echobase-ui/src/main/resources/validators.xml 2011-11-04 14:01:05 UTC (rev 12) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE validators PUBLIC + "-//OpenSymphony Group//XWork Validator Config 1.0//EN" + "http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd"> +<validators> + <!-- default validators from XWork framework --> + <validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/> + <validator name="long" class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/> + <validator name="short" class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/> + <validator name="double" class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/> + <validator name="date" class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/> + <validator name="expression" class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/> + <validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/> + <validator name="conversion" class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/> + <validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/> + + <!-- default nuiton-validator validators --> + <validator name="fieldexpressionwithparams" class="org.nuiton.validator.xwork2.field.FieldExpressionWithParamsValidator"/> + <validator name="required" class="org.nuiton.validator.xwork2.field.SkipableRequiredFieldValidator"/> + <validator name="requiredstring" class="org.nuiton.validator.xwork2.field.SkipableRequiredStringFieldValidator"/> + + <!-- EchoBase validators --> + <validator name="login" class="fr.ifremer.echobase.ui.validators.LoginValidator"/> + +</validators>