1 22 package org.jboss.ejb3.test.dd.web.servlets; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.security.Principal ; 27 import javax.naming.InitialContext ; 28 import javax.naming.Context ; 29 import javax.servlet.ServletException ; 30 import javax.servlet.http.HttpServlet ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 import org.jboss.ejb3.test.dd.web.interfaces.RunAsTargetLocal; 35 import org.jboss.logging.Logger; 36 37 43 public class UnsecureRunAsServlet extends HttpServlet 44 { 45 Logger log = Logger.getLogger(UnsecureRunAsServlet.class); 46 47 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 48 throws ServletException , IOException 49 { 50 String ejbName = request.getParameter("ejbName"); 51 try 52 { 53 InitialContext ctx = new InitialContext (); 54 Context enc = (Context ) ctx.lookup("java:comp/env"); 55 RunAsTargetLocal bean = (RunAsTargetLocal) enc.lookup(ejbName); 56 bean.checkRunAs(); 57 } 58 catch(Exception e) 59 { 60 log.error("Access to checkRunAs failed", e); 61 throw new ServletException ("Access to checkRunAs failed", e); 62 } 63 64 Principal user = request.getUserPrincipal(); 65 PrintWriter out = response.getWriter(); 66 response.setContentType("text/html"); 67 out.println("<html>"); 68 out.println("<head><title>UnsecureRunAsServlet</title></head><body>"); 69 out.println("<h1>UnsecureRunAsServlet Accessed</h1>"); 70 out.println("<pre>You have accessed this servlet as user: "+user+"<br>"); 71 out.println("</pre>"); 72 out.println("</pre></body></html>"); 73 out.close(); 74 } 75 76 protected void doGet(HttpServletRequest request, HttpServletResponse response) 77 throws ServletException , IOException 78 { 79 processRequest(request, response); 80 } 81 82 protected void doPost(HttpServletRequest request, HttpServletResponse response) 83 throws ServletException , IOException 84 { 85 processRequest(request, response); 86 } 87 88 } 89 | Popular Tags |