Java Codes
Beginners
Core Java
Date Time
Java2D
Java Applets
Java AWT
Mathematics
Networking
Servlets
Session
Sound
Swing
Threads
Util Package
JDBC
Learning
Other
Security
XML
Java > Java Servlets sample source codes
Basic authentication web resource
Basic authentication web resource package com.ack.web.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Securing a web application with basic HTTP authentication * has been reduced to a configuration within web.xml * * to test: http://localhost/ack/servlet/protected/footie/get_time *
footie_time</servlet-name>
com.ack.web.servlet.BasicAuthenticationWebResource</servlet-class> </servlet>
footie_time</servlet-name>
/protected/footie/get_time</url-pattern> </servlet-mapping>
protected_zone</web-resource-name>
/protected/footie/*</url-pattern>
GET</http-method>
POST</http-method>
PUT</http-method>
DELETE</http-method>
HEAD</http-method>
OPTIONS</http-method>
TRACE</http-method> </web-resource-collection>
footie</role-name> </auth-constraint>
NONE</transport-guarantee> </user-data-constraint> </security-constraint>
BASIC</auth-method>
pure genius football club</realm-name> </login-config>
the footie guys</description>
footie</role-name> </security-role> </web-app> * * finally we need to map from the 'footie' role name to the * security principal with the application server, in weblogic * we do the following within the supporting weblogic.xml file: * *
footie</role-name>
cleve</principal-name> </security-role-assignment> </weblogic-web-app> */ public class BasicAuthenticationWebResource extends HttpServlet { public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { res.setContentType( "text/html" ); PrintWriter pw = res.getWriter(); pw.println( "
21:00 @ The Wandle Centre, Wandsworth</strong>" ); pw.println( "
don't be late!" ); } }
Privacy Policy
|
Link to Us
|
Links