You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2012/06/14 17:34:33 UTC
svn commit: r1350297 - in /incubator/syncope/trunk/core/src:
main/java/org/apache/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java
test/java/org/apache/syncope/core/persistence/relationships/UserSearchTest.java
Author: fmartelli
Date: Thu Jun 14 15:34:33 2012
New Revision: 1350297
URL: http://svn.apache.org/viewvc?rev=1350297&view=rev
Log:
SYNCOPE-95 #comment without any role users are considered to be all in the same role
Added:
incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/relationships/UserSearchTest.java
- copied, changed from r1349376, incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/UserSearchTest.java
Modified:
incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java
Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java?rev=1350297&r1=1350296&r2=1350297&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java Thu Jun 14 15:34:33 2012
@@ -38,6 +38,7 @@ import org.apache.syncope.client.search.
import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
import org.apache.syncope.core.persistence.beans.user.UAttrValue;
import org.apache.syncope.core.persistence.beans.user.USchema;
+import org.apache.syncope.core.persistence.dao.RoleDAO;
import org.apache.syncope.core.persistence.dao.SchemaDAO;
import org.apache.syncope.core.persistence.dao.UserDAO;
import org.apache.syncope.core.persistence.dao.UserSearchDAO;
@@ -52,6 +53,9 @@ public class UserSearchDAOImpl extends A
private UserDAO userDAO;
@Autowired
+ private RoleDAO roleDAO;
+
+ @Autowired
private SchemaDAO schemaDAO;
public UserSearchDAOImpl() {
@@ -125,7 +129,7 @@ public class UserSearchDAOImpl extends A
List<SyncopeUser> result = Collections.EMPTY_LIST;
- if (adminRoles != null && !adminRoles.isEmpty()) {
+ if (adminRoles != null && (!adminRoles.isEmpty() || roleDAO.findAll().isEmpty())) {
LOG.debug("Search condition:\n{}", searchCondition);
if (!searchCondition.checkValidity()) {
Copied: incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/relationships/UserSearchTest.java (from r1349376, incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/UserSearchTest.java)
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/relationships/UserSearchTest.java?p2=incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/relationships/UserSearchTest.java&p1=incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/UserSearchTest.java&r1=1349376&r2=1350297&rev=1350297&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/UserSearchTest.java (original)
+++ incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/relationships/UserSearchTest.java Thu Jun 14 15:34:33 2012
@@ -16,11 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.syncope.core.persistence.dao;
+package org.apache.syncope.core.persistence.relationships;
-import org.apache.syncope.core.persistence.dao.EntitlementDAO;
-import org.apache.syncope.core.persistence.dao.UserDAO;
-import org.apache.syncope.core.persistence.dao.UserSearchDAO;
+import org.apache.syncope.core.persistence.dao.*;
import static org.junit.Assert.*;
import java.util.HashSet;
@@ -33,10 +31,8 @@ import org.springframework.test.context.
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.apache.syncope.client.search.AttributeCond;
-import org.apache.syncope.client.search.MembershipCond;
import org.apache.syncope.client.search.NodeCond;
-import org.apache.syncope.client.search.ResourceCond;
-import org.apache.syncope.client.search.SyncopeUserCond;
+import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
import org.apache.syncope.core.util.EntitlementUtil;
@@ -50,75 +46,25 @@ public class UserSearchTest {
private UserDAO userDAO;
@Autowired
+ private RoleDAO roleDAO;
+
+ @Autowired
private UserSearchDAO searchDAO;
@Autowired
private EntitlementDAO entitlementDAO;
@Test
- public void matches() {
- SyncopeUser user = userDAO.find(1L);
- assertNotNull(user);
-
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(5L);
-
- assertFalse(searchDAO.matches(user, NodeCond.getLeafCond(membershipCond)));
-
- membershipCond.setRoleId(1L);
-
- assertTrue(searchDAO.matches(user, NodeCond.getLeafCond(membershipCond)));
- }
-
- @Test
- public void searchWithLikeCondition() {
- AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond.setSchema("fullname");
- fullnameLeafCond.setExpression("%o%");
-
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(1L);
-
- AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
- loginDateCond.setSchema("loginDate");
- loginDateCond.setExpression("2009-05-26");
+ public void issueSYNCOPE95() {
- NodeCond subCond = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond), NodeCond.getLeafCond(
- membershipCond));
+ Set<SyncopeRole> roles = new HashSet<SyncopeRole>(roleDAO.findAll());
- assertTrue(subCond.checkValidity());
+ for (SyncopeRole role : roles) {
+ roleDAO.delete(role.getId());
+ }
- NodeCond cond = NodeCond.getAndCond(subCond, NodeCond.getLeafCond(loginDateCond));
+ roleDAO.flush();
- assertTrue(cond.checkValidity());
-
- List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), cond);
- assertNotNull(users);
- assertEquals(1, users.size());
- }
-
- @Test
- public void searchWithNotCondition() {
- final AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.EQ);
- fullnameLeafCond.setSchema("fullname");
- fullnameLeafCond.setExpression("fabio.martelli");
-
- final NodeCond cond = NodeCond.getNotLeafCond(fullnameLeafCond);
- assertTrue(cond.checkValidity());
-
- final List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), cond);
- assertNotNull(users);
- assertEquals(2, users.size());
-
- Set<Long> ids = new HashSet<Long>(2);
- ids.add(users.get(0).getId());
- ids.add(users.get(1).getId());
- assertTrue(ids.contains(1L));
- assertTrue(ids.contains(3L));
- }
-
- @Test
- public void searchByBoolean() {
final AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.EQ);
coolLeafCond.setSchema("cool");
coolLeafCond.setExpression("true");
@@ -132,213 +78,4 @@ public class UserSearchTest {
assertEquals(Long.valueOf(4L), users.get(0).getId());
}
-
- @Test
- public void searchByPageAndSize() {
- AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond.setSchema("fullname");
- fullnameLeafCond.setExpression("%o%");
-
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(1L);
-
- AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
- loginDateCond.setSchema("loginDate");
- loginDateCond.setExpression("2009-05-26");
-
- NodeCond subCond = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond), NodeCond.getLeafCond(
- membershipCond));
-
- assertTrue(subCond.checkValidity());
-
- NodeCond cond = NodeCond.getAndCond(subCond, NodeCond.getLeafCond(loginDateCond));
-
- assertTrue(cond.checkValidity());
-
- List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), cond, 1, 2);
- assertNotNull(users);
- assertEquals(1, users.size());
-
- users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), cond, 2, 2);
- assertNotNull(users);
- assertTrue(users.isEmpty());
- }
-
- @Test
- public void searchByMembership() {
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(1L);
-
- List<SyncopeUser> users = searchDAO.search(
- EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getLeafCond(membershipCond));
- assertNotNull(users);
- assertEquals(2, users.size());
-
- membershipCond = new MembershipCond();
- membershipCond.setRoleId(5L);
-
- users = searchDAO.search(
- EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getNotLeafCond(membershipCond));
- assertNotNull(users);
- assertEquals(4, users.size());
- }
-
- @Test
- public void searchByIsNull() {
- AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.ISNULL);
- coolLeafCond.setSchema("cool");
-
- List<SyncopeUser> users = searchDAO.search(
- EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getLeafCond(coolLeafCond));
- assertNotNull(users);
- assertEquals(3, users.size());
-
- coolLeafCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
- coolLeafCond.setSchema("cool");
-
- users = searchDAO.search(
- EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getLeafCond(coolLeafCond));
- assertNotNull(users);
- assertEquals(1, users.size());
- }
-
- @Test
- public void searchByResource() {
- ResourceCond ws2 = new ResourceCond();
- ws2.setResourceName("ws-target-resource-2");
-
- ResourceCond ws1 = new ResourceCond();
- ws1.setResourceName("ws-target-resource-list-mappings-2");
-
- NodeCond searchCondition = NodeCond.getAndCond(NodeCond.getNotLeafCond(ws2), NodeCond.getLeafCond(ws1));
-
- assertTrue(searchCondition.checkValidity());
-
- List<SyncopeUser> users = searchDAO.search(
- EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
-
- assertNotNull(users);
- assertEquals(1, users.size());
- }
-
- @Test
- public void searchByUsernameAndId() {
- final SyncopeUserCond usernameLeafCond = new SyncopeUserCond(SyncopeUserCond.Type.EQ);
- usernameLeafCond.setSchema("username");
- usernameLeafCond.setExpression("user1");
-
- final SyncopeUserCond idRightCond = new SyncopeUserCond(SyncopeUserCond.Type.LT);
- idRightCond.setSchema("id");
- idRightCond.setExpression("2");
-
- final NodeCond searchCondition = NodeCond.getOrCond(NodeCond.getLeafCond(usernameLeafCond),
- NodeCond.getLeafCond(idRightCond));
-
- final List<SyncopeUser> matchingUsers = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
- searchCondition);
-
- assertNotNull(matchingUsers);
- assertEquals(1, matchingUsers.size());
- assertEquals("user1", matchingUsers.iterator().next().getUsername());
- assertEquals(1L, matchingUsers.iterator().next().getId().longValue());
- }
-
- @Test
- public void searchByUsernameAndFullname() {
- final SyncopeUserCond usernameLeafCond = new SyncopeUserCond(SyncopeUserCond.Type.EQ);
- usernameLeafCond.setSchema("username");
- usernameLeafCond.setExpression("user1");
-
- final AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
- idRightCond.setSchema("fullname");
- idRightCond.setExpression("fabio.mart%");
-
- final NodeCond searchCondition = NodeCond.getOrCond(NodeCond.getLeafCond(usernameLeafCond),
- NodeCond.getLeafCond(idRightCond));
-
- final List<SyncopeUser> matchingUsers =
- searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
-
- assertNotNull(matchingUsers);
- assertEquals(2, matchingUsers.size());
- }
-
- @Test
- public void searchById() {
- SyncopeUserCond idLeafCond = new SyncopeUserCond(SyncopeUserCond.Type.LT);
- idLeafCond.setSchema("id");
- idLeafCond.setExpression("2");
-
- NodeCond searchCondition = NodeCond.getLeafCond(idLeafCond);
- assertTrue(searchCondition.checkValidity());
-
- List<SyncopeUser> matchingUsers =
- searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
-
- assertNotNull(matchingUsers);
- assertEquals(1, matchingUsers.size());
- assertEquals(1L, matchingUsers.iterator().next().getId().longValue());
-
- idLeafCond = new SyncopeUserCond(SyncopeUserCond.Type.LT);
- idLeafCond.setSchema("id");
- idLeafCond.setExpression("4");
-
- searchCondition = NodeCond.getNotLeafCond(idLeafCond);
- assertTrue(searchCondition.checkValidity());
-
- matchingUsers = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
-
- assertNotNull(matchingUsers);
- assertEquals(1, matchingUsers.size());
- assertEquals(4L, matchingUsers.iterator().next().getId().longValue());
- }
-
- @Test
- public void issue202() {
- final ResourceCond ws2 = new ResourceCond();
- ws2.setResourceName("ws-target-resource-2");
-
- final ResourceCond ws1 = new ResourceCond();
- ws1.setResourceName("ws-target-resource-list-mappings-1");
-
- final NodeCond searchCondition =
- NodeCond.getAndCond(NodeCond.getNotLeafCond(ws2), NodeCond.getNotLeafCond(ws1));
- assertTrue(searchCondition.checkValidity());
-
- final List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
- searchCondition);
- assertNotNull(users);
- assertEquals(1, users.size());
- assertEquals(4L, users.iterator().next().getId().longValue());
- }
-
- @Test
- public void issue242() {
- final SyncopeUserCond cond = new SyncopeUserCond(AttributeCond.Type.LIKE);
- cond.setSchema("id");
- cond.setExpression("test%");
-
- final NodeCond searchCondition = NodeCond.getLeafCond(cond);
- assertTrue(searchCondition.checkValidity());
-
- final List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
- searchCondition);
- assertNotNull(users);
- assertTrue(users.isEmpty());
- }
-
- @Test
- public void issueSYNCOPE46() {
- final SyncopeUserCond cond = new SyncopeUserCond(AttributeCond.Type.LIKE);
- cond.setSchema("username");
- cond.setExpression("%user%");
-
- final NodeCond searchCondition = NodeCond.getLeafCond(cond);
- assertTrue(searchCondition.checkValidity());
-
- final List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
- searchCondition);
- assertNotNull(users);
- assertEquals(4, users.size());
- }
}