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.servlet.ServletException ; 28 import javax.servlet.http.HttpServlet ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 32 39 public class SecuredPostServlet extends HttpServlet 40 { 41 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 42 throws ServletException , IOException 43 { 44 Principal user = request.getUserPrincipal(); 45 String path = request.getPathInfo(); 46 if( user == null ) 48 throw new ServletException (path+" not secured"); 49 String value = request.getParameter("checkParam"); 51 if( value == null || value.equals("123456") == false ) 52 throw new ServletException ("Did not find checkParam=123456"); 53 54 PrintWriter out = response.getWriter(); 55 response.setContentType("text/html"); 56 out.println("<html>"); 57 out.println("<head><title>"+path+"</title></head><body>"); 58 out.println("<h1>"+path+" Accessed</h1>"); 59 out.println("You have accessed this servlet as user: " + user); 60 out.println("</body></html>"); 61 out.close(); 62 } 63 64 protected void doGet(HttpServletRequest request, HttpServletResponse response) 65 throws ServletException , IOException 66 { 67 processRequest(request, response); 68 } 69 70 protected void doPost(HttpServletRequest request, HttpServletResponse response) 71 throws ServletException , IOException 72 { 73 processRequest(request, response); 74 } 75 76 } 77 | Popular Tags |