public String save() {
    logger.debug("userIds: {}, roleIds: {}", userIds, roleIds);

    for (Long userId : userIds) {
      authService.configUserRole(
          userId, roleIds, ScopeHolder.getUserRepoRef(), ScopeHolder.getScopeId(), false);
    }

    return RELOAD;
  }
  @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";
  }
Beispiel #3
0
  @RequestMapping("role-def-save")
  public String save(@ModelAttribute RoleDef roleDef, RedirectAttributes redirectAttributes) {
    try {
      // before check
      roleDefChecker.check(roleDef);

      // after invoke
      RoleDef dest = null;
      Long id = roleDef.getId();

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

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

      roleDefManager.save(dest);

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

      return "auth/role-def-input";
    }

    return "redirect:/auth/role-def-list.do";
  }
  @RequestMapping("admin-batch-list")
  public String input(@RequestParam(value = "text", required = false) String text, Model model) {
    if (text != null) {
      List<UserDTO> userDtos = new ArrayList<UserDTO>();

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

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

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

        if (userDto.getStatus() != 1) {
          continue;
        }

        userDtos.add(userDto);
      }

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

    return "party/admin-batch-input";
  }
  @RequestMapping("user-status-list")
  public String list(
      @ModelAttribute Page page, @RequestParam Map<String, Object> parameterMap, Model model) {
    List<PropertyFilter> propertyFilters = PropertyFilter.buildFromMap(parameterMap);
    propertyFilters.add(new PropertyFilter("EQS_scopeId", ScopeHolder.getScopeId()));
    page = userStatusManager.pagedQuery(page, propertyFilters);

    List<UserStatus> userStatuses = (List<UserStatus>) page.getResult();
    List<UserStatusDTO> userStatusDtos =
        userStatusConverter.createUserStatusDtos(
            userStatuses, ScopeHolder.getUserRepoRef(), ScopeHolder.getScopeId());
    page.setResult(userStatusDtos);
    model.addAttribute("page", page);

    return "auth/user-status-list";
  }
Beispiel #6
0
  @RequestMapping("role-def-checkName")
  @ResponseBody
  public boolean checkName(
      @RequestParam("name") String name, @RequestParam(value = "id", required = false) Long id)
      throws Exception {
    String hql = "from RoleDef where scopeId=" + ScopeHolder.getScopeId() + " and name=?";
    Object[] params = {name};

    if (id != null) {
      hql = "from RoleDef where scopeId=" + ScopeHolder.getScopeId() + " and name=? and id<>?";
      params = new Object[] {name, id};
    }

    boolean result = roleDefManager.findUnique(hql, params) == null;

    return result;
  }
Beispiel #7
0
  public String list() {
    List<PropertyFilter> propertyFilters =
        PropertyFilter.buildFromHttpRequest(ServletActionContext.getRequest());
    propertyFilters.add(new PropertyFilter("EQS_scopeId", ScopeHolder.getScopeId()));
    page = aclSidManager.pagedQuery(page, propertyFilters);

    return SUCCESS;
  }
  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;
  }
Beispiel #9
0
  @RequestMapping("role-def-list")
  public String list(
      @ModelAttribute Page page, @RequestParam Map<String, Object> parameterMap, Model model) {
    List<PropertyFilter> propertyFilters = PropertyFilter.buildFromMap(parameterMap);
    propertyFilters.add(new PropertyFilter("EQS_scopeId", ScopeHolder.getScopeId()));
    page = roleDefManager.pagedQuery(page, propertyFilters);
    model.addAttribute("page", page);

    return "auth/role-def-list";
  }
Beispiel #10
0
  @RequestMapping("user-status-export")
  public void export(
      @ModelAttribute Page page,
      @RequestParam Map<String, Object> parameterMap,
      HttpServletResponse response)
      throws Exception {
    List<PropertyFilter> propertyFilters = PropertyFilter.buildFromMap(parameterMap);
    page = userStatusManager.pagedQuery(page, propertyFilters);

    List<UserStatus> userStatuses = (List<UserStatus>) page.getResult();
    List<UserStatusDTO> userStatusDtos =
        userStatusConverter.createUserStatusDtos(
            userStatuses, ScopeHolder.getUserRepoRef(), ScopeHolder.getScopeId());
    TableModel tableModel = new TableModel();
    tableModel.setName("user status");
    tableModel.addHeaders("id", "username", "enabled", "authorities");
    tableModel.setData(userStatusDtos);
    exportor.export(response, tableModel);
  }
Beispiel #11
0
  @RequestMapping("role-def-sync")
  public String sync(@RequestParam("id") Long id) throws Exception {
    RoleDef roleDef = roleDefManager.get(id);
    List<Role> roles = roleManager.findBy("roleDef.id", id);

    ScopeDTO currentScope = ScopeHolder.getScopeDto();
    List<ScopeDTO> scopeDtos;

    if (currentScope.isShared()) {
      scopeDtos = scopeConnector.findAll();
    } else {
      scopeDtos = new ArrayList<ScopeDTO>();
      scopeDtos.add(currentScope);
    }

    for (ScopeDTO scopeDto : scopeDtos) {
      Role existedRole = null;

      for (Role role : roles) {
        if (role.getScopeId().equals(scopeDto.getId())) {
          existedRole = role;

          break;
        }
      }

      if (existedRole == null) {
        Role role = new Role();
        role.setName(roleDef.getName());
        role.setRoleDef(roleDef);
        role.setScopeId(scopeDto.getId());
        roleManager.save(role);
      }
    }

    for (Role role : roles) {
      boolean existed = false;

      for (ScopeDTO scopeDto : scopeDtos) {
        if (role.getScopeId().equals(scopeDto.getId())) {
          existed = true;

          break;
        }
      }

      if (!existed) {
        roleManager.remove(role);
      }
    }

    return "redirect:/auth/role-def-manage.do?id=" + id;
  }
  /** http://localhost:8080/ctx/model/service.do x-scope-code: default */
  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    String scopeCode = request.getHeader(scopeHeaderName);

    if (scopeCode == null) {
      scopeCode = defaultScopeCode;
    }

    try {
      ScopeHolder.setScopeDto(scopeConnector.findByCode(scopeCode));

      request.setAttribute("scopePrefix", request.getContextPath());
      filterChain.doFilter(request, response);
    } finally {
      ScopeHolder.clear();
    }
  }
Beispiel #13
0
  public String list() {
    List<PropertyFilter> propertyFilters =
        PropertyFilter.buildFromHttpRequest(ServletActionContext.getRequest());

    String userId =
        userConnector
            .findByUsername(SpringSecurityUtils.getCurrentUsername(), ScopeHolder.getUserRepoRef())
            .getId();
    propertyFilters.add(new PropertyFilter("EQL_userId", userId));
    page = docInfoManager.pagedQuery(page, propertyFilters);

    return SUCCESS;
  }
Beispiel #14
0
  public String save() throws Exception {
    DocInfo dest = null;

    if (id > 0) {
      dest = docInfoManager.get(id);
      beanMapper.copy(model, dest);
    } else {
      dest = model;

      String userId =
          userConnector
              .findByUsername(
                  SpringSecurityUtils.getCurrentUsername(), ScopeHolder.getUserRepoRef())
              .getId();
      dest.setUserId(Long.parseLong(userId));
    }

    new File("target/uploaded").mkdirs();

    File targetFile = new File("target/uploaded", attachment.getName());
    InputStream is = null;
    OutputStream os = null;

    try {
      is = new FileInputStream(attachment);
      os = new FileOutputStream(targetFile);
      IoUtils.copyStream(is, os);
    } finally {
      if (is != null) {
        is.close();
      }

      if (os != null) {
        os.close();
      }
    }

    dest.setPath(targetFile.getName());
    docInfoManager.save(dest);

    addActionMessage(messages.getMessage("core.success.save", "保存成功"));

    return RELOAD;
  }
Beispiel #15
0
  public String save() {
    AclSid dest = null;

    if (id > 0) {
      dest = aclSidManager.get(id);
      beanMapper.copy(model, dest);
    } else {
      dest = model;
    }

    if (id == 0) {
      dest.setScopeId(ScopeHolder.getScopeId());
    }

    aclSidManager.save(dest);

    addActionMessage(messages.getMessage("core.success.save", "保存成功"));

    return RELOAD;
  }
Beispiel #16
0
  @RequestMapping("role-def-manage")
  public String manage(@RequestParam("id") Long id, Model model) throws Exception {
    RoleDef roleDef = roleDefManager.get(id);
    List<Role> roles = roleManager.findBy("roleDef.id", id);

    ScopeDTO currentScope = ScopeHolder.getScopeDto();
    List<ScopeDTO> scopeDtos;

    if (currentScope.isShared()) {
      scopeDtos = scopeConnector.findAll();
    } else {
      scopeDtos = new ArrayList<ScopeDTO>();
      scopeDtos.add(currentScope);
    }

    List<RoleDTO> roleDtos = new ArrayList<RoleDTO>();

    for (ScopeDTO scopeDto : scopeDtos) {
      Role existedRole = null;

      for (Role role : roles) {
        if (role.getScopeId().equals(scopeDto.getId())) {
          existedRole = role;

          break;
        }
      }

      if (existedRole == null) {
        RoleDTO roleDto = new RoleDTO();
        roleDto.setName(roleDef.getName());
        roleDto.setScopeId(scopeDto.getId());
        roleDto.setStatus("added");
        roleDtos.add(roleDto);
      } else {
        RoleDTO roleDto = new RoleDTO();
        roleDto.setName(roleDef.getName());
        roleDto.setId(existedRole.getId());
        roleDto.setScopeId(scopeDto.getId());
        roleDto.setStatus("existed");
        roleDtos.add(roleDto);
      }
    }

    for (Role role : roles) {
      boolean existed = false;

      for (ScopeDTO scopeDto : scopeDtos) {
        if (role.getScopeId().equals(scopeDto.getId())) {
          existed = true;

          break;
        }
      }

      if (!existed) {
        RoleDTO roleDto = new RoleDTO();
        roleDto.setName(roleDef.getName());
        roleDto.setId(role.getId());
        roleDto.setScopeId(role.getScopeId());
        roleDto.setStatus("removed");
        roleDtos.add(roleDto);
      }
    }

    model.addAttribute("roleDts", roleDtos);

    return "auth/role-def-manage";
  }