/**
   * Finds all groups for a specific user.
   *
   * @throws Exception
   */
  @Test
  public void testFindAgentGroups() throws Exception {
    Group someGroup = createGroup("someGroup", null);
    Group someAnotherGroup = createGroup("someAnotherGroup", null);
    Group someImportantGroup = createGroup("someImportantGroup", null);

    T user = createIdentityType("someAgent", null);

    IdentityManager identityManager = getIdentityManager();

    IdentityQuery<Group> query = identityManager.createIdentityQuery(Group.class);

    query.setParameter(Group.HAS_MEMBER, new Object[] {user});

    List<Group> result = query.getResultList();

    assertFalse(contains(result, "someGroup"));
    assertFalse(contains(result, "someAnotherGroup"));
    assertFalse(contains(result, "someImportantGroup"));

    identityManager.addToGroup(user, someGroup);

    query = identityManager.createIdentityQuery(Group.class);

    query.setParameter(Group.HAS_MEMBER, new Object[] {user});

    result = query.getResultList();

    assertFalse(result.isEmpty());
    assertTrue(contains(result, "someGroup"));
    assertFalse(contains(result, "someAnotherGroup"));
    assertFalse(contains(result, "someImportantGroup"));

    identityManager.addToGroup(user, someAnotherGroup);

    query = identityManager.createIdentityQuery(Group.class);

    query.setParameter(Group.HAS_MEMBER, new Object[] {user});

    result = query.getResultList();

    assertFalse(result.isEmpty());
    assertTrue(contains(result, "someGroup"));
    assertTrue(contains(result, "someAnotherGroup"));
    assertFalse(contains(result, "someImportantGroup"));

    identityManager.addToGroup(user, someImportantGroup);

    query = identityManager.createIdentityQuery(Group.class);

    query.setParameter(Group.HAS_MEMBER, new Object[] {user});

    result = query.getResultList();

    assertFalse(result.isEmpty());
    assertTrue(contains(result, "someGroup"));
    assertTrue(contains(result, "someAnotherGroup"));
    assertTrue(contains(result, "someImportantGroup"));
  }
Ejemplo n.º 2
0
 @Override
 public RoleModel getRoleById(String id) {
   IdentityQuery<Role> query = getIdm().createIdentityQuery(Role.class);
   query.setParameter(IdentityType.ID, id);
   List<Role> roles = query.getResultList();
   if (roles.size() == 0) return null;
   return new RoleAdapter(roles.get(0), getIdm());
 }
 @Override
 public List<AeroGearUser> findAllByRole(String role) {
   List aerogearUsers = new ArrayList();
   IdentityQuery<User> query = identityManager.createQuery(User.class);
   query.setParameter(User.HAS_ROLE, new String[] {role});
   List<User> result = query.getResultList();
   for (User user : result) {
     aerogearUsers.add(Converter.convertToAerogearUser(user));
   }
   return aerogearUsers;
 }
Ejemplo n.º 4
0
 @Override
 public List<RoleModel> getRoles() {
   IdentityQuery<Role> query = getIdm().createIdentityQuery(Role.class);
   query.setParameter(Role.PARTITION, applicationData);
   List<Role> roles = query.getResultList();
   List<RoleModel> roleModels = new ArrayList<RoleModel>();
   for (Role role : roles) {
     roleModels.add(new RoleAdapter(role, idm));
   }
   return roleModels;
 }