Beispiel #1
0
 public String login() {
   // Employee employee = employeeService.login(model.getLoginName(), model.getPassword());
   // 从 SpringSecurity 中获取登录信息
   SecurityUser user =
       (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
   System.out.println("employee: " + user.getEmployee());
   this.session.put("employee", user.getEmployee());
   return "success";
 }
Beispiel #2
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";
  }