/*
   * 获取用户权限
   */
  private List<GrantedAuthority> getAuthorityByUser(User user) {
    log.debug("*** getAuthorityByUser 开始");

    List<GrantedAuthority> authsList = null;
    Set<Role> userRoles = standardRoleManager.getAllRolesByUser(user.getId(), user.getCompanyId());

    StringBuilder roles = new StringBuilder(",");
    for (Role role : userRoles) {
      roles.append(role.getCode()).append(",");
    }
    user.setRoleCodes(roles.toString());

    Set<Function> functions = standardRoleManager.getFunctionsByRoles(userRoles);
    if (isTenant) { // 如果用户属于租户,则只授权用户角色所具有的并且该用户所在的该租户已经购买的功能
      // 查询该用户所属租户购买的所有功能
      // 如果该角色的权限包含在购买的功能内,则授权该功能
      // FIXME 需要判断是否是租户时的权限分配

      authsList = getAuthorityFromFunctions(functions);

    } else { // 否则授权角色所具有的全部功能

      authsList = getAuthorityFromFunctions(functions);
    }
    log.debug("*** getAuthorityByUser 结束");

    authsList = DynamicAuthority.getLogAuthority(authsList, roles);

    return authsList;
  }
  public UserDetails loadUserByUsername(String loginName)
      throws UsernameNotFoundException, DataAccessException {
    log.debug("*** Received parameter: loginName:" + loginName);
    if (loginName.contains(
        "%")) { // 表示是swing“办公助手”中访问v1/tickets过来的,有%表示用户登录名或分支编码有中文,已进行编码URLEncoder.encode(username,
      // "utf-8"),需要解码
      try {
        loginName = URLDecoder.decode(loginName, "utf-8");
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }
    }
    // loginName的格式为loginName~~companyCode
    User user = userManager.getUserByLoginNameAndBranchCode(loginName);

    //		try {
    //			Map<String, String> licence = License.getLicense();
    //			String dateString = licence.get("end_time");
    //			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    //			Date settingDate = df.parse(dateString);
    //			Date date = userManager.getUserTs(user.getCompanyId());
    //			if(date != null && settingDate.before(date)){
    //				log.error("licence invalidation");
    //				throw new UsernameNotFoundException("licence invalidation");
    //			}
    //		} catch (Exception e) {
    //			log.error("licence invalidation");
    //			throw new UsernameNotFoundException("licence invalidation");
    //		}

    if (isTenant) {
      isCompanyValidDate(user);
    }
    Company company = companyManager.getCompany(user.getCompanyId());
    Department subCompany = null;
    if (user.getSubCompanyId() != null) {
      subCompany = departmentManager.getDepartmentById(user.getSubCompanyId());
    }
    List<GrantedAuthority> authsList = getAuthorityByUser(user);

    log.debug("*** loadUserByUsername 结束");
    return createUserdetail(user, company, authsList, subCompany, loginName);
  }
Ejemplo n.º 3
0
 public void rtxReminder(WorkflowTask task) {
   String msg =
       new StringBuilder("(")
           .append(new SimpleDateFormat("yyyy-MM-dd").format(new Date(System.currentTimeMillis())))
           .append(")任务:")
           .append(task.getTitle())
           .append("已经生成")
           .append(((System.currentTimeMillis() - task.getCreatedTime().getTime()) / MILLI_SECOND))
           .append("天了。请尽快办理!")
           .toString();
   String url =
       SystemUrls.getSystemUrl(StringUtils.substring(task.getUrl(), 0, task.getUrl().indexOf('/')))
           + StringUtils.substring(task.getUrl(), task.getUrl().indexOf('/'));
   if (url.contains("?")) {
     url = url + task.getId();
   } else {
     url = url + "?taskId=" + task.getId();
   }
   User user = userManager.getUserByLoginName(task.getTransactor());
   rtx.RtxMsgSender.sendNotify(task.getTransactor(), "任务办理提醒", "1", msg, url, user.getCompanyId());
 }