1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.security.Principal ; 22 import javax.servlet.*; 23 import javax.servlet.http.*; 24 25 32 33 public class Authentication05 extends HttpServlet { 34 35 public void doGet(HttpServletRequest request, HttpServletResponse response) 36 throws IOException, ServletException { 37 38 response.setContentType("text/plain"); 39 PrintWriter writer = response.getWriter(); 40 StringBuffer sb = new StringBuffer (); 41 42 String remoteUser = request.getRemoteUser(); 43 if (remoteUser == null) 44 sb.append(" No remote user returned/"); 45 else if (!"tomcat".equals(remoteUser)) { 46 sb.append(" Remote user is '"); 47 sb.append(remoteUser); 48 sb.append("'/"); 49 } 50 51 Principal userPrincipal = request.getUserPrincipal(); 52 if (userPrincipal == null) 53 sb.append(" No user principal returned/"); 54 else if (!"tomcat".equals(userPrincipal.getName())) { 55 sb.append(" User principal is '"); 56 sb.append(userPrincipal); 57 sb.append("'/"); 58 } 59 60 if (!request.isUserInRole("tomcat")) 61 sb.append(" Not in role 'tomcat'/"); 62 63 if (sb.length() < 1) 64 writer.println("Authentication05 PASSED"); 65 else { 66 writer.print("Authentication05 FAILED -"); 67 writer.println(sb.toString()); 68 } 69 70 while (true) { 71 String message = StaticLogger.read(); 72 if (message == null) 73 break; 74 writer.println(message); 75 } 76 StaticLogger.reset(); 77 78 } 79 80 81 } 82 | Popular Tags |