<p>In Spring Security, we will discuss about the Spring security <b>HTTP basic</b> <b>authentication</b>. When HTTP basic authentication is configured, web browser will display a login dialog for user authentication.</p>
<div dir="ltr" style="text-align: left;">
<h2><b>Required Tools used for this Application:</b></h2>
<ul style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1.4; margin: 0.5em 0px; orphans: 2; padding: 0px 2.5em; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">Spring MVC 3.0.1</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">Spring Security 3.1.0</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">STS 2.8.1.RELEASE</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">Tomcat 7</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">Jdk 1.7</li>
</ul>
<div id="ads-id" align="center"></div>
<div style="background-color: #f2f9fc; border: 1px solid #c9e6f2; border-radius: 3px; padding: 16px; line-height: 1.45;">
<p><span style="color: red; font-size: x-large; text-align: center;"><b>Popular Tutorials</b></span></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/spring-tutorial/"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/"><strong>Spring Boot Tutorial</strong> </a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint/"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/using-spring-jdbc-framework-chapter-32/"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-hateoas-hypermedia-driven-restful-web-service/"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/jax-rs-web-service-tutorial/"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-batch-process-with-example/"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<p>You can configure <b><i>HTTP basic authentication</i></b> in<i> <b>sdnext-security.xml</b> </i>as follows :</p>
<pre class="highlight"><;?xml version="1.0" encoding="UTF-8"?>; 
<;beans xmlns="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:> 
To enable <b>HTTP basic</b>, just change "<b>form-login"</b> to "<b>http-basic</b>" tag. As follows on the above file 
<pre class="highlight"><;security:http auto-config="true" >; 
 <;security:intercept-url pattern="/index*" access="ROLE_USER" />; 
 <;security:http-basic>;<;/security:http-basic>; 
 <;security:logout logout-success-url="/logout" />; 
 <;/security:http>; 
</pre>
<p><b>And all remaining code same as the previous example <b><a class="GDACNK3CPB" style="background-color: white; font-family: Arial,Tahoma,Helvetica,FreeSans,sans-serif; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" href="https://dineshonjava.com/spring-security-form-based-login-example/" target="_blank" rel="noopener">Spring Security form-based login example ,</a></b></b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/02/httpbasic.png" border="0" /></div>
<p>After that we will run the example.<br />
<b>Running the example</b></p>
<p>Export the example as war and deploy it Tomcat 7 server. While browsing the project you will get the following screen for login:<br />
<br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /> Access URL <b>“<i>http://localhost:8080/sdnext/index</i></b>“, Spring will redirect to your custom login form.<br />
<b><i>URL : http://localhost:8080/</i><i><i>sdnext</i>/</i></b><b><i>index</i></b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/02/httpbasic1.png" border="0" /></div>
<p><b>If username/password is correct, authentication success, display requested page.</b><br />
<b><br />
</b> <b>URL : <i>http://localhost:8080/sdnext/index</i></b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/02/httpbasic11.png" width="600" height="159" border="0" /></div>
<h3><b>Download Source Code + Libs</b><br />
<a style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #888888; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: start; text-decoration: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" href="https://sites.google.com/site/dinesh9582486434/my-forms/SpringSecurityHttpBasic.zip?attredirects=0&;d=1" target="_blank" rel="noopener"><b>SpringSecurityHttpBasic.zip</b></a></h3>
<p><b>References- </b><br />
<a style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #888888; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: start; text-decoration: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" href="https://dineshonjava.com/spring-security-form-based-login-example/" target="_blank" rel="noopener"><b>https://dineshonjava.com/spring-security-form-based-login-example/</b></a><br />
<a style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #888888; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: start; text-decoration: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" href="http://static.springsource.org/spring-security/site/" target="_blank" rel="noopener"><b>Spring Security</b></a><br />
<a style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #888888; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: start; text-decoration: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" href="http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity.html" target="_blank" rel="noopener"><b>Spring Security documentation</b></a></p>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px;">
<p><span style="color: red; font-size: x-large; text-align: center;"><b>Spring Security Related Posts</b></span></p>
<ul>
<li><b><a href="https://dineshonjava.com/spring-security-interview-questions-and-answers/"><span style="color: red;">Spring Security Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-java-based-configuration-with-example/"><span style="color: red;">Spring Security Java Based Configuration with Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-xml-namespace-configuration-example/"><span style="color: red;">Spring Security XML Namespace Configuration Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-hello-world-example/"><span style="color: red;">Spring Security XML Based Hello World Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-form-based-login-example/"><span style="color: red;">Spring Security form-based login example </span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-login-form-using/"><span style="color: red;">Spring Security Login Form Based Example Using Database</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-http-basic/"><span style="color: red;">Spring Security Authentication Example Using HTTP Basic </span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-authorized-access/"><span style="color: red;"> Spring Security Authorized Access Control Example </span></a></b></li>
<li><b><a href="https://dineshonjava.com/customize-http-403-access-denied-page/"><span style="color: red;">Spring Security Customized Access Denied Page</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-custom-error-message/"><span style="color: red;">Spring Security Custom Error Message</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-logout-example/"><span style="color: red;"> Spring Security Logout Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-fetch-logged-in-username/"><span style="color: red;">Spring Security Fetch Logged in Username</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-password-hashing/"><span style="color: red;">Spring Security Password Hashing</span></a></b></li>
</ul>
<p> ;</p>
</div>
<p> ;</p>
<div style="background-color: #ff99cc;"> <b> <;<;<a href="https://dineshonjava.com/spring-security-login-form-using/">previous</a><;<; || <a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/">index </a>|| >;>;<a href="https://dineshonjava.com/spring-security-authorized-access/">next</a>>;>;</b></div>
<p> ;</p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/spring-security-login-form-using/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/spring-security-authorized-access/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '576'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…