{"id":18478,"date":"2021-09-29T05:33:07","date_gmt":"2021-09-28T22:33:07","guid":{"rendered":"https:\/\/huongdanjava.com\/?p=18478"},"modified":"2021-09-29T05:33:07","modified_gmt":"2021-09-28T22:33:07","slug":"authentication-in-spring-security","status":"publish","type":"post","link":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html","title":{"rendered":"Authentication in Spring Security"},"content":{"rendered":"<p>In the tutorial <a href=\"https:\/\/huongdanjava.com\/overview-about-request-processing-in-spring-security.html\" target=\"_blank\" rel=\"noopener\">Overview about request processing in Spring Security<\/a>, I gave you a brief introduction to the main components in a flow for the authentication part of the Spring Security framework. In this tutorial, we will learn in more detail how Spring Security handles this authentication part!<\/p>\n<p>First, I will create a new Spring Boot project with Spring Security Starter and Spring Web Starter as an example.<\/p>\n<p>The following results:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18480 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/09\/authentication-in-spring-security-1.png\" alt=\"\" width=\"700\" height=\"531\" \/><\/p>\n<p>As I said in the tutorial <a href=\"https:\/\/huongdanjava.com\/overview-about-request-processing-in-spring-security.html\" target=\"_blank\" rel=\"noopener\">Overview about request processing in Spring Security<\/a>, the AuthenticationManager class will be the class that takes care of authentication in Spring Security:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18481 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/09\/authentication-in-spring-security-2.png\" alt=\"\" width=\"700\" height=\"369\" \/><\/p>\n<p>The request after going through the AuthenticationFilter, the user&#8217;s login information will be converted to the Authentication object with the implementation of the UsernamePasswordAuthenticationToken class. The AuthenticationManager will use the information in the UsernamePasswordAuthenticationToken class for authentication.<\/p>\n<p>By default, Spring supports us to authenticate username and password using the DaoAuthenticationProvider class.<\/p>\n<p>When authenticate, with authentication information in the UsernamePasswordAuthenticationToken class, Spring Security will <strong>get username information in UsernamePasswordAuthenticationToken to check if UserCache has information for this username<\/strong>? I don&#8217;t know why the current code used for UserCache is:<\/p>\n<pre class=\"lang:java decode:true\">private UserCache userCache = new NullUserCache();<\/pre>\n<p>NullUserCache only returns null for UserDetails information. Strange thing!<\/p>\n<p>Since there is no information in the cache, <strong>Spring Security will use the object of the UserDetailsService interface to get the UserDetails information using the username.<\/strong><\/p>\n<p>The UserDetailsService interface has only one abstract method, loadUserByUsername():<\/p>\n<pre class=\"lang:java decode:true \">public interface UserDetailsService {\r\n\r\n  UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;\r\n}<\/pre>\n<p>The implementation of the UserDetailsService interface used in this case is InMemoryUserDetailsManager because I am not using the database for the example in this tutorial.<\/p>\n<p>If there is user information with the username that we are sending when we click the Login button, the UserDetails object containing that user&#8217;s information will be returned.<\/p>\n<p><strong>Here, Spring Security also does a few more checks of the user before checking the user&#8217;s password information: including checking if the user is locked, is the user enabled and is the user expired?<\/strong><\/p>\n<p>The DefaultPreAuthenticationChecks class that implements the UserDetailsChecker interface is used to do this with the check() method.<\/p>\n<p><strong>Spring Security will check the password information passed by the user, is the same as the information in the system? Using the additionalAuthenticationChecks() method.<\/strong><\/p>\n<p>Here, the password information will depend on the encoder that we are configuring with Spring Security, the corresponding Encoder class will be used during password checking.<\/p>\n<p><strong>After checking the password information, Spring Security will have a step to check if the password is expired using the DefaultPostAuthenticationChecks class with the check() method.<\/strong><\/p>\n<p>During the process of handling authentication flow, if any exception occurs, the AuthenticationFailureHandler interface with SimpleUrlAuthenticationFailureHandler implementation will handle this exception.<\/p>\n<p>And if everything goes smoothly, without any errors, the AuthenticationSuccessHandler interface with the implementation of the SavedRequestAwareAuthenticationSuccessHandler class will handle..<\/p>\n<p>Details for what happened above, you can read more code of class AbstractAuthenticationProcessingFilter private doFilter() method:<\/p>\n<pre class=\"lang:java decode:true \">private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)\r\n\t\t\tthrows IOException, ServletException {\r\n    if (!requiresAuthentication(request, response)) {\r\n        chain.doFilter(request, response);\r\n        return;\r\n    }\r\n    try {\r\n        Authentication authenticationResult = attemptAuthentication(request, response);\r\n        if (authenticationResult == null) {\r\n            \/\/ return immediately as subclass has indicated that it hasn't completed\r\n            return;\r\n        }\r\n        this.sessionStrategy.onAuthentication(authenticationResult, request, response);\r\n        \/\/ Authentication success\r\n        if (this.continueChainBeforeSuccessfulAuthentication) {\r\n            chain.doFilter(request, response);\r\n        }\r\n        successfulAuthentication(request, response, chain, authenticationResult);\r\n    }\r\n    catch (InternalAuthenticationServiceException failed) {\r\n        this.logger.error(\"An internal error occurred while trying to authenticate the user.\", failed);\r\n        unsuccessfulAuthentication(request, response, failed);\r\n    }\r\n    catch (AuthenticationException ex) {\r\n        \/\/ Authentication failed\r\n        unsuccessfulAuthentication(request, response, ex);\r\n    }\r\n}<\/pre>\n<p>class UsernamePasswordAuthenticationFilter with attemptAuthentication() method:<\/p>\n<pre class=\"lang:java decode:true \">@Override\r\npublic Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)\r\n        throws AuthenticationException {\r\n    if (this.postOnly &amp;&amp; !request.getMethod().equals(\"POST\")) {\r\n        throw new AuthenticationServiceException(\"Authentication method not supported: \" + request.getMethod());\r\n    }\r\n    String username = obtainUsername(request);\r\n    username = (username != null) ? username : \"\";\r\n    username = username.trim();\r\n    String password = obtainPassword(request);\r\n    password = (password != null) ? password : \"\";\r\n    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);\r\n    \/\/ Allow subclasses to set the \"details\" property\r\n    setDetails(request, authRequest);\r\n    return this.getAuthenticationManager().authenticate(authRequest);\r\n}<\/pre>\n<p>and authenticate() method in AbstractUserDetailsAuthenticationProvider class:<\/p>\n<pre class=\"lang:java decode:true \">@Override\r\npublic Authentication authenticate(Authentication authentication) throws AuthenticationException {\r\n    Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,\r\n            () -&gt; this.messages.getMessage(\"AbstractUserDetailsAuthenticationProvider.onlySupports\",\r\n                    \"Only UsernamePasswordAuthenticationToken is supported\"));\r\n    String username = determineUsername(authentication);\r\n    boolean cacheWasUsed = true;\r\n    UserDetails user = this.userCache.getUserFromCache(username);\r\n    if (user == null) {\r\n        cacheWasUsed = false;\r\n        try {\r\n            user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);\r\n        }\r\n        catch (UsernameNotFoundException ex) {\r\n            this.logger.debug(\"Failed to find user '\" + username + \"'\");\r\n            if (!this.hideUserNotFoundExceptions) {\r\n                throw ex;\r\n            }\r\n            throw new BadCredentialsException(this.messages\r\n                    .getMessage(\"AbstractUserDetailsAuthenticationProvider.badCredentials\", \"Bad credentials\"));\r\n        }\r\n        Assert.notNull(user, \"retrieveUser returned null - a violation of the interface contract\");\r\n    }\r\n    try {\r\n        this.preAuthenticationChecks.check(user);\r\n        additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication);\r\n    }\r\n    catch (AuthenticationException ex) {\r\n        if (!cacheWasUsed) {\r\n            throw ex;\r\n        }\r\n        \/\/ There was a problem, so try again after checking\r\n        \/\/ we're using latest data (i.e. not from the cache)\r\n        cacheWasUsed = false;\r\n        user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication);\r\n        this.preAuthenticationChecks.check(user);\r\n        additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication);\r\n    }\r\n    this.postAuthenticationChecks.check(user);\r\n    if (!cacheWasUsed) {\r\n        this.userCache.putUserInCache(user);\r\n    }\r\n    Object principalToReturn = user;\r\n    if (this.forcePrincipalAsString) {\r\n        principalToReturn = user.getUsername();\r\n    }\r\n    return createSuccessAuthentication(principalToReturn, authentication, user);\r\n}<\/pre>\n<p>You can run debug, add breakpoints to these methods, to understand more about how Spring Security is handling the authentication part.<\/p>\n<p>After understanding the details, you can add a custom authentication filter like I did in the tutorial\u00a0<a href=\"https:\/\/huongdanjava.com\/custom-authentication-filter-login-without-password-in-spring-security.html\" target=\"_blank\" rel=\"noopener\">Custom authentication filter login without password in Spring Security<\/a> easily, depending on your purposes!<\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-right kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;right&quot;,&quot;id&quot;:&quot;18478&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;4&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Authentication in Spring Security&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\"><\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the tutorial Overview about request processing in Spring Security, I gave you a brief introduction to the main components in a flow for the authentication part of the Spring Security framework. In this tutorial, we will learn in more detail how Spring Security handles&hellip; <a href=\"https:\/\/huongdanjava.com\/authentication-in-spring-security.html\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":14897,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1891],"tags":[],"class_list":["post-18478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-security","clearfix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Authentication in Spring Security - Huong Dan Java<\/title>\n<meta name=\"description\" content=\"In this tutorial, I explain to you all more detail about how Spring Security authenticate a request from a user.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/huongdanjava.com\/authentication-in-spring-security.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Authentication in Spring Security - Huong Dan Java\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I explain to you all more detail about how Spring Security authenticate a request from a user.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/huongdanjava.com\/authentication-in-spring-security.html\" \/>\n<meta property=\"og:site_name\" content=\"Huong Dan Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-28T22:33:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/08\/spring-security.png\" \/>\n\t<meta property=\"og:image:width\" content=\"200\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Khanh Nguyen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/KhanhNguyenJ\" \/>\n<meta name=\"twitter:site\" content=\"@KhanhNguyenJ\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khanh Nguyen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html\"},\"author\":{\"name\":\"Khanh Nguyen\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"headline\":\"Authentication in Spring Security\",\"datePublished\":\"2021-09-28T22:33:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html\"},\"wordCount\":535,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/spring-security.png\",\"articleSection\":[\"Spring Security\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html\",\"name\":\"Authentication in Spring Security - Huong Dan Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/spring-security.png\",\"datePublished\":\"2021-09-28T22:33:07+00:00\",\"description\":\"In this tutorial, I explain to you all more detail about how Spring Security authenticate a request from a user.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#primaryimage\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/spring-security.png\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/spring-security.png\",\"width\":200,\"height\":200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/authentication-in-spring-security.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/huongdanjava.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Authentication in Spring Security\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/\",\"name\":\"Huong Dan Java\",\"description\":\"Java development tutorials\",\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/huongdanjava.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\",\"name\":\"Khanh Nguyen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"width\":1267,\"height\":1517,\"caption\":\"Khanh Nguyen\"},\"logo\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\"},\"description\":\"I love Java and everything related to Java.\",\"sameAs\":[\"https:\\\/\\\/huongdanjava.com\",\"https:\\\/\\\/www.facebook.com\\\/nhkhanh2406\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/KhanhNguyenJ\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Authentication in Spring Security - Huong Dan Java","description":"In this tutorial, I explain to you all more detail about how Spring Security authenticate a request from a user.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html","og_locale":"en_US","og_type":"article","og_title":"Authentication in Spring Security - Huong Dan Java","og_description":"In this tutorial, I explain to you all more detail about how Spring Security authenticate a request from a user.","og_url":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html","og_site_name":"Huong Dan Java","article_publisher":"https:\/\/www.facebook.com\/nhkhanh2406","article_author":"https:\/\/www.facebook.com\/nhkhanh2406","article_published_time":"2021-09-28T22:33:07+00:00","og_image":[{"width":200,"height":200,"url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/08\/spring-security.png","type":"image\/png"}],"author":"Khanh Nguyen","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/KhanhNguyenJ","twitter_site":"@KhanhNguyenJ","twitter_misc":{"Written by":"Khanh Nguyen","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html#article","isPartOf":{"@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html"},"author":{"name":"Khanh Nguyen","@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"headline":"Authentication in Spring Security","datePublished":"2021-09-28T22:33:07+00:00","mainEntityOfPage":{"@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html"},"wordCount":535,"commentCount":0,"publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"image":{"@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/08\/spring-security.png","articleSection":["Spring Security"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/huongdanjava.com\/authentication-in-spring-security.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html","url":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html","name":"Authentication in Spring Security - Huong Dan Java","isPartOf":{"@id":"https:\/\/huongdanjava.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html#primaryimage"},"image":{"@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/08\/spring-security.png","datePublished":"2021-09-28T22:33:07+00:00","description":"In this tutorial, I explain to you all more detail about how Spring Security authenticate a request from a user.","breadcrumb":{"@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/huongdanjava.com\/authentication-in-spring-security.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html#primaryimage","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/08\/spring-security.png","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/08\/spring-security.png","width":200,"height":200},{"@type":"BreadcrumbList","@id":"https:\/\/huongdanjava.com\/authentication-in-spring-security.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/huongdanjava.com\/"},{"@type":"ListItem","position":2,"name":"Authentication in Spring Security"}]},{"@type":"WebSite","@id":"https:\/\/huongdanjava.com\/#website","url":"https:\/\/huongdanjava.com\/","name":"Huong Dan Java","description":"Java development tutorials","publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/huongdanjava.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d","name":"Khanh Nguyen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","width":1267,"height":1517,"caption":"Khanh Nguyen"},"logo":{"@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg"},"description":"I love Java and everything related to Java.","sameAs":["https:\/\/huongdanjava.com","https:\/\/www.facebook.com\/nhkhanh2406","https:\/\/x.com\/https:\/\/twitter.com\/KhanhNguyenJ"]}]}},"_links":{"self":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/18478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/comments?post=18478"}],"version-history":[{"count":3,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/18478\/revisions"}],"predecessor-version":[{"id":18485,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/18478\/revisions\/18485"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media\/14897"}],"wp:attachment":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media?parent=18478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/categories?post=18478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/tags?post=18478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}