Package org.beangle.ems.security

Examples of org.beangle.ems.security.Group


  public GroupPropertyExtractor(TextResource textResource) {
    super(textResource);
  }

  public Object getPropertyValue(Object target, String property) throws Exception {
    Group group = (Group) target;
    if ("users".equals(property)) {
      return getPropertyIn(group.getMembers(), "user.name");
    } else {
      return super.getPropertyValue(target, property);
    }
  }
View Full Code Here


  protected PropertyExtractor getPropertyExtractor() {
    return new GroupPropertyExtractor(getTextResource());
  }

  protected String saveAndForward(Entity<?> entity) {
    Group group = (Group) entity;
    if (entityDao.duplicate(Group.class, group.getId(), "name", group.getName())) { return redirect(
        "edit", "error.notUnique"); }
    if (!group.isPersisted()) {
      User creator = userService.get(getUserId());
      userService.createGroup(creator, group);
    } else {
      group.setUpdatedAt(new Date(System.currentTimeMillis()));
      if (!group.isPersisted()) {
        group.setCreatedAt(new Date(System.currentTimeMillis()));
      }
      entityDao.saveOrUpdate(group);
    }
    return redirect("search", "info.save.success");
  }
View Full Code Here

  public String edit() {
    Long groupId = getLong("group.id");
    if (null == groupId) {
      groupId = getLong("groupIds");
    }
    Group ao = entityDao.get(Group.class, groupId);
    User user = entityDao.get(User.class, getUserId());
    put("manager", user);
    List<Group> mngGroups = CollectUtils.newArrayList();
    if (isAdmin()) {
      mngGroups = entityDao.getAll(Group.class);
    } else {
      for (GroupMember m : user.getGroups()) {
        if (m.isManager()) mngGroups.add(m.getGroup());
      }
    }
    put("mngGroups", mngGroups);

    List<Category> categories = CollectUtils.newArrayList();
    categories.add(((Group) ao).getCategory());

    OqlBuilder<MenuProfile> query = OqlBuilder.from(MenuProfile.class, "menuProfile");
    query.where("menuProfile.category in(:categories)", categories);
    List<MenuProfile> menuProfiles = entityDao.search(query);
    put("menuProfiles", menuProfiles);

    Long menuProfileId = getLong("menuProfileId");
    MenuProfile menuProfile = null;
    if (null != menuProfileId) {
      menuProfile = entityDao.get(MenuProfile.class, menuProfileId);
      if (!menuProfile.getCategory().equals(ao.getCategory())) {
        menuProfile = (menuProfiles.get(0));
      }
    } else {
      menuProfile = (menuProfiles.get(0));
    }
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

  public String edit() {
    Long groupId = getLong("group.id");
    if (null == groupId) {
      groupId = getLong("groupIds");
    }
    Group ao = entityDao.get(Group.class, groupId);
    User user = entityDao.get(User.class, getUserId());
    put("manager", user);
    List<Group> mngGroups = CollectUtils.newArrayList();
    if (isAdmin()) {
      mngGroups = entityDao.getAll(Group.class);
    } else {
      for (GroupMember m : user.getGroups()) {
        if (m.isManager()) mngGroups.add(m.getGroup());
      }
    }
    put("mngGroups", mngGroups);

    List<Category> categories = CollectUtils.newArrayList();
    categories.add(((Group) ao).getCategory());

    OqlBuilder<MenuProfile> query = OqlBuilder.from(MenuProfile.class, "menuProfile");
    query.where("menuProfile.category in(:categories)", categories);
    List<MenuProfile> menuProfiles = entityDao.search(query);
    put("menuProfiles", menuProfiles);

    Long menuProfileId = getLong("menuProfileId");
    MenuProfile menuProfile = null;
    if (null != menuProfileId) {
      menuProfile = entityDao.get(MenuProfile.class, menuProfileId);
      if (!menuProfile.getCategory().equals(ao.getCategory())) {
        menuProfile = (menuProfiles.get(0));
      }
    } else {
      menuProfile = (menuProfiles.get(0));
    }
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());
    }

    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

      return null;
    } else {
      User user = users.get(0);
      List<Group> groups = user.getGroups();
      List<GrantedAuthorityBean> authorities = CollectUtils.newArrayList(groups.size());
      Group defaultGroup = null;
      for (Group g : groups) {
        authorities.add(new GrantedAuthorityBean(g.getName()));
        if (groupProfileService.hasProfile(g)) {
          defaultGroup = g;
        }
      }
      String categoryName = (null == defaultGroup) ? "default" : defaultGroup.getName();
      return new UserToken(user.getId(), user.getName(), user.getFullname(), user.getPassword(),
          categoryName, user.isEnabled(), user.isAccountExpired(), user.isPasswordExpired(), false,
          authorities);
    }
  }
View Full Code Here

    return "userGroup";
  }

  protected void editSetting(Entity<?> entity) {
    List<Group> groups = entityDao.getAll(Group.class);
    Group group = (Group) entity;
    groups.removeAll(HierarchyEntityUtils.getFamily(group));
    put("parents", groups);
  }
View Full Code Here

  protected PropertyExtractor getPropertyExtractor() {
    return new GroupPropertyExtractor(getTextResource());
  }

  protected String saveAndForward(Entity<?> entity) {
    Group group = (Group) entity;
    if (entityDao.duplicate(Group.class, group.getId(), "name", group.getName())) { return redirect(
        "edit", "error.notUnique"); }
    if (!group.isPersisted()) {
      User creator = userService.get(getUserId());
      group.setCode("tmp");
      groupService.createGroup(creator, group);
    } else {
      group.setUpdatedAt(new Date(System.currentTimeMillis()));
      if (!group.isPersisted()) {
        group.setCreatedAt(new Date(System.currentTimeMillis()));
      }
      entityDao.saveOrUpdate(group);
    }
    Long newParentId = getLong("parent.id");
    int indexno = getInteger("indexno");
    Group parent = null;
    if (null != newParentId) {
      parent = entityDao.get(Group.class, newParentId);
    }
    groupService.moveGroup(group, parent, indexno);
    return redirect("search", "info.save.success");
View Full Code Here

      return null;
    } else {
      User user = users.get(0);
      List<Group> groups = user.getGroups();
      List<GrantedAuthorityBean> authorities = CollectUtils.newArrayList(groups.size());
      Group defaultGroup = null;
      for (Group g : groups) {
        authorities.add(new GrantedAuthorityBean(g.getId()));
        if (groupProfileService.hasProfile(g)) {
          defaultGroup = g;
        }
      }
      String categoryName = (null == defaultGroup) ? "default" : defaultGroup.getName();
      return new UserToken(user.getId(), user.getName(), user.getFullname(), user.getPassword(),
          categoryName, user.isEnabled(), user.isAccountExpired(), user.isPasswordExpired(), false,
          authorities);
    }
  }
View Full Code Here

TOP

Related Classes of org.beangle.ems.security.Group

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.