java

Apache Authentication (basic-form)

Create the directory structure for the new context:

  • The directory that your application resides is called the context root or document base directory. You should keep all your HTML files and resources visible to the Internet users under the context root.
  • Create a directory called “WEB-INF” under the context root. This directory, although under the context root, is not visible to the users. This is where you keep your application’s configuration files such as web.xml.
  • Create a directory called “classes” under “WEB-INF“. This is where you keep all the Java classes such as servlets.
  • Create a dectory called “lib” under “WEB-INF“. This is where you keep the jar files and native libraries.
  • Optionally, create a directory called “src” under “WEB-INF“, for keeping the source files.

Basic authentication

just add

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Example Basic Authentication Area</realm-name>
</login-config>

<security-constraint>
<web-resource-collection>
<web-resource-name>Security Example</web-resource-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>/ser/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>

<security-role>
<role-name>View Suppliers</role-name>
</security-role>

in web.xml

and add database credentials in context xml

<Context path=”/context path”
docBase=”sup”
debug=”99″>
<Realm className=”org.apache.catalina.realm.JDBCRealm”
connectionName=”user”
connectionPassword=”pass”
connectionURL=”jdbc:mysql://server host :port/ISSYSDB”
debug=”99″
driverName=”com.mysql.jdbc.Driver”
roleNameCol=”Description”
userCredCol=”Password”
userNameCol=”UserCode”
userRoleTable=”role table”
userTable=”User table”
/>

form Authentication

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginError.jsp</form-error-page>
</form-login-config>
</login-config>

in web.xml

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s