Ejemplo n.º 1
0
  public String input() {
    if (id > 0) {
      model = roleManager.get(id);
    }

    Long localId =
        scopeConnector.findLocalId(ScopeHolder.getGlobalCode(), ScopeHolder.getLocalCode());
    roleDefs = roleDefManager.find("from RoleDef where localId=?", localId);

    List<LocalScopeDTO> localScopeDtos = scopeConnector.findSharedLocalScopes();

    for (LocalScopeDTO localScopeDto : localScopeDtos) {
      roleDefs.addAll(roleDefManager.find("from RoleDef where localId=?", localScopeDto.getId()));
    }

    List<Role> roles = roleManager.findBy("localId", localId);
    List<RoleDef> removedRoleDefs = new ArrayList<RoleDef>();

    for (Role role : roles) {
      for (RoleDef roleDef : roleDefs) {
        if (roleDef.getId().equals(role.getRoleDef().getId())) {
          removedRoleDefs.add(roleDef);

          break;
        }
      }
    }

    roleDefs.removeAll(removedRoleDefs);

    return INPUT;
  }
Ejemplo n.º 2
0
  public String save() {
    try {
      // before check
      roleChecker.check(model);

      // after invoke
      Role dest = null;

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

      if (id == 0) {
        dest.setGlobalId(scopeConnector.findGlobalId(ScopeHolder.getGlobalCode()));
        dest.setLocalId(
            scopeConnector.findLocalId(ScopeHolder.getGlobalCode(), ScopeHolder.getLocalCode()));
      }

      dest.setName(roleDefManager.get(roleDefId).getName());
      dest.setRoleDef(roleDefManager.get(roleDefId));

      roleManager.save(dest);

      addActionMessage(messages.getMessage("core.success.save", "保存成功"));
    } catch (CheckRoleException ex) {
      addActionMessage(ex.getMessage());

      return INPUT;
    }

    return RELOAD;
  }
Ejemplo n.º 3
0
  public RoleDTO convertRoleDto(Role role, boolean useScope) {
    RoleDTO roleDto = new RoleDTO();
    roleDto.setId(role.getId());

    if (useScope) {
      roleDto.setName(
          role.getName() + "(" + scopeConnector.findById(role.getScopeId()).getName() + ")");
    } else {
      roleDto.setName(role.getName());
    }

    roleDto.setScopeId(role.getScopeId());

    return roleDto;
  }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
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";
  }