ORCentral
|
00001 package eu.coform.command.loginsession; 00002 00003 import java.sql.ResultSet; 00004 import java.sql.SQLException; 00005 import java.util.Date; 00006 00007 import eu.coform.ORException; 00008 import eu.coform.Session; 00009 import eu.coform.Error; 00010 import eu.coform.database.Database; 00011 import eu.coform.database.Query; 00012 00016 public class IsValidSessionCommand implements AbstractSectionLoginSession { 00017 00018 private Session session; 00019 00026 @Override 00027 public Boolean execute() throws ORException { 00028 Query query = Database.getInstance().getNewQuery(); 00029 query.setQuery("SELECT ExpirationDate FROM `session` WHERE hex(UUID) = '" 00030 + session.getSessionID().toBin16() + "'" ); 00031 00032 ResultSet set = Database.getInstance().query(query); 00033 00034 java.sql.Timestamp sqlDateTime = null; 00035 try { 00036 if (!(set.isBeforeFirst() && set.isAfterLast())) 00037 set.next(); 00038 else 00039 throw new ORException(Error.SessionInvalid); 00040 00041 sqlDateTime = set.getTimestamp("ExpirationDate"); 00042 } catch (SQLException e) { 00043 e.printStackTrace(); 00044 return false; 00045 } 00046 assert(sqlDateTime != null); 00047 00048 Date expirationDate = new Date(sqlDateTime.getTime()); 00049 Date currentDate = new Date(); 00050 if (!expirationDate.after(currentDate)) 00051 throw new ORException(Error.SessionExpired); 00052 00053 return true; 00054 } 00055 00056 public void setSession(Session session) { 00057 this.session = session; 00058 } 00059 00060 public Session getSession() { 00061 return session; 00062 } 00063 00064 }