Example #1
0
 public void prepareSave() {
   if (id == null) model = new Employee();
   else {
     model = employeeService.get(id);
     model.getRoles().clear();
   }
 }
Example #2
0
  public String validateLoginName() {

    if (oldLoginName.equals(model.getLoginName())) {
      return "success";
    }

    // 验证 loginName 是否可用
    String loginName = model.getLoginName();
    try {
      employeeService.login(loginName, "");
    } catch (EmployeeNotExitException e) {
      // 用户名可用.
      return "success";
    } catch (NotMatchPasswordException e) {
      addFieldError("loginName", getText("errors.loginname.invalid"));
      return "save-input";
    }

    return null;
  }
Example #3
0
  // ajax 检验 loginName 是否可用
  public String ajaxValidateLoginName() {
    String loginName = model.getLoginName();
    try {
      employeeService.login(loginName, "");
    } catch (EmployeeNotExitException e) {
      inputStream = new ByteArrayInputStream("1".getBytes());
    } catch (NotMatchPasswordException e) {
      inputStream = new ByteArrayInputStream("0".getBytes());
    }

    return "ajax-success";
  }
Example #4
0
  public String navigate() {
    SecurityUser user =
        (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Employee employee = user.getEmployee();

    navigations = new ArrayList<>();

    Navigation navigation = new Navigation();
    navigation.setId("1001");
    navigation.setText("尚硅谷智能网络办公");
    navigations.add(navigation);

    List<Navigation> children = new ArrayList<>();
    navigation.setChildren(children);

    // 存放每个具体权限的父权限对应的 Navigation 对象, 键为父权限对应的 Authority 对象, 值为 Navigation
    Map<Authority, Navigation> parentNavigations = new HashMap<Authority, Navigation>();

    for (Role role : employee.getRoles()) {
      for (Authority authority : role.getAuthorities()) {
        if (authority.getMainResource() == null) continue;

        String displayName = authority.getDisplayName();
        String id = authority.getId() + "";

        Navigation n = new Navigation();
        n.setId(id);
        //				n.setState("closed");
        n.setText(displayName);
        String url = authority.getMainResource().getUrl();
        url = url.substring(0, url.length() - 1);
        url = ServletActionContext.getServletContext().getContextPath() + url;
        System.out.println(url);

        n.setUrl(url);

        Navigation pn = parentNavigations.get(authority.getParentAuthority());
        if (pn == null) {
          Authority parentAuthority = authority.getParentAuthority();

          pn = new Navigation();
          pn.setState("closed");
          pn.setId(parentAuthority.getId() + "");
          pn.setText(parentAuthority.getDisplayName());
          pn.setChildren(new ArrayList<Navigation>());

          parentNavigations.put(parentAuthority, pn);
          children.add(pn);
        }

        pn.getChildren().add(n);
      }
    }

    Navigation logout = new Navigation();
    logout.setId(3000 + "");
    logout.setText("登出");
    logout.setUrl(ServletActionContext.getServletContext().getContextPath() + "/security-logout");
    children.add(logout);

    System.out.println("children:" + children);

    return "navigate-success";
  }