예제 #1
0
  @RequestMapping("user-status-save")
  public String save(
      @ModelAttribute UserStatus userStatus,
      @RequestParam("confirmPassword") String confirmPassword,
      RedirectAttributes redirectAttributes) {
    try {
      userStatusChecker.check(userStatus);

      if (userStatus.getPassword() != null) {
        if (!userStatus.getPassword().equals(confirmPassword)) {
          messageHelper.addFlashMessage(
              redirectAttributes, "user.user.input.passwordnotequals", "两次输入密码不符");

          return "auth/user-status-input";
        }

        if (customPasswordEncoder != null) {
          userStatus.setPassword(customPasswordEncoder.encode(userStatus.getPassword()));
        }
      }

      UserStatus dest = null;
      Long id = userStatus.getId();

      if (id != null) {
        dest = userStatusManager.get(id);
        beanMapper.copy(userStatus, dest);
      } else {
        dest = userStatus;
      }

      if (id == null) {
        dest.setUserRepoRef(ScopeHolder.getUserRepoRef());
        dest.setScopeId(ScopeHolder.getScopeId());
      }

      userStatusManager.save(dest);

      messageHelper.addFlashMessage(redirectAttributes, "core.success.save", "保存成功");
    } catch (CheckUserStatusException ex) {
      logger.warn(ex.getMessage(), ex);
      messageHelper.addFlashMessage(redirectAttributes, ex.getMessage());

      return "auth/user-status-input";
    }

    return "redirect:/auth/user-status-list.do";
  }
예제 #2
0
  public String input() {
    if (userText != null) {
      for (String str : userText.split("\n")) {
        str = str.trim();

        if (str.length() == 0) {
          continue;
        }

        String username = str;
        UserDTO userDto = userConnector.findByUsername(username, ScopeHolder.getUserRepoRef());

        if (userDto == null) {
          addActionMessage(str + " is not exists.");
        } else {
          UserStatus userStatus =
              authService.createOrGetUserStatus(
                  username,
                  userDto.getId(),
                  ScopeHolder.getUserRepoRef(),
                  ScopeHolder.getScopeId());

          try {
            userStatusChecker.check(userStatus);
            userStatuses.add(userStatus);
          } catch (CheckUserStatusException ex) {
            addActionMessage(ex.getMessage());
          }
        }
      }
    }

    roles = roleManager.find("from Role where scopeId=?", ScopeHolder.getScopeId());
    roleDtos.addAll(convertRoleDtos(roles, false));

    List<ScopeInfo> sharedScopeInfos = scopeConnector.findSharedScopes();

    logger.info("{}", sharedScopeInfos);

    for (ScopeInfo scopeInfo : sharedScopeInfos) {
      List<Role> sharedRoles = authService.findRoles(scopeInfo.getId());
      roleDtos.addAll(convertRoleDtos(sharedRoles, true));
    }

    return INPUT;
  }
  @RequestMapping("user-status-batch-input")
  public String input(
      @RequestParam(value = "userText", required = false) String userText,
      Model model,
      RedirectAttributes redirectAttributes) {
    if (userText != null) {
      List<UserStatus> userStatuses = new ArrayList<UserStatus>();

      for (String str : userText.split("\n")) {
        str = str.trim();

        if (str.length() == 0) {
          continue;
        }

        UserStatus userStatus =
            userStatusManager.findUnique(
                "from UserStatus where username=? and userRepoRef=?",
                str,
                tenantHolder.getUserRepoRef());

        if (userStatus == null) {
          messageHelper.addFlashMessage(redirectAttributes, str + " is not exists.");
        } else {
          try {
            userStatusChecker.check(userStatus);
            userStatuses.add(userStatus);
          } catch (CheckUserStatusException ex) {
            logger.warn(ex.getMessage(), ex);
            messageHelper.addFlashMessage(redirectAttributes, ex.getMessage());
          }
        }
      }

      model.addAttribute("userStatuses", userStatuses);
    }

    List<Role> roles = roleManager.find("from Role where tenantId=?", tenantHolder.getTenantId());

    model.addAttribute("roles", roles);

    return "auth/user-status-batch-input";
  }
예제 #4
0
  @RequestMapping("user-status-remove")
  public String remove(
      @RequestParam("selectedItem") List<Long> selectedItem,
      RedirectAttributes redirectAttributes) {
    try {
      List<UserStatus> userStatuses = userStatusManager.findByIds(selectedItem);

      for (UserStatus userStatus : userStatuses) {
        userStatusChecker.check(userStatus);
      }

      userStatusManager.removeAll(userStatuses);
      messageHelper.addFlashMessage(redirectAttributes, "core.success.delete", "删除成功");
    } catch (CheckUserStatusException ex) {
      logger.warn(ex.getMessage(), ex);
      messageHelper.addFlashMessage(redirectAttributes, ex.getMessage());
    }

    return "redirect:/auth/user-status-list.do";
  }