コード例 #1
0
  /**
   * Get full name from given user code
   *
   * @param code
   * @return
   */
  public String getFullName(String code) {
    LdapAccount account = this.accountManager.findByName(code, true);

    if (account != null) {
      String fullname = account.getLastName();
      if (StringService.hasLength(account.getMiddleName())) {
        fullname = fullname + " " + account.getMiddleName();
      }

      fullname = fullname + " " + account.getFirstName();

      return fullname;
    }

    return StringService.EMPTY_STRING;
  }
コード例 #2
0
ファイル: QuotaService.java プロジェクト: ngonvv/iMail
  /**
   * load quota and current using space
   *
   * @return JSON
   */
  private JSON loadQuota() {
    MailAcctConfigInfo config = this.configBo.findByUser();
    if (config == null) return FAILURE_JSON;

    String smtpDef = config.getDefaultSMTP();
    if (!StringService.hasLength(smtpDef)) {
      return FAILURE_JSON;
    }

    // get email account from ticket
    String email = MailService.getUsername(smtpDef);

    // find detail LDAP mail account
    LdapMailAccount ldapMailAccount = mailAccountManager.findByName(email);

    if (ldapMailAccount == null) return FAILURE_JSON;

    // get quota
    int quota = 0;
    try {
      quota = Integer.parseInt(ldapMailAccount.getQuota());
    } catch (NumberFormatException ex) {
      logger.warning("Error to parse quota to integer", ex);
      return FAILURE_JSON;
    }

    // check quota equal zero
    if (quota == 0) return FAILURE_JSON;

    long spaceUsed = this.headerBo.getCurrentUsing(getCode(), smtpDef);

    // create JSON to return result
    JSONObject object = new JSONObject();
    object.accumulate(FIELD_QUOTA, quota).accumulate(FIELD_USED, spaceUsed);

    return object;
  }
コード例 #3
0
  /** {@inheritDoc} */
  public void logout(
      HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    if (logger.isDebugEnabled()) logger.debug("BEFORE cleaning the account cache...");

    if (authentication != null) {
      String username = authentication.getName();
      if (authentication instanceof PrincipalAcegiUserToken) {
        username = ((PrincipalAcegiUserToken) authentication).getName();
      } else if (authentication.getPrincipal() instanceof UserDetails) {
        username = ((UserDetails) authentication.getPrincipal()).getUsername();
      }

      // show information.
      if (logger.isDebugEnabled()) logger.debug("Cleaning account of user: [" + username + "]");

      try {
        if (StringService.hasLength(username)) AccountCacheService.remove(username);
      } catch (Exception ex) {
        logger.warning("Could not cleaning the cache, message: [" + ex.getMessage() + "].");
      }
    }

    if (logger.isDebugEnabled()) logger.debug("AFTER cleaning the account cache...");
  }
コード例 #4
0
 /** @return the cache key from the given user code. */
 protected static String applyStrategy(String code) {
   if (!StringService.hasLength(code)) return PERMISSION_CACHE_KEY;
   return PERMISSION_CACHE_KEY + '#' + code;
 }