1 23 24 package com.rift.coad.lib.interceptor.authenticator; 26 27 import org.apache.log4j.Logger; 29 30 import com.rift.coad.lib.interceptor.InterceptorAuthenticator; 32 import com.rift.coad.lib.interceptor.InterceptorException; 33 import com.rift.coad.lib.interceptor.credentials.Credential; 34 import com.rift.coad.lib.interceptor.credentials.Login; 35 import com.rift.coad.lib.security.AuthorizationException; 36 import com.rift.coad.lib.security.UserSession; 37 import com.rift.coad.lib.security.login.SessionLogin; 38 import com.rift.coad.lib.security.login.handlers.PasswordInfoHandler; 39 40 45 public class UserPasswordAuthenticator implements InterceptorAuthenticator { 46 47 protected Logger log = 49 Logger.getLogger(UserPasswordAuthenticator.class.getName()); 50 51 52 53 public UserPasswordAuthenticator() { 54 } 55 56 65 public UserSession authenticate(Credential credential) throws 66 InterceptorException, AuthorizationException { 67 if (!(credential instanceof Login)) { 68 throw new InterceptorException( 69 "The User Password Authenticator is only capable of " + 70 "dealling with login credentials."); 71 } 72 try { 73 Login loginInfo = (Login)credential; 74 SessionLogin sessionLogin = new SessionLogin( 75 new PasswordInfoHandler(loginInfo.getUsername(), 76 loginInfo.getPassword())); 77 78 sessionLogin.login(); 79 80 return sessionLogin.getUser(); 81 } catch (Exception ex) { 82 log.error("Failed to authenticate the user because : " + 83 ex.getMessage(),ex); 84 throw new InterceptorException( 85 "Failed to authenticate the user because : " + 86 ex.getMessage(),ex); 87 } 88 } 89 90 91 } 92 | Popular Tags |