Author: tchemit Date: 2008-01-24 20:37:52 +0000 (Thu, 24 Jan 2008) New Revision: 508 Added: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java Removed: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java Modified: trunk/simexplorer-is-security/pom.xml trunk/simexplorer-is-service/pom.xml Log: ajout description du module + suppression d?\195?\169pendances inutiles suite au d?\195?\169placement du service vers le module service Modified: trunk/simexplorer-is-security/pom.xml =================================================================== --- trunk/simexplorer-is-security/pom.xml 2008-01-24 20:10:18 UTC (rev 507) +++ trunk/simexplorer-is-security/pom.xml 2008-01-24 20:37:52 UTC (rev 508) @@ -10,7 +10,7 @@ <name>Security</name> <version>0.0.1-SNAPSHOT</version> - <description></description> + <description>SimExplorer SI security module</description> <packaging>ejb</packaging> <parent> @@ -43,11 +43,11 @@ <artifactId>h2</artifactId> <version>1.0.64</version> </dependency> - <dependency> + <!--dependency> <groupId>jboss</groupId> <artifactId>jbossall-client</artifactId> <version>4.2.2.GA</version> <scope>provided</scope> - </dependency> + </dependency--> </dependencies> </project> Deleted: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java =================================================================== --- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java 2008-01-24 20:10:18 UTC (rev 507) +++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java 2008-01-24 20:37:52 UTC (rev 508) @@ -1,79 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.security.service; - -import javax.ejb.Remote; - -import fr.cemagref.simexplorer.is.security.entities.Group; -import fr.cemagref.simexplorer.is.security.entities.User; - - at Remote -public interface AuthenticationService { - - public String loginUser(String login, String password); - - public void closeSessionTimer(String token); - - public User requestAccount(String login, String mail); - - public User saveUser(String token, String login, String mail); - - public void resetPassword(String token, String login); - - public void changePassword(String token, String login, String password); - - public User getUser(String token, Integer id); - - public User getUser(String token, String login); - - public User updateUser(String token, User user); - - public void deleteUser(String token, Integer id); - - public User[] getUsers(String token); - - public User[] getUsersOfGroup(String token, Group group); - - public void setUsersOfGroup(String token, Group group, - Integer[] usersInGroup); - - public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds); - - public Group[] getGroupsOfUser(String token, User user); - - public Group[] getGroupsOfGroup(String token, Group group); - - public void setGroupsOfUser(String token, User user, Integer[] groupsIds); - - public Group saveGroup(String token, String name, User owner); - - public Group getGroup(String token, Integer id); - - public Group getGroup(String token, String name); - - public Group updateGroup(String token, Group group); - - public void deleteGroup(String token, Integer id); - - public Group[] getGroups(String token); - - public Group[] getGroupsOwnedBy(String token, User user); - - public User getLoggedUser(String token); - -} Deleted: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java =================================================================== --- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java 2008-01-24 20:10:18 UTC (rev 507) +++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508) @@ -1,331 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.security.service; - -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.UUID; -import java.util.Arrays; - -import javax.annotation.Resource; -import javax.ejb.EJB; -import javax.ejb.Remote; -import javax.ejb.SessionContext; -import javax.ejb.Stateless; -import javax.ejb.Timeout; -import javax.ejb.Timer; -import javax.ejb.TimerService; -import javax.ejb.TransactionAttribute; -import javax.ejb.TransactionAttributeType; - -import org.jboss.annotation.ejb.RemoteBinding; - -import fr.cemagref.simexplorer.is.security.dao.DaoSecurity; -import fr.cemagref.simexplorer.is.security.entities.Group; -import fr.cemagref.simexplorer.is.security.entities.LoginAction; -import fr.cemagref.simexplorer.is.security.entities.User; - - at Stateless(name = "AuthenticationService") - at Remote(AuthenticationService.class) - at RemoteBinding(jndiBinding = "AuthenticationService") - at TransactionAttribute(TransactionAttributeType.REQUIRED) -public class AuthenticationServiceImpl implements AuthenticationService { - - @EJB - private DaoSecurity dao; - - @Resource - private SessionContext sessionContext; - - private static boolean superAdminCheck = false; - - private void sendMail(String login, String mail, String password) { - /* - javax.mail.Session mailSession = (javax.mail.Session) new InitialContext().lookup("java:/Mail"); - javax.mail.Message msg = new MimeMessage(mailSession); - msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse("AQui at aQui.be,siplusieuradresse at hotmail.com", false)); - msg.setSubject("This is a test"); - msg.setContent("<html><body><h2>Helle le monde mondial des terriens " + - " Petit test de jboss Mail-Service" + - " Ne m'en voulez pas si vous recevez ce mail alors que vous nedevrez pas " + - " Braim " + - "</h2></body></html>", "text/html"); - msg.setHeader("X-Mailer", "JavaMailer"); - msg.setSentDate(new java.util.Date()); - Transport.send(msg); - */ - } - - private String computeHash(String clearString) { - MessageDigest messageDigest = null; - try { - messageDigest = MessageDigest.getInstance("SHA-1"); - } catch (Exception e) { - // TODO: handle exception - } - messageDigest.reset(); - messageDigest.update(clearString.getBytes()); - String hashedPassword; - hashedPassword = new String(messageDigest.digest()); - return hashedPassword; - } - - private String generatePassword() { - // FIXME - return "password"; - } - - private void removeUserFromGroup(User user, Group group) { - List<Group> toRemove = new ArrayList<Group>(); - for (Group testGroup : user.getGroups()) { - if (testGroup.getId().equals(group.getId())) { - toRemove.add(testGroup); - } - } - for (Group groupToRemove : toRemove) { - user.getGroups().remove(groupToRemove); - } - } - - public void deleteGroup(String token, Integer id) { - dao.deleteGroup(id); - } - - public void deleteUser(String token, Integer id) { - dao.deleteUser(id); - } - - public Group getGroup(String token, Integer id) { - return dao.getGroup(id); - } - - public Group getGroup(String token, String name) { - return dao.getGroup(name); - } - - public User getUser(String token, Integer id) { - return dao.getUser(id); - } - - public User getUser(String token, String login) { - return dao.getUser(login); - } - - public Group saveGroup(String token, String name, User owner) { - Group group = new Group(); - group.setName(name); - group.setOwner(owner); - dao.saveGroup(group); - group = getGroup(token, group.getId()); - return group; - } - - public User saveUser(String token, String login, String mail) { - User user = new User(); - user.setLogin(login); - user.setMail(mail); - String password = generatePassword(); - sendMail(login, mail, password); - String passwordHash = computeHash(password); - user.setPasswordHash(passwordHash); - user.setAdmin(false); - user.setSuperAdmin(false); - dao.saveUser(user); - user = getUser(token, user.getId()); - return user; - } - - public Group updateGroup(String token, Group group) { - return dao.updateGroup(group); - } - - public User updateUser(String token, User user) { - return dao.updateUser(user); - } - - public User getLoggedUser(String token) { - User loggedUser; - loggedUser = dao.getLoggedUser(token); - return loggedUser; - } - - private void checkSuperAdmin() { - if (dao.getUser("superadmin") == null) { - User user = new User(); - user.setLogin("superadmin"); - user.setMail(""); - String password = "password"; - String passwordHash = computeHash(password); - user.setPasswordHash(passwordHash); - user.setAdmin(true); - user.setSuperAdmin(true); - dao.saveUser(user); - } - } - - public String loginUser(String login, String password) { - if (!superAdminCheck) { - checkSuperAdmin(); - superAdminCheck = true; - } - String token = null; - User loggedUser = dao.loginUser(login, computeHash(password)); - if (loggedUser != null) { - LoginAction loginAction = new LoginAction(); - loginAction.setLoggedUser(loggedUser); - loginAction.setTime(new Date()); - loginAction.setToken(UUID.randomUUID().toString()); - dao.saveToken(loginAction); - token = loginAction.getToken(); - } - return token; - } - - public void closeSessionTimer(String token) { - // FIXME session length - TimerService timerService = sessionContext.getTimerService(); - timerService.createTimer(10 * 60 * 1000, token); - } - - @Timeout - public void timeoutHandler(Timer timer) { - String token = (String) timer.getInfo(); - dao.deleteToken(token); - } - - public User requestAccount(String login, String mail) { - User user = new User(); - user.setLogin(login); - user.setMail(mail); - String password = generatePassword(); - sendMail(login, mail, password); - String passwordHash = computeHash(password); - user.setPasswordHash(passwordHash); - dao.saveUser(user); - return user; - } - - public void changePassword(String token, String login, String password) { - User user = getUser(token, login); - String passwordHash = computeHash(password); - user.setPasswordHash(passwordHash); - dao.saveUser(user); - } - - public void resetPassword(String token, String login) { - User user = getUser(token, login); - String password = generatePassword(); - sendMail(login, user.getMail(), password); - String passwordHash = computeHash(password); - user.setPasswordHash(passwordHash); - dao.saveUser(user); - } - - public Group[] getGroups(String token) { - List<Group> groups = dao.getGroups(); - Group[] result; - result = groups.toArray(new Group[groups.size()]); - return result; - } - - public Group[] getGroupsOwnedBy(String token, User user) { - List<Group> list = dao.getGroupsOwnedBy(user); - return list.toArray(new Group[list.size()]); - } - - public User[] getUsers(String token) { - return dao.getUsers().toArray(new User[dao.getUsers().size()]); - } - - public User[] getUsersOfGroup(String token, Group group) { - List<User> usersOfGroup = dao.getUsersOfGroup(group); - return usersOfGroup.toArray(new User[usersOfGroup.size()]); - } - - public void setUsersOfGroup(String token, Group group, - Integer[] usersInGroup) { - List<Integer> newUsers = new ArrayList<Integer>(); - newUsers.addAll(Arrays.asList(usersInGroup)); - - List<Integer> usersToAdd = new ArrayList<Integer>(); - List<Integer> usersToRemove = new ArrayList<Integer>(); - - List<User> users = dao.getUsersOfGroup(group); - - List<Integer> currentUsers = new ArrayList<Integer>(); - for (User user : users) { - currentUsers.add(user.getId()); - } - - for (Integer user : currentUsers) { - if (!newUsers.contains(user)) { - usersToRemove.add(user); - } - } - for (Integer user : newUsers) { - if (!currentUsers.contains(user)) { - usersToAdd.add(user); - } - } - - for (Integer idUser : usersToAdd) { - User user = dao.getUser(idUser); - user.getGroups().add(group); - dao.updateUser(user); - } - for (Integer idUser : usersToRemove) { - User user = dao.getUser(idUser); - removeUserFromGroup(user, group); - dao.updateUser(user); - } - } - - public void setGroupsOfUser(String token, User user, Integer[] groupsIds) { - User realUser = dao.getUser(user.getId()); - realUser.getGroups().clear(); - for (Integer groupsId : groupsIds) { - Group group = dao.getGroup(groupsId); - realUser.getGroups().add(group); - } - dao.updateUser(realUser); - - } - - public Group[] getGroupsOfUser(String token, User user) { - List<Group> list = dao.getGroupsOfUser(user); - return list.toArray(new Group[list.size()]); - } - - public Group[] getGroupsOfGroup(String token, Group group) { - List<Group> groupsOfGroup = dao.getGroupsOfGroup(group); - return groupsOfGroup.toArray(new Group[groupsOfGroup.size()]); - } - - public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) { - Group realGroup = dao.getGroup(group.getId()); - realGroup.getGroups().clear(); - for (Integer groupsId : groupsIds) { - Group groupOwned = dao.getGroup(groupsId); - realGroup.getGroups().add(groupOwned); - } - dao.updateGroup(realGroup); - } - -} Deleted: trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java =================================================================== --- trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java 2008-01-24 20:10:18 UTC (rev 507) +++ trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508) @@ -1,130 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Tony Chemit, Gabriel Landais -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.security.service; - -import fr.cemagref.simexplorer.is.security.entities.Group; -import fr.cemagref.simexplorer.is.security.entities.User; - - -public class MockAuthenticationServiceImpl implements AuthenticationService { - - - public String loginUser(String login, String password) { - return (String) checkImplemented(); - } - - public void closeSessionTimer(String token) { - checkImplemented(); - } - - public User requestAccount(String login, String mail) { - return (User) checkImplemented(); - } - - public User saveUser(String token, String login, String mail) { - return (User) checkImplemented(); - } - - public void resetPassword(String token, String login) { - checkImplemented(); - } - - public void changePassword(String token, String login, String password) { - checkImplemented(); - } - - public User getUser(String token, Integer id) { - return (User) checkImplemented(); - } - - public User getUser(String token, String login) { - return (User) checkImplemented(); - } - - public User updateUser(String token, User user) { - return (User) checkImplemented(); - } - - public void deleteUser(String token, Integer id) { - checkImplemented(); - } - - public User[] getUsers(String token) { - return (User[]) checkImplemented(); - } - - public User[] getUsersOfGroup(String token, Group group) { - return (User[]) checkImplemented(); - } - - public void setUsersOfGroup(String token, Group group, Integer[] usersInGroup) { - checkImplemented(); - } - - public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) { - checkImplemented(); - } - - public Group[] getGroupsOfUser(String token, User user) { - return (Group[]) checkImplemented(); - } - - public Group[] getGroupsOfGroup(String token, Group group) { - return (Group[]) checkImplemented(); - } - - public void setGroupsOfUser(String token, User user, Integer[] groupsIds) { - checkImplemented(); - } - - public Group saveGroup(String token, String name, User owner) { - return (Group) checkImplemented(); - } - - public Group getGroup(String token, Integer id) { - return (Group) checkImplemented(); - } - - public Group getGroup(String token, String name) { - return (Group) checkImplemented(); - } - - public Group updateGroup(String token, Group group) { - return (Group) checkImplemented(); - } - - public void deleteGroup(String token, Integer id) { - checkImplemented(); - } - - public Group[] getGroups(String token) { - return (Group[]) checkImplemented(); - } - - public Group[] getGroupsOwnedBy(String token, User user) { - return (Group[]) checkImplemented(); - } - - public User getLoggedUser(String token) { - return (User) checkImplemented(); - } - - private Object checkImplemented() { - throw new IllegalStateException("not implemented"); - } -} \ No newline at end of file Deleted: trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java =================================================================== --- trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java 2008-01-24 20:10:18 UTC (rev 507) +++ trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java 2008-01-24 20:37:52 UTC (rev 508) @@ -1,61 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.security.test; - -import java.util.Properties; - -import javax.naming.Context; -import javax.naming.InitialContext; - -import junit.framework.TestCase; -import fr.cemagref.simexplorer.is.security.entities.User; -import fr.cemagref.simexplorer.is.security.service.AuthenticationService; - -public class SecurityEqualsTestCase extends TestCase { - - AuthenticationService authenticationService = null; - - @Override - protected void setUp() throws Exception { - super.setUp(); - Properties properties = (Properties) System.getProperties().clone(); - properties.put("java.naming.provider.url", "jnp://localhost:1099"); - properties.put("java.naming.factory.initial", - "org.jnp.interfaces.NamingContextFactory"); - properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces"); - - Context context = new InitialContext(properties); - authenticationService = (AuthenticationService) context - .lookup("AuthenticationService"); - - } - - public void testHashCode() { - String token = authenticationService.loginUser("superadmin", "password"); - User[] users1 = authenticationService.getUsers(token); - User[] users2 = authenticationService.getUsers(token); - for (int i = 0; i < users1.length; i++) { - User user1 = users1[i]; - User user2 = users2[i]; - System.out.println("User " + i + " :"); - System.out.println(user1.hashCode() + " " + user2.hashCode()); - System.out.println(user1.equals(user2)); - } - } - -} Deleted: trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java =================================================================== --- trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java 2008-01-24 20:10:18 UTC (rev 507) +++ trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java 2008-01-24 20:37:52 UTC (rev 508) @@ -1,128 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.security.test; - -import java.util.Properties; - -import javax.naming.Context; -import javax.naming.InitialContext; - -import junit.framework.TestCase; -import fr.cemagref.simexplorer.is.security.entities.Group; -import fr.cemagref.simexplorer.is.security.entities.User; -import fr.cemagref.simexplorer.is.security.service.AuthenticationService; - -public class SecurityTestCase extends TestCase { - - AuthenticationService authenticationService = null; - - @Override - protected void setUp() throws Exception { - super.setUp(); - Properties properties = (Properties) System.getProperties().clone(); - properties.put("java.naming.provider.url", "jnp://localhost:1099"); - properties.put("java.naming.factory.initial", - "org.jnp.interfaces.NamingContextFactory"); - properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces"); - - Context context = new InitialContext(properties); - authenticationService = (AuthenticationService) context - .lookup("AuthenticationService"); - - } - - public void testSecurityEntities() { - /* - User user = authenticationService.getUser("user3"); - Group[] groups = authenticationService.getGroupsOfUser(user); - for (Group group : groups) { - System.out.println(group.getName()); - } - */ - String token = authenticationService - .loginUser("superadmin", "password"); - - Group everybody = authenticationService.saveGroup(token, "everybody", - authenticationService.getLoggedUser(token)); - - User me = authenticationService.getLoggedUser(token); - me.getGroups().add(everybody); - authenticationService.updateUser(token, me); - - User[] simpleUsers = new User[20]; - for (int i = 0; i < 20; i++) { - simpleUsers[i] = authenticationService.saveUser(token, "user" + i, - "landais+simtest at codelutin.com"); - simpleUsers[i].setAdmin(false); - simpleUsers[i].setSuperAdmin(false); - simpleUsers[i].getGroups().add(everybody); - authenticationService.updateUser(token, simpleUsers[i]); - } - - User[] adminUsers = new User[4]; - Group[] groups = new Group[4]; - for (int i = 0; i < 4; i++) { - adminUsers[i] = authenticationService.saveUser(token, "admin" + i, - "landais+simtest at codelutin.com"); - adminUsers[i].setAdmin(true); - adminUsers[i].setSuperAdmin(false); - adminUsers[i].getGroups().add(everybody); - authenticationService.updateUser(token, adminUsers[i]); - - groups[i] = authenticationService.saveGroup(token, "group" + i, - adminUsers[i]); - for (int j = i * 4; j < (i * 4 + 5); j++) { - simpleUsers[j].getGroups().add(groups[i]); - authenticationService.updateUser(token, simpleUsers[j]); - } - } - - /* - User superAdminUser = authenticationService.saveUser(token, - "superadmin", "landais+simtest at codelutin.com"); - superAdminUser.setAdmin(true); - superAdminUser.setSuperAdmin(true); - authenticationService.updateUser(token, superAdminUser); - */ - - /* - User[] users = new User[10]; - Group[] groups = new Group[10]; - for (int i = 0; i < 10; i++) { - users[i] = authenticationService.saveUser("user" + i, - "user1 at abc.fr"); - users[i].setAdmin(true); - users[i].setSuperAdmin(true); - authenticationService.updateUser(users[i]); - groups[i] = authenticationService.saveGroup("group" + i, users[i]); - } - - for (int i = 0; i < 10; i++) { - System.out.println(users[i].getId()); - System.out.println(groups[i].getId()); - } - - String token = authenticationService.loginUser(users[4].getLogin(), - "hierugheriugh"); - User userLogged = authenticationService.getLoggedUser(token); - - assertEquals(userLogged.getLogin(), users[4].getLogin()); - */ - } - -} Modified: trunk/simexplorer-is-service/pom.xml =================================================================== --- trunk/simexplorer-is-service/pom.xml 2008-01-24 20:10:18 UTC (rev 507) +++ trunk/simexplorer-is-service/pom.xml 2008-01-24 20:37:52 UTC (rev 508) @@ -44,5 +44,11 @@ <version>4.2.2.GA</version> <scope>provided</scope> </dependency> - </dependencies> + <dependency> + <groupId>jboss</groupId> + <artifactId>jbossall-client</artifactId> + <version>4.2.2.GA</version> + <scope>provided</scope> + </dependency> + </dependencies> </project> Copied: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java (from rev 506, trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationService.java) =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java (rev 0) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java 2008-01-24 20:37:52 UTC (rev 508) @@ -0,0 +1,79 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 2 +* 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, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.service; + +import javax.ejb.Remote; + +import fr.cemagref.simexplorer.is.security.entities.Group; +import fr.cemagref.simexplorer.is.security.entities.User; + + at Remote +public interface AuthenticationService { + + public String loginUser(String login, String password); + + public void closeSessionTimer(String token); + + public User requestAccount(String login, String mail); + + public User saveUser(String token, String login, String mail); + + public void resetPassword(String token, String login); + + public void changePassword(String token, String login, String password); + + public User getUser(String token, Integer id); + + public User getUser(String token, String login); + + public User updateUser(String token, User user); + + public void deleteUser(String token, Integer id); + + public User[] getUsers(String token); + + public User[] getUsersOfGroup(String token, Group group); + + public void setUsersOfGroup(String token, Group group, + Integer[] usersInGroup); + + public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds); + + public Group[] getGroupsOfUser(String token, User user); + + public Group[] getGroupsOfGroup(String token, Group group); + + public void setGroupsOfUser(String token, User user, Integer[] groupsIds); + + public Group saveGroup(String token, String name, User owner); + + public Group getGroup(String token, Integer id); + + public Group getGroup(String token, String name); + + public Group updateGroup(String token, Group group); + + public void deleteGroup(String token, Integer id); + + public Group[] getGroups(String token); + + public Group[] getGroupsOwnedBy(String token, User user); + + public User getLoggedUser(String token); + +} Copied: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java (from rev 506, trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/AuthenticationServiceImpl.java) =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java (rev 0) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508) @@ -0,0 +1,331 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 2 +* 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, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.service; + +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; +import java.util.Arrays; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.Remote; +import javax.ejb.SessionContext; +import javax.ejb.Stateless; +import javax.ejb.Timeout; +import javax.ejb.Timer; +import javax.ejb.TimerService; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; + +import org.jboss.annotation.ejb.RemoteBinding; + +import fr.cemagref.simexplorer.is.security.dao.DaoSecurity; +import fr.cemagref.simexplorer.is.security.entities.Group; +import fr.cemagref.simexplorer.is.security.entities.LoginAction; +import fr.cemagref.simexplorer.is.security.entities.User; + + at Stateless(name = "AuthenticationService") + at Remote(AuthenticationService.class) + at RemoteBinding(jndiBinding = "AuthenticationService") + at TransactionAttribute(TransactionAttributeType.REQUIRED) +public class AuthenticationServiceImpl implements AuthenticationService { + + @EJB + private DaoSecurity dao; + + @Resource + private SessionContext sessionContext; + + private static boolean superAdminCheck = false; + + private void sendMail(String login, String mail, String password) { + /* + javax.mail.Session mailSession = (javax.mail.Session) new InitialContext().lookup("java:/Mail"); + javax.mail.Message msg = new MimeMessage(mailSession); + msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse("AQui at aQui.be,siplusieuradresse at hotmail.com", false)); + msg.setSubject("This is a test"); + msg.setContent("<html><body><h2>Helle le monde mondial des terriens " + + " Petit test de jboss Mail-Service" + + " Ne m'en voulez pas si vous recevez ce mail alors que vous nedevrez pas " + + " Braim " + + "</h2></body></html>", "text/html"); + msg.setHeader("X-Mailer", "JavaMailer"); + msg.setSentDate(new java.util.Date()); + Transport.send(msg); + */ + } + + private String computeHash(String clearString) { + MessageDigest messageDigest = null; + try { + messageDigest = MessageDigest.getInstance("SHA-1"); + } catch (Exception e) { + // TODO: handle exception + } + messageDigest.reset(); + messageDigest.update(clearString.getBytes()); + String hashedPassword; + hashedPassword = new String(messageDigest.digest()); + return hashedPassword; + } + + private String generatePassword() { + // FIXME + return "password"; + } + + private void removeUserFromGroup(User user, Group group) { + List<Group> toRemove = new ArrayList<Group>(); + for (Group testGroup : user.getGroups()) { + if (testGroup.getId().equals(group.getId())) { + toRemove.add(testGroup); + } + } + for (Group groupToRemove : toRemove) { + user.getGroups().remove(groupToRemove); + } + } + + public void deleteGroup(String token, Integer id) { + dao.deleteGroup(id); + } + + public void deleteUser(String token, Integer id) { + dao.deleteUser(id); + } + + public Group getGroup(String token, Integer id) { + return dao.getGroup(id); + } + + public Group getGroup(String token, String name) { + return dao.getGroup(name); + } + + public User getUser(String token, Integer id) { + return dao.getUser(id); + } + + public User getUser(String token, String login) { + return dao.getUser(login); + } + + public Group saveGroup(String token, String name, User owner) { + Group group = new Group(); + group.setName(name); + group.setOwner(owner); + dao.saveGroup(group); + group = getGroup(token, group.getId()); + return group; + } + + public User saveUser(String token, String login, String mail) { + User user = new User(); + user.setLogin(login); + user.setMail(mail); + String password = generatePassword(); + sendMail(login, mail, password); + String passwordHash = computeHash(password); + user.setPasswordHash(passwordHash); + user.setAdmin(false); + user.setSuperAdmin(false); + dao.saveUser(user); + user = getUser(token, user.getId()); + return user; + } + + public Group updateGroup(String token, Group group) { + return dao.updateGroup(group); + } + + public User updateUser(String token, User user) { + return dao.updateUser(user); + } + + public User getLoggedUser(String token) { + User loggedUser; + loggedUser = dao.getLoggedUser(token); + return loggedUser; + } + + private void checkSuperAdmin() { + if (dao.getUser("superadmin") == null) { + User user = new User(); + user.setLogin("superadmin"); + user.setMail(""); + String password = "password"; + String passwordHash = computeHash(password); + user.setPasswordHash(passwordHash); + user.setAdmin(true); + user.setSuperAdmin(true); + dao.saveUser(user); + } + } + + public String loginUser(String login, String password) { + if (!superAdminCheck) { + checkSuperAdmin(); + superAdminCheck = true; + } + String token = null; + User loggedUser = dao.loginUser(login, computeHash(password)); + if (loggedUser != null) { + LoginAction loginAction = new LoginAction(); + loginAction.setLoggedUser(loggedUser); + loginAction.setTime(new Date()); + loginAction.setToken(UUID.randomUUID().toString()); + dao.saveToken(loginAction); + token = loginAction.getToken(); + } + return token; + } + + public void closeSessionTimer(String token) { + // FIXME session length + TimerService timerService = sessionContext.getTimerService(); + timerService.createTimer(10 * 60 * 1000, token); + } + + @Timeout + public void timeoutHandler(Timer timer) { + String token = (String) timer.getInfo(); + dao.deleteToken(token); + } + + public User requestAccount(String login, String mail) { + User user = new User(); + user.setLogin(login); + user.setMail(mail); + String password = generatePassword(); + sendMail(login, mail, password); + String passwordHash = computeHash(password); + user.setPasswordHash(passwordHash); + dao.saveUser(user); + return user; + } + + public void changePassword(String token, String login, String password) { + User user = getUser(token, login); + String passwordHash = computeHash(password); + user.setPasswordHash(passwordHash); + dao.saveUser(user); + } + + public void resetPassword(String token, String login) { + User user = getUser(token, login); + String password = generatePassword(); + sendMail(login, user.getMail(), password); + String passwordHash = computeHash(password); + user.setPasswordHash(passwordHash); + dao.saveUser(user); + } + + public Group[] getGroups(String token) { + List<Group> groups = dao.getGroups(); + Group[] result; + result = groups.toArray(new Group[groups.size()]); + return result; + } + + public Group[] getGroupsOwnedBy(String token, User user) { + List<Group> list = dao.getGroupsOwnedBy(user); + return list.toArray(new Group[list.size()]); + } + + public User[] getUsers(String token) { + return dao.getUsers().toArray(new User[dao.getUsers().size()]); + } + + public User[] getUsersOfGroup(String token, Group group) { + List<User> usersOfGroup = dao.getUsersOfGroup(group); + return usersOfGroup.toArray(new User[usersOfGroup.size()]); + } + + public void setUsersOfGroup(String token, Group group, + Integer[] usersInGroup) { + List<Integer> newUsers = new ArrayList<Integer>(); + newUsers.addAll(Arrays.asList(usersInGroup)); + + List<Integer> usersToAdd = new ArrayList<Integer>(); + List<Integer> usersToRemove = new ArrayList<Integer>(); + + List<User> users = dao.getUsersOfGroup(group); + + List<Integer> currentUsers = new ArrayList<Integer>(); + for (User user : users) { + currentUsers.add(user.getId()); + } + + for (Integer user : currentUsers) { + if (!newUsers.contains(user)) { + usersToRemove.add(user); + } + } + for (Integer user : newUsers) { + if (!currentUsers.contains(user)) { + usersToAdd.add(user); + } + } + + for (Integer idUser : usersToAdd) { + User user = dao.getUser(idUser); + user.getGroups().add(group); + dao.updateUser(user); + } + for (Integer idUser : usersToRemove) { + User user = dao.getUser(idUser); + removeUserFromGroup(user, group); + dao.updateUser(user); + } + } + + public void setGroupsOfUser(String token, User user, Integer[] groupsIds) { + User realUser = dao.getUser(user.getId()); + realUser.getGroups().clear(); + for (Integer groupsId : groupsIds) { + Group group = dao.getGroup(groupsId); + realUser.getGroups().add(group); + } + dao.updateUser(realUser); + + } + + public Group[] getGroupsOfUser(String token, User user) { + List<Group> list = dao.getGroupsOfUser(user); + return list.toArray(new Group[list.size()]); + } + + public Group[] getGroupsOfGroup(String token, Group group) { + List<Group> groupsOfGroup = dao.getGroupsOfGroup(group); + return groupsOfGroup.toArray(new Group[groupsOfGroup.size()]); + } + + public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) { + Group realGroup = dao.getGroup(group.getId()); + realGroup.getGroups().clear(); + for (Integer groupsId : groupsIds) { + Group groupOwned = dao.getGroup(groupsId); + realGroup.getGroups().add(groupOwned); + } + dao.updateGroup(realGroup); + } + +} Copied: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java (from rev 506, trunk/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/service/MockAuthenticationServiceImpl.java) =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java (rev 0) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockAuthenticationServiceImpl.java 2008-01-24 20:37:52 UTC (rev 508) @@ -0,0 +1,130 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Tony Chemit, Gabriel Landais +* +* 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 2 +* 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, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.service; + +import fr.cemagref.simexplorer.is.security.entities.Group; +import fr.cemagref.simexplorer.is.security.entities.User; + + +public class MockAuthenticationServiceImpl implements AuthenticationService { + + + public String loginUser(String login, String password) { + return (String) checkImplemented(); + } + + public void closeSessionTimer(String token) { + checkImplemented(); + } + + public User requestAccount(String login, String mail) { + return (User) checkImplemented(); + } + + public User saveUser(String token, String login, String mail) { + return (User) checkImplemented(); + } + + public void resetPassword(String token, String login) { + checkImplemented(); + } + + public void changePassword(String token, String login, String password) { + checkImplemented(); + } + + public User getUser(String token, Integer id) { + return (User) checkImplemented(); + } + + public User getUser(String token, String login) { + return (User) checkImplemented(); + } + + public User updateUser(String token, User user) { + return (User) checkImplemented(); + } + + public void deleteUser(String token, Integer id) { + checkImplemented(); + } + + public User[] getUsers(String token) { + return (User[]) checkImplemented(); + } + + public User[] getUsersOfGroup(String token, Group group) { + return (User[]) checkImplemented(); + } + + public void setUsersOfGroup(String token, Group group, Integer[] usersInGroup) { + checkImplemented(); + } + + public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) { + checkImplemented(); + } + + public Group[] getGroupsOfUser(String token, User user) { + return (Group[]) checkImplemented(); + } + + public Group[] getGroupsOfGroup(String token, Group group) { + return (Group[]) checkImplemented(); + } + + public void setGroupsOfUser(String token, User user, Integer[] groupsIds) { + checkImplemented(); + } + + public Group saveGroup(String token, String name, User owner) { + return (Group) checkImplemented(); + } + + public Group getGroup(String token, Integer id) { + return (Group) checkImplemented(); + } + + public Group getGroup(String token, String name) { + return (Group) checkImplemented(); + } + + public Group updateGroup(String token, Group group) { + return (Group) checkImplemented(); + } + + public void deleteGroup(String token, Integer id) { + checkImplemented(); + } + + public Group[] getGroups(String token) { + return (Group[]) checkImplemented(); + } + + public Group[] getGroupsOwnedBy(String token, User user) { + return (Group[]) checkImplemented(); + } + + public User getLoggedUser(String token) { + return (User) checkImplemented(); + } + + private Object checkImplemented() { + throw new IllegalStateException("not implemented"); + } +} \ No newline at end of file Copied: trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java (from rev 506, trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityEqualsTestCase.java) =================================================================== --- trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java (rev 0) +++ trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityEqualsTestCase.java 2008-01-24 20:37:52 UTC (rev 508) @@ -0,0 +1,61 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 2 +* 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, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.service; + +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import junit.framework.TestCase; +import fr.cemagref.simexplorer.is.security.entities.User; + +public class SecurityEqualsTestCase extends TestCase { + + AuthenticationService authenticationService = null; + + @Override + protected void setUp() throws Exception { + super.setUp(); + Properties properties = (Properties) System.getProperties().clone(); + properties.put("java.naming.provider.url", "jnp://localhost:1099"); + properties.put("java.naming.factory.initial", + "org.jnp.interfaces.NamingContextFactory"); + properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces"); + + Context context = new InitialContext(properties); + authenticationService = (AuthenticationService) context + .lookup("AuthenticationService"); + + } + + public void testHashCode() { + String token = authenticationService.loginUser("superadmin", "password"); + User[] users1 = authenticationService.getUsers(token); + User[] users2 = authenticationService.getUsers(token); + for (int i = 0; i < users1.length; i++) { + User user1 = users1[i]; + User user2 = users2[i]; + System.out.println("User " + i + " :"); + System.out.println(user1.hashCode() + " " + user2.hashCode()); + assertEquals(user1.hashCode(),user2.hashCode()); + assertEquals(user1,user2); + } + } + +} Copied: trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java (from rev 506, trunk/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/test/SecurityTestCase.java) =================================================================== --- trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java (rev 0) +++ trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/SecurityTestCase.java 2008-01-24 20:37:52 UTC (rev 508) @@ -0,0 +1,127 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 2 +* 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, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.service; + +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import junit.framework.TestCase; +import fr.cemagref.simexplorer.is.security.entities.Group; +import fr.cemagref.simexplorer.is.security.entities.User; + +public class SecurityTestCase extends TestCase { + + AuthenticationService authenticationService = null; + + @Override + protected void setUp() throws Exception { + super.setUp(); + Properties properties = (Properties) System.getProperties().clone(); + properties.put("java.naming.provider.url", "jnp://localhost:1099"); + properties.put("java.naming.factory.initial", + "org.jnp.interfaces.NamingContextFactory"); + properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces"); + + Context context = new InitialContext(properties); + authenticationService = (AuthenticationService) context + .lookup("AuthenticationService"); + + } + + public void testSecurityEntities() { + /* + User user = authenticationService.getUser("user3"); + Group[] groups = authenticationService.getGroupsOfUser(user); + for (Group group : groups) { + System.out.println(group.getName()); + } + */ + String token = authenticationService + .loginUser("superadmin", "password"); + + Group everybody = authenticationService.saveGroup(token, "everybody", + authenticationService.getLoggedUser(token)); + + User me = authenticationService.getLoggedUser(token); + me.getGroups().add(everybody); + authenticationService.updateUser(token, me); + + User[] simpleUsers = new User[20]; + for (int i = 0; i < 20; i++) { + simpleUsers[i] = authenticationService.saveUser(token, "user" + i, + "landais+simtest at codelutin.com"); + simpleUsers[i].setAdmin(false); + simpleUsers[i].setSuperAdmin(false); + simpleUsers[i].getGroups().add(everybody); + authenticationService.updateUser(token, simpleUsers[i]); + } + + User[] adminUsers = new User[4]; + Group[] groups = new Group[4]; + for (int i = 0; i < 4; i++) { + adminUsers[i] = authenticationService.saveUser(token, "admin" + i, + "landais+simtest at codelutin.com"); + adminUsers[i].setAdmin(true); + adminUsers[i].setSuperAdmin(false); + adminUsers[i].getGroups().add(everybody); + authenticationService.updateUser(token, adminUsers[i]); + + groups[i] = authenticationService.saveGroup(token, "group" + i, + adminUsers[i]); + for (int j = i * 4; j < (i * 4 + 5); j++) { + simpleUsers[j].getGroups().add(groups[i]); + authenticationService.updateUser(token, simpleUsers[j]); + } + } + + /* + User superAdminUser = authenticationService.saveUser(token, + "superadmin", "landais+simtest at codelutin.com"); + superAdminUser.setAdmin(true); + superAdminUser.setSuperAdmin(true); + authenticationService.updateUser(token, superAdminUser); + */ + + /* + User[] users = new User[10]; + Group[] groups = new Group[10]; + for (int i = 0; i < 10; i++) { + users[i] = authenticationService.saveUser("user" + i, + "user1 at abc.fr"); + users[i].setAdmin(true); + users[i].setSuperAdmin(true); + authenticationService.updateUser(users[i]); + groups[i] = authenticationService.saveGroup("group" + i, users[i]); + } + + for (int i = 0; i < 10; i++) { + System.out.println(users[i].getId()); + System.out.println(groups[i].getId()); + } + + String token = authenticationService.loginUser(users[4].getLogin(), + "hierugheriugh"); + User userLogged = authenticationService.getLoggedUser(token); + + assertEquals(userLogged.getLogin(), users[4].getLogin()); + */ + } + +}