Esempio n. 1
0
  @Test
  public void testUser() {
    User user = new User();
    user.setUserName("MyName1");
    user.setEmail("*****@*****.**");
    user.setCreatedUser(getUser("user"));
    user.setCreatedDate(new Date());
    user.setUserId("hello");
    user.setRole(Role.USER);
    user = userRepository.save(user);
    User user2 = new User();
    user2.setUserId("hello2");
    user2.setUserName("MyName2");
    user2.setEmail("*****@*****.**");
    user2.setCreatedUser(getUser("user"));
    user2.setCreatedDate(new Date());
    user2.setRole(Role.USER);
    userRepository.save(user2);

    assertThat(userRepository.count(), is(2L));

    assertThat(userRepository.findAll(UserSpecification.emailLike("gmail")).size(), is(1));

    assertThat(
        userRepository
            .findAll(
                Specifications.where(UserSpecification.emailLike("@paran"))
                    .and(UserSpecification.nameLike("MyName2")))
            .size(),
        is(1));
  }
Esempio n. 2
0
  /**
   * Save or Update user detail info.
   *
   * @param user current user
   * @param model model
   * @param updatedUser user to be updated.
   * @param followersStr user Id list that current will share his permission to.
   * @return "redirect:/user/list" if current user change his info, otheriwise return "redirect:/"
   */
  @RequestMapping("/save")
  @PreAuthorize("hasAnyRole('A') or #user.id == #updatedUser.id")
  public String saveOrUpdateUserDetail(
      User user,
      ModelMap model,
      @ModelAttribute("user") User updatedUser,
      @RequestParam(required = false) String followersStr) {
    checkArgument(updatedUser.validate());
    if (user.getRole() == Role.USER) {
      // General user can not change their role.
      User updatedUserInDb = userService.getUserById(updatedUser.getUserId());
      checkNotNull(updatedUserInDb);
      updatedUser.setRole(updatedUserInDb.getRole());

      // prevent user to modify with other user id
      checkArgument(
          updatedUserInDb.getId().equals(updatedUser.getId()),
          "Illegal request to update user:%s",
          updatedUser);
    }
    if (updatedUser.exist()) {
      userService.modifyUser(updatedUser, followersStr);
    } else {
      userService.saveUser(updatedUser);
    }
    model.clear();
    if (user.getId().equals(updatedUser.getId())) {
      return "redirect:/";
    } else {
      return "redirect:/user/";
    }
  }
 /**
  * Add new user into local db.
  *
  * @param securedUser user
  */
 @Transactional
 public void addNewUserIntoLocal(SecuredUser securedUser) {
   User user = securedUser.getUser();
   user.setAuthProviderClass(securedUser.getUserInfoProviderClass());
   user.setCreatedDate(new Date());
   User newUser = userService.getUserById(user.getUserId());
   if (newUser != null) {
     user = newUser.merge(user);
   }
   if (user.getRole() == null) {
     user.setRole(Role.USER);
   }
   User savedUser = userService.saveUser(user);
   securedUser.setUser(savedUser);
 }
 @Override
 public User loadUser(final String userId) {
   Map<String, String> map = SiteMinderFilter.threadStorage.get();
   User user = null;
   if (map != null) {
     user = new User();
     user.setUserId(userId);
     user.setUserName(getString(map, "name", ""));
     user.setEmail(getString(map, "email", ""));
     user.setMobilePhone(getString(map, "cellphone", ""));
     user.setAuthProviderClass(SiteminderSSOPlugin.this.getClass().getName());
     user.setEnabled(true);
     user.setExternal(true);
     user.setRole(Role.USER);
     SiteMinderFilter.threadStorage.remove();
   }
   return user;
 }