Package org.milowski.db

Examples of org.milowski.db.DBConnection


   }
  
   public void setEmail(final String email)
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.CHANGE_USER_NAME, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               if (email==null) {
                  s.setNull(1,Types.VARCHAR);
View Full Code Here


   public Authenticated isAuthenticated(final Realm realm,final UUID session)
      throws SQLException
   {
      final Slot<Authenticated> retval = new Slot<Authenticated>();
      if (realm==null) {
         DBConnection connection = db.getConnection();
         try {
            connection.query(AuthDB.USER_AUTHENTICATED, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,id);
                  s.setString(2,session.toString());
               }
               public void onResults(ResultSet set)
                  throws SQLException
               {
                  if (set.next()) {
                     Timestamp created = set.getTimestamp(2);
                     Timestamp expiration = set.getTimestamp(3);
                     Authenticated auth = new Authenticated(db,set.getInt(1),session,created,expiration,User.this,realm);
                     retval.set(auth);
                  }
               }
            });
            if (retval.get().isExpired()) {
               // the session has expired
               retval.get().delete();
               retval.set(null);
            }
           
         } finally {
            db.release(connection);
         }
      } else {
         DBConnection connection = db.getConnection();
         try {
            connection.query(AuthDB.REALM_USER_AUTHENTICATED, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,id);
                  s.setInt(2,realm.getId());
View Full Code Here

      throws SQLException,NoSuchAlgorithmException
   {
      if (session!=null) {
         // delete any session authentication information first
         if (realm==null) {
            DBConnection connection = db.getConnection();
            try {
               connection.update(AuthDB.DELETE_USER_AUTHENTICATION, new DBUpdateHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                     s.setString(2,session.toString());
                  }
               });
            } finally {
               db.release(connection);
            }
         } else {
            DBConnection connection = db.getConnection();
            try {
               connection.update(AuthDB.DELETE_REALM_USER_AUTHENTICATION, new DBUpdateHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                     s.setInt(2,realm.getId());
                     s.setString(3,session.toString());
                  }
               });
            } finally {
               db.release(connection);
            }
         }
      }

      // delete any expired sessions for the user
      final Timestamp created = new Timestamp(System.currentTimeMillis());
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.DELETE_EXPIRED_SESSIONS, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setTimestamp(2,created);
            }
         });
      } finally {
         db.release(connection);
      }
     
      // check the internal password
      if (checkPassword(password)) {
         // We have the correct password
         int dbid = -1;
         if (expires>0) {
            //construct an auth record with a session id
            final UUID theSession = session==null ? UUID.randomUUID() : session;
            final Timestamp expiration = new Timestamp(created.getTime()+expires);
            connection = db.getConnection();
            try {
               connection.update(AuthDB.CREATE_AUTHENTICATED, new DBUpdateHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                     if (realm==null) {
View Full Code Here

      throws SQLException,NoSuchAlgorithmException
   {

      // delete any expired sessions for the user
      final Timestamp created = new Timestamp(System.currentTimeMillis());
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.DELETE_EXPIRED_SESSIONS, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setTimestamp(2,created);
            }
         });
      } finally {
         db.release(connection);
      }
     
      int dbid = -1;
      if (expires>0) {
         //construct an auth record with a session id
         final UUID session = UUID.randomUUID();
         final Timestamp expiration = new Timestamp(created.getTime()+expires);
         connection = db.getConnection();
         try {
            connection.update(AuthDB.CREATE_AUTHENTICATED, new DBUpdateHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,id);
                  if (realm==null) {
View Full Code Here

   public boolean checkPassword(String password)
      throws SQLException,NoSuchAlgorithmException
   {
      final Slot<Boolean> found = new Slot<Boolean>(false);
      final String encrypted = md5Password(password);
      DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.CHECK_PASSWORD, new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setString(2,encrypted);
View Full Code Here

  
   public String getEncryptedPassword()
      throws SQLException
   {
      final Slot<String> found = new Slot<String>();
      DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.ENCRYPTED_PASSWORD, new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
            }
View Full Code Here

      }
     
      public void delete()
         throws SQLException
      {
         DBConnection connection = db.getConnection();
         try {
            connection.deleteById(AuthDB.DELETE_AUTHENTICATED, dbid);
         } finally {
            db.release(connection);
         }
      }
View Full Code Here

  
   protected void init()
      throws SQLException
   {
     
      DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.ROLE_PERMISSIONS, new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1, id);
            }
View Full Code Here

   }
  
   public void delete()
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.deleteById(AuthDB.DELETE_ROLE_PERMISSIONS, id);
         connection.deleteById(AuthDB.DELETE_USER_ROLES_BY_ROLE, id);
         connection.deleteById(AuthDB.DELETE_GROUP_ROLES_BY_ROLE, id);
         connection.deleteById(AuthDB.DELETE_ROLE, id);
         db.realmGroupCaches.clear();
         db.roleCache.remove(id);
      } finally {
         db.release(connection);
      }
View Full Code Here

      throws SQLException
   {
      if (permissions.contains(p)) {
         return true;
      }
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.CREATE_ROLE_PERMISSION, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1, id);
               s.setInt(2, p.getId());
View Full Code Here

TOP

Related Classes of org.milowski.db.DBConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.