1 package example.cmp.transaction; 2 3 import java.util.*; 4 import java.security.*; 5 import com.caucho.util.*; 6 import com.caucho.server.security.AbstractAuthenticator; 7 8 import javax.ejb.*; 9 import javax.naming.*; 10 11 15 public class CMPAuthenticator extends AbstractAuthenticator { 16 19 StudentHome studentHome = null; 20 21 28 public Principal authenticateCookie(String cookieValue) 29 { 30 return null; 31 } 32 33 36 public Principal authenticate(String user, String password) 37 { 38 Student student = null; 39 try { 40 student = getStudentHome().findByName(user); 41 42 if (student.getPassword().equals(password)) 43 return student; 44 } catch (NamingException e) { 45 e.printStackTrace(); 46 } catch (FinderException e) { 47 e.printStackTrace(); 48 } 49 50 return null; 51 } 52 53 57 private StudentHome getStudentHome() 58 throws NamingException 59 { 60 if (studentHome == null) { 61 Context cmp = (Context) new InitialContext().lookup("java:comp/env/cmp"); 63 64 studentHome = (StudentHome) cmp.lookup("transaction_student"); 66 } 67 68 return studentHome; 69 } 70 71 72 76 public boolean updateCookie(Principal user, String cookieValue) 77 { 78 return true; 79 } 80 81 85 public boolean isUserInRole(Principal user, String role) 86 { 87 return user != null; 88 } 89 } 90 91 | Popular Tags |