1 4 5 package org.enhydra.shark.authentication; 6 7 import net.sf.hibernate.Session; 8 9 import org.enhydra.shark.api.RootException; 10 import org.enhydra.shark.api.UserTransaction; 11 import org.enhydra.shark.api.internal.authentication.AuthenticationManager; 12 import org.enhydra.shark.api.internal.working.CallbackUtilities; 13 import org.enhydra.shark.usergroup.HibernateUser; 14 import org.enhydra.shark.usertransaction.SharkHibernateUserTransaction; 15 import org.enhydra.shark.utilities.hibernate.HibernateUtilities; 16 17 21 public class HibernateAuthenticationManager implements AuthenticationManager { 22 23 private static final String LDB_PARAM_NAME = "HibernateAuthenticationManager.DatabaseName"; 24 private CallbackUtilities callback; 25 26 public void configure (CallbackUtilities cus) throws RootException { 27 if (null == cus) 28 throw new RootException("Cannot configure without call back impl."); 29 callback = cus; 30 HibernateUtilities.init(callback.getProperties()); 31 callback.debug("HibernateUserGroupManager configured"); 32 } 33 34 public boolean validateUser(UserTransaction t, 35 String username, 36 String password) throws RootException { 37 boolean ret = false; 38 try { 39 Session session = ((SharkHibernateUserTransaction)t).getSession(); 40 41 HibernateUser user = (HibernateUser) session.get(HibernateUser.class,username); 42 43 ret = (null != user) 44 ? passwordDigest(password).equals(user.getPasswd()) 45 : false; 46 47 endTransaction(t, false); 48 } catch (Exception e) { 49 if (e instanceof RootException) { 50 throw (RootException)e; 51 } 52 throw new RootException(e); 53 } 54 return ret; 55 } 56 57 private void endTransaction(UserTransaction t, 58 boolean commitToo) throws RootException { 59 try { 60 if (commitToo) { 61 t.commit(); 62 } 63 } catch (Exception e) { 64 throw new RootException(e); 65 } finally { 66 t.release(); 67 } 68 } 69 70 private static String passwordDigest(String password) { 71 return password; 73 } 74 } 75 76 | Popular Tags |