Exemplo n.º 1
0
/**
 * AccountCacheLogoutHandler
 *
 * @author <a href="mailto:[email protected]">Dung Nguyen</a>
 * @version $Id: AccountCacheLogoutHandler.java Nov 12, 2008 nguyen_dv $
 *     <p>Create date: Nov 12, 2008
 *     <pre>
 *  Initialization AccountCacheLogoutHandler class.
 * </pre>
 */
public class AccountCacheLogoutHandler implements LogoutHandler {
  // ~ Static fields =========================================================
  /* class logger. */
  private static final INetLogger logger = INetLogger.getLogger(AccountCacheLogoutHandler.class);

  // ~ Methods ===============================================================
  /** {@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...");
  }
}
Exemplo n.º 2
0
  /**
   * 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;
  }
Exemplo n.º 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...");
  }
Exemplo n.º 4
0
/**
 * QuotaService.
 *
 * @author <a href="mailto:[email protected]">Tan Truong</a>
 * @version $Id: QuotaService.java Jan 7, 2010 10:29:50 AM Tan Truong $
 * @since 1.0
 */
public class QuotaService extends AbstractWebOSService {
  /** logger. */
  private static final INetLogger logger = INetLogger.getLogger(QuotaService.class);

  private static final String ACTION_QUOTA = "loadQuota";
  private static final String FIELD_QUOTA = "quota";
  private static final String FIELD_USED = "used";

  /** the {@link MailHeaderBO} instance. */
  private MailHeaderBO headerBo;

  /** the {@link MailConfigureBO} instance. */
  private MailConfigureBO configBo;
  /** the {@link LdapMailAccountManager} instance. */
  private final LdapMailAccountManager mailAccountManager;
  /** @param accountManager */
  public QuotaService(
      AccountManager<Account> accountManager,
      MailHeaderBO headerBo,
      MailConfigureBO configBo,
      LdapMailAccountManager mailAccountManager) {
    super(accountManager);
    this.headerBo = headerBo;
    this.configBo = configBo;
    this.mailAccountManager = mailAccountManager;
  }

  /**
   * @see com.inet.web.service.AbstractWebOSService#execute(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  public JSON execute(HttpServletRequest request, HttpServletResponse response)
      throws WebOSServiceException {
    String action = getData(request, MailConstants.ACTION);

    if (ACTION_QUOTA.equals(action)) {
      return loadQuota();
    }
    return FAILURE_JSON;
  }

  /**
   * 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;
  }
}