Example usage for org.apache.commons.lang.time DateUtils DateUtils

List of usage examples for org.apache.commons.lang.time DateUtils DateUtils

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils DateUtils.

Prototype

public DateUtils() 

Source Link

Document

DateUtils instances should NOT be constructed in standard programming.

Usage

From source file:com.livgrhm.kansas.api.AuthMap.java

public boolean isAuthorised(String hash, String ip) {
    System.out.println("AUTHORISING: " + hash + " IP: " + ip);

    if (hash == null || hash.equals("")) {
        return false;
    }//from w w  w .  j a v  a2 s .  c  o m

    this.thisAuth = (AuthItem) this.authMap.get(hash);

    // current expiration time set as 8 hours
    DateUtils du = new DateUtils();
    java.sql.Date testDate = new java.sql.Date((new java.util.Date()).getTime());

    if (this.thisAuth != null) {
        if (!this.thisAuth.loginDate.toString().equals(testDate.toString())
                || !this.thisAuth.ipAddress.equals(ip)) {
            // session expired - so return false, and delete this entry
            authMap.remove(hash);
            return false;
        }
        return true; // i.e. the hash exists, and is current!
    }

    // hash is not in the list, but could be in the database (i.e. logged on from another instance of the server, or server could have
    // been bounced. So see if it is in the db
    User user = this.dao.getUserByCurrentHash(hash);
    if (user == null) {
        return false; // hash doesn't exist
    }
    if (!user.getUserAuthTimestamp().toString().equals(testDate.toString())) {
        return false; // hash is in the db, but has expired
    }
    if (!user.getUserLastIP().equals(ip)) {
        return false; // hash is in the db, but wrong IP address
    }

    // so has exists and is still current - update thisAuth (i.e. for the current request), and update the hash table and return true
    AuthItem ai = new AuthItem();
    ai.userId = user.getUserId();
    ai.loginDate = user.getUserAuthTimestamp();
    ai.ipAddress = ip;
    authMap.put(hash, ai);
    thisAuth = ai;
    return true;
}