{"id":73739,"date":"2018-02-21T22:00:49","date_gmt":"2018-02-21T20:00:49","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=73739"},"modified":"2018-02-21T10:55:49","modified_gmt":"2018-02-21T08:55:49","slug":"securitycontext-securitycontextholder-spring-security","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html","title":{"rendered":"What is SecurityContext and SecurityContextHolder in Spring Security?"},"content":{"rendered":"<p>The\u00a0<b>SecurityContext <\/b>and <b>SecurityContextHolder\u00a0<\/b>are two fundamental classes of Spring Security. The <code>SecurityContext <\/code>is used to store the details of the currently authenticated user, also known as a principle. So, if you have to get the username or any other user details, you need to get this <code>SecurityContext <\/code>first. The <code>SecurityContextHolder <\/code>is a helper class, which provide access to the security context. By default, it uses a\u00a0<a href=\"http:\/\/javarevisited.blogspot.com\/2012\/05\/how-to-use-threadlocal-in-java-benefits.html#axzz54hCQprEv\" target=\"_blank\" rel=\"noopener\">ThreadLocal<\/a> object to store security context, which means that the security context is always available to methods in the same thread of execution, even if you don&#8217;t pass the SecurityContext object around. Don&#8217;t worry about the\u00a0<a href=\"http:\/\/javarevisited.blogspot.sg\/2013\/01\/threadlocal-memory-leak-in-java-web.html#axzz57W6MT09l\" target=\"_blank\" rel=\"noopener\">ThreadLocal memory leak<\/a> in web application though, Spring Security takes care of cleaning ThreadLocal.<\/p>\n<p>Btw, that&#8217;s not the only way a <code>SecurityContextHolder <\/code>can store current <code>SecurityContext<\/code>, it can be configured with a strategy on startup to specify how you would the context to be stored. For example, you can use <code>SecurityContextHolder.MODE_GLOBAL<\/code> strategy for a standalone application.<\/p>\n<p>The key thing to learn is that\u00a0<i>how do you get the SecurityContext from the SecurityContextHolder?<\/i> and then retrieving current user details from that? For example, if you want to know the username of the current logged in user then how do you get that in Spring security?<\/p>\n<p>In order to get the current username, you first need a <code>SecurityContext<\/code>, which is obtained from <code>SecurityContextHolder<\/code>. This <code>SecurityContext <\/code>keep the user details in an Authentication object, which can be obtained by calling <code>getAuthentication()<\/code> method.<\/p>\n<p>Once you got the Authentication object, you can either cast into UserDetails or use it as it is. The UserDetails object is the one Spring Security uses to keep user-related information.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>How to get the current logged-in Username in Spring Security<\/h2>\n<p>Here is the code to get the security context in Spring security and obtain the name of the currently logged in user:<\/p>\n<pre class=\"brush:java\">Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();\r\n\r\nif (principal instanceof UserDetails) {\r\n  String username = ((UserDetails)principal).getUsername();\r\n} else {\r\n  String username = principal.toString();\r\n}<\/pre>\n<p>The object returned by <code>getContext()<\/code> is an instance of the <code>SecurityContext <\/code>interface. This is the object that is stored in a thread-local storage.<\/p>\n<p>The <code>getPrincipal()<\/code> method normally return UserDetails object in Spring Security, which contains all the details of currently logged in user.<\/p>\n<p>Anyway, if you look closer, you will find that this is not really a nice code when we think about\u00a0<a href=\"https:\/\/www.javacodegeeks.com\/2018\/01\/7-reasons-use-spring-develop-restful-web-services-java.html\" target=\"_blank\" rel=\"noopener\">Spring<\/a> and\u00a0<a href=\"http:\/\/javarevisited.blogspot.sg\/2012\/12\/inversion-of-control-dependency-injection-design-pattern-spring-example-tutorial.html\" target=\"_blank\" rel=\"noopener\">dependency injection<\/a>. So if you ever need to know current logged-in user details e.g. in Spring MVC controller, I suggest you declare a dependency and let the Spring provide you the <code>Principal <\/code>object, rather you querying for them and create a tightly coupled system.<\/p>\n<p>Here is an example of that<\/p>\n<pre class=\"brush:java\">import java.security.Principal;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.ResponseBody;\r\n\r\n@Controller\r\npublic class MVCController {\r\n\r\n  @RequestMapping(value = \"\/username\", method = RequestMethod.GET)\r\n  @ResponseBody\r\n  public String currentUserName(Principal principal) {\r\n     return principal.getName();\r\n  }\r\n\r\n}<\/pre>\n<p>Alternatively, you can also ask for\u00a0<a href=\"http:\/\/javarevisited.blogspot.sg\/2011\/11\/ldap-authentication-active-directory.html\" target=\"_blank\" rel=\"noopener\">Authentication<\/a> object instead of a\u00a0<a href=\"http:\/\/javarevisited.blogspot.sg\/2013\/07\/role-based-access-control-using-spring-security-ldap-authorities-mapping-mvc.html\" target=\"_blank\" rel=\"noopener\">Principal<\/a> object as shown below:<\/p>\n<pre class=\"brush:java\">import org.springframework.security.core.Authentication;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.ResponseBody;\r\n\r\n@Controller\r\npublic class SpringMVCController {\r\n\r\n  @RequestMapping(value = \"\/username\", method = RequestMethod.GET)\r\n  @ResponseBody\r\n  public String currentUserName(Authentication authentication) {\r\n     return authentication.getName();\r\n  }\r\n}<\/pre>\n<p>If you want to know more ways, you can also see my post about\u00a0<a href=\"http:\/\/javarevisited.blogspot.sg\/2011\/09\/spring-interview-questions-answers-j2ee.html#axzz57W6MT09l\" target=\"_blank\" rel=\"nofollow noopener\">3 ways to get the current username in Spring Security<\/a>, where I have discussed a couple of more ways to retrieve the current username in Spring MVC controller.<\/p>\n<p>That&#8217;s all about\u00a0<b>what is security context in Spring security<\/b> and how you can obtain a SecurityContext from SecurityContextHolder class. These are some of the fundamental classes, hence you must be familiar with them.<\/p>\n<p>The storage part i.e. <code>SecurityContext <\/code>is stored in <code>ThreadLocal <\/code>is optional, but it&#8217;s also good to know the detail. Just remember, if you ever need user details e.g. username etc, you better ask for Principal or Authentication object in Spring MVC controller, rather than using <code>SecurityContextHolder <\/code>to obtain them.<\/p>\n<p>Thanks for reading this article so far. If you like this Spring Security tutorial then please share with your friends and colleagues. If you have any questions or feedback then please drop a note.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Javin Paul, partner at our <a href=\"http:\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/javarevisited.blogspot.com\/2018\/02\/what-is-securitycontext-and-SecurityContextHolder-Spring-security.html\" target=\"_blank\" rel=\"noopener\">What is SecurityContext and SecurityContextHolder in Spring Security?<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The\u00a0SecurityContext and SecurityContextHolder\u00a0are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the currently authenticated user, also known as a principle. So, if you have to get the username or any other user details, you need to get this SecurityContext first. The SecurityContextHolder is a helper class, which provide &hellip;<\/p>\n","protected":false},"author":251,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30,125],"class_list":["post-73739","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring","tag-spring-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is SecurityContext and SecurityContextHolder in Spring Security? - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"The\u00a0SecurityContext and SecurityContextHolder\u00a0are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is SecurityContext and SecurityContextHolder in Spring Security? - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"The\u00a0SecurityContext and SecurityContextHolder\u00a0are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-21T20:00:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Javin Paul\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Javin Paul\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html\"},\"author\":{\"name\":\"Javin Paul\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40\"},\"headline\":\"What is SecurityContext and SecurityContextHolder in Spring Security?\",\"datePublished\":\"2018-02-21T20:00:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html\"},\"wordCount\":631,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\",\"Spring Security\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html\",\"name\":\"What is SecurityContext and SecurityContextHolder in Spring Security? - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2018-02-21T20:00:49+00:00\",\"description\":\"The\u00a0SecurityContext and SecurityContextHolder\u00a0are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/02\\\/securitycontext-securitycontextholder-spring-security.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"What is SecurityContext and SecurityContextHolder in Spring Security?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40\",\"name\":\"Javin Paul\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g\",\"caption\":\"Javin Paul\"},\"description\":\"I have been working in Java, FIX Tutorial and Tibco RV messaging technology from past 7 years. I am interested in writing and meeting people, reading and learning about new subjects.\",\"sameAs\":[\"http:\\\/\\\/javarevisited.blogspot.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/javin-paul\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is SecurityContext and SecurityContextHolder in Spring Security? - Java Code Geeks","description":"The\u00a0SecurityContext and SecurityContextHolder\u00a0are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the","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:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html","og_locale":"en_US","og_type":"article","og_title":"What is SecurityContext and SecurityContextHolder in Spring Security? - Java Code Geeks","og_description":"The\u00a0SecurityContext and SecurityContextHolder\u00a0are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the","og_url":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-02-21T20:00:49+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Javin Paul","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Javin Paul","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html"},"author":{"name":"Javin Paul","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40"},"headline":"What is SecurityContext and SecurityContextHolder in Spring Security?","datePublished":"2018-02-21T20:00:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html"},"wordCount":631,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring","Spring Security"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html","url":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html","name":"What is SecurityContext and SecurityContextHolder in Spring Security? - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2018-02-21T20:00:49+00:00","description":"The\u00a0SecurityContext and SecurityContextHolder\u00a0are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/02\/securitycontext-securitycontextholder-spring-security.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"What is SecurityContext and SecurityContextHolder in Spring Security?"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40","name":"Javin Paul","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g","caption":"Javin Paul"},"description":"I have been working in Java, FIX Tutorial and Tibco RV messaging technology from past 7 years. I am interested in writing and meeting people, reading and learning about new subjects.","sameAs":["http:\/\/javarevisited.blogspot.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/javin-paul"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/73739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/251"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=73739"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/73739\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=73739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=73739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=73739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}