Пример #1
0
  @Override
  protected boolean processFormSubmit(
      AjaxRequestTarget target, AdminBackingBean backingBean, AjaxEventType type) throws Exception {
    UserManageBackingBean userManageBackingBean = (UserManageBackingBean) backingBean;

    boolean eventHandled;

    try {
      User user = userManageBackingBean.getUser();
      eventHandled = false;

      if (type == USER_CREATED) {
        userService.persistNewUser(user, user.getPassword());
      } else if (type == USER_UPDATED) {
        userService.persistEditedUser(user);

        String password = user.getPassword();
        if (StringUtils.isNotBlank(password)) {
          userService.changePassword(user.getUsername(), password);
        }
      } else if (type == USER_DELETED) {
        deleteUser(userManageBackingBean);
      }
    } catch (ObjectNotUniqueException obnu) {
      backingBean.setServerMessage(obnu.getMessage());
      target.add(this);
      eventHandled = true;
    }

    return !eventHandled;
  }
  @Test
  public void createThreeProjectsForTwoUsers() {
    User userA = UserMother.createUser();
    userA.setUserId(1);
    User userB = UserMother.createUser();
    userB.setUserId(2);

    Project pA = ProjectMother.createProject(1);
    Project pB = ProjectMother.createProject(2);
    Project pC = ProjectMother.createProject(3);

    assignments.add(ProjectAssignmentMother.createProjectAssignment(userA, pA));
    assignments.add(ProjectAssignmentMother.createProjectAssignment(userB, pB));
    assignments.add(ProjectAssignmentMother.createProjectAssignment(userA, pC));

    int id = 1;

    for (ProjectAssignment assignment : assignments) {
      assignment.setAssignmentId(id++);
    }

    for (ProjectAssignment assignment : assignments) {
      collection.addProjectAssignment(assignment);
    }

    assertEquals(3, collection.getAssignments().size());
    assertEquals(2, collection.getUserIds().size());
  }
Пример #3
0
  @Override
  protected void onInitialize() {
    super.onInitialize();

    IModel<T> userModel = getPanelModel();

    T manageUserBackingBean = getPanelModelObject();
    User user = manageUserBackingBean.getUser();

    boolean editMode = user.getPK() != null;

    GreySquaredRoundedBorder greyBorder = new GreySquaredRoundedBorder(BORDER, WebGeo.AUTO);
    add(greyBorder);

    setOutputMarkupId(true);

    final Form<T> form = new Form<T>(FORM, userModel);

    createUsernameInput(form);
    createNameInput(form);
    createMailInput(form);
    createPasswordInput(userModel, manageUserBackingBean, form);
    createDepartmentInput(form);
    createRoleInput(form);
    createActiveInput(form);

    // show assignments
    CheckBox showAssignments = new CheckBox("showAssignments");
    showAssignments.setMarkupId("showAssignments");
    showAssignments.setVisible(!manageUserBackingBean.isEditMode());
    form.add(showAssignments);

    // data save label
    form.add(new ServerMessageLabel("serverMessage", "formValidationError"));

    boolean deletable = user.isDeletable();

    FormConfig formConfig =
        FormConfig.forForm(form)
            .withDelete(deletable)
            .withDeleteEventType(USER_DELETED)
            .withSubmitTarget(this)
            .withSubmitEventType(editMode ? USER_UPDATED : USER_CREATED);

    FormUtil.setSubmitActions(formConfig);

    greyBorder.add(form);

    onFormCreated(form);
  }
Пример #4
0
  /** Authenticate based on username/pass */
  @Override
  public boolean authenticate(String username, String password) {
    String u = username == null ? "" : username;
    String p = password == null ? "" : password;

    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(u, p);

    // Attempt authentication.
    try {
      AuthenticationManager authenticationManager =
          ((EhourWebApplication) getApplication()).getAuthenticationManager();

      if (authenticationManager == null) {
        throw new AuthenticationServiceException("no authentication manager defined");
      }

      Authentication authResult = authenticationManager.authenticate(authRequest);
      setAuthentication(authResult);

      User user = ((AuthUser) authResult.getPrincipal()).getUser();

      auditService.doAudit(
          new Audit()
              .setAuditActionType(AuditActionType.LOGIN)
              .setUser(user)
              .setUserFullName(user.getFullName())
              .setDate(new Date())
              .setSuccess(Boolean.TRUE));

      LOGGER.info("Login by user '" + username + "'.");
      return true;

    } catch (BadCredentialsException e) {
      LOGGER.info("Failed to login for" + " user '" + username + "': " + e.getMessage());
      setAuthentication(null);
      return false;

    } catch (AuthenticationException e) {
      LOGGER.info("Could not authenticate a user", e);
      setAuthentication(null);
      throw e;

    } catch (RuntimeException e) {
      LOGGER.info("Unexpected exception while authenticating a user", e);
      setAuthentication(null);
      throw e;
    }
  }
Пример #5
0
  protected User createAuthenticatedUser() {
    if (authenticatedUser == null) {
      User user = new User(4);
      user.setUsername("thies");
      user.setPassword("secret");

      Set<UserRole> userRoles = new HashSet<UserRole>();
      userRoles.addAll(UserRole.ROLES.values());

      user.setUserRoles(userRoles);

      authenticatedUser = user;
    }

    return authenticatedUser;
  }
Пример #6
0
  private void logAndAuditStopImpersonation(User originalUser, User impUser) {
    StringBuilder auditMsg =
        new StringBuilder((originalUser != null) ? originalUser.getFullName() : "N/A");
    auditMsg.append(" stopped impersonating as ");
    auditMsg.append(impUser.getFullName());

    LOGGER.info(auditMsg.toString());

    auditService.doAudit(
        new Audit()
            .setAuditActionType(AuditActionType.STOP_IMPERSONATE)
            .setUser(originalUser)
            .setUserFullName(auditMsg.toString())
            .setDate(new Date())
            .setSuccess(true));
  }
Пример #7
0
  @Before
  public void setup_userservice() throws Exception {
    super.setUp();
    getMockContext().putBean("userService", userService);

    List<User> users = new ArrayList<User>();
    user = new User();
    user.setFirstName("thies");
    user.setUserId(1);
    user.setLastName("Edeling");
    user.setUserRoles(Sets.newHashSet(UserRole.ADMIN));
    users.add(user);

    when(userService.getActiveUsers()).thenReturn(users);
    when(userService.getUserRoles()).thenReturn(new ArrayList<UserRole>());
    when(userService.getUserDepartments()).thenReturn(new ArrayList<UserDepartment>());
  }
Пример #8
0
  /**
   * Sync criteria for users, only customers & projects are displayed for users in this list
   *
   * @param reportCriteria
   */
  private void syncCriteriaForSingleUser(ReportCriteria reportCriteria) {
    Set<Customer> customers = new HashSet<Customer>();
    Set<Project> projects = new HashSet<Project>();
    AvailableCriteria availCriteria = reportCriteria.getAvailableCriteria();
    User user;

    user = reportCriteria.getUserCriteria().getUsers().get(0);

    List<ProjectAssignment> assignments =
        projectAssignmentDAO.findProjectAssignmentsForUser(
            user.getUserId(), reportCriteria.getUserCriteria().getReportRange());

    for (ProjectAssignment assignment : assignments) {
      customers.add(assignment.getProject().getCustomer());
      projects.add(assignment.getProject());
    }

    availCriteria.setCustomers(new ArrayList<Customer>(customers));
    availCriteria.setProjects(new ArrayList<Project>(projects));

    availCriteria.setReportRange(reportAggregatedDAO.getMinMaxDateTimesheetEntry(user));
  }
Пример #9
0
  @Test
  public void use_edit_when_manager_views_non_admins() throws ObjectNotFoundException {
    getConfig().setSplitAdminRole(true);
    user.setUserRoles(Sets.newHashSet(UserRole.USER));
    when(userService.getUserAndCheckDeletability(1)).thenReturn(user);

    webApp.setAuthorizedRoles(new Roles(UserRole.ROLE_MANAGER));
    super.startTester();

    tester.startPage(ManageUserPage.class);

    tester.executeAjaxEvent(
        "userSelection:border:border_body:entrySelectorFrame:entrySelectorFrame:blueBorder:blueBorder_body:itemListHolder:itemList:0",
        "click");

    tester.assertComponent("tabs:panel", ManageUserFormPanel.class);
  }