1 22 package org.jboss.test.web.security.authenticators; 23 24 import java.io.IOException ; 25 import java.security.Principal ; 26 27 import org.apache.catalina.Realm; 28 import org.apache.catalina.Session; 29 import org.apache.catalina.authenticator.AuthenticatorBase; 30 import org.apache.catalina.authenticator.Constants; 31 import org.apache.catalina.connector.Request; 32 import org.apache.catalina.connector.Response; 33 import org.apache.catalina.deploy.LoginConfig; 34 import org.jboss.logging.Logger; 35 import javax.servlet.http.HttpServletResponse ; 36 37 39 47 public class HeaderAuthenticator extends AuthenticatorBase 48 { 49 private static Logger log = Logger.getLogger(HeaderAuthenticator.class); 50 51 54 public HeaderAuthenticator() 55 { 56 super(); 57 } 58 59 72 protected boolean authenticate(Request request, 73 Response response, 74 LoginConfig config) 75 throws IOException 76 { 77 Realm realm = context.getRealm(); 78 81 Session session = request.getSessionInternal(true); 82 String username = request.getHeader("JBOSS_TEST_USER_NAME"); 83 String password = request.getHeader("JBOSS_TEST_CREDENTIAL"); 84 log.debug("Test UserName =" + username); 85 log.debug("Test cred present?:" + (password != null)); 86 Principal principal = realm.authenticate(username,password); 87 if(principal == null) 88 { 89 response.sendError(HttpServletResponse.SC_FORBIDDEN); 90 return false; 91 } 92 93 session.setNote(Constants.SESS_USERNAME_NOTE, principal); 95 request.setUserPrincipal(principal); 96 return true; 97 } 98 99 } 100 | Popular Tags |