1 22 package org.jboss.ejb3.test.security.servlets; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.net.URL ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import javax.persistence.EntityManager; 30 import javax.servlet.ServletConfig ; 31 import javax.servlet.ServletException ; 32 import javax.servlet.http.HttpServlet ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import javax.transaction.UserTransaction ; 36 import org.jboss.ejb3.test.security.JobDAO; 37 import org.jboss.logging.Logger; 38 import org.jboss.security.SecurityAssociation; 39 import org.jboss.security.SimplePrincipal; 40 import org.jboss.security.auth.callback.UsernamePasswordHandler; 41 import javax.security.auth.login.LoginContext ; 42 43 44 50 public class EJBServlet extends HttpServlet 51 { 52 private static final Logger log = Logger.getLogger(EJBServlet.class); 53 54 public void init(ServletConfig config) throws ServletException 55 { 56 } 57 58 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 59 throws ServletException , IOException 60 { 61 try 62 { 63 UsernamePasswordHandler handler = new UsernamePasswordHandler("scott", "echoman"); 64 65 LoginContext lc = new LoginContext ("client-login", handler); 66 lc.login(); 67 68 InitialContext jndiContext = new InitialContext (); 69 JobDAO bean = (JobDAO)jndiContext.lookup("JobDAOBean/local"); 70 bean.foo(); 71 } catch (Exception e) 72 { 73 e.printStackTrace(); 74 throw new ServletException (e); 75 } 76 77 } 78 79 protected void doGet(HttpServletRequest request, HttpServletResponse response) 80 throws ServletException , IOException 81 { 82 processRequest(request, response); 83 } 84 85 protected void doPost(HttpServletRequest request, HttpServletResponse response) 86 throws ServletException , IOException 87 { 88 processRequest(request, response); 89 } 90 } 91 | Popular Tags |