Exemplo n.º 1
0
  @Test
  public void addUserToOrganizationTest() {
    User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER);

    Organization newOrganization = new Organization();
    newOrganization.setName("New Organization");
    organizationService.add(newOrganization);

    organizationService.getAll();

    userService.addUserToOrganization(user, newOrganization.getId(), UserRole.ROLE_ORG_USER);
    List<Organization> organizations = userService.getOrganizations(user);
    assertTrue(organizations.size() == 2);
    assertTrue(userService.isUserInOrganization(user, newOrganization, UserRole.ROLE_ORG_USER));
  }
Exemplo n.º 2
0
  @Test
  public void addUserAdminToGroup() {
    User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER);

    Organization newOrganization = new Organization();
    newOrganization.setName("New Organization");
    organizationService.add(newOrganization);

    Group group = new Group();
    group.setAccessCode(UUID.randomUUID().toString());
    group.setName("New Group");
    group.setOrganization(newOrganization);
    groupService.save(group);
    groupService.getAll();

    GroupUserRequest groupUserRequest =
        requestService.createGroupUserRequest(user, group.getAccessCode());
    requestService.getAll(group.getId());

    boolean isAdded =
        userService.addUserToGroup(
            groupUserRequest.getUser(),
            groupUserRequest.getGroup().getId(),
            UserRole.ROLE_GROUP_ADMIN);
    assertTrue(isAdded);
  }
Exemplo n.º 3
0
  @Before
  public void setup() throws ConstraintViolation, NullDomainReference {

    createContacts();

    committee = new Committee();
    committee.setName("Committee Name");
    committeeService.create(committee);
    contactService.addContactToCommittee(first, committee);
    contactService.addContactToCommittee(second, committee);

    organization = new Organization();
    organization.setName("Organization Name");
    organizationService.create(organization);
    contactService.addContactToOrganization(first, organization);
    contactService.addContactToOrganization(second, organization);

    event = new Event();
    event.setName("Event Name");
    event.setDateHeld("2015-01-01");
    eventService.create(event);
    contactService.attendEvent(first, event);
    contactService.attendEvent(second, event);

    group = new Group();
    group.setGroupName("New AlinskyGroup");
  }
Exemplo n.º 4
0
  @Test
  @Transactional
  public void testAddContactToOrganizationMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(organization, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(organization, secondGroup);

    Contact newContact = new Contact();
    newContact.setFirstName("Fresh Contact");
    newContact.setEmail("Fresh email");
    contactService.create(newContact);

    contactService.addContactToOrganization(newContact, organization);

    newContact = contactService.findById(newContact.getId());
    assertTrue(newContact.getOrganizations().contains(organization));

    group = groupService.findById(group.getId());
    assertTrue(group.getAggregations().contains(organization));

    secondGroup = groupService.findById(secondGroup.getId());
    assertTrue(secondGroup.getAggregations().contains(organization));

    organization = organizationService.findById(organization.getId());
    assertTrue(organization.getMembers().contains(newContact));
  }
  // This method returns all of the vulnerabilities and tab numbers
  public Object tableMap(int orgId, int appId, TableSortBean bean) throws IOException {

    if (appId != -1) {
      Application application = applicationService.loadApplication(appId);
      if (application == null || !application.isActive()) {
        log.warn(ResourceNotFoundException.getLogMessage("Application", appId));
        throw new ResourceNotFoundException();
      }
      // we update vulns and application information but not scan
      vulnerabilityFilterService.updateVulnerabilities(application);
    }
    if (orgId != -1) {
      Organization organization = organizationService.loadById(orgId);
      if (organization == null || !organization.isActive()) {
        log.warn(ResourceNotFoundException.getLogMessage("Team", orgId));
        throw new ResourceNotFoundException();
      }
      // we update vulns and team information but not scan
      vulnerabilityFilterService.updateVulnerabilities(
          organization, organization.getActiveAppIds());
    }

    if (!PermissionUtils.isAuthorized(Permission.READ_ACCESS, orgId, appId)) {
      return RestResponse.failure("You are not authorized to view this information.");
    }

    return RestResponse.success("Bulk Operation successfully ended.");
  }
Exemplo n.º 6
0
 @After
 public void tearDown() {
   groupService.deleteAll();
   organizationService.deleteAll();
   committeeService.deleteAll();
   eventService.deleteAll();
   contactService.deleteAll();
 }
Exemplo n.º 7
0
  private Organization createOrganization() {
    Organization organization = new Organization();
    organization.setAccessCode(UUID.randomUUID().toString());
    organization.setName("Test Organization 2");
    organization.setDomainConfiguration(new DomainConfiguration());
    organization.getCategories().add(createCategory(organization));
    organizationService.add(organization);

    return organization;
  }
Exemplo n.º 8
0
 @Test
 public void getApplicationsByUserApplicationTypeCategoryAppStatesTest() {
   User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER);
   user = userService.getByEmail(user.getEmail());
   Organization organization = organizationService.getAll().get(0);
   Category category = organization.getCategories().get(0);
   List<Application> applications =
       userService.getApplicationsForUser(
           user, ApplicationType.ANDROID, category.getId(), AppState.GROUP_PUBLISH);
   assertTrue(applications.size() == 1);
 }
Exemplo n.º 9
0
  @ModelAttribute("organizationList")
  public List<Organization> getOrganizations() {
    List<Organization> organizationList = organizationService.loadAllActiveFilter();
    List<Organization> returnList = list();

    for (Organization org : organizationList) {
      List<Application> validApps = PermissionUtils.filterApps(org);
      if (validApps != null && !validApps.isEmpty()) {
        org.setActiveApplications(validApps);
        returnList.add(org);
      }
    }
    return returnList;
  }
Exemplo n.º 10
0
  private User getUser(UserRole organizationUserRole, UserRole groupUserRole) {
    User user = getUser();

    Role orgRole = null;
    if (organizationUserRole != null) {
      orgRole = roleService.getRoleByAuthority(organizationUserRole.name());
      user.getRoles().add(orgRole);
    }
    Role groupRole = null;
    if (groupUserRole != null) {
      groupRole = roleService.getRoleByAuthority(groupUserRole.name());
      user.getRoles().add(groupRole);
    }

    Organization organization = createOrganization();

    Application application =
        createApplication(
            organization.getCategories().get(0), "Test Application", AppState.GROUP_PUBLISH);
    Application application2 =
        createApplication(
            organization.getCategories().get(0),
            "Test Application 2",
            AppState.ORGANIZATION_PUBLISH);

    Group group = createGroup(organization);

    group.getOwnedApplications().add(application);
    group.getOwnedApplications().add(application2);

    organization.getGroups().add(group);

    userService.save(user);

    organizationService.getAll();

    if (groupRole != null) {
      UserDomain userDomainGroup = new UserDomain();
      userDomainGroup.setUser(user);
      userDomainGroup.setDomainId(group.getId());
      userDomainGroup.setDomainType(DomainType.GROUP);
      userDomainGroup.setRole(groupRole);
      userDomainGroup.setDomainId(group.getId());

      user.getUserDomains().add(userDomainGroup);
    }

    if (orgRole != null) {
      UserDomain userDomainOrg = new UserDomain();
      userDomainOrg.setUser(user);
      userDomainOrg.setDomainId(group.getId());
      userDomainOrg.setDomainType(DomainType.ORGANIZATION);
      userDomainOrg.setRole(orgRole);
      userDomainOrg.setDomainId(organization.getId());

      user.getUserDomains().add(userDomainOrg);
    }

    userService.save(user);

    entityManager.flush();

    return user;
  }