Simexplorer-si-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- 1607 discussions
r1405 - trunk/simexplorer-is/simexplorer-is-swing-generated
by tchemit@users.labs.libre-entreprise.org 20 Mar '08
by tchemit@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: tchemit
Date: 2008-03-20 01:54:37 +0000 (Thu, 20 Mar 2008)
New Revision: 1405
Modified:
trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml
Log:
add commandline:genRst goal execution
todo define where to sotck this
Modified: trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml 2008-03-19 18:10:23 UTC (rev 1404)
+++ trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml 2008-03-20 01:54:37 UTC (rev 1405)
@@ -27,6 +27,7 @@
<properties>
<maven.verbose>false</maven.verbose>
<maven.java.src.dir>${maven.src.dir}/java</maven.java.src.dir>
+ <maven.classes.dir>${basedir}/target/classes</maven.classes.dir>
</properties>
</profile>
</profiles>
@@ -70,17 +71,28 @@
<version>0.3</version>
<configuration>
<prefix>SimExplorer</prefix>
+ <packageName>fr.cemagref.simexplorer.is.ui.swing.commandline</packageName>
<source>${maven.src.dir}/resources/commandline.properties</source>
- <out>${maven.java.src.dir}</out>
- <parserPackageName>fr.cemagref.simexplorer.is.ui.swing.commandline</parserPackageName>
<concreteConfig>true</concreteConfig>
+ <rstFilePath>${basedir}/target</rstFilePath>
+ <bundles>
+ <param>fr</param>
+ <param>en</param>
+ </bundles>
</configuration>
<executions>
<execution>
+ <id>genJava</id>
<goals>
<goal>genJava</goal>
</goals>
</execution>
+ <execution>
+ <id>genRst</id>
+ <goals>
+ <goal>genRst</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
<plugin>
1
0
r1404 - in trunk/simexplorer-is: simexplorer-is-security simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities simexplorer-is-security/src/test simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities simexp
by glandais@users.labs.libre-entreprise.org 19 Mar '08
by glandais@users.labs.libre-entreprise.org 19 Mar '08
19 Mar '08
Author: glandais
Date: 2008-03-19 18:10:23 +0000 (Wed, 19 Mar 2008)
New Revision: 1404
Added:
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/log4j.properties
trunk/simexplorer-is/src/site/fr/rst/rules.rst
Removed:
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java
Modified:
trunk/simexplorer-is/simexplorer-is-security/pom.xml
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java
trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupEdit.java
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/UserEdit.java
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/GroupValueEncoder.java
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/UserValueEncoder.java
Log:
Security update
JPA friendly
Rules written
Modified: trunk/simexplorer-is/simexplorer-is-security/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/pom.xml 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/pom.xml 2008-03-19 18:10:23 UTC (rev 1404)
@@ -19,31 +19,6 @@
<version>0.1-SNAPSHOT</version>
</parent>
- <!--build>
- <plugins>
- <plugin>
- <groupId>lutinplugin</groupId>
- <artifactId>maven-i18n-plugin</artifactId>
- <version>0.2-SNAPSHOT</version>
- <configuration>
- <bundles>
- <param>fr_FR</param>
- <param>en_GB</param>
- </bundles>
- </configuration>
- <executions>
- <execution>
- <phase>compile</phase>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build-->
-
<repositories>
<repository>
<snapshots>
@@ -54,8 +29,8 @@
<url>http://ejb3unit.sourceforge.net/maven2</url>
</repository>
</repositories>
-
- <dependencies>
+
+ <dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
@@ -79,13 +54,13 @@
<artifactId>h2</artifactId>
<version>1.0.64</version>
</dependency>
-
- <dependency>
- <groupId>com.bm</groupId>
- <artifactId>ejb3unit</artifactId>
- <version>1.2</version>
- <scope>test</scope>
- </dependency>
-
+
+ <dependency>
+ <groupId>com.bm</groupId>
+ <artifactId>ejb3unit</artifactId>
+ <version>1.2</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -49,7 +49,7 @@
/** The Constant log. */
private static final Log log = LogFactory.getLog(CredentialManagerImpl.class);
-
+
/** The dao. */
@EJB
private DaoActor daoActor;
@@ -65,27 +65,24 @@
private final static Object usersCachedSynchronizer = new Object();
/**
- * Gets the relative level.
+ * Check if permission accorded to actor applies to user.
*
+ * @param userActor the user
* @param actor the actor
- * @param permission the permission
*
- * @return the relative level
+ * @return true, if successful
*/
- private int getRelativeLevel(Actor actor, Permission permission) {
- int level = -1;
- if (actor.equals(permission.getActor())) {
- return 0;
+ private boolean appliesTo(Actor userActor, Actor actor) {
+ if (userActor.equals(actor)) {
+ return true;
}
- Collection<Group> groups = actor.getGroups();
+ Collection<Group> groups = userActor.getMemberOf();
for (Group group : groups) {
- int levelGroup = getRelativeLevel(group, permission);
- if (levelGroup >= 0) {
- level = levelGroup + 1;
+ if (appliesTo(group, actor)) {
+ return true;
}
}
-
- return level;
+ return false;
}
/* (non-Javadoc)
@@ -98,54 +95,32 @@
if (user.isSuperAdmin()) {
p = new Permission();
- p.setActor(user);
- p.setBusinessId(businessId);
p.setOwner(true);
} else {
- List<Permission> permissions = daoPermission.getPermissions(businessId);
+ p = new Permission();
+ p.setOwner(false);
+ p.setCanAdmin(false);
+ p.setCanRead(false);
+ p.setCanWrite(false);
- if (permissions.size() > 0) {
- int minLevel = 0;
-
- for (Permission permission : permissions) {
- int relativeLevel = getRelativeLevel(user, permission);
- if (relativeLevel >= 0) {
- if (p == null || minLevel > relativeLevel) {
- p = permission;
- minLevel = relativeLevel;
- }
- // TODO if minLevel == relativeLevel do OR
- }
+ List<Permission> permissions = daoPermission.getPermissions(businessId);
+ for (Permission permission : permissions) {
+ boolean appliesTo = appliesTo(user, permission.getActor());
+ if (appliesTo) {
+ p.setOwner(p.isOwner() || permission.isOwner());
+ p.setCanAdmin(p.isCanAdmin() || permission.isCanAdmin());
+ p.setCanRead(p.isCanRead() || permission.isCanRead());
+ p.setCanWrite(p.isCanWrite() || permission.isCanWrite());
}
- } else {
- // no permission with this id exists, so create a default one with all rights
- p = new Permission();
- p.setActor(user);
- p.setBusinessId(businessId);
- p.setOwner(true);
- p.setCanAdmin(true);
- p.setCanRead(true);
- p.setCanWrite(true);
}
-
}
- if (p != null && p.isOwner()) {
+ if (p.isOwner()) {
p.setCanAdmin(true);
p.setCanRead(true);
p.setCanWrite(true);
}
- if (p == null) {
- p = new Permission();
- p.setActor(user);
- p.setBusinessId(businessId);
- p.setOwner(false);
- p.setCanAdmin(false);
- p.setCanRead(false);
- p.setCanWrite(false);
- }
-
return p;
}
@@ -154,9 +129,9 @@
*/
public void saveElement(String token, String businessId) {
User user = daoActor.getLoggedUser(token);
- Permission p = getPermission(token, businessId);
if (!user.isSuperAdmin()) {
- if ((p == null) || (!user.getId().equals(p.getActor().getId()))) {
+ Permission p = daoPermission.getPermission(businessId, user);
+ if (p == null) {
p = new Permission();
p.setActor(user);
p.setBusinessId(businessId);
@@ -238,7 +213,7 @@
*/
private void getActors(Actor actor, Collection<Actor> actors) {
actors.add(actor);
- Collection<Group> groups = actor.getGroups();
+ Collection<Group> groups = actor.getMemberOf();
for (Group group : groups) {
getActors(group, actors);
}
@@ -251,7 +226,7 @@
@Override
public String getUserFilter(String token) {
User user = daoActor.getLoggedUser(token);
- return user.getId().toString();
+ return user.getActorId().toString();
}
/* (non-Javadoc)
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -17,7 +17,7 @@
* ##% */
package fr.cemagref.simexplorer.is.security.dao;
-import java.util.List;
+import java.util.Collection;
import fr.cemagref.simexplorer.is.security.entities.Actor;
import fr.cemagref.simexplorer.is.security.entities.Group;
@@ -159,42 +159,15 @@
*
* @return the groups
*/
- public List<Group> getGroups();
+ public Collection<Group> getGroups();
/**
- * Gets the groups owned by.
- *
- * @param user the user
- *
- * @return the groups owned by
- */
- public List<Group> getGroupsOwnedBy(User user);
-
- /**
* Gets the users.
*
* @return the users
*/
- public List<User> getUsers();
+ public Collection<User> getUsers();
- /**
- * Gets the users of group.
- *
- * @param group the group
- *
- * @return the users of group
- */
- public List<User> getUsersOfGroup(Group group);
-
- /**
- * Gets the groups of actor.
- *
- * @param actor the actor
- *
- * @return the groups of actor
- */
- public List<Group> getGroupsOfActor(Actor actor);
-
//public Object debugQuery(String query, int type);
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -17,6 +17,7 @@
* ##% */
package fr.cemagref.simexplorer.is.security.dao;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -43,7 +44,7 @@
/** The Constant log. */
private static final Log log = LogFactory.getLog(DaoActorImpl.class);
-
+
/** The em. */
@PersistenceContext(unitName = "simexploreris-security")
private EntityManager em;
@@ -73,8 +74,8 @@
*
* @return the object
*/
- private Object find(Class<?> clazz, Object arg) {
- Object o;
+ private <T> T find(Class<T> clazz, Object arg) {
+ T o;
try {
o = em.find(clazz, arg);
} catch (NoResultException e) {
@@ -105,7 +106,7 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroup(java.lang.Integer)
*/
public Group getGroup(Integer id) {
- Group g = (Group) find(Group.class, id);
+ Group g = find(Group.class, id);
return g;
}
@@ -122,7 +123,7 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getUser(java.lang.Integer)
*/
public User getUser(Integer id) {
- User u = (User) find(User.class, id);
+ User u = find(User.class, id);
return u;
}
@@ -130,7 +131,7 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getActor(java.lang.Integer)
*/
public Actor getActor(Integer id) {
- Actor a = (Actor) find(Actor.class, id);
+ Actor a = find(Actor.class, id);
return a;
}
@@ -142,7 +143,7 @@
private void setActorVisible(Actor actor) {
actor.setVisible(true);
}
-
+
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.security.dao.DaoActor#saveGroup(fr.cemagref.simexplorer.is.security.entities.Group)
*/
@@ -195,8 +196,8 @@
*/
public User loginUser(String login, String passwordHash) {
User user = (User) getSingleResult(em.createQuery(
- "select u from User u where u.login=:login and u.passwordHash=:passwordHash and u.visible = true").setParameter("login",
- login).setParameter("passwordHash", passwordHash));
+ "select u from User u where u.login=:login and u.passwordHash=:passwordHash and u.visible = true")
+ .setParameter("login", login).setParameter("passwordHash", passwordHash));
return user;
}
@@ -231,51 +232,20 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroups()
*/
public List<Group> getGroups() {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g where g.visible = true").getResultList(),
- Group.class);
+ List<Group> groups = CollectionUtil.toGenericList(em
+ .createQuery("select g from Group g where g.visible = true").getResultList(), Group.class);
return groups;
}
/* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroupsOwnedBy(fr.cemagref.simexplorer.is.security.entities.User)
- */
- public List<Group> getGroupsOwnedBy(User user) {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g where g.owner=:owner and g.visible = true")
- .setParameter("owner", user).getResultList(), Group.class);
- return groups;
- }
-
- /* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getUsers()
*/
- public List<User> getUsers() {
- List<User> users = CollectionUtil.toGenericList(em.createQuery("select u from User u where u.visible = true").getResultList(),
- User.class);
- return users;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getUsersOfGroup(fr.cemagref.simexplorer.is.security.entities.Group)
- */
- public List<User> getUsersOfGroup(Group group) {
- List<User> users = CollectionUtil.toGenericList(em.createQuery(
- "select distinct u from User u where :group member of u.groups and u.visible = true").setParameter("group", group)
+ public Collection<User> getUsers() {
+ List<User> users = CollectionUtil.toGenericList(em.createQuery("select u from User u where u.visible = true")
.getResultList(), User.class);
return users;
}
- public List<Group> getGroupsOfActor(Actor actor) {
-
- //String query = "select distinct group from Actor actor join actor.groups as group where actor = :actor and group.visible = true";
- String query = "select distinct g from Group g, Actor actor where g member of actor.groups and g.visible = true and actor=:actor";
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
- query)
- .setParameter("actor", actor).getResultList(),
- Group.class);
-
- return groups;
- }
-
/*
public Object debugQuery(String query, int type) {
Query jpaQuery = em.createQuery(query);
@@ -291,7 +261,6 @@
}
return null;
}
-*/
-
+ */
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -58,6 +58,16 @@
public int getPermissionsOwnedByCount(Actor user);
/**
+ * Gets the permission.
+ *
+ * @param businessId the business id
+ * @param user the user
+ *
+ * @return the permission
+ */
+ public Permission getPermission(String businessId, Actor user);
+
+ /**
* Save permission.
*
* @param p the p
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -17,11 +17,14 @@
* ##% */
package fr.cemagref.simexplorer.is.security.dao;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
@@ -55,6 +58,20 @@
return permissions;
}
+ @Override
+ public Permission getPermission(String businessId, Actor actor) {
+ Permission permission;
+ try {
+ permission = (Permission) em.createQuery(
+ "select p from Permission p where p.businessId=:businessId and p.actor=:actor").setParameter(
+ "businessId", businessId).setParameter("actor", actor).getSingleResult();
+ } catch (NoResultException e) {
+ permission = null;
+ }
+
+ return permission;
+ }
+
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.security.dao.DaoPermission#getPermissionsOwnedBy(fr.cemagref.simexplorer.is.security.entities.Actor)
*/
@@ -87,9 +104,21 @@
*/
@Override
public void setPermissions(String uuid, Permission[] permissions) {
- em.createQuery("delete from Permission p where p.businessId=:businessId").setParameter("businessId", uuid)
- .executeUpdate();
- for (Permission permission : permissions) {
+ HashSet<Permission> permissionSet = new HashSet<Permission>(Arrays.asList(permissions));
+ List<Permission> existingPermissions = CollectionUtil.toGenericList(em.createQuery(
+ "select p from Permission p where p.businessId=:businessId").setParameter("businessId", uuid)
+ .getResultList(), Permission.class);
+
+ for (Permission permission : existingPermissions) {
+ if (permissionSet.contains(permission)) {
+ em.merge(permission);
+ permissionSet.remove(permission);
+ } else {
+ em.remove(permission);
+ }
+ }
+
+ for (Permission permission : permissionSet) {
em.persist(permission);
}
}
@@ -106,9 +135,11 @@
public List<String> getBusinessIdsVisibleBy(Collection<Actor> actors) {
StringBuffer query = new StringBuffer();
query.append("select p.businessId from Permission p").append(
- " where (p.canRead = true or p.canAdmin = true or p.isOwner = true)").append(" and p.actor in (:actors)");
+ " where (p.canRead = true or p.canAdmin = true or p.isOwner = true)").append(
+ " and p.actor in (:actors)");
List<String> businessIds = CollectionUtil.toGenericList(em.createQuery(query.toString()).setParameter("actors",
actors).getResultList(), String.class);
return businessIds;
}
+
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -21,17 +21,16 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
-import javax.persistence.Basic;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
+import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -42,42 +41,44 @@
@Table(name = "ACTORS")
@Inheritance(strategy = InheritanceType.JOINED)
public class Actor implements Serializable {
-
+
/** The Constant serialVersionUID. */
@Transient
private static final long serialVersionUID = 1;
/** The id. */
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE)
- protected Integer id;
+ @GeneratedValue
+ protected Integer actorId;
- /** The groups. */
+ /** The groups with actor is member of. */
@ManyToMany(fetch = FetchType.EAGER, targetEntity = Group.class)
- //@Cascade(value = {CascadeType.ALL})
- private Collection<Group> groups;
+ private Collection<Group> memberOf;
/** The visible. */
- @Basic
+ @Column(nullable = false)
private boolean visible;
-
+
+ /** The permissions. */
+ @OneToMany(targetEntity = Permission.class, mappedBy = "actor")
+ private Collection<Permission> permissions;
+
/**
- * Gets the id.
+ * Gets the actor id.
*
- * @return the id
+ * @return the actor id
*/
- public Integer getId() {
- return id;
+ public Integer getActorId() {
+ return actorId;
}
/**
- * Sets the id.
+ * Sets the actor id.
*
- * @param id
- * the new id
+ * @param actorId the new actor id
*/
- public void setId(Integer id) {
- this.id = id;
+ public void setActorId(Integer actorId) {
+ this.actorId = actorId;
}
/**
@@ -92,40 +93,58 @@
/**
* Sets the visible.
*
- * @param visible
- * the new visible
+ * @param visible the new visible
*/
public void setVisible(boolean visible) {
this.visible = visible;
}
/**
- * Gets the groups.
+ * Gets the member of.
*
- * @return the groups
+ * @return the member of
*/
- public Collection<Group> getGroups() {
- if (groups == null) {
- groups = new ArrayList<Group>();
+ public Collection<Group> getMemberOf() {
+ if (memberOf == null) {
+ return new ArrayList<Group>();
}
- return groups;
+ return memberOf;
}
/**
- * Sets the groups.
+ * Sets the member of.
*
- * @param groups
- * the new groups
+ * @param memberOf the new member of
*/
- public void setGroups(List<Group> groups) {
- this.groups = groups;
+ public void setMemberOf(Collection<Group> memberOf) {
+ this.memberOf = memberOf;
}
/**
+ * Gets the permissions.
+ *
+ * @return the permissions
+ */
+ public Collection<Permission> getPermissions() {
+ if (permissions == null) {
+ return new ArrayList<Permission>();
+ }
+ return permissions;
+ }
+
+ /**
+ * Sets the permissions.
+ *
+ * @param permissions the new permissions
+ */
+ public void setPermissions(Collection<Permission> permissions) {
+ this.permissions = permissions;
+ }
+
+ /**
* Hash code groups.
*
- * @param hashedGroups
- * the hashed groups
+ * @param hashedGroups the hashed groups
*
* @return the int
*/
@@ -134,7 +153,7 @@
int result = 1;
result = prime * result + hashedGroups.size();
for (Group group : hashedGroups) {
- result = prime * result + ((group == null) ? 0 : group.getId());
+ result = prime * result + ((group == null) ? 0 : group.actorId);
}
return result;
}
@@ -146,18 +165,16 @@
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + hashCodeGroups(groups);
- result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + hashCodeGroups(memberOf);
+ result = prime * result + ((actorId == null) ? 0 : actorId.hashCode());
return result;
}
/**
* Equals groups.
*
- * @param groups1
- * the groups1
- * @param groups2
- * the groups2
+ * @param groups1 the groups1
+ * @param groups2 the groups2
*
* @return true, if successful
*/
@@ -175,9 +192,9 @@
if (group1 == null) {
if (group2 != null)
return false;
- } else if (group1.getId() == null) {
+ } else if (group1.actorId == null) {
return false;
- } else if (!group1.getId().equals(group2.getId()))
+ } else if (!group1.actorId.equals(group2.actorId))
return false;
}
return true;
@@ -195,15 +212,15 @@
if (getClass() != obj.getClass())
return false;
final Actor other = (Actor) obj;
- if (groups == null) {
- if (other.groups != null)
+ if (memberOf == null) {
+ if (other.memberOf != null)
return false;
- } else if (!equalsGroups(groups, other.groups))
+ } else if (!equalsGroups(memberOf, other.memberOf))
return false;
- if (id == null) {
- if (other.id != null)
+ if (actorId == null) {
+ if (other.actorId != null)
return false;
- } else if (!id.equals(other.id))
+ } else if (!actorId.equals(other.actorId))
return false;
return true;
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -17,11 +17,14 @@
* ##% */
package fr.cemagref.simexplorer.is.security.entities;
-import javax.persistence.Basic;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.OneToOne;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -35,16 +38,19 @@
/** The Constant serialVersionUID. */
@Transient
private static final long serialVersionUID = 1;
-
+
/** The name. */
- @Basic
- @Column(unique = true)
+ @Column(unique = true, nullable = false, length = 256)
private String name;
-
+
/** The owner. */
- @OneToOne(fetch = FetchType.EAGER)
+ @ManyToOne(optional = false)
private User owner;
+ /** The members. */
+ @ManyToMany(targetEntity = Actor.class, mappedBy = "memberOf")
+ private Collection<Actor> members;
+
/**
* Gets the name.
*
@@ -81,6 +87,27 @@
this.owner = owner;
}
+ /**
+ * Gets the members.
+ *
+ * @return the members
+ */
+ public Collection<Actor> getMembers() {
+ if (members == null) {
+ return new ArrayList<Actor>();
+ }
+ return members;
+ }
+
+ /**
+ * Sets the members.
+ *
+ * @param members the new members
+ */
+ public void setMembers(Collection<Actor> members) {
+ this.members = members;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -19,13 +19,11 @@
import java.io.Serializable;
-import javax.persistence.Basic;
+import javax.persistence.Column;
import javax.persistence.Entity;
-import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
import javax.persistence.Id;
-import javax.persistence.OneToOne;
+import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -36,29 +34,25 @@
@Table(name = "LOGINS")
public class LoginAction implements Serializable {
- /** The Constant log. */
- private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
- .getLog(LoginAction.class);
-
/** The Constant serialVersionUID. */
@Transient
private static final long serialVersionUID = 1;
/** The id. */
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE)
+ @GeneratedValue
private Integer id;
/** The time. */
- @Basic
+ @Column(nullable = false)
private long loginDate;
/** The logged user. */
- @OneToOne(fetch = FetchType.EAGER)
+ @ManyToOne(optional = false)
private User loggedUser;
/** The token. */
- @Basic
+ @Column(unique = true, nullable = false, length = 64)
private String token;
/**
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -19,13 +19,11 @@
import java.io.Serializable;
-import javax.persistence.Basic;
+import javax.persistence.Column;
import javax.persistence.Entity;
-import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
import javax.persistence.Id;
-import javax.persistence.OneToOne;
+import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -42,31 +40,31 @@
/** The id. */
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE)
+ @GeneratedValue
private Integer id;
/** The business id. */
- @Basic
+ @Column(unique = false, nullable = false, length = 64)
private String businessId;
/** The actor. */
- @OneToOne(fetch = FetchType.EAGER)
+ @ManyToOne(optional = false)
private Actor actor;
/** The can read. */
- @Basic
+ @Column(nullable = false)
private boolean canRead;
/** The can write. */
- @Basic
+ @Column(nullable = false)
private boolean canWrite;
/** The can admin. */
- @Basic
+ @Column(nullable = false)
private boolean canAdmin;
/** The is owner. */
- @Basic
+ @Column(nullable = false)
private boolean isOwner;
/* (non-Javadoc)
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -17,9 +17,13 @@
* ##% */
package fr.cemagref.simexplorer.is.security.entities;
-import javax.persistence.Basic;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
@@ -33,28 +37,35 @@
/** The Constant serialVersionUID. */
@Transient
private static final long serialVersionUID = 1;
-
+
/** The login. */
- @Basic
- @Column(unique = true)
+ @Column(unique = true, nullable = false, length = 256)
private String login;
-
+
/** The mail. */
- @Basic
+ @Column(unique = true, nullable = false, length = 256)
private String mail;
-
+
/** The password hash. */
- @Basic
+ @Column(unique = false, nullable = false, length = 256)
private String passwordHash;
-
+
/** The admin. */
- @Basic
+ @Column(nullable = false)
private boolean admin;
-
+
/** The super admin. */
- @Basic
+ @Column(nullable = false)
private boolean superAdmin;
+ /** The groups owned. */
+ @OneToMany(targetEntity = Group.class, mappedBy = "owner")
+ private Collection<Group> groupsOwned;
+
+ /** The logins. */
+ @OneToMany(targetEntity = LoginAction.class, mappedBy = "loggedUser")
+ private Collection<LoginAction> logins;
+
/**
* Gets the login.
*
@@ -145,6 +156,48 @@
this.superAdmin = superAdmin;
}
+ /**
+ * Gets the groups owned.
+ *
+ * @return the groups owned
+ */
+ public Collection<Group> getGroupsOwned() {
+ if (groupsOwned == null) {
+ return new ArrayList<Group>();
+ }
+ return groupsOwned;
+ }
+
+ /**
+ * Sets the groups owned.
+ *
+ * @param groupsOwned the new groups owned
+ */
+ public void setGroupsOwned(Collection<Group> groupsOwned) {
+ this.groupsOwned = groupsOwned;
+ }
+
+ /**
+ * Gets the logins.
+ *
+ * @return the logins
+ */
+ public Collection<LoginAction> getLogins() {
+ if (logins == null) {
+ return new ArrayList<LoginAction>();
+ }
+ return logins;
+ }
+
+ /**
+ * Sets the logins.
+ *
+ * @param logins the new logins
+ */
+ public void setLogins(Collection<LoginAction> logins) {
+ this.logins = logins;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -163,8 +216,7 @@
result = prime * result + (admin ? 1231 : 1237);
result = prime * result + ((login == null) ? 0 : login.hashCode());
result = prime * result + ((mail == null) ? 0 : mail.hashCode());
- result = prime * result
- + ((passwordHash == null) ? 0 : passwordHash.hashCode());
+ result = prime * result + ((passwordHash == null) ? 0 : passwordHash.hashCode());
result = prime * result + (superAdmin ? 1231 : 1237);
return result;
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,3 +1,12 @@
### The ejb3unit configuration file ###
-ejb3unit.inMemoryTest=true
+#ejb3unit.inMemoryTest=true
+ejb3unit.inMemoryTest=false
+ejb3unit.connection.url=jdbc:h2:mem:ejb3unit
+ejb3unit.connection.driver_class=org.h2.Driver
+ejb3unit.connection.username=
+ejb3unit.connection.password=
+ejb3unit.dialect=org.hibernate.dialect.H2Dialect
ejb3unit.show_sql=false
+
+## values are create-drop, create, update ##
+ejb3unit.schema.update=create
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,279 +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.credentials;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
-
-import com.bm.introspectors.EntityBeanIntrospector;
-import com.bm.testsuite.dataloader.EntityInitialDataSet;
-import com.bm.utils.UndoScriptGenerator;
-
-import fr.cemagref.simexplorer.is.security.entities.Actor;
-import fr.cemagref.simexplorer.is.security.entities.Group;
-import fr.cemagref.simexplorer.is.security.entities.LoginAction;
-import fr.cemagref.simexplorer.is.security.entities.Permission;
-import fr.cemagref.simexplorer.is.security.entities.User;
-
-public class CredentialDataSet extends EntityInitialDataSet {
-
- private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
- .getLog(CredentialDataSet.class);
-
- protected EntityManager entityManager = null;
-
- private User user3;
-
- public static final int N_PERMISSIONS_USER3 = 378;
-
- public CredentialDataSet() {
- // ...
- super(Actor.class);
- }
-
- public CredentialDataSet(Class entityType) {
- super(entityType);
- throw new IllegalStateException();
- }
-
- public void setEntityManager(EntityManager em) {
- this.entityManager = em;
- }
-
- @Override
- public void cleanup(EntityManager em) {
- EntityTransaction tx = entityManager.getTransaction();
- tx.begin();
- List resultList = entityManager.createQuery("SELECT a FROM Actor a").getResultList();
- for (Object object : resultList) {
- Actor actor = (Actor) object;
- actor.getGroups().clear();
- entityManager.merge(actor);
- }
- tx.commit();
-
- tx.begin();
- entityManager.createQuery("DELETE FROM LoginAction").executeUpdate();
- entityManager.createQuery("DELETE FROM Permission").executeUpdate();
- entityManager.createQuery("DELETE FROM Group").executeUpdate();
- entityManager.createQuery("DELETE FROM User").executeUpdate();
- entityManager.createQuery("DELETE FROM Actor").executeUpdate();
- tx.commit();
- }
-
- @Override
- public void create() {
- User user1 = new User();
- user1.setAdmin(false);
- user1.setSuperAdmin(false);
- user1.setGroups(new ArrayList<Group>());
- user1.setLogin("user1");
- user1.setMail("user1 at user.user");
- user1.setVisible(true);
- entityManager.persist(user1);
-
- User user2 = new User();
- user2.setAdmin(false);
- user2.setSuperAdmin(false);
- user2.setGroups(new ArrayList<Group>());
- user2.setLogin("user2");
- user2.setMail("user2 at user.user");
- user2.setVisible(true);
- entityManager.persist(user2);
-
- user3 = new User();
- user3.setAdmin(false);
- user3.setSuperAdmin(false);
- user3.setGroups(new ArrayList<Group>());
- user3.setLogin("user3");
- user3.setMail("user3 at user.user");
- user3.setVisible(true);
- entityManager.persist(user3);
-
- User user4 = new User();
- user4.setAdmin(false);
- user4.setSuperAdmin(false);
- user4.setGroups(new ArrayList<Group>());
- user4.setLogin("user4");
- user4.setMail("user4 at user.user");
- user4.setVisible(true);
- entityManager.persist(user4);
-
- User admin = new User();
- admin.setAdmin(true);
- admin.setSuperAdmin(false);
- admin.setGroups(new ArrayList<Group>());
- admin.setLogin("admin");
- admin.setMail("admin at admin.admin");
- admin.setVisible(true);
- entityManager.persist(admin);
-
- User superadmin = new User();
- superadmin.setAdmin(true);
- superadmin.setSuperAdmin(true);
- superadmin.setGroups(new ArrayList<Group>());
- superadmin.setLogin("superadmin");
- superadmin.setMail("superadmin at superadmin.superadmin");
- superadmin.setVisible(true);
- entityManager.persist(superadmin);
-
- LoginAction loginActionUser1 = new LoginAction();
- loginActionUser1.setLoggedUser(user1);
- loginActionUser1.setLoginDate((new Date()).getTime());
- loginActionUser1.setToken("user1");
- entityManager.persist(loginActionUser1);
-
- LoginAction loginActionUser2 = new LoginAction();
- loginActionUser2.setLoggedUser(user2);
- loginActionUser2.setLoginDate((new Date()).getTime());
- loginActionUser2.setToken("user2");
- entityManager.persist(loginActionUser2);
-
- LoginAction loginActionUser4 = new LoginAction();
- loginActionUser4.setLoggedUser(user4);
- loginActionUser4.setLoginDate((new Date()).getTime());
- loginActionUser4.setToken("user4");
- entityManager.persist(loginActionUser4);
-
- LoginAction loginActionAdmin = new LoginAction();
- loginActionAdmin.setLoggedUser(admin);
- loginActionAdmin.setLoginDate((new Date()).getTime());
- loginActionAdmin.setToken("admin");
- entityManager.persist(loginActionAdmin);
-
- LoginAction loginActionSuperAdmin = new LoginAction();
- loginActionSuperAdmin.setLoggedUser(superadmin);
- loginActionSuperAdmin.setLoginDate((new Date()).getTime());
- loginActionSuperAdmin.setToken("superadmin");
- entityManager.persist(loginActionSuperAdmin);
-
- Group groupA = new Group();
- groupA.setGroups(new ArrayList<Group>());
- groupA.setName("groupA");
- groupA.setOwner(admin);
- groupA.setVisible(true);
- entityManager.persist(groupA);
-
- Group groupB = new Group();
- groupB.setGroups(new ArrayList<Group>());
- groupB.setName("groupB");
- groupB.setOwner(admin);
- groupB.setVisible(true);
- entityManager.persist(groupB);
-
- user1.getGroups().add(groupA);
- entityManager.merge(user1);
-
- user2.getGroups().add(groupB);
- entityManager.merge(user2);
-
- user4.getGroups().add(groupB);
- entityManager.merge(user4);
-
- Group groupC = new Group();
- groupC.setGroups(new ArrayList<Group>());
- groupC.setName("groupC");
- groupC.setOwner(admin);
- groupC.setVisible(true);
- entityManager.persist(groupC);
-
- groupB.getGroups().add(groupC);
- entityManager.merge(groupB);
-
- Permission[] p = new Permission[6];
- int i = 0;
-
- p[i] = new Permission();
- p[i].setActor(user1);
- p[i].setBusinessId("b" + i);
- p[i].setCanRead(true);
- p[i].setCanAdmin(true);
- p[i].setCanWrite(true);
- p[i].setOwner(true);
-
- i++;
- p[i] = new Permission();
- p[i].setActor(user2);
- p[i].setBusinessId("b" + i);
- p[i].setCanRead(true);
- p[i].setCanAdmin(true);
- p[i].setCanWrite(true);
- p[i].setOwner(true);
-
- i++;
- p[i] = new Permission();
- p[i].setActor(groupA);
- p[i].setBusinessId("b" + i);
- p[i].setCanRead(true);
- p[i].setCanAdmin(true);
- p[i].setCanWrite(true);
- p[i].setOwner(true);
-
- i++;
- p[i] = new Permission();
- p[i].setActor(groupB);
- p[i].setBusinessId("b" + i);
- p[i].setCanRead(true);
- p[i].setCanAdmin(true);
- p[i].setCanWrite(true);
- p[i].setOwner(true);
-
- i++;
- p[i] = new Permission();
- p[i].setActor(groupC);
- p[i].setBusinessId("b" + i);
- p[i].setCanRead(true);
- p[i].setCanAdmin(true);
- p[i].setCanWrite(true);
- p[i].setOwner(true);
-
- i++;
- p[i] = new Permission();
- p[i].setActor(user4);
- p[i].setBusinessId("b" + i);
- p[i].setCanRead(true);
- p[i].setCanAdmin(true);
- p[i].setCanWrite(true);
- p[i].setOwner(true);
-
- for (Permission permission : p) {
- entityManager.persist(permission);
- }
-
- for (int j = 0; j < N_PERMISSIONS_USER3; j++) {
- Permission permission = new Permission();
- permission.setActor(user3);
- permission.setBusinessId("u3_" + j);
- permission.setCanRead(true);
- permission.setCanAdmin(true);
- permission.setCanWrite(true);
- permission.setOwner(true);
- entityManager.persist(permission);
- }
-
- }
-
- public User getUser3() {
- return user3;
- }
-
-}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,245 @@
+/*
+* ##% 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.credentials;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import com.bm.testsuite.dataloader.EntityInitialDataSet;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.LoginAction;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+/**
+ * The Class CredentialDataSet.
+ */
+public class CredentialDataSet extends EntityInitialDataSet {
+
+ /** The Constant log. */
+ private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
+ .getLog(CredentialDataSet.class);
+
+ /** The entity manager. */
+ protected EntityManager entityManager = null;
+
+ /** The user3. */
+ private User user3;
+
+ /** The Constant N_PERMISSIONS_USER3. */
+ public static final int N_PERMISSIONS_USER3 = 13;
+
+ /**
+ * Instantiates a new credential data set.
+ */
+ public CredentialDataSet() {
+ // ...
+ super(Actor.class);
+ }
+
+ /**
+ * Instantiates a new credential data set.
+ *
+ * @param entityType the entity type
+ */
+ public CredentialDataSet(Class entityType) {
+ super(entityType);
+ throw new IllegalStateException();
+ }
+
+ /* (non-Javadoc)
+ * @see com.bm.testsuite.dataloader.EntityInitialDataSet#setEntityManager(javax.persistence.EntityManager)
+ */
+ public void setEntityManager(EntityManager em) {
+ this.entityManager = em;
+ }
+
+ /* (non-Javadoc)
+ * @see com.bm.testsuite.dataloader.EntityInitialDataSet#cleanup(javax.persistence.EntityManager)
+ */
+ @Override
+ public void cleanup(EntityManager em) {
+ EntityTransaction tx = em.getTransaction();
+ if (!tx.isActive())
+ tx.begin();
+
+ List resultList = entityManager.createQuery("SELECT a FROM Actor a").getResultList();
+ for (Object object : resultList) {
+ Actor actor = (Actor) object;
+ actor.getMemberOf().clear();
+ actor.getPermissions().clear();
+ entityManager.merge(actor);
+ }
+
+ resultList = entityManager.createQuery("SELECT u FROM User u").getResultList();
+ for (Object object : resultList) {
+ User user = (User) object;
+ user.getGroupsOwned().clear();
+ user.getLogins().clear();
+ entityManager.merge(user);
+ }
+ tx.commit();
+ tx.begin();
+
+ em.createQuery("DELETE FROM LoginAction").executeUpdate();
+ em.createQuery("DELETE FROM Permission").executeUpdate();
+
+ em.createQuery("DELETE FROM Group").executeUpdate();
+ em.createQuery("DELETE FROM User").executeUpdate();
+ em.createQuery("DELETE FROM Actor").executeUpdate();
+
+ tx.commit();
+ }
+
+ /**
+ * Creates the user.
+ *
+ * @param login the login
+ * @param admin the admin
+ * @param superadmin the superadmin
+ *
+ * @return the user
+ */
+ private User createUser(String login, boolean admin, boolean superadmin) {
+ User user = new User();
+ user.setAdmin(admin);
+ user.setSuperAdmin(superadmin);
+ user.setGroupsOwned(new ArrayList<Group>());
+ user.setMemberOf(new ArrayList<Group>());
+ user.setLogin(login);
+ user.setMail(login + "@user.user");
+ user.setVisible(true);
+ user.setPasswordHash("---");
+ entityManager.persist(user);
+
+ LoginAction loginActionUser = new LoginAction();
+ loginActionUser.setLoggedUser(user);
+ loginActionUser.setLoginDate((new Date()).getTime());
+ loginActionUser.setToken(login);
+ entityManager.persist(loginActionUser);
+
+ return user;
+ }
+
+ /**
+ * Creates the group.
+ *
+ * @param name the name
+ * @param owner the owner
+ *
+ * @return the group
+ */
+ private Group createGroup(String name, User owner) {
+ Group group = new Group();
+ group.setMemberOf(new ArrayList<Group>());
+ group.setMembers(new ArrayList<Actor>());
+ group.setName(name);
+ group.setOwner(owner);
+ group.setVisible(true);
+ entityManager.persist(group);
+ return group;
+ }
+
+ /**
+ * Creates the permission.
+ *
+ * @param bid the bid
+ * @param actor the actor
+ *
+ * @return the permission
+ */
+ private Permission createPermission(String bid, Actor actor) {
+ Permission p = new Permission();
+ p.setActor(actor);
+ p.setBusinessId(bid);
+ p.setCanRead(true);
+ p.setCanAdmin(true);
+ p.setCanWrite(true);
+ p.setOwner(true);
+ entityManager.persist(p);
+ return p;
+ }
+
+ /* (non-Javadoc)
+ * @see com.bm.testsuite.dataloader.InitialDataSet#create()
+ */
+ @Override
+ public void create() {
+ User user1 = createUser("user1", false, false);
+ User user2 = createUser("user2", false, false);
+ user3 = createUser("user3", false, false);
+ User user4 = createUser("user4", false, false);
+ User admin = createUser("admin", true, false);
+ User superadmin = createUser("superadmin", true, true);
+
+ Group groupA = createGroup("groupA", admin);
+
+ user1.getMemberOf().add(groupA);
+ entityManager.merge(user1);
+
+ Group groupB = createGroup("groupB", admin);
+ groupB.getMembers().add(user2);
+ groupB.getMembers().add(user4);
+ entityManager.merge(groupB);
+
+ user2.getMemberOf().add(groupB);
+ user4.getMemberOf().add(groupB);
+ entityManager.merge(user2);
+ entityManager.merge(user4);
+
+ Group groupC = createGroup("groupC", admin);
+ groupB.getMemberOf().add(groupC);
+ entityManager.merge(groupB);
+
+ Permission[] p = new Permission[6];
+ int i = 0;
+
+ p[i] = createPermission("b" + i, user1);
+ i++;
+ p[i] = createPermission("b" + i, user2);
+ i++;
+ p[i] = createPermission("b" + i, groupA);
+ i++;
+ p[i] = createPermission("b" + i, groupB);
+ i++;
+ p[i] = createPermission("b" + i, groupC);
+ i++;
+ p[i] = createPermission("b" + i, user4);
+
+ for (int j = 0; j < N_PERMISSIONS_USER3; j++) {
+ createPermission("u3_" + j, user3);
+ }
+
+ }
+
+ /**
+ * Gets the user3.
+ *
+ * @return the user3
+ */
+ public User getUser3() {
+ return user3;
+ }
+
+}
Copied: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTest.java (from rev 1402, trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,207 @@
+/*
+* ##% 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.credentials;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.persistence.EntityTransaction;
+
+import com.bm.testsuite.BaseSessionBeanFixture;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.LoginAction;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+/**
+ * The Class CredentialManagerTest.
+ */
+public class CredentialManagerTest extends BaseSessionBeanFixture<CredentialManagerImpl> {
+
+ /** The Constant usedEntityBeans. */
+ private static final Class<?>[] usedEntityBeans = { Actor.class, User.class, Group.class, Permission.class,
+ LoginAction.class };
+
+ /** The credential data set. */
+ private static CredentialDataSet credentialDataSet = new CredentialDataSet();
+
+ /**
+ * Instantiates a new credential manager testbase.
+ */
+ public CredentialManagerTest() {
+ super(CredentialManagerImpl.class, usedEntityBeans, credentialDataSet);
+ }
+
+ /**
+ * Gets the credential manager.
+ *
+ * @return the credential manager
+ */
+ private CredentialManager getCredentialManager() {
+ return getBeanToTest();
+ }
+
+ /**
+ * Assert permission ok.
+ *
+ * @param p the p
+ * @param onlyOwner the only owner
+ */
+ private static void assertPermissionOk(Permission p, boolean onlyOwner) {
+ if (!onlyOwner) {
+ assertTrue(p.isCanRead());
+ assertTrue(p.isCanWrite());
+ assertTrue(p.isCanAdmin());
+ }
+ assertTrue(p.isOwner());
+ }
+
+ /**
+ * Test get permission.
+ */
+ public void testGetPermission() {
+ assertPermissionOk(getCredentialManager().getPermission("user1", "b0"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user2", "b1"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user1", "b2"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user2", "b3"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user2", "b4"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user4", "b3"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user4", "b4"), false);
+ }
+
+ /**
+ * Test get permissions.
+ */
+ public void testGetPermissions() {
+ Permission[] permissions;
+ for (int i = 0; i < 5; i++) {
+ permissions = getCredentialManager().getPermissions("b" + i);
+ assertEquals(permissions.length, 1);
+ }
+ }
+
+ /**
+ * Test save element.
+ */
+ public void testSaveElement() {
+ if (!getEntityManager().getTransaction().isActive()) {
+ getEntityManager().getTransaction().begin();
+ }
+ getCredentialManager().saveElement("user1", "s0");
+ getEntityManager().getTransaction().commit();
+ getEntityManager().getTransaction().begin();
+ assertPermissionOk(getCredentialManager().getPermission("user1", "s0"), true);
+ }
+
+ /**
+ * Test set permissions.
+ */
+ public void testSetPermissions() {
+ if (!getEntityManager().getTransaction().isActive()) {
+ getEntityManager().getTransaction().begin();
+ }
+ getCredentialManager().saveElement("user1", "s1");
+ getCredentialManager().saveElement("user2", "s1");
+ getEntityManager().getTransaction().commit();
+
+ Permission[] permissions = getCredentialManager().getPermissions("s1");
+ for (Permission permission : permissions) {
+ permission.setOwner(false);
+ permission.setCanAdmin(false);
+ permission.setCanWrite(false);
+ permission.setCanRead(true);
+ }
+
+ getEntityManager().getTransaction().begin();
+ getCredentialManager().setPermissions("s1", permissions);
+ getEntityManager().getTransaction().commit();
+
+ for (int i = 1; i < 3; i++) {
+ Permission permission = getCredentialManager().getPermission("user" + i, "s1");
+ assertFalse(permission.isCanAdmin());
+ assertFalse(permission.isCanWrite());
+ assertFalse(permission.isOwner());
+ assertTrue(permission.isCanRead());
+ }
+ }
+
+ /**
+ * Test get permissions owned by.
+ */
+ public void testGetPermissionsOwnedBy() {
+ List<Permission> permissionsOwnedBy = getCredentialManager().getPermissionsOwnedBy(
+ credentialDataSet.getUser3(), 0, CredentialDataSet.N_PERMISSIONS_USER3);
+ for (Permission permission : permissionsOwnedBy) {
+ assertTrue(credentialDataSet.getUser3().equals(permission.getActor()));
+ assertPermissionOk(permission, false);
+ }
+ }
+
+ /**
+ * Test get permissions owned by count.
+ */
+ public void testGetPermissionsOwnedByCount() {
+ int permissionsOwnedByCount = getCredentialManager().getPermissionsOwnedByCount(credentialDataSet.getUser3());
+ assertEquals(permissionsOwnedByCount, CredentialDataSet.N_PERMISSIONS_USER3);
+ }
+
+ /**
+ * Test get elements visible by.
+ */
+ public void testGetElementsVisibleBy() {
+ Collection<String> elementsVisibleBy = getCredentialManager().getElementsVisibleBy("user4");
+ assertTrue(elementsVisibleBy.contains("b3"));
+ assertTrue(elementsVisibleBy.contains("b4"));
+ assertTrue(elementsVisibleBy.contains("b5"));
+ assertEquals(elementsVisibleBy.size(), 3);
+ }
+
+ /**
+ * Test get user filter.
+ */
+ public void testGetUserFilter() {
+ assertNotNull(getCredentialManager().getUserFilter("user1"));
+ assertNotNull(getCredentialManager().getUserFilter("user2"));
+ assertNotNull(getCredentialManager().getUserFilter("admin"));
+ assertNotNull(getCredentialManager().getUserFilter("superadmin"));
+ }
+
+ /**
+ * Test is cache valid for.
+ */
+ public void testIsCacheValidFor() {
+ EntityTransaction transaction = getEntityManager().getTransaction();
+ if (!transaction.isActive()) {
+ transaction.begin();
+ }
+ getCredentialManager().saveElement("user1", "c1");
+ transaction.commit();
+ assertFalse(getCredentialManager().isCacheValidFor(getCredentialManager().getUserFilter("user1")));
+ getCredentialManager().getElementsVisibleBy("user1");
+ assertTrue(getCredentialManager().isCacheValidFor(getCredentialManager().getUserFilter("user1")));
+ Permission[] permissions = new Permission[0];
+ transaction.begin();
+ getCredentialManager().setPermissions("c1", permissions);
+ transaction.commit();
+ assertFalse(getCredentialManager().isCacheValidFor(getCredentialManager().getUserFilter("user1")));
+ getCredentialManager().getElementsVisibleBy("user1");
+ assertTrue(getCredentialManager().isCacheValidFor(getCredentialManager().getUserFilter("user1")));
+ }
+}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,153 +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.credentials;
-
-import java.util.Collection;
-import java.util.List;
-
-import com.bm.testsuite.BaseSessionBeanFixture;
-
-import fr.cemagref.simexplorer.is.security.entities.Actor;
-import fr.cemagref.simexplorer.is.security.entities.Group;
-import fr.cemagref.simexplorer.is.security.entities.LoginAction;
-import fr.cemagref.simexplorer.is.security.entities.Permission;
-import fr.cemagref.simexplorer.is.security.entities.User;
-
-/**
- * The Class CredentialManagerTestbase.
- */
-public class CredentialManagerTestbase extends BaseSessionBeanFixture<CredentialManagerImpl> {
-
- private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
- .getLog(CredentialManagerTestbase.class);
-
- /** The Constant usedEntityBeans. */
- private static final Class<?>[] usedEntityBeans = { Permission.class, User.class, Group.class, Actor.class,
- LoginAction.class };
-
- private static CredentialDataSet credentialDataSet = new CredentialDataSet();
-
- /**
- * Instantiates a new credential manager testbase.
- */
- public CredentialManagerTestbase() {
- super(CredentialManagerImpl.class, usedEntityBeans, credentialDataSet);
- }
-
- private CredentialManager getCredentialManager() {
- return (CredentialManager) getBeanToTest();
- }
-
- private static void assertPermissionOk(Permission p, boolean onlyOwner) {
- log.info(p);
- if (!onlyOwner) {
- assertTrue(p.isCanRead());
- assertTrue(p.isCanWrite());
- assertTrue(p.isCanAdmin());
- }
- assertTrue(p.isOwner());
- }
-
- public void testGetPermission() {
- assertPermissionOk(getCredentialManager().getPermission("user1", "b0"), false);
- assertPermissionOk(getCredentialManager().getPermission("user2", "b1"), false);
- assertPermissionOk(getCredentialManager().getPermission("user1", "b2"), false);
- assertPermissionOk(getCredentialManager().getPermission("user2", "b3"), false);
- assertPermissionOk(getCredentialManager().getPermission("user2", "b4"), false);
- }
-
- public void testGetPermissions() {
- Permission[] permissions;
- for (int i = 0; i < 5; i++) {
- permissions = getCredentialManager().getPermissions("b" + i);
- assertEquals(permissions.length, 1);
- }
- }
-
- public void testSaveElement() {
- getCredentialManager().saveElement("user1", "s0");
- assertPermissionOk(getCredentialManager().getPermission("user1", "s0"), true);
- }
-
- public void testSetPermissions() {
- getEntityManager().getTransaction().begin();
- getCredentialManager().saveElement("user1", "s1");
- getCredentialManager().saveElement("user2", "s1");
- getEntityManager().getTransaction().commit();
- Permission[] permissions = getCredentialManager().getPermissions("s1");
- for (Permission permission : permissions) {
- permission.setOwner(false);
- permission.setCanAdmin(false);
- permission.setCanWrite(false);
- permission.setCanRead(true);
- }
-
- getEntityManager().getTransaction().begin();
- getCredentialManager().setPermissions("s1", permissions);
- getEntityManager().getTransaction().commit();
-
- for (int i = 1; i < 3; i++) {
- Permission permission = getCredentialManager().getPermission("user" + i, "s1");
- assertFalse(permission.isCanAdmin());
- assertFalse(permission.isCanWrite());
- assertFalse(permission.isOwner());
- assertTrue(permission.isCanRead());
- }
- }
-
- public void testGetPermissionsOwnedBy() {
- List<Permission> permissionsOwnedBy = getCredentialManager().getPermissionsOwnedBy(
- credentialDataSet.getUser3(), 0, credentialDataSet.N_PERMISSIONS_USER3);
- for (Permission permission : permissionsOwnedBy) {
- assertTrue(credentialDataSet.getUser3().equals(permission.getActor()));
- assertPermissionOk(permission, false);
- }
- }
-
- public void testGetPermissionsOwnedByCount() {
- int permissionsOwnedByCount = getCredentialManager().getPermissionsOwnedByCount(credentialDataSet.getUser3());
- assertEquals(permissionsOwnedByCount, credentialDataSet.N_PERMISSIONS_USER3);
- }
-
- public void testGetElementsVisibleBy() {
- Collection<String> elementsVisibleBy = getCredentialManager().getElementsVisibleBy("user4");
- assertTrue(elementsVisibleBy.contains("b3"));
- assertTrue(elementsVisibleBy.contains("b4"));
- assertTrue(elementsVisibleBy.contains("b5"));
- assertEquals(elementsVisibleBy.size(), 3);
- }
-
- public void testGetUserFilter() {
- assertNotNull(getCredentialManager().getUserFilter("user1"));
- assertNotNull(getCredentialManager().getUserFilter("user2"));
- assertNotNull(getCredentialManager().getUserFilter("admin"));
- assertNotNull(getCredentialManager().getUserFilter("superadmin"));
- }
-
- public void testIsCacheValidFor() {
- getCredentialManager().saveElement("user1", "c1");
- assertFalse(getCredentialManager().isCacheValidFor("user1"));
- getCredentialManager().getElementsVisibleBy("user1");
- assertTrue(getCredentialManager().isCacheValidFor("user1"));
- Permission[] permissions = new Permission[0];
- getCredentialManager().setPermissions("c1", permissions);
- assertFalse(getCredentialManager().isCacheValidFor("user1"));
- getCredentialManager().getElementsVisibleBy("user1");
- assertTrue(getCredentialManager().isCacheValidFor("user1"));
- }
-}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,32 +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.entities;
-
-/**
- * The Class GroupTest.
- */
-public class GroupTest extends SecurityEntityTest {
-
- /**
- * Instantiates a new group test.
- */
- public GroupTest() {
- super(Group.class, SPECIAL_GENERATORS);
- }
-
-}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class GroupTest.
+ */
+public class GroupTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new group test.
+ */
+ public GroupTest() {
+ super(Group.class, SPECIAL_GENERATORS);
+ }
+
+}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,32 +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.entities;
-
-/**
- * The Class LoginActionTest.
- */
-public class LoginActionTest extends SecurityEntityTest {
-
- /**
- * Instantiates a new login action test.
- */
- public LoginActionTest() {
- super(LoginAction.class, SPECIAL_GENERATORS);
- }
-
-}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class LoginActionTest.
+ */
+public class LoginActionTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new login action test.
+ */
+ public LoginActionTest() {
+ super(LoginAction.class, SPECIAL_GENERATORS);
+ }
+
+}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,32 +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.entities;
-
-/**
- * The Class PermissionTest.
- */
-public class PermissionTest extends SecurityEntityTest {
-
- /**
- * Instantiates a new permission test.
- */
- public PermissionTest() {
- super(Permission.class, SPECIAL_GENERATORS);
- }
-
-}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class PermissionTest.
+ */
+public class PermissionTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new permission test.
+ */
+ public PermissionTest() {
+ super(Permission.class, SPECIAL_GENERATORS);
+ }
+
+}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,139 +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.entities;
-
-import java.util.List;
-
-import com.bm.datagen.Generator;
-import com.bm.datagen.annotations.GeneratorType;
-import com.bm.datagen.relation.BeanCollectionGenerator;
-import com.bm.datagen.relation.SingleBeanGenerator;
-import com.bm.testsuite.BaseEntityFixture;
-
-/**
- * The Class SecurityEntityTest.
- */
- at SuppressWarnings("unchecked")
-public abstract class SecurityEntityTest extends BaseEntityFixture {
-
- /** The Constant SPECIAL_GENERATORS. */
- protected static final Generator<?>[] SPECIAL_GENERATORS = { new GroupCreator(), new GroupsCreator(),
- new ActorCreator(), new UserCreator(), new LoginActionCreator(), new PermissionCreator() };
-
- /**
- * Should not be called...
- */
- public SecurityEntityTest() {
- super(null);
- }
-
- /**
- * Instantiates a new security entity test.
- *
- * @param entityToTest the entity to test
- * @param additionalGenerators the additional generators
- */
- public SecurityEntityTest(Class<?> entityToTest, Generator<?>[] additionalGenerators) {
- super(entityToTest, additionalGenerators);
- }
-
- /**
- * The Class GroupCreator.
- */
- @GeneratorType(className = Group.class)
- protected static final class GroupCreator extends SingleBeanGenerator<Group> {
-
- /**
- * Instantiates a new group creator.
- */
- protected GroupCreator() {
- super(Group.class);
- }
- }
-
- /**
- * The Class GroupsCreator.
- */
- @GeneratorType(className = List.class, field = "groups")
- protected static final class GroupsCreator extends BeanCollectionGenerator<Group> {
-
- /**
- * Instantiates a new groups creator.
- */
- protected GroupsCreator() {
- super(Group.class, 10);
- }
- }
-
- /**
- * The Class UserCreator.
- */
- @GeneratorType(className = User.class)
- protected static final class UserCreator extends SingleBeanGenerator<User> {
-
- /**
- * Instantiates a new user creator.
- */
- protected UserCreator() {
- super(User.class);
- }
- }
-
- /**
- * The Class UserCreator.
- */
- @GeneratorType(className = Actor.class)
- protected static final class ActorCreator extends SingleBeanGenerator {
-
- /**
- * Instantiates a new user creator.
- */
- protected ActorCreator() {
- super(User.class);
- }
- }
-
- /**
- * The Class LoginActionCreator.
- */
- @GeneratorType(className = LoginAction.class)
- protected static final class LoginActionCreator extends SingleBeanGenerator<LoginAction> {
-
- /**
- * Instantiates a new login action creator.
- */
- protected LoginActionCreator() {
- super(LoginAction.class);
- }
- }
-
- /**
- * The Class PermissionCreator.
- */
- @GeneratorType(className = Permission.class)
- protected static final class PermissionCreator extends SingleBeanGenerator<Permission> {
-
- /**
- * Instantiates a new permission creator.
- */
- protected PermissionCreator() {
- super(Permission.class);
- }
- }
-
-}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,159 @@
+/*
+* ##% 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.entities;
+
+import java.util.List;
+
+import com.bm.datagen.Generator;
+import com.bm.datagen.annotations.GeneratorType;
+import com.bm.datagen.relation.BeanCollectionGenerator;
+import com.bm.datagen.relation.SingleBeanGenerator;
+import com.bm.testsuite.BaseEntityFixture;
+
+/**
+ * The Class SecurityEntityTest.
+ */
+ at SuppressWarnings("unchecked")
+public abstract class SecurityEntityTest extends BaseEntityFixture {
+
+ private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
+ .getLog(SecurityEntityTest.class);
+
+ /** The Constant ACTOR_GENERATORS. */
+ protected static final SingleBeanGenerator ACTOR_GENERATORS = new ActorCreator();
+
+ /** The Constant GROUP_GENERATORS. */
+ protected static final SingleBeanGenerator<Group> GROUP_GENERATORS = new GroupCreator();
+
+ /** The Constant GROUPS_GENERATORS. */
+ protected static final BeanCollectionGenerator<Group> GROUPS_GENERATORS = new GroupsCreator();
+
+ /** The Constant USER_GENERATORS. */
+ protected static final SingleBeanGenerator<User> USER_GENERATORS = new UserCreator();
+
+ /** The Constant LOGINACTION_GENERATORS. */
+ protected static final SingleBeanGenerator<LoginAction> LOGINACTION_GENERATORS = new LoginActionCreator();
+
+ /** The Constant PERMISSION_GENERATORS. */
+ protected static final SingleBeanGenerator<Permission> PERMISSION_GENERATORS = new PermissionCreator();
+
+ protected static final Generator<?>[] SPECIAL_GENERATORS = { ACTOR_GENERATORS, USER_GENERATORS, GROUP_GENERATORS,
+ GROUPS_GENERATORS, LOGINACTION_GENERATORS, PERMISSION_GENERATORS };
+
+ /**
+ * Should not be called...
+ */
+ public SecurityEntityTest() {
+ super(null);
+ }
+
+ /**
+ * Instantiates a new security entity test.
+ *
+ * @param entityToTest the entity to test
+ * @param additionalGenerators the additional generators
+ */
+ public SecurityEntityTest(Class<?> entityToTest, Generator<?>[] additionalGenerators) {
+ super(entityToTest, additionalGenerators);
+ }
+
+ /**
+ * The Class GroupCreator.
+ */
+ @GeneratorType(className = Group.class)
+ protected static final class GroupCreator extends SingleBeanGenerator<Group> {
+
+ /**
+ * Instantiates a new group creator.
+ */
+ protected GroupCreator() {
+ super(Group.class);
+ }
+ }
+
+ /**
+ * The Class GroupsCreator.
+ */
+ @GeneratorType(className = List.class, field = "groups")
+ protected static final class GroupsCreator extends BeanCollectionGenerator<Group> {
+
+ /**
+ * Instantiates a new groups creator.
+ */
+ protected GroupsCreator() {
+ super(Group.class, 10);
+ }
+ }
+
+ /**
+ * The Class UserCreator.
+ */
+ @GeneratorType(className = User.class)
+ protected static final class UserCreator extends SingleBeanGenerator<User> {
+
+ /**
+ * Instantiates a new user creator.
+ */
+ protected UserCreator() {
+ super(User.class);
+ }
+ }
+
+ /**
+ * The Class UserCreator.
+ */
+ @GeneratorType(className = Actor.class)
+ protected static final class ActorCreator extends SingleBeanGenerator {
+
+ /**
+ * Instantiates a new user creator.
+ */
+ protected ActorCreator() {
+ super(User.class);
+ }
+ }
+
+ /**
+ * The Class LoginActionCreator.
+ */
+ @GeneratorType(className = LoginAction.class)
+ protected static final class LoginActionCreator extends SingleBeanGenerator<LoginAction> {
+
+ /**
+ * Instantiates a new login action creator.
+ */
+ protected LoginActionCreator() {
+ super(LoginAction.class);
+ }
+ }
+
+ /**
+ * The Class PermissionCreator.
+ */
+ @GeneratorType(className = Permission.class)
+ protected static final class PermissionCreator extends SingleBeanGenerator<Permission> {
+
+ /**
+ * Instantiates a new permission creator.
+ */
+ protected PermissionCreator() {
+ super(Permission.class);
+ }
+ }
+
+}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,46 +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.entities;
-
-import fr.cemagref.simexplorer.is.security.credentials.CredentialManagerTestbase;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * The Class SecurityEntityTests.
- */
-public class SecurityEntityTests {
-
- /**
- * Suite.
- *
- * @return the test
- */
- public static Test suite() {
- TestSuite suite = new TestSuite("Test for fr.cemagref.simexplorer.is.security.entities");
- // $JUnit-BEGIN$
- suite.addTestSuite(CredentialManagerTestbase.class);
- suite.addTestSuite(UserTest.class);
- suite.addTestSuite(GroupTest.class);
- suite.addTestSuite(PermissionTest.class);
- suite.addTestSuite(LoginActionTest.class);
- // $JUnit-END$
- return suite;
- }
-
-}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -1,32 +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.entities;
-
-/**
- * The Class UserTest.
- */
-public class UserTest extends SecurityEntityTest {
-
- /**
- * Instantiates a new user test.
- */
- public UserTest() {
- super(User.class, SPECIAL_GENERATORS);
- }
-
-}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class UserTest.
+ */
+public class UserTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new user test.
+ */
+ public UserTest() {
+ super(User.class, SPECIAL_GENERATORS);
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/log4j.properties
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/log4j.properties (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/log4j.properties 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,13 @@
+# Global logging configuration
+log4j.rootLogger=ERROR, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+
+# package level
+log4j.logger.fr.cemagref.simexplorer.is=ERROR
+log4j.logger.org.codelutin=ERROR
+log4j.logger.com.bm=ERROR
+
+
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationService.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -148,75 +148,6 @@
public User[] getUsers(String token) throws SimExplorerException;
/**
- * Gets the users of group.
- *
- * @param token the token
- * @param group the group
- *
- * @return the users of group
- *
- * @throws SimExplorerException the sim explorer service exception
- */
- public User[] getUsersOfGroup(String token, Group group) throws SimExplorerException;
-
- /**
- * Sets the users of group.
- *
- * @param token the token
- * @param group the group
- * @param usersInGroup the users in group
- *
- * @throws SimExplorerException the sim explorer service exception
- */
- public void setUsersOfGroup(String token, Group group, Integer[] usersInGroup) throws SimExplorerException;
-
- /**
- * Sets the groups of group.
- *
- * @param token the token
- * @param group the group
- * @param groupsIds the groups ids
- *
- * @throws SimExplorerException the sim explorer service exception
- */
- public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) throws SimExplorerException;
-
- /**
- * Gets the groups of user.
- *
- * @param token the token
- * @param user the user
- *
- * @return the groups of user
- *
- * @throws SimExplorerException the sim explorer service exception
- */
- public Group[] getGroupsOfUser(String token, User user) throws SimExplorerException;
-
- /**
- * Gets the groups of group.
- *
- * @param token the token
- * @param group the group
- *
- * @return the groups of group
- *
- * @throws SimExplorerException the sim explorer service exception
- */
- public Group[] getGroupsOfGroup(String token, Group group) throws SimExplorerException;
-
- /**
- * Sets the groups of user.
- *
- * @param token the token
- * @param user the user
- * @param groupsIds the groups ids
- *
- * @throws SimExplorerException the sim explorer service exception
- */
- public void setGroupsOfUser(String token, User user, Integer[] groupsIds) throws SimExplorerException;
-
- /**
* Save group.
*
* @param token the token
@@ -286,19 +217,8 @@
public Group[] getGroups(String token) throws SimExplorerException;
/**
- * Gets the groups owned by.
- *
- * @param token the token
- * @param user the user
- *
- * @return the groups owned by
- *
- * @throws SimExplorerException the sim explorer service exception
- */
- public Group[] getGroupsOwnedBy(String token, User user) throws SimExplorerException;
-
- /**
* Gets the logged user.
+ * Throws SimExplorerException if token is invalid (ie not logged)
*
* @param token the token
*
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -193,10 +193,10 @@
* @return true, if successful
*/
private boolean userOwnerOfGroup(User loggedUser, Group group) {
- if (group.getOwner().getId().equals(loggedUser.getId())) {
+ if (group.getOwner().getActorId().equals(loggedUser.getActorId())) {
return true;
}
- Collection<Group> groups = group.getGroups();
+ Collection<Group> groups = group.getMemberOf();
for (Group parent : groups) {
if (userOwnerOfGroup(loggedUser, parent)) {
return true;
@@ -223,9 +223,9 @@
}
if (loggedUser.isAdmin()) {
User user = daoActor.getUser(id);
- Collection<Group> groups = user.getGroups();
+ Collection<Group> groups = user.getMemberOf();
for (Group group : groups) {
- if (canAdminGroup(token, group.getId())) {
+ if (canAdminGroup(token, group.getActorId())) {
return true;
}
}
@@ -235,24 +235,6 @@
}
/**
- * Removes the user from group.
- *
- * @param user the user
- * @param group the group
- */
- 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);
- }
- }
-
- /**
* Can delete group.
*
* @param token the token
@@ -266,22 +248,12 @@
return canAdminGroup(token, id);
}
- /**
- * Delete group impl.
- *
- * @param token the token
- * @param id the id
- */
- private void deleteGroupImpl(String token, Integer id) {
- daoActor.deleteGroup(id);
- }
-
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#deleteGroup(java.lang.String, java.lang.Integer)
*/
public void deleteGroup(String token, Integer id) throws SimExplorerException {
if (canDeleteGroup(token, id)) {
- deleteGroupImpl(token, id);
+ daoActor.deleteGroup(id);
} else {
throw new SimExplorerSecurityException();
}
@@ -301,22 +273,12 @@
return canAdminUser(token, id);
}
- /**
- * Delete user impl.
- *
- * @param token the token
- * @param id the id
- */
- private void deleteUserImpl(String token, Integer id) {
- daoActor.deleteUser(id);
- }
-
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#deleteUser(java.lang.String, java.lang.Integer)
*/
public void deleteUser(String token, Integer id) throws SimExplorerException {
if (canDeleteUser(token, id)) {
- deleteUserImpl(token, id);
+ daoActor.deleteUser(id);
} else {
throw new SimExplorerSecurityException();
}
@@ -405,8 +367,8 @@
*/
private boolean canSaveElement(String token) throws SimExplorerException {
User loggedUser = getLoggedUser(token);
- boolean canView = loggedUser.isAdmin() || loggedUser.isSuperAdmin();
- return canView;
+ boolean canSave = loggedUser.isAdmin() || loggedUser.isSuperAdmin();
+ return canSave;
}
/* (non-Javadoc)
@@ -423,7 +385,7 @@
group.setName(name);
group.setOwner(getLoggedUser(token));
daoActor.saveGroup(group);
- group = getGroup(token, group.getId());
+ group = getGroup(token, group.getActorId());
return group;
}
throw new SimExplorerSecurityException();
@@ -452,7 +414,7 @@
user.setAdmin(false);
user.setSuperAdmin(false);
daoActor.saveUser(user);
- user = getUser(token, user.getId());
+ user = getUser(token, user.getActorId());
return user;
}
throw new SimExplorerSecurityException();
@@ -476,7 +438,8 @@
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#updateGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group)
*/
public Group updateGroup(String token, Group group) throws SimExplorerException {
- if (canUpdateGroup(token, group.getId())) {
+ if (canUpdateGroup(token, group.getActorId())) {
+ // TODO isContaining
return daoActor.updateGroup(group);
}
throw new SimExplorerSecurityException();
@@ -493,11 +456,11 @@
* @throws SimExplorerException the sim explorer service exception
*/
private boolean canUpdateUser(String token, User user) throws SimExplorerException {
- if (canAdminUser(token, user.getId())) {
+ if (canAdminUser(token, user.getActorId())) {
if (getLoggedUser(token).isSuperAdmin()) {
return true;
}
- User oldUser = daoActor.getUser(user.getId());
+ User oldUser = daoActor.getUser(user.getActorId());
if (oldUser.isAdmin() == user.isAdmin() && oldUser.isSuperAdmin() == user.isSuperAdmin()) {
return true;
}
@@ -597,7 +560,7 @@
*/
public void resetPassword(String token, String login) throws SimExplorerException {
User user = getUser(token, login);
- if (canAdminUser(token, user.getId())) {
+ if (canAdminUser(token, user.getActorId())) {
char[] password = generatePassword();
sendMail(Config.getProperties().getProperty("simexplorer.adminmail"), user.getMail(),
_("simexplorer.service.mail.subject"), getMailContentWithPassword(login, password));
@@ -616,128 +579,23 @@
*/
public Group[] getGroups(String token) throws SimExplorerException {
if (canViewElements(token)) {
- List<Group> groups = daoActor.getGroups();
+ Collection<Group> groups = daoActor.getGroups();
return groups.toArray(new Group[groups.size()]);
}
throw new SimExplorerSecurityException();
}
/* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroupsOwnedBy(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User)
- */
- public Group[] getGroupsOwnedBy(String token, User user) throws SimExplorerException {
- if (canViewElements(token)) {
- List<Group> list = daoActor.getGroupsOwnedBy(user);
- return list.toArray(new Group[list.size()]);
- }
- throw new SimExplorerSecurityException();
- }
-
- /* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#getUsers(java.lang.String)
*/
public User[] getUsers(String token) throws SimExplorerException {
if (canViewElements(token)) {
- List<User> users = daoActor.getUsers();
+ Collection<User> users = daoActor.getUsers();
return users.toArray(new User[users.size()]);
}
throw new SimExplorerSecurityException();
}
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getUsersOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group)
- */
- public User[] getUsersOfGroup(String token, Group group) throws SimExplorerException {
- if (canViewElements(token)) {
- List<User> usersOfGroup = daoActor.getUsersOfGroup(group);
- return usersOfGroup.toArray(new User[usersOfGroup.size()]);
- }
- throw new SimExplorerSecurityException();
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.AuthenticationService#setUsersOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group, java.lang.Integer[])
- */
- public void setUsersOfGroup(String token, Group group, Integer[] usersInGroup) throws SimExplorerException {
- if (canUpdateGroup(token, group.getId())) {
- 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 = daoActor.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 = daoActor.getUser(idUser);
- user.getGroups().add(group);
- daoActor.updateUser(user);
- }
- for (Integer idUser : usersToRemove) {
- User user = daoActor.getUser(idUser);
- removeUserFromGroup(user, group);
- daoActor.updateUser(user);
- }
- } else {
- throw new SimExplorerSecurityException();
- }
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.AuthenticationService#setGroupsOfUser(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User, java.lang.Integer[])
- */
- public void setGroupsOfUser(String token, User user, Integer[] groupsIds) throws SimExplorerException {
- if (canUpdateUser(token, user)) {
- User realUser = daoActor.getUser(user.getId());
- realUser.getGroups().clear();
- for (Integer groupsId : groupsIds) {
- Group group = daoActor.getGroup(groupsId);
- realUser.getGroups().add(group);
- }
- daoActor.updateUser(realUser);
- } else {
- throw new SimExplorerSecurityException();
- }
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroupsOfUser(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User)
- */
- public Group[] getGroupsOfUser(String token, User user) throws SimExplorerException {
- if (canViewElements(token)) {
- List<Group> list = daoActor.getGroupsOfActor(user);
- return list.toArray(new Group[list.size()]);
- }
- throw new SimExplorerSecurityException();
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.AuthenticationService#getGroupsOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group)
- */
- public Group[] getGroupsOfGroup(String token, Group group) throws SimExplorerException {
- if (canViewElements(token)) {
- List<Group> groupsOfGroup = daoActor.getGroupsOfActor(group);
- return groupsOfGroup.toArray(new Group[groupsOfGroup.size()]);
- }
- throw new SimExplorerSecurityException();
- }
-
/**
* Checks if container contains contained.
*
@@ -747,10 +605,10 @@
* @return true, if is containing
*/
private boolean isContaining(Group container, Group contained) {
- if (container.getId().equals(contained.getId())) {
+ if (container.getActorId().equals(contained.getActorId())) {
return true;
}
- Collection<Group> groups = container.getGroups();
+ Collection<Group> groups = container.getMemberOf();
for (Group group : groups) {
if (isContaining(group, contained)) {
return true;
@@ -759,25 +617,6 @@
return false;
}
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.AuthenticationService#setGroupsOfGroup(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Group, java.lang.Integer[])
- */
- public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) throws SimExplorerException {
- if (canUpdateGroup(token, group.getId())) {
- Group realGroup = daoActor.getGroup(group.getId());
- realGroup.getGroups().clear();
- for (Integer groupsId : groupsIds) {
- Group groupOwned = daoActor.getGroup(groupsId);
- if (!isContaining(groupOwned, realGroup)) {
- realGroup.getGroups().add(groupOwned);
- }
- }
- daoActor.updateGroup(realGroup);
- } else {
- throw new SimExplorerSecurityException();
- }
- }
-
/**
* Can admin permissions.
*
@@ -815,6 +654,7 @@
*/
@Override
public String[] getElementsOwnedBy(String token, User user, int indexStart, int count) {
+ // TODO security
List<String> uuids = new ArrayList<String>();
List<Permission> permissions = credentialManager.getPermissionsOwnedBy(user, indexStart, count);
for (Permission permission : permissions) {
@@ -827,6 +667,7 @@
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#getElementsOwnedByCount(java.lang.String, fr.cemagref.simexplorer.is.security.entities.User)
*/
public int getElementsOwnedByCount(String token, User user) {
+ // TODO security
return credentialManager.getPermissionsOwnedByCount(user);
}
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupEdit.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupEdit.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupEdit.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;
@@ -27,6 +28,7 @@
import org.apache.tapestry.annotations.Persist;
import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
+import fr.cemagref.simexplorer.is.security.entities.Actor;
import fr.cemagref.simexplorer.is.security.entities.Group;
import fr.cemagref.simexplorer.is.security.entities.User;
import fr.cemagref.simexplorer.is.service.remote.RemoteSecurityService;
@@ -87,11 +89,15 @@
} else {
this.group = RemoteSecurityService.getAuthentificationService().getGroup(getToken(), groupId);
- User[] users = RemoteSecurityService.getAuthentificationService().getUsersOfGroup(getToken(), group);
- this.usersInGroup.addAll(Arrays.asList(users));
-
- Group[] groups = RemoteSecurityService.getAuthentificationService().getGroupsOfGroup(getToken(), group);
- this.groupsInGroup.addAll(Arrays.asList(groups));
+ Collection<Actor> members = this.group.getMembers();
+ for (Actor actor : members) {
+ if (actor instanceof User) {
+ this.usersInGroup.add((User) actor);
+ }
+ if (actor instanceof Group) {
+ this.groupsInGroup.add((Group) actor);
+ }
+ }
}
userEncoder = new UserValueEncoder(getToken());
groupEncoder = new GroupValueEncoder(getToken());
@@ -118,28 +124,17 @@
* @throws SimExplorerException the sim explorer exception
*/
public Object onSuccess() throws SimExplorerException {
- if (group.getId() == null) {
+ Collection<Actor> members = new ArrayList<Actor>();
+ members.addAll(usersInGroup);
+ members.addAll(groupsInGroup);
+ group.setMembers(members);
+
+ if (group.getActorId() == null) {
group = RemoteSecurityService.getAuthentificationService().saveGroup(getToken(), group.getName());
} else {
group = RemoteSecurityService.getAuthentificationService().updateGroup(getToken(), group);
}
- Integer[] usersIds = new Integer[usersInGroup.size()];
- int i = 0;
- for (User user : usersInGroup) {
- usersIds[i] = user.getId();
- i++;
- }
- RemoteSecurityService.getAuthentificationService().setUsersOfGroup(getToken(), group, usersIds);
-
- Integer[] groupsIds = new Integer[groupsInGroup.size()];
- i = 0;
- for (Group aGroup : groupsInGroup) {
- groupsIds[i] = aGroup.getId();
- i++;
- }
- RemoteSecurityService.getAuthentificationService().setGroupsOfGroup(getToken(), group, groupsIds);
-
return groupList;
}
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -92,7 +92,8 @@
if (isUserSuperAdmin()) {
groups = RemoteSecurityService.getAuthentificationService().getGroups(getToken());
} else {
- groups = RemoteSecurityService.getAuthentificationService().getGroupsOwnedBy(getToken(), getUserLogged());
+ Collection<Group> groupsOwned = getUserLogged().getGroupsOwned();
+ groups = groupsOwned.toArray(new Group[groupsOwned.size()]);
}
return groups;
@@ -148,7 +149,7 @@
private TreeNode buildNode(Group group) {
TreeNode node = new TreeNode();
- Collection<Group> children = group.getGroups();
+ Collection<Group> children = group.getMemberOf();
if (children.size() == 0) {
node.setType(TreeNode.TYPE_DOCUMENT);
} else {
@@ -160,7 +161,7 @@
node.setChildren(childrenNodes);
}
- Link link = getResources().createPageLink("GroupEdit", false, group.getId());
+ Link link = getResources().createPageLink("GroupEdit", false, group.getActorId());
StringBuffer sb = new StringBuffer("");
sb.append("<a href=\"");
sb.append(link.toString());
@@ -191,7 +192,7 @@
usage.put(group, 0);
}
for (Group group : groups) {
- Collection<Group> children = group.getGroups();
+ Collection<Group> children = group.getMemberOf();
for (Group child : children) {
usage.put(child, usage.get(child) + 1);
}
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/UserEdit.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/UserEdit.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/UserEdit.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import org.apache.tapestry.ComponentResources;
@@ -57,7 +58,7 @@
/** The groups of user. */
@Persist
- private List<Group> groupsOfUser;
+ private Collection<Group> groupsOfUser;
/** The group encoder. */
@Persist
@@ -120,10 +121,7 @@
if (userId == -1) {
this.user = new User();
} else {
- this.user = RemoteSecurityService.getAuthentificationService().getUser(getToken(), userId);
- Group[] groups = RemoteSecurityService.getAuthentificationService().getGroupsOfUser(getToken(), this.user);
- groupsOfUser.addAll(Arrays.asList(groups));
-
+ groupsOfUser = getUserLogged().getMemberOf();
}
groupEncoder = new GroupValueEncoder(getToken());
}
@@ -149,19 +147,13 @@
* @throws SimExplorerException the sim explorer exception
*/
public Object onSuccess() throws SimExplorerException {
- if (user.getId() == null) {
+ if (user.getActorId() == null) {
user = RemoteSecurityService.getAuthentificationService().saveUser(getToken(), user.getLogin(),
user.getMail());
return this;
- }
- user = RemoteSecurityService.getAuthentificationService().updateUser(getToken(), user);
- Integer[] groupsIds = new Integer[groupsOfUser.size()];
- int i = 0;
- for (Group group : groupsOfUser) {
- groupsIds[i] = group.getId();
- i++;
- }
- RemoteSecurityService.getAuthentificationService().setGroupsOfUser(getToken(), user, groupsIds);
+ }
+ user.setMemberOf(groupsOfUser);
+ user = RemoteSecurityService.getAuthentificationService().updateUser(getToken(), user);
return userList;
}
@@ -188,10 +180,12 @@
* @throws SimExplorerException the sim explorer exception
*/
public Group[] getOwnedGroups() throws SimExplorerException {
- if (user.getId() == null) {
+ if (user.getActorId() == null) {
return new Group[0];
}
- return RemoteSecurityService.getAuthentificationService().getGroupsOwnedBy(getToken(), user);
+ Collection<Group> groupsOwned = user.getGroupsOwned();
+ Group[] result = groupsOwned.toArray(new Group[groupsOwned.size()]);
+ return result;
}
/**
@@ -222,7 +216,7 @@
* @return the creating
*/
public boolean getCreating() {
- return (user.getId() == null);
+ return (user.getActorId() == null);
}
/**
@@ -278,7 +272,7 @@
*
* @return the groups of user
*/
- public List<Group> getGroupsOfUser() {
+ public Collection<Group> getGroupsOfUser() {
return groupsOfUser;
}
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/GroupValueEncoder.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/GroupValueEncoder.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/GroupValueEncoder.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -46,7 +46,7 @@
* @see org.apache.tapestry.ValueEncoder#toClient(java.lang.Object)
*/
public String toClient(Group arg0) {
- return Integer.toString(arg0.getId());
+ return Integer.toString(arg0.getActorId());
}
/* (non-Javadoc)
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/UserValueEncoder.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/UserValueEncoder.java 2008-03-19 18:05:45 UTC (rev 1403)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/services/UserValueEncoder.java 2008-03-19 18:10:23 UTC (rev 1404)
@@ -46,7 +46,7 @@
* @see org.apache.tapestry.ValueEncoder#toClient(java.lang.Object)
*/
public String toClient(User arg0) {
- return Integer.toString(arg0.getId());
+ return Integer.toString(arg0.getActorId());
}
/* (non-Javadoc)
Added: trunk/simexplorer-is/src/site/fr/rst/rules.rst
===================================================================
--- trunk/simexplorer-is/src/site/fr/rst/rules.rst (rev 0)
+++ trunk/simexplorer-is/src/site/fr/rst/rules.rst 2008-03-19 18:10:23 UTC (rev 1404)
@@ -0,0 +1,25 @@
+Security
+========
+
+Accès à l'EJB
+-------------
+
+L'accès peut se faire uniquement au sein d'autres EJB déployés au sein du même serveur d'application (EJB local).
+
+Permissions
+-----------
+
+Droits sur un élément :
+
+ - le superadmin possède tous les droits sur tous les éléments
+ - "atomique" : droits explicites ou d'admin ou propriétaire de l'Actor
+ - global : droits atomique de l'Actor ou d'un de ses parents (memberOf récursif). Ainsi
+ si l'utilisateur n'a pas les droits explicites, mais qu'un de ses groupes auxquels il apprtient les possède,
+ l'utilisateur acquière ces droits.
+ - si un User est propriétaire d'un groupe sans en être membre, il n'a pas les droits du groupe
+
+Sauvegarde d'un élément :
+
+ - les droits associés sont mis à jour via cette méthode
+ - aucune permission n'est créée si l'utilisateur est super admin
+ -
1
0
r1403 - in trunk/simexplorer-is/simexplorer-is-security/src/test: . com com/bm com/bm/introspectors com/bm/introspectors/relations
by glandais@users.labs.libre-entreprise.org 19 Mar '08
by glandais@users.labs.libre-entreprise.org 19 Mar '08
19 Mar '08
Author: glandais
Date: 2008-03-19 18:05:45 +0000 (Wed, 19 Mar 2008)
New Revision: 1403
Added:
trunk/simexplorer-is/simexplorer-is-security/src/test/com/
trunk/simexplorer-is/simexplorer-is-security/src/test/com/bm/
trunk/simexplorer-is/simexplorer-is-security/src/test/com/bm/introspectors/
trunk/simexplorer-is/simexplorer-is-security/src/test/com/bm/introspectors/relations/
trunk/simexplorer-is/simexplorer-is-security/src/test/com/bm/introspectors/relations/GlobalPrimaryKeyStore.java
Log:
Patch to ejb3unit
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/com/bm/introspectors/relations/GlobalPrimaryKeyStore.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/com/bm/introspectors/relations/GlobalPrimaryKeyStore.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/com/bm/introspectors/relations/GlobalPrimaryKeyStore.java 2008-03-19 18:05:45 UTC (rev 1403)
@@ -0,0 +1,74 @@
+package com.bm.introspectors.relations;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import com.bm.introspectors.PrimaryKeyInfo;
+import com.bm.introspectors.Property;
+
+/**
+ * Global store for storing the primary key properties of entity classes.
+ * Such a global store is necessary to avoid cyclic dependencies while processing relations.
+ *
+ * @author Peter Doornbosch
+ */
+public class GlobalPrimaryKeyStore {
+
+ private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
+ .getLog(GlobalPrimaryKeyStore.class);
+
+ private static final GlobalPrimaryKeyStore singleton = new GlobalPrimaryKeyStore();
+
+ private Map<Class, Map<Property, PrimaryKeyInfo>> store = new HashMap<Class, Map<Property, PrimaryKeyInfo>>();
+
+ private GlobalPrimaryKeyStore() {
+ // singleton constructor
+ }
+
+ /**
+ * Returns the singleton instance.
+ *
+ * @return - the singleton instance
+ */
+ public static GlobalPrimaryKeyStore getStore() {
+ return singleton;
+ }
+
+ /**
+ * Stores primary key info of a given entity class.
+ * @param entityClass the entity class
+ * @param pkFieldInfo the primary key property and field info; usually the map will contain
+ * just one entry, but it might contain more entries in case of a composite primary key.
+ */
+ public void put(Class entityClass, Map<Property, PrimaryKeyInfo> pkFieldInfo) {
+ log.info(entityClass);
+ log.info(pkFieldInfo);
+ store.put(entityClass, pkFieldInfo);
+ }
+
+ private Map<Property, PrimaryKeyInfo> getPkInfo(Class entityClass) {
+ Map<Property, PrimaryKeyInfo> pkInfo = store.get(entityClass);
+ if (pkInfo == null && entityClass != null) {
+ pkInfo = getPkInfo(entityClass.getSuperclass());
+ }
+ return pkInfo;
+ }
+
+ /**
+ * Retrieves primary key info.
+ * @param entityClass
+ * @return one or more (in case of a composite primary key) properties that specify the
+ * primary key(s), or null if no primary key info is registered for the given class.
+ */
+ public Set<Property> getPrimaryKeyInfo(Class entityClass) {
+ log.info(entityClass);
+ Map<Property, PrimaryKeyInfo> pkInfo = getPkInfo(entityClass); //store.get(entityClass);
+ if (pkInfo == null) {
+ return null;
+ }
+ else {
+ return pkInfo.keySet();
+ }
+ }
+}
1
0
r1402 - in trunk/simexplorer-is: . simexplorer-is-service simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-web simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages
by glandais@users.labs.libre-entreprise.org 18 Mar '08
by glandais@users.labs.libre-entreprise.org 18 Mar '08
18 Mar '08
Author: glandais
Date: 2008-03-18 20:03:52 +0000 (Tue, 18 Mar 2008)
New Revision: 1402
Modified:
trunk/simexplorer-is/pom.xml
trunk/simexplorer-is/simexplorer-is-service/pom.xml
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
trunk/simexplorer-is/simexplorer-is-web/pom.xml
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java
Log:
Removed orm.xml
Modified: trunk/simexplorer-is/pom.xml
===================================================================
--- trunk/simexplorer-is/pom.xml 2008-03-18 20:03:23 UTC (rev 1401)
+++ trunk/simexplorer-is/pom.xml 2008-03-18 20:03:52 UTC (rev 1402)
@@ -95,14 +95,14 @@
http://lutinbuilder.labs.libre-entreprise.org/maven2
</url>
</pluginRepository>
- <!--pluginRepository>
- <id>evolvis-release-repository</id>
- <name>evolvis.org release repository</name>
- <url>http://maven-repo.evolvis.org/releases</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </pluginRepository-->
+ <!--pluginRepository>
+ <id>evolvis-release-repository</id>
+ <name>evolvis.org release repository</name>
+ <url>http://maven-repo.evolvis.org/releases</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository-->
</pluginRepositories>
<!--Tracking-->
Modified: trunk/simexplorer-is/simexplorer-is-service/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/pom.xml 2008-03-18 20:03:23 UTC (rev 1401)
+++ trunk/simexplorer-is/simexplorer-is-service/pom.xml 2008-03-18 20:03:52 UTC (rev 1402)
@@ -86,6 +86,12 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-03-18 20:03:23 UTC (rev 1401)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-03-18 20:03:52 UTC (rev 1402)
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@@ -195,7 +196,7 @@
if (group.getOwner().getId().equals(loggedUser.getId())) {
return true;
}
- List<Group> groups = group.getGroups();
+ Collection<Group> groups = group.getGroups();
for (Group parent : groups) {
if (userOwnerOfGroup(loggedUser, parent)) {
return true;
@@ -222,7 +223,7 @@
}
if (loggedUser.isAdmin()) {
User user = daoActor.getUser(id);
- List<Group> groups = user.getGroups();
+ Collection<Group> groups = user.getGroups();
for (Group group : groups) {
if (canAdminGroup(token, group.getId())) {
return true;
@@ -557,14 +558,14 @@
superAdminCheck = true;
}
String token = null;
- // le password est deja haché
+ // le password est deja haché
// User loggedUser = daoActor.loginUser(login, AuthenticationServiceHelper.computeHash(password));
User loggedUser = daoActor.loginUser(login, password);
if (loggedUser != null) {
daoActor.deleteTokens(loggedUser, 24 * 60 * 60 * 1000);
LoginAction loginAction = new LoginAction();
loginAction.setLoggedUser(loggedUser);
- loginAction.setLoginDate(new Date());
+ loginAction.setLoginDate((new Date()).getTime());
loginAction.setToken(UUID.randomUUID().toString());
daoActor.saveToken(loginAction);
token = loginAction.getToken();
@@ -749,7 +750,7 @@
if (container.getId().equals(contained.getId())) {
return true;
}
- List<Group> groups = container.getGroups();
+ Collection<Group> groups = container.getGroups();
for (Group group : groups) {
if (isContaining(group, contained)) {
return true;
@@ -839,4 +840,4 @@
{
I18n.initISO88591("fr", "FR");
}
-}
\ No newline at end of file
+}
Modified: trunk/simexplorer-is/simexplorer-is-web/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/pom.xml 2008-03-18 20:03:23 UTC (rev 1401)
+++ trunk/simexplorer-is/simexplorer-is-web/pom.xml 2008-03-18 20:03:52 UTC (rev 1402)
@@ -126,6 +126,12 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.1</version>
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java 2008-03-18 20:03:23 UTC (rev 1401)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java 2008-03-18 20:03:52 UTC (rev 1402)
@@ -18,6 +18,7 @@
package fr.cemagref.simexplorer.is.ui.web.pages;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -147,7 +148,7 @@
private TreeNode buildNode(Group group) {
TreeNode node = new TreeNode();
- List<Group> children = group.getGroups();
+ Collection<Group> children = group.getGroups();
if (children.size() == 0) {
node.setType(TreeNode.TYPE_DOCUMENT);
} else {
@@ -190,7 +191,7 @@
usage.put(group, 0);
}
for (Group group : groups) {
- List<Group> children = group.getGroups();
+ Collection<Group> children = group.getGroups();
for (Group child : children) {
usage.put(child, usage.get(child) + 1);
}
1
0
r1401 - in trunk/simexplorer-is/simexplorer-is-security: . src/test src/test/fr src/test/fr/cemagref src/test/fr/cemagref/simexplorer src/test/fr/cemagref/simexplorer/is src/test/fr/cemagref/simexplorer/is/security src/test/fr/cemagref/simexplorer/is/security/credentials src/test/fr/cemagref/simexplorer/is/security/entities
by glandais@users.labs.libre-entreprise.org 18 Mar '08
by glandais@users.labs.libre-entreprise.org 18 Mar '08
18 Mar '08
Author: glandais
Date: 2008-03-18 20:03:23 +0000 (Tue, 18 Mar 2008)
New Revision: 1401
Added:
trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java
trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java
Modified:
trunk/simexplorer-is/simexplorer-is-security/pom.xml
Log:
ejb3unit tests
Modified: trunk/simexplorer-is/simexplorer-is-security/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/pom.xml 2008-03-18 20:02:53 UTC (rev 1400)
+++ trunk/simexplorer-is/simexplorer-is-security/pom.xml 2008-03-18 20:03:23 UTC (rev 1401)
@@ -44,6 +44,17 @@
</plugins>
</build-->
+ <repositories>
+ <repository>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>ejb3unit</id>
+ <name>ejb3unit repository</name>
+ <url>http://ejb3unit.sourceforge.net/maven2</url>
+ </repository>
+ </repositories>
+
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
@@ -68,11 +79,13 @@
<artifactId>h2</artifactId>
<version>1.0.64</version>
</dependency>
- <!--dependency>
- <groupId>jboss</groupId>
- <artifactId>jbossall-client</artifactId>
- <version>4.2.2.GA</version>
- <scope>provided</scope>
- </dependency-->
+
+ <dependency>
+ <groupId>com.bm</groupId>
+ <artifactId>ejb3unit</artifactId>
+ <version>1.2</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/ejb3unit.properties 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,3 @@
+### The ejb3unit configuration file ###
+ejb3unit.inMemoryTest=true
+ejb3unit.show_sql=false
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialDataSet.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,279 @@
+/*
+* ##% 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.credentials;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import com.bm.introspectors.EntityBeanIntrospector;
+import com.bm.testsuite.dataloader.EntityInitialDataSet;
+import com.bm.utils.UndoScriptGenerator;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.LoginAction;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+public class CredentialDataSet extends EntityInitialDataSet {
+
+ private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
+ .getLog(CredentialDataSet.class);
+
+ protected EntityManager entityManager = null;
+
+ private User user3;
+
+ public static final int N_PERMISSIONS_USER3 = 378;
+
+ public CredentialDataSet() {
+ // ...
+ super(Actor.class);
+ }
+
+ public CredentialDataSet(Class entityType) {
+ super(entityType);
+ throw new IllegalStateException();
+ }
+
+ public void setEntityManager(EntityManager em) {
+ this.entityManager = em;
+ }
+
+ @Override
+ public void cleanup(EntityManager em) {
+ EntityTransaction tx = entityManager.getTransaction();
+ tx.begin();
+ List resultList = entityManager.createQuery("SELECT a FROM Actor a").getResultList();
+ for (Object object : resultList) {
+ Actor actor = (Actor) object;
+ actor.getGroups().clear();
+ entityManager.merge(actor);
+ }
+ tx.commit();
+
+ tx.begin();
+ entityManager.createQuery("DELETE FROM LoginAction").executeUpdate();
+ entityManager.createQuery("DELETE FROM Permission").executeUpdate();
+ entityManager.createQuery("DELETE FROM Group").executeUpdate();
+ entityManager.createQuery("DELETE FROM User").executeUpdate();
+ entityManager.createQuery("DELETE FROM Actor").executeUpdate();
+ tx.commit();
+ }
+
+ @Override
+ public void create() {
+ User user1 = new User();
+ user1.setAdmin(false);
+ user1.setSuperAdmin(false);
+ user1.setGroups(new ArrayList<Group>());
+ user1.setLogin("user1");
+ user1.setMail("user1 at user.user");
+ user1.setVisible(true);
+ entityManager.persist(user1);
+
+ User user2 = new User();
+ user2.setAdmin(false);
+ user2.setSuperAdmin(false);
+ user2.setGroups(new ArrayList<Group>());
+ user2.setLogin("user2");
+ user2.setMail("user2 at user.user");
+ user2.setVisible(true);
+ entityManager.persist(user2);
+
+ user3 = new User();
+ user3.setAdmin(false);
+ user3.setSuperAdmin(false);
+ user3.setGroups(new ArrayList<Group>());
+ user3.setLogin("user3");
+ user3.setMail("user3 at user.user");
+ user3.setVisible(true);
+ entityManager.persist(user3);
+
+ User user4 = new User();
+ user4.setAdmin(false);
+ user4.setSuperAdmin(false);
+ user4.setGroups(new ArrayList<Group>());
+ user4.setLogin("user4");
+ user4.setMail("user4 at user.user");
+ user4.setVisible(true);
+ entityManager.persist(user4);
+
+ User admin = new User();
+ admin.setAdmin(true);
+ admin.setSuperAdmin(false);
+ admin.setGroups(new ArrayList<Group>());
+ admin.setLogin("admin");
+ admin.setMail("admin at admin.admin");
+ admin.setVisible(true);
+ entityManager.persist(admin);
+
+ User superadmin = new User();
+ superadmin.setAdmin(true);
+ superadmin.setSuperAdmin(true);
+ superadmin.setGroups(new ArrayList<Group>());
+ superadmin.setLogin("superadmin");
+ superadmin.setMail("superadmin at superadmin.superadmin");
+ superadmin.setVisible(true);
+ entityManager.persist(superadmin);
+
+ LoginAction loginActionUser1 = new LoginAction();
+ loginActionUser1.setLoggedUser(user1);
+ loginActionUser1.setLoginDate((new Date()).getTime());
+ loginActionUser1.setToken("user1");
+ entityManager.persist(loginActionUser1);
+
+ LoginAction loginActionUser2 = new LoginAction();
+ loginActionUser2.setLoggedUser(user2);
+ loginActionUser2.setLoginDate((new Date()).getTime());
+ loginActionUser2.setToken("user2");
+ entityManager.persist(loginActionUser2);
+
+ LoginAction loginActionUser4 = new LoginAction();
+ loginActionUser4.setLoggedUser(user4);
+ loginActionUser4.setLoginDate((new Date()).getTime());
+ loginActionUser4.setToken("user4");
+ entityManager.persist(loginActionUser4);
+
+ LoginAction loginActionAdmin = new LoginAction();
+ loginActionAdmin.setLoggedUser(admin);
+ loginActionAdmin.setLoginDate((new Date()).getTime());
+ loginActionAdmin.setToken("admin");
+ entityManager.persist(loginActionAdmin);
+
+ LoginAction loginActionSuperAdmin = new LoginAction();
+ loginActionSuperAdmin.setLoggedUser(superadmin);
+ loginActionSuperAdmin.setLoginDate((new Date()).getTime());
+ loginActionSuperAdmin.setToken("superadmin");
+ entityManager.persist(loginActionSuperAdmin);
+
+ Group groupA = new Group();
+ groupA.setGroups(new ArrayList<Group>());
+ groupA.setName("groupA");
+ groupA.setOwner(admin);
+ groupA.setVisible(true);
+ entityManager.persist(groupA);
+
+ Group groupB = new Group();
+ groupB.setGroups(new ArrayList<Group>());
+ groupB.setName("groupB");
+ groupB.setOwner(admin);
+ groupB.setVisible(true);
+ entityManager.persist(groupB);
+
+ user1.getGroups().add(groupA);
+ entityManager.merge(user1);
+
+ user2.getGroups().add(groupB);
+ entityManager.merge(user2);
+
+ user4.getGroups().add(groupB);
+ entityManager.merge(user4);
+
+ Group groupC = new Group();
+ groupC.setGroups(new ArrayList<Group>());
+ groupC.setName("groupC");
+ groupC.setOwner(admin);
+ groupC.setVisible(true);
+ entityManager.persist(groupC);
+
+ groupB.getGroups().add(groupC);
+ entityManager.merge(groupB);
+
+ Permission[] p = new Permission[6];
+ int i = 0;
+
+ p[i] = new Permission();
+ p[i].setActor(user1);
+ p[i].setBusinessId("b" + i);
+ p[i].setCanRead(true);
+ p[i].setCanAdmin(true);
+ p[i].setCanWrite(true);
+ p[i].setOwner(true);
+
+ i++;
+ p[i] = new Permission();
+ p[i].setActor(user2);
+ p[i].setBusinessId("b" + i);
+ p[i].setCanRead(true);
+ p[i].setCanAdmin(true);
+ p[i].setCanWrite(true);
+ p[i].setOwner(true);
+
+ i++;
+ p[i] = new Permission();
+ p[i].setActor(groupA);
+ p[i].setBusinessId("b" + i);
+ p[i].setCanRead(true);
+ p[i].setCanAdmin(true);
+ p[i].setCanWrite(true);
+ p[i].setOwner(true);
+
+ i++;
+ p[i] = new Permission();
+ p[i].setActor(groupB);
+ p[i].setBusinessId("b" + i);
+ p[i].setCanRead(true);
+ p[i].setCanAdmin(true);
+ p[i].setCanWrite(true);
+ p[i].setOwner(true);
+
+ i++;
+ p[i] = new Permission();
+ p[i].setActor(groupC);
+ p[i].setBusinessId("b" + i);
+ p[i].setCanRead(true);
+ p[i].setCanAdmin(true);
+ p[i].setCanWrite(true);
+ p[i].setOwner(true);
+
+ i++;
+ p[i] = new Permission();
+ p[i].setActor(user4);
+ p[i].setBusinessId("b" + i);
+ p[i].setCanRead(true);
+ p[i].setCanAdmin(true);
+ p[i].setCanWrite(true);
+ p[i].setOwner(true);
+
+ for (Permission permission : p) {
+ entityManager.persist(permission);
+ }
+
+ for (int j = 0; j < N_PERMISSIONS_USER3; j++) {
+ Permission permission = new Permission();
+ permission.setActor(user3);
+ permission.setBusinessId("u3_" + j);
+ permission.setCanRead(true);
+ permission.setCanAdmin(true);
+ permission.setCanWrite(true);
+ permission.setOwner(true);
+ entityManager.persist(permission);
+ }
+
+ }
+
+ public User getUser3() {
+ return user3;
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerTestbase.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,153 @@
+/*
+* ##% 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.credentials;
+
+import java.util.Collection;
+import java.util.List;
+
+import com.bm.testsuite.BaseSessionBeanFixture;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.LoginAction;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+/**
+ * The Class CredentialManagerTestbase.
+ */
+public class CredentialManagerTestbase extends BaseSessionBeanFixture<CredentialManagerImpl> {
+
+ private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
+ .getLog(CredentialManagerTestbase.class);
+
+ /** The Constant usedEntityBeans. */
+ private static final Class<?>[] usedEntityBeans = { Permission.class, User.class, Group.class, Actor.class,
+ LoginAction.class };
+
+ private static CredentialDataSet credentialDataSet = new CredentialDataSet();
+
+ /**
+ * Instantiates a new credential manager testbase.
+ */
+ public CredentialManagerTestbase() {
+ super(CredentialManagerImpl.class, usedEntityBeans, credentialDataSet);
+ }
+
+ private CredentialManager getCredentialManager() {
+ return (CredentialManager) getBeanToTest();
+ }
+
+ private static void assertPermissionOk(Permission p, boolean onlyOwner) {
+ log.info(p);
+ if (!onlyOwner) {
+ assertTrue(p.isCanRead());
+ assertTrue(p.isCanWrite());
+ assertTrue(p.isCanAdmin());
+ }
+ assertTrue(p.isOwner());
+ }
+
+ public void testGetPermission() {
+ assertPermissionOk(getCredentialManager().getPermission("user1", "b0"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user2", "b1"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user1", "b2"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user2", "b3"), false);
+ assertPermissionOk(getCredentialManager().getPermission("user2", "b4"), false);
+ }
+
+ public void testGetPermissions() {
+ Permission[] permissions;
+ for (int i = 0; i < 5; i++) {
+ permissions = getCredentialManager().getPermissions("b" + i);
+ assertEquals(permissions.length, 1);
+ }
+ }
+
+ public void testSaveElement() {
+ getCredentialManager().saveElement("user1", "s0");
+ assertPermissionOk(getCredentialManager().getPermission("user1", "s0"), true);
+ }
+
+ public void testSetPermissions() {
+ getEntityManager().getTransaction().begin();
+ getCredentialManager().saveElement("user1", "s1");
+ getCredentialManager().saveElement("user2", "s1");
+ getEntityManager().getTransaction().commit();
+ Permission[] permissions = getCredentialManager().getPermissions("s1");
+ for (Permission permission : permissions) {
+ permission.setOwner(false);
+ permission.setCanAdmin(false);
+ permission.setCanWrite(false);
+ permission.setCanRead(true);
+ }
+
+ getEntityManager().getTransaction().begin();
+ getCredentialManager().setPermissions("s1", permissions);
+ getEntityManager().getTransaction().commit();
+
+ for (int i = 1; i < 3; i++) {
+ Permission permission = getCredentialManager().getPermission("user" + i, "s1");
+ assertFalse(permission.isCanAdmin());
+ assertFalse(permission.isCanWrite());
+ assertFalse(permission.isOwner());
+ assertTrue(permission.isCanRead());
+ }
+ }
+
+ public void testGetPermissionsOwnedBy() {
+ List<Permission> permissionsOwnedBy = getCredentialManager().getPermissionsOwnedBy(
+ credentialDataSet.getUser3(), 0, credentialDataSet.N_PERMISSIONS_USER3);
+ for (Permission permission : permissionsOwnedBy) {
+ assertTrue(credentialDataSet.getUser3().equals(permission.getActor()));
+ assertPermissionOk(permission, false);
+ }
+ }
+
+ public void testGetPermissionsOwnedByCount() {
+ int permissionsOwnedByCount = getCredentialManager().getPermissionsOwnedByCount(credentialDataSet.getUser3());
+ assertEquals(permissionsOwnedByCount, credentialDataSet.N_PERMISSIONS_USER3);
+ }
+
+ public void testGetElementsVisibleBy() {
+ Collection<String> elementsVisibleBy = getCredentialManager().getElementsVisibleBy("user4");
+ assertTrue(elementsVisibleBy.contains("b3"));
+ assertTrue(elementsVisibleBy.contains("b4"));
+ assertTrue(elementsVisibleBy.contains("b5"));
+ assertEquals(elementsVisibleBy.size(), 3);
+ }
+
+ public void testGetUserFilter() {
+ assertNotNull(getCredentialManager().getUserFilter("user1"));
+ assertNotNull(getCredentialManager().getUserFilter("user2"));
+ assertNotNull(getCredentialManager().getUserFilter("admin"));
+ assertNotNull(getCredentialManager().getUserFilter("superadmin"));
+ }
+
+ public void testIsCacheValidFor() {
+ getCredentialManager().saveElement("user1", "c1");
+ assertFalse(getCredentialManager().isCacheValidFor("user1"));
+ getCredentialManager().getElementsVisibleBy("user1");
+ assertTrue(getCredentialManager().isCacheValidFor("user1"));
+ Permission[] permissions = new Permission[0];
+ getCredentialManager().setPermissions("c1", permissions);
+ assertFalse(getCredentialManager().isCacheValidFor("user1"));
+ getCredentialManager().getElementsVisibleBy("user1");
+ assertTrue(getCredentialManager().isCacheValidFor("user1"));
+ }
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/GroupTest.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class GroupTest.
+ */
+public class GroupTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new group test.
+ */
+ public GroupTest() {
+ super(Group.class, SPECIAL_GENERATORS);
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/LoginActionTest.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class LoginActionTest.
+ */
+public class LoginActionTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new login action test.
+ */
+ public LoginActionTest() {
+ super(LoginAction.class, SPECIAL_GENERATORS);
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/PermissionTest.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class PermissionTest.
+ */
+public class PermissionTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new permission test.
+ */
+ public PermissionTest() {
+ super(Permission.class, SPECIAL_GENERATORS);
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTest.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,139 @@
+/*
+* ##% 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.entities;
+
+import java.util.List;
+
+import com.bm.datagen.Generator;
+import com.bm.datagen.annotations.GeneratorType;
+import com.bm.datagen.relation.BeanCollectionGenerator;
+import com.bm.datagen.relation.SingleBeanGenerator;
+import com.bm.testsuite.BaseEntityFixture;
+
+/**
+ * The Class SecurityEntityTest.
+ */
+ at SuppressWarnings("unchecked")
+public abstract class SecurityEntityTest extends BaseEntityFixture {
+
+ /** The Constant SPECIAL_GENERATORS. */
+ protected static final Generator<?>[] SPECIAL_GENERATORS = { new GroupCreator(), new GroupsCreator(),
+ new ActorCreator(), new UserCreator(), new LoginActionCreator(), new PermissionCreator() };
+
+ /**
+ * Should not be called...
+ */
+ public SecurityEntityTest() {
+ super(null);
+ }
+
+ /**
+ * Instantiates a new security entity test.
+ *
+ * @param entityToTest the entity to test
+ * @param additionalGenerators the additional generators
+ */
+ public SecurityEntityTest(Class<?> entityToTest, Generator<?>[] additionalGenerators) {
+ super(entityToTest, additionalGenerators);
+ }
+
+ /**
+ * The Class GroupCreator.
+ */
+ @GeneratorType(className = Group.class)
+ protected static final class GroupCreator extends SingleBeanGenerator<Group> {
+
+ /**
+ * Instantiates a new group creator.
+ */
+ protected GroupCreator() {
+ super(Group.class);
+ }
+ }
+
+ /**
+ * The Class GroupsCreator.
+ */
+ @GeneratorType(className = List.class, field = "groups")
+ protected static final class GroupsCreator extends BeanCollectionGenerator<Group> {
+
+ /**
+ * Instantiates a new groups creator.
+ */
+ protected GroupsCreator() {
+ super(Group.class, 10);
+ }
+ }
+
+ /**
+ * The Class UserCreator.
+ */
+ @GeneratorType(className = User.class)
+ protected static final class UserCreator extends SingleBeanGenerator<User> {
+
+ /**
+ * Instantiates a new user creator.
+ */
+ protected UserCreator() {
+ super(User.class);
+ }
+ }
+
+ /**
+ * The Class UserCreator.
+ */
+ @GeneratorType(className = Actor.class)
+ protected static final class ActorCreator extends SingleBeanGenerator {
+
+ /**
+ * Instantiates a new user creator.
+ */
+ protected ActorCreator() {
+ super(User.class);
+ }
+ }
+
+ /**
+ * The Class LoginActionCreator.
+ */
+ @GeneratorType(className = LoginAction.class)
+ protected static final class LoginActionCreator extends SingleBeanGenerator<LoginAction> {
+
+ /**
+ * Instantiates a new login action creator.
+ */
+ protected LoginActionCreator() {
+ super(LoginAction.class);
+ }
+ }
+
+ /**
+ * The Class PermissionCreator.
+ */
+ @GeneratorType(className = Permission.class)
+ protected static final class PermissionCreator extends SingleBeanGenerator<Permission> {
+
+ /**
+ * Instantiates a new permission creator.
+ */
+ protected PermissionCreator() {
+ super(Permission.class);
+ }
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/SecurityEntityTests.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,46 @@
+/*
+* ##% 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.entities;
+
+import fr.cemagref.simexplorer.is.security.credentials.CredentialManagerTestbase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * The Class SecurityEntityTests.
+ */
+public class SecurityEntityTests {
+
+ /**
+ * Suite.
+ *
+ * @return the test
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for fr.cemagref.simexplorer.is.security.entities");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(CredentialManagerTestbase.class);
+ suite.addTestSuite(UserTest.class);
+ suite.addTestSuite(GroupTest.class);
+ suite.addTestSuite(PermissionTest.class);
+ suite.addTestSuite(LoginActionTest.class);
+ // $JUnit-END$
+ return suite;
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/test/fr/cemagref/simexplorer/is/security/entities/UserTest.java 2008-03-18 20:03:23 UTC (rev 1401)
@@ -0,0 +1,32 @@
+/*
+* ##% 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.entities;
+
+/**
+ * The Class UserTest.
+ */
+public class UserTest extends SecurityEntityTest {
+
+ /**
+ * Instantiates a new user test.
+ */
+ public UserTest() {
+ super(User.class, SPECIAL_GENERATORS);
+ }
+
+}
1
0
r1400 - in trunk/simexplorer-is/simexplorer-is-security/src: java/fr/cemagref/simexplorer/is/security/credentials java/fr/cemagref/simexplorer/is/security/dao java/fr/cemagref/simexplorer/is/security/entities resources/META-INF
by glandais@users.labs.libre-entreprise.org 18 Mar '08
by glandais@users.labs.libre-entreprise.org 18 Mar '08
18 Mar '08
Author: glandais
Date: 2008-03-18 20:02:53 +0000 (Tue, 18 Mar 2008)
New Revision: 1400
Removed:
trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/orm.xml
Modified:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java
trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/persistence.xml
Log:
Removed orm.xml
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -77,7 +77,7 @@
if (actor.equals(permission.getActor())) {
return 0;
}
- List<Group> groups = actor.getGroups();
+ Collection<Group> groups = actor.getGroups();
for (Group group : groups) {
int levelGroup = getRelativeLevel(group, permission);
if (levelGroup >= 0) {
@@ -114,6 +114,7 @@
p = permission;
minLevel = relativeLevel;
}
+ // TODO if minLevel == relativeLevel do OR
}
}
} else {
@@ -237,7 +238,7 @@
*/
private void getActors(Actor actor, Collection<Actor> actors) {
actors.add(actor);
- List<Group> groups = actor.getGroups();
+ Collection<Group> groups = actor.getGroups();
for (Group group : groups) {
getActors(group, actors);
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -184,7 +184,7 @@
"select la from LoginAction la where la.token=:token").setParameter("token", token));
if (loginAction != null) {
loggedUser = loginAction.getLoggedUser();
- loginAction.setLoginDate(new Date());
+ loginAction.setLoginDate((new Date()).getTime());
em.merge(loginAction);
}
return loggedUser;
@@ -213,8 +213,9 @@
public void deleteTokens(Actor actor, long before) {
Date now = new Date();
Date date = new Date(now.getTime() - before);
+ long dateLimit = date.getTime();
em.createQuery("delete from LoginAction la where la.loggedUser = :actor and la.loginDate < :dateLimit")
- .setParameter("dateLimit", date).setParameter("actor", actor).executeUpdate();
+ .setParameter("dateLimit", dateLimit).setParameter("actor", actor).executeUpdate();
}
/* (non-Javadoc)
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -61,14 +61,14 @@
@Override
public List<Permission> getPermissionsOwnedBy(Actor actor, int indexStart, int count) {
List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
- "select p from Permission p where p.actor=:actor and p.owner = true").setParameter("actor", actor)
+ "select p from Permission p where p.actor=:actor and p.isOwner = true").setParameter("actor", actor)
.setFirstResult(indexStart).setMaxResults(count).getResultList(), Permission.class);
return permissions;
}
public int getPermissionsOwnedByCount(Actor actor) {
Object singleResult = em.createQuery(
- "select count(p) from Permission p where p.actor=:actor and p.owner = true").setParameter("actor",
+ "select count(p) from Permission p where p.actor=:actor and p.isOwner = true").setParameter("actor",
actor).getSingleResult();
int result = ((Number) singleResult).intValue();
return result;
@@ -106,7 +106,7 @@
public List<String> getBusinessIdsVisibleBy(Collection<Actor> actors) {
StringBuffer query = new StringBuffer();
query.append("select p.businessId from Permission p").append(
- " where (p.canRead = true or p.canAdmin = true or p.owner = true)").append(" and p.actor in (:actors)");
+ " where (p.canRead = true or p.canAdmin = true or p.isOwner = true)").append(" and p.actor in (:actors)");
List<String> businessIds = CollectionUtil.toGenericList(em.createQuery(query.toString()).setParameter("actors",
actors).getResultList(), String.class);
return businessIds;
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Actor.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -19,24 +19,46 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
/**
* The Class Actor.
*/
+ at Entity
+ at Table(name = "ACTORS")
+ at Inheritance(strategy = InheritanceType.JOINED)
public class Actor implements Serializable {
-
+
/** The Constant serialVersionUID. */
+ @Transient
private static final long serialVersionUID = 1;
/** The id. */
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE)
protected Integer id;
/** The groups. */
- private List<Group> groups;
+ @ManyToMany(fetch = FetchType.EAGER, targetEntity = Group.class)
+ //@Cascade(value = {CascadeType.ALL})
+ private Collection<Group> groups;
/** The visible. */
+ @Basic
private boolean visible;
/**
@@ -82,7 +104,7 @@
*
* @return the groups
*/
- public List<Group> getGroups() {
+ public Collection<Group> getGroups() {
if (groups == null) {
groups = new ArrayList<Group>();
}
@@ -107,7 +129,7 @@
*
* @return the int
*/
- private int hashCodeGroups(List<Group> hashedGroups) {
+ private int hashCodeGroups(Collection<Group> hashedGroups) {
final int prime = 31;
int result = 1;
result = prime * result + hashedGroups.size();
@@ -139,7 +161,7 @@
*
* @return true, if successful
*/
- private boolean equalsGroups(List<Group> groups1, List<Group> groups2) {
+ private boolean equalsGroups(Collection<Group> groups1, Collection<Group> groups2) {
if (groups1 == groups2)
return true;
if (groups2 == null)
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Group.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -17,18 +17,32 @@
* ##% */
package fr.cemagref.simexplorer.is.security.entities;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
/**
* The Class Group.
*/
+ at Entity
+ at Table(name = "GROUPS")
public class Group extends Actor {
/** The Constant serialVersionUID. */
+ @Transient
private static final long serialVersionUID = 1;
/** The name. */
+ @Basic
+ @Column(unique = true)
private String name;
/** The owner. */
+ @OneToOne(fetch = FetchType.EAGER)
private User owner;
/**
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/LoginAction.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -18,26 +18,47 @@
package fr.cemagref.simexplorer.is.security.entities;
import java.io.Serializable;
-import java.util.Date;
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
/**
* The Class LoginAction.
*/
+ at Entity
+ at Table(name = "LOGINS")
public class LoginAction implements Serializable {
+ /** The Constant log. */
+ private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
+ .getLog(LoginAction.class);
+
/** The Constant serialVersionUID. */
+ @Transient
private static final long serialVersionUID = 1;
/** The id. */
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
/** The time. */
- private Date loginDate;
+ @Basic
+ private long loginDate;
/** The logged user. */
+ @OneToOne(fetch = FetchType.EAGER)
private User loggedUser;
/** The token. */
+ @Basic
private String token;
/**
@@ -63,7 +84,7 @@
*
* @return the login date
*/
- public Date getLoginDate() {
+ public long getLoginDate() {
return loginDate;
}
@@ -72,7 +93,7 @@
*
* @param loginDate the new login date
*/
- public void setLoginDate(Date loginDate) {
+ public void setLoginDate(long loginDate) {
this.loginDate = loginDate;
}
@@ -112,4 +133,44 @@
this.token = token;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((loggedUser == null) ? 0 : loggedUser.hashCode());
+ result = prime * result + (int) (loginDate ^ (loginDate >>> 32));
+ result = prime * result + ((token == null) ? 0 : token.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final LoginAction other = (LoginAction) obj;
+ if (loggedUser == null) {
+ if (other.loggedUser != null)
+ return false;
+ } else if (!loggedUser.equals(other.loggedUser))
+ return false;
+ if (loginDate != other.loginDate)
+ return false;
+ if (token == null) {
+ if (other.token != null)
+ return false;
+ } else if (!token.equals(other.token))
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/Permission.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -19,35 +19,59 @@
import java.io.Serializable;
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
/**
* The Class Permission.
*/
+ at Entity
+ at Table(name = "PERMISSIONS")
public class Permission implements Serializable {
/** The Constant serialVersionUID. */
+ @Transient
private static final long serialVersionUID = 1;
/** The id. */
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
/** The business id. */
+ @Basic
private String businessId;
/** The actor. */
+ @OneToOne(fetch = FetchType.EAGER)
private Actor actor;
/** The can read. */
+ @Basic
private boolean canRead;
/** The can write. */
+ @Basic
private boolean canWrite;
/** The can admin. */
+ @Basic
private boolean canAdmin;
/** The is owner. */
+ @Basic
private boolean isOwner;
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
@@ -188,4 +212,53 @@
this.isOwner = isOwner;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((actor == null) ? 0 : actor.hashCode());
+ result = prime * result + ((businessId == null) ? 0 : businessId.hashCode());
+ result = prime * result + (canAdmin ? 1231 : 1237);
+ result = prime * result + (canRead ? 1231 : 1237);
+ result = prime * result + (canWrite ? 1231 : 1237);
+ result = prime * result + (isOwner ? 1231 : 1237);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Permission other = (Permission) obj;
+ if (actor == null) {
+ if (other.actor != null)
+ return false;
+ } else if (!actor.equals(other.actor))
+ return false;
+ if (businessId == null) {
+ if (other.businessId != null)
+ return false;
+ } else if (!businessId.equals(other.businessId))
+ return false;
+ if (canAdmin != other.canAdmin)
+ return false;
+ if (canRead != other.canRead)
+ return false;
+ if (canWrite != other.canWrite)
+ return false;
+ if (isOwner != other.isOwner)
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/entities/User.java 2008-03-18 20:02:53 UTC (rev 1400)
@@ -17,27 +17,42 @@
* ##% */
package fr.cemagref.simexplorer.is.security.entities;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
/**
* The Class User.
*/
+ at Entity
+ at Table(name = "USERS")
public class User extends Actor {
/** The Constant serialVersionUID. */
+ @Transient
private static final long serialVersionUID = 1;
/** The login. */
+ @Basic
+ @Column(unique = true)
private String login;
/** The mail. */
+ @Basic
private String mail;
/** The password hash. */
+ @Basic
private String passwordHash;
/** The admin. */
+ @Basic
private boolean admin;
/** The super admin. */
+ @Basic
private boolean superAdmin;
/**
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/orm.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/orm.xml 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/orm.xml 2008-03-18 20:02:53 UTC (rev 1400)
@@ -1,82 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
- version="1.0">
-
- <persistence-unit-metadata>
- <xml-mapping-metadata-complete />
- </persistence-unit-metadata>
-
- <package>fr.cemagref.simexplorer.is.security.entities</package>
-
- <entity class="Actor">
- <table name="ACTORS" />
- <inheritance strategy="JOINED" />
- <attributes>
- <id name="id">
- <generated-value strategy="SEQUENCE" />
- </id>
- <basic name="visible"></basic>
- <many-to-many name="groups" target-entity="Group"
- fetch="EAGER">
- <cascade>
- <cascade-all />
- </cascade>
- </many-to-many>
- </attributes>
- </entity>
-
- <entity class="Group">
- <table name="GROUPS" />
- <attributes>
- <basic name="name">
- <column unique="true" />
- </basic>
- <one-to-one name="owner" fetch="EAGER" />
- </attributes>
- </entity>
-
- <entity class="User">
- <table name="USERS" />
- <attributes>
- <basic name="login">
- <column unique="true" />
- </basic>
- <basic name="mail"></basic>
- <basic name="passwordHash"></basic>
- <basic name="admin"></basic>
- <basic name="superAdmin"></basic>
- </attributes>
- </entity>
-
- <entity class="LoginAction">
- <table name="LOGINS" />
- <attributes>
- <id name="id">
- <generated-value strategy="SEQUENCE" />
- </id>
- <basic name="token" />
- <basic name="loginDate">
- <temporal>DATE</temporal>
- </basic>
- <one-to-one name="loggedUser" fetch="EAGER" />
- </attributes>
- </entity>
-
- <entity class="Permission">
- <table name="PERMISSIONS" />
- <attributes>
- <id name="id">
- <generated-value strategy="SEQUENCE" />
- </id>
- <basic name="businessId" />
- <basic name="canRead" />
- <basic name="canWrite" />
- <basic name="canAdmin" />
- <basic name="isOwner" />
- <one-to-one name="actor" fetch="EAGER" />
- </attributes>
- </entity>
-
-</entity-mappings>
Modified: trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/persistence.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/persistence.xml 2008-03-18 17:42:04 UTC (rev 1399)
+++ trunk/simexplorer-is/simexplorer-is-security/src/resources/META-INF/persistence.xml 2008-03-18 20:02:53 UTC (rev 1400)
@@ -10,8 +10,6 @@
<!-- la DataSource JTA gérée par l'environnement Java EE5 -->
<jta-data-source>java:/h2datasource</jta-data-source>
- <mapping-file>META-INF/orm.xml</mapping-file>
-
<properties>
<!-- logs SQL Hibernate
<property name="hibernate.show_sql" value="true"/>
1
0
r1399 - in trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities: . attachment composite metadata
by tchemit@users.labs.libre-entreprise.org 18 Mar '08
by tchemit@users.labs.libre-entreprise.org 18 Mar '08
18 Mar '08
Author: tchemit
Date: 2008-03-18 17:42:04 +0000 (Tue, 18 Mar 2008)
New Revision: 1399
Modified:
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimExplorerPage.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/RawType.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java
Log:
add annotation I18nable on i18n java file to be treated by maven-i18n-plugin.
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -19,10 +19,11 @@
/**
* Une enum pour definir les differents types d'entities rencontres dans le projet. <p/> On ajoute ici une clef i18n
* pour pouvoir traduire plus tard ces types. <p/> Note: on n'utilise pas directement les traductions pour permettre le
- * mécanisme de changement de langue (voir module swing et web).
+ * mécanisme de changement de langue (voir module swing et web).
*
* @author chemit
*/
+ at org.codelutin.i18n.I18nable
public enum EntityTypeEnum {
/** The Attachment. */
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimExplorerPage.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimExplorerPage.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimExplorerPage.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -22,6 +22,7 @@
/**
* The Enum SimExplorerPage.
*/
+ at org.codelutin.i18n.I18nable
public enum SimExplorerPage {
/** The Element delete. */
@@ -77,4 +78,4 @@
return captionKey;
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/RawType.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/RawType.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/RawType.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -28,6 +28,7 @@
*
* @author landais
*/
+ at org.codelutin.i18n.I18nable
public class RawType implements ContentType {
/** The Constant serialVersionUID. */
@@ -58,4 +59,4 @@
return "text/text";
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -29,6 +29,7 @@
/**
* The Class Attachments.
*/
+ at org.codelutin.i18n.I18nable
public final class Attachments extends SimpleComposite<Attachment> {
/** The Constant serialVersionUID. */
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -26,6 +26,7 @@
/**
* The Class Codes.
*/
+ at org.codelutin.i18n.I18nable
public final class Codes extends SimpleComposite<Code> {
/** The Constant serialVersionUID. */
@@ -42,4 +43,4 @@
return row;
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -26,6 +26,7 @@
/**
* The Class ConstantValues.
*/
+ at org.codelutin.i18n.I18nable
public final class ConstantValues extends SimpleComposite<ConstantValue> {
/** The Constant serialVersionUID. */
@@ -41,4 +42,4 @@
row.add(_("simexplorer.common.constantvalue.value"));
return row;
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -26,6 +26,7 @@
/**
* The Class Constants.
*/
+ at org.codelutin.i18n.I18nable
public final class Constants extends SimpleComposite<Constant> {
/** The Constant serialVersionUID. */
@@ -42,4 +43,4 @@
return row;
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -27,6 +27,7 @@
/**
* The Class Descriptors.
*/
+ at org.codelutin.i18n.I18nable
public final class Descriptors extends SimpleComposite<Descriptor> {
/** The Constant serialVersionUID. */
@@ -48,4 +49,4 @@
return row;
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-03-18 17:25:35 UTC (rev 1398)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-03-18 17:42:04 UTC (rev 1399)
@@ -30,6 +30,7 @@
* The Class MetaData. Used by IS to store relative data of a LoggableElement. SimExplorer should not set properties of
* this class.
*/
+ at org.codelutin.i18n.I18nable
public class MetaData extends Leaf {
/** The Constant serialVersionUID. */
@@ -314,4 +315,4 @@
return getEntityType().getLibelle();
}
-}
+}
\ No newline at end of file
1
0
r1398 - trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service
by tchemit@users.labs.libre-entreprise.org 18 Mar '08
by tchemit@users.labs.libre-entreprise.org 18 Mar '08
18 Mar '08
Author: tchemit
Date: 2008-03-18 17:25:35 +0000 (Tue, 18 Mar 2008)
New Revision: 1398
Modified:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
Log:
add annotation I18nable on i18n java file to be treated by maven-i18n-plugin.
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-03-18 17:09:57 UTC (rev 1397)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-03-18 17:25:35 UTC (rev 1398)
@@ -64,6 +64,7 @@
@Remote(AuthenticationService.class)
@RemoteBinding(jndiBinding = "AuthenticationService")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
+ at org.codelutin.i18n.I18nable
public class AuthenticationServiceImpl implements AuthenticationService {
/** The Constant log. */
@@ -556,7 +557,7 @@
superAdminCheck = true;
}
String token = null;
- // le password est deja haché
+ // le password est deja haché
// User loggedUser = daoActor.loginUser(login, AuthenticationServiceHelper.computeHash(password));
User loggedUser = daoActor.loginUser(login, password);
if (loggedUser != null) {
@@ -838,4 +839,4 @@
{
I18n.initISO88591("fr", "FR");
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java 2008-03-18 17:09:57 UTC (rev 1397)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java 2008-03-18 17:25:35 UTC (rev 1398)
@@ -25,17 +25,18 @@
import fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl;
/** The Class StorageServiceClient. */
+ at org.codelutin.i18n.I18nable
public class StorageServiceClient extends StorageServiceCommon {
/** The storage engine. */
private StorageEngine storageEngine;
/**
- * la localisation du fichier de configuration à lire, si null utilisera le
- * fichier par défaut (properties/config.properties)
+ * la localisation du fichier de configuration à lire, si null utilisera le
+ * fichier par défaut (properties/config.properties)
*/
private String configFile;
- /** le prefixe à supprimera chaque clef de la configuration. (voir Config) * */
+ /** le prefixe à supprimera chaque clef de la configuration. (voir Config) * */
private String prefixKey;
public StorageServiceClient() {
@@ -91,4 +92,4 @@
return result;
}
-}
+}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-03-18 17:09:57 UTC (rev 1397)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-03-18 17:25:35 UTC (rev 1398)
@@ -60,6 +60,7 @@
/**
* The Class StorageServiceCommon.
*/
+ at org.codelutin.i18n.I18nable
public abstract class StorageServiceCommon implements StorageService {
/** The Constant FILE_XML. */
@@ -835,4 +836,4 @@
return element;
}
-}
+}
\ No newline at end of file
1
0
r1397 - trunk/simexplorer-is/simexplorer-is-swing-generated
by tchemit@users.labs.libre-entreprise.org 18 Mar '08
by tchemit@users.labs.libre-entreprise.org 18 Mar '08
18 Mar '08
Author: tchemit
Date: 2008-03-18 17:09:57 +0000 (Tue, 18 Mar 2008)
New Revision: 1397
Modified:
trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml
Log:
i18n pour jaxx ne requiere pas d'ea, il faut donc le distinguer du parsing du code java => 2 executions i18n
Modified: trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml 2008-03-18 13:30:41 UTC (rev 1396)
+++ trunk/simexplorer-is/simexplorer-is-swing-generated/pom.xml 2008-03-18 17:09:57 UTC (rev 1397)
@@ -119,11 +119,30 @@
<executions>
<execution>
<phase>process-classes</phase>
+ <id>jaxx</id>
<goals>
+ <goal>parserJaxx</goal>
+ </goals>
+ </execution>
+ <execution>
+ <phase>process-classes</phase>
+ <id>commandline</id>
+ <goals>
<goal>parserJava</goal>
- <goal>parserJaxx</goal>
<goal>gen</goal>
</goals>
+ <configuration>
+ <ea>true</ea>
+ <treateDefaultEntry>false</treateDefaultEntry>
+ <entries>
+ <entry>
+ <basedir>${maven.src.dir}/java</basedir>
+ <excludes>
+ <param>fr\/cemagref\/simexplorer\/is\/ui\/swing\/ui\/**\/*</param>
+ </excludes>
+ </entry>
+ </entries>
+ </configuration>
</execution>
</executions>
</plugin>
1
0
Author: glandais
Date: 2008-03-18 13:30:41 +0000 (Tue, 18 Mar 2008)
New Revision: 1396
Modified:
trunk/simexplorer-is/
Log:
Ignore .classpath
Property changes on: trunk/simexplorer-is
___________________________________________________________________
Name: svn:ignore
- target
.project
*.iml
*.ipr
*.iws
+ target
.project
*.iml
*.ipr
*.iws
.classpath
1
0