Package org.beangle.ems.security.nav

Examples of org.beangle.ems.security.nav.MenuProfile


  /**
   * 保存模块级权限
   */
  public String save() {
    Group mao = entityDao.get(Group.class, getLong("group.id"));
    MenuProfile menuProfile = (MenuProfile) entityDao.get(MenuProfile.class, getLong("menuProfileId"));
    Set<Resource> newResources = CollectUtils.newHashSet(entityDao.get(Resource.class,
        StrUtils.splitToLong(get("resourceId"))));

    // 管理员拥有的菜单权限和系统资源
    User manager = entityDao.get(User.class, getUserId());
    Set<Menu> mngMenus = null;
    Set<Resource> mngResources = CollectUtils.newHashSet();
    if (isAdmin()) {
      mngMenus = CollectUtils.newHashSet(menuProfile.getMenus());
    } else {
      mngMenus = CollectUtils.newHashSet(menuService.getMenus(menuProfile, (User) manager));
    }
    for (final Menu m : mngMenus) {
      mngResources.addAll(m.getResources());
    }

    Set<Authority> removedAuthorities = CollectUtils.newHashSet();
    for (final Authority au : mao.getAuthorities()) {
      if (mngResources.contains(au.getResource())) {
        if (!newResources.contains(au.getResource())) {
          removedAuthorities.add(au);
        } else {
          newResources.remove(au.getResource());
        }
      }
    }

    // 删除菜单和系统资源
    mao.getAuthorities().removeAll(removedAuthorities);

    for (Resource resource : newResources) {
      Authority authority = Model.newInstance(Authority.class);
      authority.setGroup(mao);
      authority.setResource(resource);
      mao.getAuthorities().add(authority);
    }

    entityDao.remove(removedAuthorities);
    entityDao.saveOrUpdate(mao);
    authorityManager.refreshGroupAuthorities(new GrantedAuthorityBean(mao.getName()));

    Action redirect = Action.to(this).method("edit");
    redirect.param("group.id", mao.getId()).param("menuProfileId", menuProfile.getId());
    String displayFreezen = get("displayFreezen");
    if (null != displayFreezen) {
      redirect.param("displayFreezen", displayFreezen);
    }
    return redirect(redirect, "info.save.success");
View Full Code Here


    User user = entityDao.get(User.class, getUserId());
    List<MenuProfile> profiles = menuService.getProfiles(user);
    if (profiles.isEmpty()) {
      put("menus", Collections.EMPTY_LIST);
    } else {
      MenuProfile profile = menuService.getProfile(user, getLong("security.menuProfileId"));
      put("menus", HierarchyEntityUtils.getRoots(menuService.getMenus(profile, user)));
    }
    put("menuProfiles",profiles);
    put("user", user);
    return forward();
View Full Code Here

  }

  public MenuProfile getProfile(User user, Long profileId) {
    List<MenuProfile> profiles = getProfiles(user);
    if (profiles.isEmpty()) return null;
    MenuProfile profile = profiles.get(0);
    if (null != profileId) {
      for (MenuProfile mp : profiles) {
        if (mp.getId().equals(profileId)) {
          profile = mp;
          break;
View Full Code Here

  public MenuProfile getProfile(Group group, Long profileId) {
    List<Group> path = HierarchyEntityUtils.getPath(group);
    List<MenuProfile> profiles = getProfilesInternal(path.toArray(new Group[path.size()]));
    if (profiles.isEmpty()) return null;
    MenuProfile profile = profiles.get(0);
    if (null != profileId) {
      for (MenuProfile mp : profiles) {
        if (mp.getId().equals(profileId)) {
          profile = mp;
          break;
View Full Code Here

    put("profiles", entityDao.getAll(MenuProfile.class));
    Menu menu = (Menu) entity;
    List<Menu> folders = CollectUtils.newArrayList();
    OqlBuilder<Resource> builder = OqlBuilder.from(Resource.class, "r");
    if (null != menu.getProfile() && null != menu.getProfile().getId()) {
      MenuProfile profile = entityDao.get(MenuProfile.class, menu.getProfile().getId());
      // 查找可以作为父节点的菜单
      OqlBuilder<Menu> folderBuilder = OqlBuilder.from(Menu.class, "m");
      folderBuilder.where("m.entry is null and m.profile=:profile", profile);
      folderBuilder.orderBy("m.code");
      folders = entityDao.search(folderBuilder);
View Full Code Here

      family = null;
      givenMenu = null;
    }

    User user = entityDao.get(User.class, getUserId());
    MenuProfile profile = menuService.getProfile(user, getLong("security.menuProfileId"));
    List<Menu> menus = Collections.emptyList();
    if (null != profile) {
      menus = menuService.getMenus(profile, user);
    }
    CollectionUtils.filter(menus, new Predicate() {
View Full Code Here

    return forward();
  }

  public String search() {
    User user = entityDao.get(User.class, getUserId());
    MenuProfile profile = menuService.getProfile(user, getLong("security.menuProfileId"));
    List<Menu> menus = menuService.getMenus(profile, user);
    List<Menu> menuPath = CollectUtils.newArrayList();
    Long menuId = getLong("menu.id");
    if (null != menuId) {
      Menu menu = entityDao.get(Menu.class, menuId);
View Full Code Here

      }
    }
    put("mngGroups", mngGroups);
    put("menuProfiles", menuService.getProfiles(ao));

    MenuProfile menuProfile = menuService.getProfile(ao, getLong("menuProfileId"));
    if (null != menuProfile) {
      List<Menu> menus = null;
      Collection<Resource> resources = null;
      if (isAdmin()) {
        menus = menuProfile.getMenus();
        resources = entityDao.getAll(Resource.class);
      } else {
        menus = menuService.getMenus(menuProfile, user);
        resources = authorityService.getResources(user);
      }
View Full Code Here

  /**
   * 保存模块级权限
   */
  public String save() {
    Group mao = entityDao.get(Group.class, getLong("group.id"));
    MenuProfile menuProfile = (MenuProfile) entityDao.get(MenuProfile.class, getLong("menuProfileId"));
    Set<Resource> newResources = CollectUtils.newHashSet(entityDao.get(Resource.class,
        StrUtils.splitToLong(get("resourceId"))));

    // 管理员拥有的菜单权限和系统资源
    User manager = entityDao.get(User.class, getUserId());
    Set<Menu> mngMenus = null;
    Set<Resource> mngResources = CollectUtils.newHashSet();
    if (isAdmin()) {
      mngMenus = CollectUtils.newHashSet(menuProfile.getMenus());
    } else {
      mngMenus = CollectUtils.newHashSet(menuService.getMenus(menuProfile, (User) manager));
    }
    for (final Menu m : mngMenus) {
      mngResources.addAll(m.getResources());
    }
    newResources.retainAll(mngResources);
    authorityService.authorize(mao, newResources);
    authorityManager.refreshGroupAuthorities(new GrantedAuthorityBean(mao.getName()));

    Action redirect = Action.to(this).method("edit");
    redirect.param("group.id", mao.getId()).param("menuProfileId", menuProfile.getId());
    String displayFreezen = get("displayFreezen");
    if (null != displayFreezen) {
      redirect.param("displayFreezen", displayFreezen);
    }
    return redirect(redirect, "info.save.success");
View Full Code Here

    Long menuProfileId = Params.getLong("menuProfileId");
    if (null == menuProfileId && !menuProfiles.isEmpty()) {
      menuProfileId = ((MenuProfile) (menuProfiles.get(0))).getId();
    }
    if (null != menuProfileId) {
      MenuProfile menuProfile = (MenuProfile) entityDao.get(MenuProfile.class, menuProfileId);
      List<Menu> menus = menuService.getMenus(menuProfile, user);
      Set<Resource> resources = CollectUtils.newHashSet(authorityService.getResources(user));
      Map<Group, List<Menu>> groupMenusMap = CollectUtils.newHashMap();

      for (Group group : user.getGroups()) {
View Full Code Here

TOP

Related Classes of org.beangle.ems.security.nav.MenuProfile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.