Spring Security

Spring Security Java Configuration Annotation Example

<div dir&equals;"ltr" style&equals;"text-align&colon; justify&semi;">&NewLine;<p>In this<a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-take-baby-step-to-secure&sol;"> Spring Security tutorial<&sol;a>&comma; we’ll take a look at Spring Security Java Configuration&period; Spring Security provides authentication and access-control features for the web layer of an application&period; Spring Security is a very powerful and highly customizable authentication and access-control framework&period; Spring security provides support for authentication and access control via configuring lot of filters in a order to filter any request before accessing any secured resource&period;<&sol;p>&NewLine;<p>Here we will describe how to configure Spring Security in the web application by java based configuration instead of <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-xml-namespace-configuration-example&sol;">XML namespace configuration<&sol;a>&period; Spring Security provides support for Java Based Configuration from Spring Security 3&period;2&period; Java developers can easily configure Spring Security in the web application by Java based without the use of any XML&period;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><a href&equals;"https&colon;&sol;&sol;certification-questions&period;com&sol;buy-mock-exams&period;html&quest;affiliateCode&equals;4f5a35d8-0022-4c9c-b8d3-265ed0b825a2&amp&semi;utm&lowbar;source&equals;Dineshh&amp&semi;utm&lowbar;medium&equals;affiliate&amp&semi;utm&lowbar;campaign&equals;affiliate" target&equals;"&lowbar;blank" rel&equals;"noopener"><img src&equals;"https&colon;&sol;&sol;i1&period;wp&period;com&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2013&sol;03&sol;spring-certification-dumps&period;png" border&equals;"0" &sol;><&sol;a><&sol;div>&NewLine;<p>Spring Security&&num;8217&semi;s web infrastructure is nothing but it is collection of standard servlet filters&period; There is no web components exists into Spring Security infrastructure as like Spring MVC&comma; Struts etc&period; Spring Security only provides filter to the requests&comma; doesn&&num;8217&semi;t matter whether requests are coming from any browser&comma; device&comma; AJAX&comma; REST etc&period;<&sol;p>&NewLine;<div style&equals;"background-color&colon; &num;f2f9fc&semi; border&colon; 1px solid &num;c9e6f2&semi; border-radius&colon; 3px&semi; padding&colon; 16px&semi; line-height&colon; 1&period;45&semi;">&NewLine;<p><span style&equals;"color&colon; red&semi; font-size&colon; x-large&semi; text-align&colon; center&semi;"><b>Popular Tutorials<&sol;b><&sol;span><&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-tutorial&sol;"><em><strong>Spring Tutorial<&sol;strong> <&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-web-mvc-framework-chapter-38&sol;"><strong><em>Spring MVC Web Tutorial <&sol;em><&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;introduction-to-spring-boot-a-spring-boot-complete-guide&sol;"><strong>Spring Boot Tutorial<&sol;strong> <&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-take-baby-step-to-secure&sol;"><em>Spring Security Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint&sol;"><em>Spring AOP Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;using-spring-jdbc-framework-chapter-32&sol;"><em>Spring JDBC Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-hateoas-hypermedia-driven-restful-web-service&sol;"><em><strong>Spring HATEOAS <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;microservices-with-spring-boot&sol;"><em><strong>Microservices with Spring Boot<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;jax-rs-web-service-tutorial&sol;"><strong><em>REST Webservice<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;core-java-baby-step-to-be-best-java-ian&sol;"><em><strong>Core Java <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;hibernate-3-on-baby-steps&sol;"><em><strong>Hibernate Tutorial<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-batch-process-with-example&sol;"><strong><em>Spring Batch<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;div>&NewLine;<p>Even Spring Security provide application security but it is not a panacea which will solve all security issues&period; So we have also take care about the many potential vulnerabilities such as cross-site scripting&comma; request-forgery when application designed&period; Let&&num;8217&semi;s see this java based configuration with an example&period; Before example let recall some spring security terms with meaning&period;<&sol;p>&NewLine;<h2><b>Spring Security Terms<&sol;b><&sol;h2>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li><b style&equals;"font-size&colon; x-large&semi;">Principal<&sol;b>– User&comma; device or system that performs an action<&sol;li>&NewLine;<li><b style&equals;"font-size&colon; x-large&semi;">Authentication<&sol;b>– Establishing that a principal’s credentials are valid<&sol;li>&NewLine;<li><b style&equals;"font-size&colon; x-large&semi;">Authorization<&sol;b>– Deciding if a principal is allowed to perform an action<&sol;li>&NewLine;<li><b style&equals;"font-size&colon; x-large&semi;">Secured item<&sol;b>– Resource that is being secured<&sol;li>&NewLine;<&sol;ul>&NewLine;<h2><b>Spring Security Flow in the Application<&sol;b><&sol;h2>&NewLine;<p>Let&&num;8217&semi;s take a look into flow of Spring Security in the Application with example&period; In this article we just setup Spring Security into a simple web application&period; After setup Spring Security will work as below picture&period;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img title&equals;"Spring Security Java Based Configuration" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2017&sol;02&sol;Spring-Security-Big-Picture&period;jpg" width&equals;"640" height&equals;"294" border&equals;"0" &sol;><&sol;div>&NewLine;<p>According to the above picture one thread want to access one secured resource at web but security applied by the spring security interceptors so thread should be authenticated and also it have proper access-control to access this secured resource&period; That means Spring Security provides two main mechanisms one is Authentication and another is Authorization&period; Authentication provided by AuthenticationManager and access decision taken by AccessDecisionManager in the Spring Security&period; Irrespective of the authentication mechanism&comma; Spring Security provides a deep set of authorization capabilities&period; There are three main areas of interest&colon; authorizing web requests&comma; authorizing whether methods can be invoked and authorizing access to individual domain object instances&period;<&sol;p>&NewLine;<h2><b>1&period; Setup Spring Security to Web Application<&sol;b><br &sol;>&NewLine;<b style&equals;"font-size&colon; x-large&semi;"><&sol;b><&sol;h2>&NewLine;<h3><b style&equals;"font-size&colon; x-large&semi;">1&period;1 Setup of Spring Security Filter &lpar;<&sol;b><b>DelegatingFilterProxy<&sol;b><b style&equals;"font-size&colon; x-large&semi;">&rpar;<&sol;b><&sol;h3>&NewLine;<p>As I told you already that Spring Security provides lot of filters in the infrastructure&period; When using servlet filters&comma; you obviously need to declare them in your web&period;xml&comma; or they will be ignored by the servlet container&period; These filter classes are also Spring beans in Spring Security so we can define these filter beans in the application context and thus we can take advantage of Spring’s rich dependency-injection facilities and lifecycle interfaces&period;<&sol;p>&NewLine;<p><i><b>But question is that how to apply these spring security filters to intercepting the requests if you configure these filters in your application context file instead of web&period;xml&quest;<&sol;b><&sol;i> Don&&num;8217&semi;t worry Spring Security also provides solution for this problem&period; It provides you a special DelegatingFilterProxy filter&period; Spring’s DelegatingFilterProxy provides the link between web&period;xml and the application context&period; So each filter in Spring Security has own corresponding delegating filter to provide the link between web&period;xml and the application context&period;  DelegatingFilterProxy delegates the Filter &&num;8216&semi;s methods through to a bean which is obtained from the Spring application context&period;<&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;filter&gt&semi; &NewLine;&lt&semi;filter-name&gt&semi;myFilter&lt&semi;&sol;filter-name&gt&semi; &NewLine;&lt&semi;filter-class&gt&semi;org&period;springframework&period;web&period;filter&period;DelegatingFilterProxy&lt&semi;&sol;filter-class&gt&semi; &NewLine;&lt&semi;&sol;filter&gt&semi; &NewLine; &NewLine;&lt&semi;filter-mapping&gt&semi; &NewLine;&lt&semi;filter-name&gt&semi;myFilter&lt&semi;&sol;filter-name&gt&semi; &NewLine;&lt&semi;url-pattern&gt&semi;&sol;&ast;&lt&semi;&sol;url-pattern&gt&semi; &NewLine;&lt&semi;&sol;filter-mapping&gt&semi; &NewLine;<&sol;pre>&NewLine;<p><b>DelegatingFilterProxy <&sol;b>delegates the filter&&num;8217&semi;s methods to a bean in the application context only when the bean must implement javax&period;servlet&period;Filter and it must have the same name as that in the filter-name element&period;<&sol;p>&NewLine;<h3><b>1&period;2 Setup Order of Spring Security Filters Chain <&sol;b><b style&equals;"font-size&colon; x-large&semi;">&lpar;<&sol;b><b>FilterChainProxy<&sol;b><b style&equals;"font-size&colon; x-large&semi;">&rpar;<&sol;b><&sol;h3>&NewLine;<p>As we know Spring Security has lot of filters to be configured in a specific order in the web&period;xml by using corresponding delegating filter&period; But it would be cumbersome task to maintain web&period;xml in case of robust application&comma; have a lot of filters&period; Spring Security provides us a <b>FilterChainProxy <&sol;b>bean to maintain the order filters as below&period;<&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;bean id&equals;"filterChainProxy" class&equals;"org&period;springframework&period;security&period;web&period;FilterChainProxy"&gt&semi; &NewLine;&lt&semi;constructor-arg&gt&semi; &NewLine; &lt&semi;list&gt&semi; &NewLine; &lt&semi;sec&colon;filter-chain pattern&equals;"&sol;restful&sol;&ast;&ast;" filters&equals;" &NewLine; securityContextPersistenceFilterWithASCFalse&comma; &NewLine; basicAuthenticationFilter&comma; &NewLine; exceptionTranslationFilter&comma; &NewLine; filterSecurityInterceptor" &sol;&gt&semi; &NewLine; &lt&semi;sec&colon;filter-chain pattern&equals;"&sol;&ast;&ast;" filters&equals;" &NewLine; securityContextPersistenceFilterWithASCTrue&comma; &NewLine; formLoginFilter&comma; &NewLine; exceptionTranslationFilter&comma; &NewLine; filterSecurityInterceptor" &sol;&gt&semi; &NewLine; &lt&semi;&sol;list&gt&semi; &NewLine;&lt&semi;&sol;constructor-arg&gt&semi; &NewLine;&lt&semi;&sol;bean&gt&semi; &NewLine;<&sol;pre>&NewLine;<p>Now add the delegating filter for <b>FilterChainProxy <&sol;b>to <b>web&period;xml<&sol;b> filter name should same as bean name in the application context &&num;8220&semi;<b>filterChainProxy<&sol;b>&&num;8221&semi; as below&colon;<&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;filter&gt&semi; &NewLine;&lt&semi;filter-name&gt&semi;filterChainProxy&lt&semi;&sol;filter-name&gt&semi; &NewLine;&lt&semi;filter-class&gt&semi;org&period;springframework&period;web&period;filter&period;DelegatingFilterProxy&lt&semi;&sol;filter-class&gt&semi; &NewLine;&lt&semi;&sol;filter&gt&semi; &NewLine; &NewLine;&lt&semi;filter-mapping&gt&semi; &NewLine;&lt&semi;filter-name&gt&semi;filterChainProxy&lt&semi;&sol;filter-name&gt&semi; &NewLine;&lt&semi;url-pattern&gt&semi;&sol;&ast;&lt&semi;&sol;url-pattern&gt&semi; &NewLine;&lt&semi;&sol;filter-mapping&gt&semi; &NewLine;<&sol;pre>&NewLine;<p><b>FilterChainProxy <&sol;b>add a single entry to <b>web&period;xml <&sol;b>and deal entirely with the application context file for managing our web security beans&period; It is wired using a DelegatingFilterProxy&comma; just like in the example above&comma; but with the filter-name set to the bean name &&num;8220&semi;filterChainProxy&&num;8221&semi;&period; The filter chain is then declared in the application context with the same bean name&period;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2017&sol;02&sol;Spring-Security-Filter-Configuration-1&period;jpg" width&equals;"640" height&equals;"371" border&equals;"0" &sol;><&sol;div>&NewLine;<h2><b>2&period; Spring Security Java Based Configuration Example<&sol;b><&sol;h2>&NewLine;<p>Java configuration creates a Servlet Filter known as the <b>springSecurityFilterChain <&sol;b>which is responsible for all the security &lpar;protecting the application URLs&comma; validating submitted username and passwords&comma; redirecting to the log in form&comma; etc&rpar; within your application&period; Spring Security provides an abstract class AbstractSecurityWebApplicationInitializer to ensure register the springSecurityFilterChain with the war Filter for every URL in your application&period; It will be work only on Servlet 3&period;0&plus; environment&period;<&sol;p>&NewLine;<h3><b>2&period;1 Setup DelegatingFilterProxy and FilterChainProxy <&sol;b><&sol;h3>&NewLine;<h3><b>2&period;1&period;1 Spring Security Configuration in the Application Context<&sol;b><&sol;h3>&NewLine;<pre class&equals;"highlight">&commat;Configuration &NewLine;&commat;EnableWebSecurity &NewLine;public class SecurityConfig extends WebSecurityConfigurerAdapter &lbrace; &NewLine; &commat;Bean &NewLine; public UserDetailsService userDetailsService&lpar;&rpar; &lbrace; &NewLine; InMemoryUserDetailsManager manager &equals; new InMemoryUserDetailsManager&lpar;&rpar;&semi; &NewLine; manager&period;createUser&lpar;User&period;withUsername&lpar;"user"&rpar;&period;password&lpar;"password"&rpar;&period;roles&lpar;"USER"&rpar;&period;build&lpar;&rpar;&rpar;&semi; &NewLine; return manager&semi; &NewLine; &rcub; &NewLine; &commat;Override &NewLine; protected void configure&lpar;HttpSecurity http&rpar; throws Exception &lbrace; &NewLine; &NewLine; &rcub; &NewLine; &commat;Autowired &NewLine; public void configureGlobal&lpar;AuthenticationManagerBuilder auth&rpar; throws Exception &lbrace; &NewLine; &NewLine; &rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<h3><b>2&period;1&period;2 AbstractSecurityWebApplicationInitializer without Existing Spring<&sol;b><&sol;h3>&NewLine;<p>Suppose if you are using Spring Security in non Spring application then you will need to pass in the SecurityConfig into the superclass to ensure the configuration is picked up&period;<&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&ast;&ast; &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;package com&period;doj&period;app&period;web&semi; &NewLine; &NewLine;import org&period;springframework&period;security&period;web&period;context&period;AbstractSecurityWebApplicationInitializer&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh&period;Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;public class SecurityWebApplicationInitializer extends &NewLine; AbstractSecurityWebApplicationInitializer &lbrace; &NewLine; public SecurityWebApplicationInitializer&lpar;&rpar; &lbrace; &NewLine; super&lpar;SecurityConfig&period;class&rpar;&semi; &NewLine; &rcub; &NewLine; &NewLine;&rcub; &NewLine; &NewLine;<&sol;pre>&NewLine;<p><b>SecurityWebApplicationInitializer <&sol;b>class do automatically register the <b>springSecurityFilterChain <&sol;b>Filter for every URL in your application and also add a <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;difference-between-applicationcontext-webapplicationcontext-in-spring-mvc&sol;">ContextLoaderListener<&sol;a> <&sol;b>that loads the <b>SecurityConfig <&sol;b>class&period;<&sol;p>&NewLine;<h3><b>2&period;1&period;3 AbstractSecurityWebApplicationInitializer with <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-web-mvc-framework-chapter-38&sol;">Spring MVC<&sol;a><&sol;b><&sol;h3>&NewLine;<p>Suppose if you are using <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-tutorial&sol;">Spring<&sol;a> in your application then you can register Spring Security with the existing <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;difference-between-applicationcontext-webapplicationcontext-in-spring-mvc&sol;">ApplicationContext<&sol;a>&period;<&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&ast;&ast; &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;package com&period;doj&period;app&period;web&semi; &NewLine; &NewLine;import org&period;springframework&period;security&period;web&period;context&period;AbstractSecurityWebApplicationInitializer&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh&period;Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;public class SecurityWebApplicationInitializer extends &NewLine; AbstractSecurityWebApplicationInitializer &lbrace; &NewLine; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p>This would simply only register the <b>springSecurityFilterChain <&sol;b>Filter for every URL in your application&period; After that we would ensure that SecurityConfig was loaded in our existing ApplicationInitializer&period;<&sol;p>&NewLine;<h3><b>2&period;2 HttpSecurity &lpar;authorizeRequests&lpar;&rpar;&rpar;<&sol;b><&sol;h3>&NewLine;<p>Thus far our SecurityConfig file only contains default information about how to authenticate our users&period; In above our configuration file SecurityConfig extends WebSecurityConfigurerAdapter class for more control over the default configuration&period; WebSecurityConfigurerAdapter provides a default configuration in the configure&lpar;HttpSecurity http&rpar; method that is why all users require to be authenticated for accessing any URLs of web application&period; But we can override this method as below&colon;<&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&sol;1&period; Default &NewLine;&sol;&sol;Default configuration in WebSecurityConfigurerAdapter &NewLine;protected void configure&lpar;HttpSecurity http&rpar; throws Exception &lbrace; &NewLine; http &NewLine; &period;authorizeRequests&lpar;&rpar; &NewLine; &period;anyRequest&lpar;&rpar;&period;authenticated&lpar;&rpar; &NewLine; &period;and&lpar;&rpar; &NewLine; &period;formLogin&lpar;&rpar; &NewLine; &period;and&lpar;&rpar; &NewLine; &period;httpBasic&lpar;&rpar;&semi; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b>The default configuration above&colon;<&sol;b><&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>Ensures that any request to our application requires the user to be authenticated<&sol;li>&NewLine;<li>Allows users to authenticate with form based login<&sol;li>&NewLine;<li>Allows users to authenticate with HTTP Basic authentication<&sol;li>&NewLine;<&sol;ul>&NewLine;<h2><b>2&period;3 Custom Login Form Java Configuration<&sol;b><&sol;h2>&NewLine;<p>Spring Security generates login form automatically&comma; based on the features that are enabled and using standard values for the URL which processes the submitted login&comma; the default target URL the user will be sent to after logging in and so on&period;<&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&sol;2&period; Custom Login Form &NewLine;&sol;&sol;Override Default configuration in WebSecurityConfigurerAdapter for custom login form instead auto generated login form by spring security &NewLine;&sol;&sol;The updated configuration specifies the location of the log in page&period; &NewLine;&sol;&sol;We must grant all users &lpar;i&period;e&period; unauthenticated users&rpar; access to our log in page &NewLine;protected void configure&lpar;HttpSecurity http&rpar; throws Exception &lbrace; &NewLine; http &NewLine; &period;authorizeRequests&lpar;&rpar; &NewLine; &period;anyRequest&lpar;&rpar;&period;authenticated&lpar;&rpar; &NewLine; &period;and&lpar;&rpar; &NewLine; &period;formLogin&lpar;&rpar; &NewLine; &period;loginPage&lpar;"&sol;login"&rpar; &sol;&sol;specifies the location of the log in page &NewLine; &period;permitAll&lpar;&rpar;&semi; &sol;&sol;allows granting access to all users for all URLs &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p>And login file as below <b>login&period;jsp<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;&percnt;&commat; taglib prefix&equals;"c" uri&equals;"http&colon;&sol;&sol;java&period;sun&period;com&sol;jsp&sol;jstl&sol;core" &percnt;&gt&semi; &NewLine;&lt&semi;c&colon;url value&equals;"&sol;login" var&equals;"loginUrl"&sol;&gt&semi; &NewLine;&lt&semi;form action&equals;"&dollar;&lbrace;loginUrl&rcub;" method&equals;"post"&gt&semi; &NewLine; &lt&semi;c&colon;if test&equals;"&dollar;&lbrace;param&period;error &excl;&equals; null&rcub;"&gt&semi; &NewLine; &lt&semi;p&gt&semi; &NewLine; Invalid username and password&period; &NewLine; &lt&semi;&sol;p&gt&semi; &NewLine; &lt&semi;&sol;c&colon;if&gt&semi; &NewLine; &lt&semi;c&colon;if test&equals;"&dollar;&lbrace;param&period;logout &excl;&equals; null&rcub;"&gt&semi; &NewLine; &lt&semi;p&gt&semi; &NewLine; You have been logged out&period; &NewLine; &lt&semi;&sol;p&gt&semi; &NewLine; &lt&semi;&sol;c&colon;if&gt&semi; &NewLine; &lt&semi;p&gt&semi; &NewLine; &lt&semi;label for&equals;"username"&gt&semi;Username&lt&semi;&sol;label&gt&semi; &NewLine; &lt&semi;input type&equals;"text" id&equals;"username" name&equals;"username"&sol;&gt&semi; &NewLine; &lt&semi;&sol;p&gt&semi; &NewLine; &lt&semi;p&gt&semi; &NewLine; &lt&semi;label for&equals;"password"&gt&semi;Password&lt&semi;&sol;label&gt&semi; &NewLine; &lt&semi;input type&equals;"password" id&equals;"password" name&equals;"password"&sol;&gt&semi; &NewLine; &lt&semi;&sol;p&gt&semi; &NewLine; &lt&semi;input type&equals;"hidden" &NewLine; name&equals;"&dollar;&lbrace;&lowbar;csrf&period;parameterName&rcub;" &NewLine; value&equals;"&dollar;&lbrace;&lowbar;csrf&period;token&rcub;"&sol;&gt&semi; &NewLine; &lt&semi;button type&equals;"submit" class&equals;"btn"&gt&semi;Log in&lt&semi;&sol;button&gt&semi; &NewLine;&lt&semi;&sol;form&gt&semi; &NewLine;<&sol;pre>&NewLine;<h2><b>2&period;4&period; Authorize Requests<&sol;b><&sol;h2>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>Adds specific authorization requirements to URLs<&sol;li>&NewLine;<li>Evaluated in the order listed – first match is used&comma; put specific matches first<&sol;li>&NewLine;<&sol;ul>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<pre class&equals;"highlight" style&equals;"text-align&colon; left&semi;">&sol;&sol;3&period; Customization to authorize request &NewLine;&sol;&sol;Override Default configuration in WebSecurityConfigurerAdapter for custom login form and authorize requests &NewLine;&sol;&sol;We specified multiple URL patterns that any user can access like "&sol;resources&sol;"&comma; "&sol;scripts&sol;"&comma; "&sol;css&sol;" etc&period; &NewLine;http &NewLine;&period;authorizeRequests&lpar;&rpar; &NewLine;&period;antMatchers&lpar;"&sol;css&sol;&ast;&ast;"&comma;"&sol;images&sol;&ast;&ast;"&comma;"&sol;scripts&sol;&ast;&ast;"&rpar;&period;permitAll&lpar;&rpar; &NewLine;&period;antMatchers&lpar;"&sol;accounts&sol;edit&ast;"&rpar;&period;hasRole&lpar;"ADMIN"&rpar; &NewLine;&period;antMatchers&lpar;"&sol;accounts&sol;account&ast;"&rpar;&period;hasAnyRole&lpar;"USER"&comma;”ADMIN”&rpar; &NewLine;&period;anyRequest&lpar;&rpar;&period;authenticated&lpar;&rpar; &NewLine;&period;and&lpar;&rpar; &NewLine;&period;formLogin&lpar;&rpar; &NewLine;&period;loginPage&lpar;"&sol;login"&rpar; &NewLine;&period;permitAll&lpar;&rpar;&semi; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<div style&equals;"text-align&colon; left&semi;"><&sol;div>&NewLine;<ul>&NewLine;<li>Any URL that starts with &&num;8220&semi;&sol;accounts&sol;edit&&num;8221&semi; will be restricted to users who have the role &&num;8220&semi;ROLE&lowbar;ADMIN&&num;8221&semi;&period;<&sol;li>&NewLine;<li>Any URL that starts with &&num;8220&semi;&sol;accounts&sol;account&&num;8221&semi; requires the user to have both &&num;8220&semi;ROLE&lowbar;ADMIN&&num;8221&semi; and &&num;8220&semi;ROLE&lowbar;USER&&num;8221&semi;&period;<&sol;li>&NewLine;<li>Any URL that has not already been matched on only requires that the user be authenticated<&sol;li>&NewLine;<&sol;ul>&NewLine;<h2><b>2&period;5&period; Handling Logouts<&sol;b><&sol;h2>&NewLine;<p>When using the <b>WebSecurityConfigurerAdapter<&sol;b>&comma; logout capabilities are automatically applied&period;<br &sol;>&NewLine;The default is that accessing the URL &sol;logout will log the user out by&colon;<&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>Invalidating the HTTP Session<&sol;li>&NewLine;<li>Cleaning up any RememberMe authentication that was configured<&sol;li>&NewLine;<li>Clearing the SecurityContextHolder<&sol;li>&NewLine;<li>Redirect to &sol;login&quest;logout<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre class&equals;"highlight">protected void configure&lpar;HttpSecurity http&rpar; throws Exception &lbrace; &NewLine;http &NewLine;&period;authorizeRequests&lpar;&rpar; &NewLine;&period;antMatchers&lpar;"&sol;aaa&ast;"&rpar;&period;hasRole&lpar;"ADMIN"&rpar; &NewLine;&period;and&lpar;&rpar; &sol;&sol; method chaining&excl; &NewLine;&period;formLogin&lpar;&rpar; &sol;&sol; setup form-based authentication &NewLine;&period;loginPage&lpar;"&sol;login&period;jsp"&rpar; &sol;&sol; URL to use when login is needed &NewLine;&period;permitAll&lpar;&rpar; &sol;&sol; any user can access &NewLine;&period;and&lpar;&rpar; &sol;&sol; method chaining&excl; &NewLine;&period;logout&lpar;&rpar; &sol;&sol; configure logout &NewLine;&period;permitAll&lpar;&rpar;&semi; &sol;&sol; any user can access &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<h3><b>2&period;5&period;1&period; LogoutHandler<&sol;b><&sol;h3>&NewLine;<p>Generally&comma; LogoutHandler implementations indicate classes that are able to participate in logout handling&period; They are expected to be invoked to perform necessary clean-up&period;<&sol;p>&NewLine;<h3><b>2&period;5&period;2&period; LogoutSuccessHandler<&sol;b><&sol;h3>&NewLine;<p>The LogoutSuccessHandler is called after a successful logout by the LogoutFilter&comma; to handle e&period;g&period; redirection or forwarding to the appropriate destination&period; Note that the interface is almost the same as the LogoutHandler but may raise an exception&period;<&sol;p>&NewLine;<h2><b>2&period;6&period; Configure Authentication<&sol;b><&sol;h2>&NewLine;<p>Thus far we have only taken a look at the most basic authentication configuration&period; Let’s take a look at a few slightly more advanced options for configuring authentication&period; Spring Security provides various Authentication Provider as below&colon;<&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>DAO Authentication provider is default&NewLine;<ul>&NewLine;<li>Expects a UserDetailsService implementation to provide credentials and authorities&NewLine;<ul>&NewLine;<li><b>Built-in&colon;<&sol;b> In-memory &lpar;properties&rpar;&comma; JDBC &lpar;database&rpar;&comma; LDAP<&sol;li>&NewLine;<li><b>Custom<&sol;b><&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;li>&NewLine;<li>Or define your own Authentication provider&NewLine;<ul>&NewLine;<li>Example&colon; to get pre-authenticated user details when using single sign-on&NewLine;<ul>&NewLine;<li>CAS&comma; TAM&comma; SiteMinder<&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;li>&NewLine;<&sol;ul>&NewLine;<h3><b>2&period;6&period;1 Authentication provider&colon; Use a UserDetailsManagerConfigurer<&sol;b><&sol;h3>&NewLine;<p>– Three built in options&colon; LDAP&comma; JDBC&comma; in-memory &lpar;for quick testing&rpar;<br &sol;>&NewLine;– Or use your own UserDetailsService implementation<&sol;p>&NewLine;<p><b>In-Memory Authentication Java Configuration<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&sol;In memory authentication java configuration &NewLine;&sol;&sol;Not web-specific &NewLine;&commat;Autowired &NewLine;public void configureGlobal&lpar;AuthenticationManagerBuilder auth&rpar; throws Exception &lbrace; &NewLine;auth &NewLine;&period;inMemoryAuthentication&lpar;&rpar; &sol;&sol;Adds a UserDetailsManagerConfigurer &NewLine;&sol;&sol;login&comma; password and supported role &NewLine;&period;withUser&lpar;"user"&rpar;&period;password&lpar;"password"&rpar;&period;roles&lpar;"USER"&rpar;&period;and&lpar;&rpar; &NewLine;&period;withUser&lpar;"admin"&rpar;&period;password&lpar;"adminpassword"&rpar;&period;roles&lpar;"ADMIN"&rpar;&period;and&lpar;&rpar; &NewLine;&period;withUser&lpar;"dinesh"&rpar;&period;password&lpar;"support"&rpar;&period;roles&lpar;"SUPPORT"&rpar;&semi; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b>JDBC Authentication Java Configuration<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&sol;JDBC Authentication &NewLine;&sol;&sol;Provides default queries &NewLine;&sol;&sol;– SELECT username&comma; password&comma; enabled FROM users WHERE username &equals; &quest; &NewLine;&sol;&sol;– SELECT username&comma; authority FROM authorities WHERE username &equals; &quest; &NewLine;public void configureGlobal&lpar;AuthenticationManagerBuilder auth&rpar; throws Exception &lbrace; &NewLine;auth&period;jdbcAuthentication&lpar;&rpar;&period;dataSource&lpar;dataSource&rpar;&semi; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p>We can customize the default queries by using following methods<&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>usersByUsernameQuery&lpar;&rpar;<&sol;li>&NewLine;<li>authoritiesByUsernameQuery&lpar;&rpar;<&sol;li>&NewLine;<li>groupAuthoritiesByUsername&lpar;&rpar;<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre class&equals;"highlight">&sol;&sol;JDBC Authentication &NewLine;&sol;&sol;Provides default queries &NewLine;&sol;&sol;– SELECT username&comma; password&comma; enabled FROM users WHERE username &equals; &quest; &NewLine;&sol;&sol;– SELECT username&comma; authority FROM authorities WHERE username &equals; &quest; &NewLine;&sol;&sol;We can customize the default queries by using following methods &NewLine;&sol;&sol;usersByUsernameQuery&lpar;&rpar; &NewLine;&sol;&sol;authoritiesByUsernameQuery&lpar;&rpar; &NewLine;&sol;&sol;groupAuthoritiesByUsername&lpar;&rpar; &NewLine;public void configureGlobal&lpar;AuthenticationManagerBuilder auth&rpar; throws Exception &lbrace; &NewLine;auth &NewLine;&period;jdbcAuthentication&lpar;&rpar; &NewLine;&period;usersByUsernameQuery&lpar;"SELECT username&comma; password&comma; enabled FROM users WHERE username &equals; &quest;"&rpar; &NewLine;&period;authoritiesByUsernameQuery&lpar;"SELECT username&comma; authority FROM authorities WHERE username &equals; &quest;"&rpar; &NewLine;&period;dataSource&lpar;dataSource&rpar;&semi; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<h3><b>2&period;6&period;2 Password Encoder<&sol;b><&sol;h3>&NewLine;<p>You can also customize how passwords are encoded by exposing a PasswordEncoder as a bean&period; We can encode passwords using a hash – sha&comma; md5&comma; bcrypt etc&period;<&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&sol;SHA-256 encoding &NewLine;auth&period;jdbcAuthentication&lpar;&rpar; &NewLine;&period;dataSource&lpar;dataSource&rpar; &NewLine;&period;passwordEncoder&lpar;new StandardPasswordEncoder&lpar;&rpar;&rpar;&semi; &NewLine;<&sol;pre>&NewLine;<h3><b>2&period;6&period;3 Use Salting in Password Encoder<&sol;b><&sol;h3>&NewLine;<p>Secure passwords using a well-known string known as a &&num;8216&semi;salt&&num;8217&semi;&comma; makes brute force attacks harder<&sol;p>&NewLine;<pre class&equals;"highlight">&sol;&sol;Encoding with salt &NewLine;auth&period;jdbcAuthentication&lpar;&rpar; &NewLine;&period;dataSource&lpar;dataSource&rpar; &NewLine;&period;passwordEncoder&lpar;new StandardPasswordEncoder&lpar;"sodium-chloride"&rpar;&rpar;&semi; &NewLine;<&sol;pre>&NewLine;<p><b>Note&colon; <i>Authorization is not affected by changes to Authentication&excl;<&sol;i><&sol;b><&sol;p>&NewLine;<h3><b>2&period;7&period; Configure Multiple HttpSecurity<&sol;b><&sol;h3>&NewLine;<p>We can configure multiple HttpSecurity instances&period; The key is to extend the WebSecurityConfigurationAdapter multiple times&period;<&sol;p>&NewLine;<h2><b>2&period;8&period; Method Security<&sol;b><&sol;h2>&NewLine;<p>From Spring version 2&period;0 Spring Security provides support to adding security to your service layer methods&period; Spring Security uses AOP for security at the method level&period;<br &sol;>&NewLine;– annotations based on Spring annotations or JSR-250 annotations<br &sol;>&NewLine;– Java configuration to activate detection of annotations<br &sol;>&NewLine;&&num;8211&semi; From 3&period;0 you can also make use of new expression-based annotations&period;<br &sol;>&NewLine;Typically secure your services<br &sol;>&NewLine;– Do not access repositories directly&comma; bypasses security &lpar;and transactions&rpar;<&sol;p>&NewLine;<h3><b>2&period;8&period;1 EnableGlobalMethodSecurity<&sol;b><&sol;h3>&NewLine;<p>We can enable annotation-based security using the &commat;EnableGlobalMethodSecurity annotation on any &commat;Configuration instance&period;<&sol;p>&NewLine;<h3><b>2&period;8&period;2 <&sol;b><b>Enable Method Security &&num;8211&semi; JSR-250<&sol;b><&sol;h3>&NewLine;<pre class&equals;"highlight">&commat;EnableGlobalMethodSecurity&lpar;jsr250Enabled &equals; true&rpar; &NewLine;public class MethodSecurityConfig &lbrace; &NewLine;&sol;&sol; &period;&period;&period; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<pre class&equals;"highlight">import javax&period;annotation&period;security&period;RolesAllowed&semi; &NewLine; &NewLine;public class ItemManagerService &lbrace; &NewLine;&commat;RolesAllowed&lpar;&lbrace;"ROLE&lowbar;MEMBER"&comma; "ROLE&lowbar;USER"&rcub;&rpar; &NewLine;public Item findItem&lpar;long itemNumber&rpar; &lbrace; &NewLine;&period;&period;&period; &NewLine;&rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b><i>Note&colon; Only supports role-based security – hence the name<&sol;i><&sol;b><&sol;p>&NewLine;<h3><b>2&period;8&period;3 Enable Spring Security’s &commat;Secured annotation<&sol;b><&sol;h3>&NewLine;<pre class&equals;"highlight">&commat;EnableGlobalMethodSecurity&lpar;securedEnabled &equals; true&rpar; &NewLine;public class MethodSecurityConfig &lbrace; &NewLine;&sol;&sol; &period;&period;&period; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<pre class&equals;"highlight">import org&period;springframework&period;security&period;annotation&period;Secured&semi; &NewLine; &NewLine;public class ItemManagerService &lbrace; &NewLine;&commat;Secured&lpar;"IS&lowbar;AUTHENTICATED&lowbar;FULLY"&rpar; &NewLine;public Item findItem&lpar;long itemNumber&rpar; &lbrace; &NewLine;&period;&period;&period; &NewLine;&rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b>We can also use <&sol;b><&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>&commat;Secured&lpar;&&num;8220&semi;ROLE&lowbar;MEMBER&&num;8221&semi;&rpar;<&sol;li>&NewLine;<li>&commat;Secured&lpar;&lbrace;&&num;8220&semi;ROLE&lowbar;MEMBER&&num;8221&semi;&comma; &&num;8220&semi;ROLE&lowbar;USER&&num;8221&semi;&rcub;&rpar;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p><b><i>Note&colon; Spring 2&period;0 syntax&comma; so not limited to roles&period; SpEL not supported&period;<&sol;i><&sol;b><&sol;p>&NewLine;<h3><b>2&period;8&period;4 Method Security with SpEL<&sol;b><&sol;h3>&NewLine;<pre class&equals;"highlight">&commat;EnableGlobalMethodSecurity&lpar;prePostEnabled &equals; true&rpar; &NewLine;public class MethodSecurityConfig &lbrace; &NewLine;&sol;&sol; &period;&period;&period; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<pre class&equals;"highlight">public interface ItemManagerService &lbrace; &NewLine; &NewLine;&commat;PreAuthorize&lpar;"isAnonymous&lpar;&rpar;"&rpar; &NewLine;public Item findItem&lpar;Long itemNumber&rpar;&semi; &NewLine; &NewLine;&commat;PreAuthorize&lpar;"isAnonymous&lpar;&rpar;"&rpar; &NewLine;public Item&lbrack;&rsqb; findItems&lpar;&rpar;&semi; &NewLine; &NewLine;&commat;PreAuthorize&lpar;"hasAuthority&lpar;'ROLE&lowbar;USER'&rpar;"&rpar; &NewLine;public Item post&lpar;Item item&rpar;&semi; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<h2><b>Download Java Based Configuration Example<&sol;b><br &sol;>&NewLine;<b><br &sol;>&NewLine;<&sol;b> <a href&equals;"https&colon;&sol;&sol;github&period;com&sol;DOJ-SoftwareConsultant&sol;Spring-Security-Java-Config" target&equals;"&lowbar;blank" rel&equals;"noopener"><b>Source Code of Example from Git&period;<&sol;b><&sol;a><&sol;h2>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2017&sol;02&sol;Spring-Security-java-based-cnfiguration-example&period;jpg" border&equals;"0" &sol;><&sol;div>&NewLine;<h2><b>Summary<&sol;b><&sol;h2>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li>Spring Security secure URLs using a chain of Servlet filters and methods on Spring beans using AOP proxies<&sol;li>&NewLine;<li>Out-of-the-box setup usually sufficient – you define&colon;&NewLine;<ul>&NewLine;<li>– URL and&sol;or method restrictions<&sol;li>&NewLine;<li>– How to login &lpar;typically using an HTML form&rpar;<&sol;li>&NewLine;<li>– Supports in-memory&comma; database&comma; LDAP credentials &lpar;and more&rpar;<&sol;li>&NewLine;<li>– Password encryption using familiar hashing techniques<&sol;li>&NewLine;<li>– Support for security tags in JSP views<&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<div style&equals;"background-color&colon; &num;f2f9fc&semi; border-radius&colon; 3px&semi; border&colon; 1px solid &num;c9e6f2&semi; line-height&colon; 1&period;45&semi; padding&colon; 16px&semi;">&NewLine;<p><span style&equals;"color&colon; red&semi; font-size&colon; x-large&semi; text-align&colon; center&semi;"><b>Spring Security Related Posts<&sol;b><&sol;span><&sol;p>&NewLine;<ul>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-interview-questions-and-answers&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Interview Questions and Answers<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-java-based-configuration-with-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Java Based Configuration with Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-xml-namespace-configuration-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security XML Namespace Configuration Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-hello-world-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security XML Based Hello World Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-form-based-login-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security form-based login example <&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-login-form-using&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Login Form Based Example Using Database<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-http-basic&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Authentication Example Using HTTP Basic <&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-authorized-access&sol;"><span style&equals;"color&colon; red&semi;"> Spring Security Authorized Access Control Example <&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;customize-http-403-access-denied-page&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Customized Access Denied Page<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-custom-error-message&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Custom Error Message<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-logout-example&sol;"><span style&equals;"color&colon; red&semi;"> Spring Security Logout Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-fetch-logged-in-username&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Fetch Logged in Username<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-password-hashing&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Password Hashing<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<&sol;ul>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<&sol;div>&NewLine;<&sol;div>&NewLine;<div class&equals;"wp-post-navigation"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-pre"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-interview-questions-and-answers&sol;">Previous<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-next"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-xml-namespace-configuration-example&sol;">Next<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;<&sol;div>&NewLine;<script type&equals;"text&sol;javascript">&NewLine;jQuery&lpar;document&rpar;&period;ready&lpar;function&lpar;&dollar;&rpar; &lbrace;&NewLine; &dollar;&period;post&lpar;'https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-admin&sol;admin-ajax&period;php'&comma; &lbrace;action&colon; 'mts&lowbar;view&lowbar;count'&comma; id&colon; '60'&rcub;&rpar;&semi;&NewLine;&rcub;&rpar;&semi;&NewLine;<&sol;script>

Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

4 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

4 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

4 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

4 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

4 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

4 years ago