{"id":45203,"date":"2017-01-24T19:01:07","date_gmt":"2017-01-24T13:31:07","guid":{"rendered":"https:\/\/2thenew.xyz\/blog\/?p=45203"},"modified":"2022-01-10T18:40:41","modified_gmt":"2022-01-10T13:10:41","slug":"fortifying-your-rest-api-using-spring-security","status":"publish","type":"post","link":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/","title":{"rendered":"Fortifying your REST API using Spring security"},"content":{"rendered":"<p><a title=\"Spring security\" href=\"https:\/\/projects.spring.io\/spring-security\/\"><b>Spring Security<\/b><\/a><span style=\"font-weight: 400\"> is a lightweight security framework that provides authentication and authorization support in order to secure <a href=\"https:\/\/spring.io\/\">Spring-based<\/a> applications. It comes bundled with popular security algorithm implementations.<\/span><\/p>\n<p>I would cover a series of different topic related to <a href=\"https:\/\/projects.spring.io\/spring-security\/\">spring security<\/a>\u00a0in my upcoming blogs. We will go through the setup process first, then analyze when and where to apply, explore different authentication methods and securing password with encoding schemes.<\/p>\n<p><b>User and Role Management<\/b><span style=\"font-weight: 400\">\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Suppose you want\u00a0to create a REST application,\u00a0<\/span><b>User and Role management system to\u00a0<\/b><span style=\"font-weight: 400\">give each user a set of roles that grants access to the different functions. Also give users privileges as per the role and capability to apply the\u00a0role to specific assets, networks, or other objects.<\/span><\/p>\n<p>In this scenario, you can view the existing users, their roles and privileges from the Administration section. And only\u00a0the user of Administration privilege would be allowed\u00a0to create\/update other users.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/01\/15.jpg\" alt=\"Blog image\" width=\"860\" height=\"360\" class=\"aligncenter size-full wp-image-54487\" \/><\/p>\n<p><span style=\"font-weight: 400\">If you are a <\/span><span style=\"font-weight: 400\">Spring user and new to <a title=\"Spring security\" href=\"https:\/\/projects.spring.io\/spring-security\/\">Spring security<\/a>, basic authentication would be best option to start with and for demonstration, we\u2019ll be creating a sample application using the following tech stack:<\/span><\/p>\n<table style=\"height: 187px\" width=\"624\">\n<tbody>\n<tr>\n<td><span style=\"color: #000080\">Build Tool \u00a0\u00a0<\/span><\/td>\n<td><a href=\"https:\/\/gradle.org\/\"><span style=\"font-weight: 400\">Gradle 2.3 or higher<\/span><\/a><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color: #000080\">Web framework<\/span><\/td>\n<td><a href=\"https:\/\/projects.spring.io\/spring-boot\/\"><span style=\"font-weight: 400\">Spring Boot 1.4.3.RELEASE<\/span><\/a><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color: #000080\">Security Tool<\/span><\/td>\n<td><a title=\"Spring security\" href=\"https:\/\/projects.spring.io\/spring-security\/\"><span style=\"font-weight: 400\">Spring security<\/span><\/a><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color: #000080\">Repository<\/span><\/td>\n<td><a href=\"https:\/\/www.mysql.com\/\"><span style=\"font-weight: 400\">MySQL<\/span><\/a><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color: #000080\">ORM Tool<\/span><\/td>\n<td><a href=\"http:\/\/projects.spring.io\/spring-data\/\"><span style=\"font-weight: 400\">Spring Data Jpa<\/span><\/a><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color: #000080\">Version Control<\/span><\/td>\n<td><a href=\"https:\/\/en.wikipedia.org\/wiki\/Git\"><span style=\"font-weight: 400\">GIT<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>For simplicity there will be 3 types of users in this application:<\/p>\n<table style=\"height: 121px\" width=\"624\">\n<tbody>\n<tr>\n<td><b>Role<\/b><\/td>\n<td><b>Permission<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">ADMIN<\/span><\/td>\n<td><span style=\"font-weight: 400\">Create user, View users<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">USER<\/span><\/td>\n<td><span style=\"font-weight: 400\">Can view\/update own details<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">ANONYMOUS<\/span><\/td>\n<td><span style=\"font-weight: 400\">Can only view total no of users in the system<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Step 1: Application Setup<\/b><\/p>\n<p>Let\u2019s start with a very basic application (in terms of setup needed) that boots a Spring application context. Two tools that will help us with that are\u00a0<a title=\"Gradle\" href=\"https:\/\/gradle.org\/\">Gradle<\/a> and <a title=\"Spring Boot\" href=\"https:\/\/projects.spring.io\/spring-boot\/\">Spring Boot<\/a>.<\/p>\n<p><span style=\"font-weight: 400\">I skip lines that aren\u2019t particularly interesting like the maven repository configuration. You can find the complete code at <\/span><a href=\"https:\/\/github.com\/bjpaul\/restful-spring-security\/blob\/basic-crud\/build.gradle\"><span style=\"font-weight: 400\">GitHub<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<\/p>\n<p>apply plugin: &#8216;org.springframework.boot&#8217;<\/p>\n<p>dependencies {<br \/>\n\tcompile(&#8216;org.springframework.boot:spring-boot-starter-data-jpa&#8217;)<br \/>\n\tcompile(&#8216;org.springframework.boot:spring-boot-starter-web&#8217;)<br \/>\n\truntime(&#8216;mysql:mysql-connector-java:5.1.13&#8217;)<br \/>\n}<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"font-weight: 400\">Here we are using<\/span><span style=\"font-weight: 400\"><span style=\"color: #339966\">: spring-boot-starter-data-jpa<\/span>\u00a0as the<\/span><span style=\"font-weight: 400\">\u00a0ORM tool.<\/span><\/p>\n<p><b>Step 2 : CRUD for User entity<\/b><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Entity<br \/>\npublic class UserDetail {<br \/>\n    @Id<br \/>\n    @GeneratedValue(strategy = GenerationType.AUTO)<br \/>\n    private long id;<\/p>\n<p>    private String name;<\/p>\n<p>\tprivate int age;<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p>Create the following api\u2019s for <strong><span class=\"kix-wordhtmlgenerator-word-node\" style=\"font-size: 14.6667px;font-family: 'Courier New';color: #bf616a;background-color: #f4f4f4;font-style: normal;text-decoration: none;vertical-align: baseline\">UserDetail<\/span><\/strong> Entity:<\/p>\n<table style=\"height: 259px\" width=\"901\">\n<tbody>\n<tr>\n<td><b>URL<\/b><\/td>\n<td><b>Method<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">{host}\/user\/<\/span><\/td>\n<td><span style=\"font-weight: 400\">GET<\/span><\/td>\n<td><span style=\"font-weight: 400\">List all user details<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">{host}\/user\/{id}<\/span><\/td>\n<td><span style=\"font-weight: 400\">GET<\/span><\/td>\n<td><span style=\"font-weight: 400\">Fetch specific user detail<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">{host}\/user\/<\/span><\/td>\n<td><span style=\"font-weight: 400\">POST<\/span><\/td>\n<td><span style=\"font-weight: 400\">Add new user<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">{host}\/user\/{id}<\/span><\/td>\n<td><span style=\"font-weight: 400\">PUT<\/span><\/td>\n<td><span style=\"font-weight: 400\">Update detail for a user<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">{host}\/user\/{id}<\/span><\/td>\n<td><span style=\"font-weight: 400\">DELETE<\/span><\/td>\n<td><span style=\"font-weight: 400\">Delete a specific user<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #000080\">{host}\/user\/<\/span><\/td>\n<td><span style=\"font-weight: 400\">DELETE<\/span><\/td>\n<td><span style=\"font-weight: 400\">Delete all user<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">You can find the complete code for CRUD and Api\u2019s at <\/span><a href=\"https:\/\/github.com\/bjpaul\/restful-spring-security\/blob\/basic-crud\/src\/main\/java\/org\/basic\/spring\/security\/rest\/controller\/UserController.java\"><span style=\"font-weight: 400\">GitHub<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p><b>Step 3: User Authentication<\/b><\/p>\n<p>Now we need an authentication mechanism to allow only authenticated users\u00a0to access the system.<\/p>\n<p>Add a domain for user credentials:<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Entity<br \/>\npublic class Authentication {<\/p>\n<p>\t@Id<br \/>\n\tprivate String username;<br \/>\n\tprivate String password;<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"font-weight: 400\">Associate it with the <strong><span class=\"kix-wordhtmlgenerator-word-node\" style=\"font-size: 14.6667px;font-family: 'Courier New';color: #bf616a;background-color: #f4f4f4;font-style: normal;text-decoration: none;vertical-align: baseline\">UserDetail<\/span><\/strong> domain:<\/span><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Entity<br \/>\npublic class UserDetail {<br \/>\n    &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n<p>\t@OneToOne(cascade= CascadeType.ALL)<br \/>\n\t@JoinColumn(name = &#8216;user_authentication_id&#8217;)<br \/>\n\tprivate Authentication authentication;<\/p>\n<p>\t&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"font-weight: 400\">Add spring security dependency in <\/span><strong><span class=\"kix-wordhtmlgenerator-word-node\" style=\"font-size: 14.6667px;font-family: 'Courier New';color: #bf616a;background-color: #f4f4f4;font-style: normal;text-decoration: none;vertical-align: baseline\">build.gradle<\/span><\/strong><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<\/p>\n<p>dependencies {<br \/>\n &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n<p> compile(&#8216;org.springframework.boot:spring-boot-starter-security&#8217;)<\/p>\n<p> &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<br \/>\n}<\/p>\n<p>[\/sourcecode]<\/p>\n<p>And\u00a0configure your application to enable basic authentication using below code: \u00a0<strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">org.springframework.security.core.userdetails.UserDetailsService<\/span><\/strong><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@EnableWebSecurity<br \/>\npublic class ApiSecurityConfig extends WebSecurityConfigurerAdapter{<\/p>\n<p> &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<br \/>\n &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n<p> @Autowired<br \/>\n public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {<br \/>\n     auth.userDetailsService(userDetailsService);<br \/>\n }<\/p>\n<p> @Override<br \/>\n protected void configure(HttpSecurity http) throws Exception {<\/p>\n<p>     http<br \/>\n      .authorizeRequests()<br \/>\n      .anyRequest().authenticated()<br \/>\n      .and()<br \/>\n      .httpBasic().authenticationEntryPoint(entryPoint)<br \/>\n      .and()<br \/>\n      .exceptionHandling().accessDeniedHandler(handler);<br \/>\n  }<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p>Here we are configuring Spring security by overriding individual methods of\u00a0<strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter<\/span><\/strong>. <strong><span style=\"font-weight: 400\">\u00a0<strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">@EnableWebSecurity<\/span><\/strong>\u00a0 that helps to auto-configure this.<\/span><\/strong><\/p>\n<p>To enable Spring Security integration with Spring MVC add the <strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">@EnableWebSecurity<\/span><\/strong><\/span><\/strong><\/strong>\u00a0annotation to your configuration.<\/p>\n<p><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">configureGlobalSecurity<\/span><\/strong><\/span><\/strong><\/strong>\u00a0<span style=\"font-weight: 400\">method is pretty straightforward, we are just providing the implementation for <\/span><span style=\"font-weight: 400\">UserDetailService <\/span><span style=\"font-weight: 400\">as<\/span><span style=\"font-weight: 400\">\u00a0the <span style=\"color: #000000\">\u00a0<strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">AuthenticationProvider\u00a0<\/span><\/strong><\/span><\/strong><\/strong><\/span><\/span><\/p>\n<p><span style=\"font-weight: 400\">In <\/span><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">configure\u00a0<\/span><\/strong><\/span><\/strong><\/strong><span style=\"font-weight: 400\">method we are using \u00a0<span style=\"color: #000000\"><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">HTTP Basic Authentication<\/span><\/strong><\/span><\/strong><\/strong><\/span>, \u00a0also providing the \u00a0Implementation of <strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">AuthenticationEntryPoint\u00a0<\/span><\/strong><\/span><\/strong><\/strong>and\u00a0<strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">AccessDeniedHandler\u00a0<\/span><\/strong><\/span><\/strong><\/strong>\u00a0for \u00a0handling\u00a0<span style=\"color: #000000\"><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">Authentication<\/span><\/strong><\/span><\/strong><\/strong><\/span>\u00a0 exception and\u00a0<span style=\"color: #000000\"><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">Access denied<\/span><\/strong><\/span><\/strong><\/strong><\/span>\u00a0exception.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The implementation for\u00a0<strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">UserDetailService<\/span><\/strong><\/span><\/strong><\/strong>\u00a0is pretty straightforward and self-descriptive,\u00a0<\/span><a href=\"https:\/\/github.com\/bjpaul\/restful-spring-security\/blob\/user-authentication\/src\/main\/java\/org\/basic\/spring\/security\/rest\/service\/AuthenticationService.java\"><span style=\"font-weight: 400\">GitHub<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p>Let\u2019s test the functionality using <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/postman\/fhbjgbiflinjbdggehcddcbncdddomop?hl=en\">postman<\/a>\u00a0. Or you can pick any other REST client.<\/p>\n<p>\u21d2 On accessing <span style=\"color: #000080\"><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">GET : &lt;host&gt;\/user\/\u00a0<\/span><\/strong><\/span><\/strong><\/strong><\/span>we\u2019ll get an\u00a0authentication error as below:<\/p>\n<p><span style=\"font-weight: 400\"><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">HTTP Status 401 : <span style=\"color: #000000\">Full authentication is required to access this resource<\/span><\/span><\/strong><\/span><\/strong><\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-45654\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/auth-error-get.gif\" alt=\"auth-error-get\" width=\"1200\" height=\"800\" \/><\/p>\n<p>To resolve this we are adding a new user with sample credential\u00a0using the following script:<\/p>\n<p>[sourcecode language=&#8221;sql&#8221;]<br \/>\ninsert into authentication(username, password) values(&#8216;username1&#8217;, &#8216;password1&#8217;);<br \/>\ninsert into user_detail(age, name,user_authentication_id) values(23, &#8216;User 1&#8242;,&#8217;username1&#8217;);<br \/>\n[\/sourcecode]<\/p>\n<p>Now add the same credential in postman with basic authentication<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-45657\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/auth-success.gif\" alt=\"auth-success\" width=\"1200\" height=\"800\" \/><\/p>\n<p>In response, a token is automatically added into the header with key <strong>\u00a0<strong><strong><strong>Authorization<\/strong><\/strong><\/strong><\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-45213\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/10.png\" alt=\"10\" width=\"1664\" height=\"338\" srcset=\"https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/10.png 1664w, https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/10-300x60.png 300w, https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/10-1024x208.png 1024w, https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/10-624x126.png 624w\" sizes=\"auto, (max-width: 1664px) 100vw, 1664px\" \/><strong><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">Basic dXNlcm5hbWUxOnBhc3N3b3JkMQ==\u00a0<\/span><\/strong><\/span><\/strong><\/strong><\/strong><span style=\"font-weight: 400\">is the encoded form of <\/span><span style=\"font-weight: 400;color: #0000ff\">username1:password1<\/span><span style=\"font-weight: 400\">\u00a0in <\/span><span style=\"font-weight: 400\"><strong><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">base64\u00a0<\/span><\/strong><\/span><\/strong><\/strong><\/strong><\/span><span style=\"font-weight: 400\">and prepended with <\/span><span style=\"font-weight: 400\"><span style=\"color: #0000ff\">\u2018Basic \u00a0\u2018<\/span>. <\/span><span style=\"font-weight: 400\">Now you can access all the API&#8217;s using this entry into the header.<\/span><\/p>\n<p>Again\u00a0we\u2019ll get forbidden error in <strong><strong><strong><strong>POST<\/strong><\/strong><\/strong><\/strong>\u00a0<strong><strong><strong><strong>PUT<\/strong><\/strong><\/strong><\/strong>\u00a0<strong><strong><strong><strong>DELETE<\/strong><\/strong><\/strong><\/strong> operation<\/p>\n<p><span style=\"font-weight: 400\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-45656\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/csrf-error.gif\" alt=\"csrf-error\" width=\"1200\" height=\"800\" \/>To resolve this we can simply disable the CSRF configuration in\u00a0<strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">configure<\/span><\/strong><\/span><\/strong><\/strong>\u00a0method.<\/span><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Override<br \/>\nprotected void configure(HttpSecurity http) throws Exception {<\/p>\n<p>  http.csrf().disable()<br \/>\n      .authorizeRequests()<br \/>\n      .anyRequest().authenticated()<br \/>\n      .and()<br \/>\n      .httpBasic().authenticationEntryPoint(entryPoint)<br \/>\n      .and()<br \/>\n      .exceptionHandling().accessDeniedHandler(handler);<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><strong>When should we use CSRF protection?<\/strong><\/p>\n<p><strong>CSRF<\/strong> protection is a request that could be processed by a browser by normal users.<br \/>\nIf you are only creating a service that is used by non-browser clients, you will likely want to disable <strong>CSRF<\/strong> protection.<\/p>\n<p>To know more about CSRF, read <a href=\"https:\/\/www.owasp.org\/index.php\/Cross-Site_Request_Forgery_(CSRF)\">https:\/\/www.owasp.org\/index.php\/Cross-Site_Request_Forgery_(CSRF)<\/a><\/p>\n<p>As we discussed earlier<strong>\u00a0<strong><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">ANONYMOUS<\/span><\/strong><\/span><\/strong><\/strong><\/strong><\/strong><span style=\"font-weight: 400\">\u00a0user can only view the total no of users in the system i.e API with URL\u00a0<\/span><span style=\"font-weight: 400\"><span style=\"color: #000080\"><strong><strong><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\"><strong>&lt;<\/strong><strong>host&gt;\/user\/count<\/strong><\/span><\/strong><\/span><\/strong><\/strong><\/strong><\/strong><\/span>. To do that change the <\/span><span style=\"font-weight: 400\">\u00a0<strong><strong><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\">chainRequestMatchers<\/span><\/strong><\/span><\/strong><\/strong><\/strong><\/strong><\/span><span style=\"font-weight: 400\">\u00a0in the\u00a0<strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">configure<\/span><\/strong><\/span><\/strong><\/strong><\/span><span style=\"font-weight: 400\">\u00a0method:<\/span><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Override<br \/>\nprotected void configure(HttpSecurity http) throws Exception {<br \/>\n http.csrf().disable()<br \/>\n  .authorizeRequests()<br \/>\n  .antMatchers(&#8216;\/user\/count&#8217;).permitAll() \/\/ request matcher for anonymous user<br \/>\n  .antMatchers(&#8216;\/user\/**&#8217;).authenticated() \/\/ request matcher for authenticate user<br \/>\n  .and()<br \/>\n  .httpBasic().authenticationEntryPoint(entryPoint)<br \/>\n  .and()<br \/>\n  .exceptionHandling().accessDeniedHandler(handler);<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-45661\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/anonymous.gif\" alt=\"anonymous\" width=\"1200\" height=\"800\" \/><\/p>\n<p><span style=\"font-weight: 400\">Find the complete code at <\/span><a href=\"https:\/\/github.com\/bjpaul\/restful-spring-security\/blob\/user-authentication\/src\/main\/java\/org\/basic\/spring\/security\/rest\/config\/ApiSecurityConfig.java\"><span style=\"font-weight: 400\">GitHub<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p><b>Step 4: User Authorization<\/b><\/p>\n<p><span style=\"font-weight: 400\">Now as per the use case non-administrator user will have access to the profile only. i.e<\/span>\u00a0<strong>\u00a0<strong><strong><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;font-family: 'Courier New';font-size: 14.6667px\"><span style=\"color: #000080\"><strong>GET: &lt;host&gt;\/user\/profile<\/strong><\/span>\u00a0<\/span><\/strong><\/span><\/strong><\/strong><\/strong><\/strong><\/strong>\u00a0.<\/p>\n<p>To manage this we need to introduce\u00a0<span style=\"color: #0000ff\">Role\/Authority<\/span> based authentication system.<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Entity<br \/>\npublic class Role {<\/p>\n<p> @Id<br \/>\n @GeneratedValue(strategy = GenerationType.AUTO)<br \/>\n private Long id;<\/p>\n<p> @Column(unique = true)<br \/>\n private String authority;<\/p>\n<p> @ManyToMany(mappedBy = &#8216;roles&#8217;, fetch = FetchType.LAZY)<br \/>\n private Set&lt;Authentication&gt; users;<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"font-weight: 400\">And associate it with\u00a0<\/span><strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">Authentication\u00a0<\/span><\/strong><\/span><\/strong><\/strong>entity:<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Entity<br \/>\npublic class Authentication {<\/p>\n<p> @Id<br \/>\n private String username;<br \/>\n private String password;<br \/>\n @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)<br \/>\n @JoinTable(<br \/>\n joinColumns = @JoinColumn(name = &#8216;user_id&#8217;), inverseJoinColumns = @JoinColumn(name = &#8216;role_id&#8217;)<br \/>\n )<br \/>\n private Set&lt;Role&gt; roles;<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"font-weight: 400\">Add user credentials and their roles\u00a0using the following script:<\/span><\/p>\n<p>[sourcecode language=&#8221;sql&#8221;]<br \/>\ninsert into role(authority) values(&#8216;ROLE_ADMIN&#8217;), (&#8216;ROLE_USER&#8217;);<br \/>\ninsert into authentication(username, password) values(&#8216;admin&#8217;, &#8216;password&#8217;),(&#8216;user&#8217;, &#8216;password&#8217;);<br \/>\ninsert into user_detail(age, name, user_authentication_id) values(25, &#8216;Admin user&#8217;,&#8217;admin&#8217;),(23, &#8216;user&#8217;,&#8217;user&#8217;);<br \/>\ninsert into authentication_roles values(&#8216;admin&#8217;,1),(&#8216;admin&#8217;,2),(&#8216;user&#8217;,2);<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"font-weight: 400\">Finally, modify the\u00a0<strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">UserDetailService<\/span><\/strong><\/span><\/strong><\/strong><\/span><span style=\"font-weight: 400\">\u00a0implementation by providing user authorities and\u00a0<strong><strong><span style=\"font-weight: 400\"><strong><span style=\"background-color: #f4f4f4;color: #bf616a;font-family: 'Courier New';font-size: 14.6667px\">configure<\/span><\/strong><\/span><\/strong><\/strong>\u00a0method to get the desired result.<\/span><\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\n@Override<br \/>\nprotected void configure(HttpSecurity http) throws Exception {<br \/>\n  http.csrf().disable()<br \/>\n   .authorizeRequests()<br \/>\n   .antMatchers(&#8216;\/user\/count&#8217;).permitAll()  \/\/ request matcher for anonymous user<br \/>\n   .antMatchers(&#8216;\/user\/profile&#8217;).hasRole(&#8216;USER&#8217;) \/\/ check for authority with ROLE_USER in the database<br \/>\n   .antMatchers(&#8216;\/user\/**&#8217;).hasRole(&#8216;ADMIN&#8217;) \/\/ check for authority with ROLE_ADMIN in the database<br \/>\n   .and()<br \/>\n   .httpBasic().authenticationEntryPoint(entryPoint)<br \/>\n   .and()<br \/>\n   .exceptionHandling().accessDeniedHandler(handler);<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-45685\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/Screen-Shot-2017-01-29-at-1.50.39-PM.png\" alt=\"Screen Shot 2017-01-29 at 1.50.39 PM\" width=\"1098\" height=\"456\" srcset=\"https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-29-at-1.50.39-PM.png 1098w, https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-29-at-1.50.39-PM-300x124.png 300w, https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-29-at-1.50.39-PM-1024x425.png 1024w, https:\/\/2thenew.xyz\/blog\/wp-content\/uploads\/2017\/01\/Screen-Shot-2017-01-29-at-1.50.39-PM-624x259.png 624w\" sizes=\"auto, (max-width: 1098px) 100vw, 1098px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-45662\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/01\/authenticate-user.gif\" alt=\"authenticate-user\" width=\"1200\" height=\"800\" \/><\/p>\n<p>Hope this will help you to understand the flow for basic authentication using spring security.\u00a0<span style=\"font-weight: 400\">Find the complete code at <\/span><a href=\"https:\/\/github.com\/bjpaul\/restful-spring-security\/blob\/user\/authorization\/src\/main\/java\/org\/basic\/spring\/security\/rest\/service\"><span style=\"font-weight: 400\">GitHub<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<pre class=\"brush: erlang\"><strong>You can\u00a0run the application by below steps,--\r\n<\/strong>\r\n1. git clone <a href=\"mailto:git@github.com\"><span style=\"font-weight: 400\">git@github.com<\/span><\/a><span style=\"font-weight: 400\">:bjpaul\/restful-spring-security.git\r\n2. cd restful-spring-security\r\n3. gradle bootRun\r\n<\/span><\/pre>\n<p>Stay tuned for more on:-<\/p>\n<ul>\n<li style=\"font-weight: 400\">Stateless token based authentication using Spring Security<\/li>\n<li style=\"font-weight: 400\">Domain object security (ACLs)<\/li>\n<li style=\"font-weight: 400\">CAS authentication using spring security<\/li>\n<li style=\"font-weight: 400\">Web socket security in spring<\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">OAuth2 authentication using Spring Security<\/span><\/li>\n<li style=\"font-weight: 400\">Single sign on with OAuth2<\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Spring security with JWT<\/span><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications. It comes bundled with popular security algorithm implementations. I would cover a series of different topic related to spring security\u00a0in my upcoming blogs. We will go through the setup process first, then analyze when and where [&hellip;]<\/p>\n","protected":false},"author":349,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":36,"footnotes":""},"categories":[446,1],"tags":[3133,4841,1202,672],"class_list":["post-45203","post","type-post","status-publish","format-standard","hentry","category-java","category-technology","tag-basic-authentication","tag-spring","tag-spring-boot","tag-spring-security"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Bijoy Paul\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Fortifying your REST API using Spring security | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Fortifying your REST API using Spring security | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#article\",\"name\":\"Fortifying your REST API using Spring security | TO THE NEW Blog\",\"headline\":\"Fortifying your REST API using Spring security\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bijoy-2\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"\\\/blog\\\/wp-ttn-blog\\\/uploads\\\/2022\\\/01\\\/15.jpg\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#articleImage\"},\"datePublished\":\"2017-01-24T19:01:07+05:30\",\"dateModified\":\"2022-01-10T18:40:41+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":3,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#webpage\"},\"articleSection\":\"Java\\\/JVM, Technology, Basic Authentication, Spring, spring boot, spring security\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#listItem\",\"name\":\"Fortifying your REST API using Spring security\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#listItem\",\"position\":3,\"name\":\"Fortifying your REST API using Spring security\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bijoy-2\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bijoy-2\\\/\",\"name\":\"Bijoy Paul\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/bc4159e3-9c1f-4f6b-8f4f-f8f989004c95_712-Bijoy-Paul-PROFILEPICTURE.jpeg\",\"width\":96,\"height\":96,\"caption\":\"Bijoy Paul\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/\",\"name\":\"Fortifying your REST API using Spring security | TO THE NEW Blog\",\"description\":\"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/fortifying-your-rest-api-using-spring-security\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bijoy-2\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bijoy-2\\\/#author\"},\"datePublished\":\"2017-01-24T19:01:07+05:30\",\"dateModified\":\"2022-01-10T18:40:41+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Fortifying your REST API using Spring security | TO THE NEW Blog","description":"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.","canonical_url":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#article","name":"Fortifying your REST API using Spring security | TO THE NEW Blog","headline":"Fortifying your REST API using Spring security","author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/bijoy-2\/#author"},"publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"},"image":{"@type":"ImageObject","url":"\/blog\/wp-ttn-blog\/uploads\/2022\/01\/15.jpg","@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#articleImage"},"datePublished":"2017-01-24T19:01:07+05:30","dateModified":"2022-01-10T18:40:41+05:30","inLanguage":"en-US","commentCount":3,"mainEntityOfPage":{"@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#webpage"},"isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#webpage"},"articleSection":"Java\/JVM, Technology, Basic Authentication, Spring, spring boot, spring security"},{"@type":"BreadcrumbList","@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","position":1,"name":"Home","item":"https:\/\/2thenew.xyz\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/2thenew.xyz\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#listItem","name":"Fortifying your REST API using Spring security"},"previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#listItem","position":3,"name":"Fortifying your REST API using Spring security","previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/2thenew.xyz\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/2thenew.xyz\/blog\/"},{"@type":"Person","@id":"https:\/\/2thenew.xyz\/blog\/author\/bijoy-2\/#author","url":"https:\/\/2thenew.xyz\/blog\/author\/bijoy-2\/","name":"Bijoy Paul","image":{"@type":"ImageObject","@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/bc4159e3-9c1f-4f6b-8f4f-f8f989004c95_712-Bijoy-Paul-PROFILEPICTURE.jpeg","width":96,"height":96,"caption":"Bijoy Paul"}},{"@type":"WebPage","@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#webpage","url":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/","name":"Fortifying your REST API using Spring security | TO THE NEW Blog","description":"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/#breadcrumblist"},"author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/bijoy-2\/#author"},"creator":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/bijoy-2\/#author"},"datePublished":"2017-01-24T19:01:07+05:30","dateModified":"2022-01-10T18:40:41+05:30"},{"@type":"WebSite","@id":"https:\/\/2thenew.xyz\/blog\/#website","url":"https:\/\/2thenew.xyz\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Fortifying your REST API using Spring security | TO THE NEW Blog","og:description":"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.","og:url":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/","og:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Fortifying your REST API using Spring security | TO THE NEW Blog","twitter:description":"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.","twitter:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"45203","title":null,"description":"Spring Security is a lightweight security framework that provides authentication and authorization support in order to secure Spring-based applications.","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-65e044cb5f1d0","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2021-04-29 13:40:15","updated":"2024-02-29 08:48:11","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tFortifying your REST API using Spring security\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/2thenew.xyz\/blog"},{"label":"Technology","link":"https:\/\/2thenew.xyz\/blog\/category\/technology\/"},{"label":"Fortifying your REST API using Spring security","link":"https:\/\/2thenew.xyz\/blog\/fortifying-your-rest-api-using-spring-security\/"}],"_links":{"self":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/45203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/users\/349"}],"replies":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/comments?post=45203"}],"version-history":[{"count":2,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/45203\/revisions"}],"predecessor-version":[{"id":54490,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/45203\/revisions\/54490"}],"wp:attachment":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/media?parent=45203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/categories?post=45203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/tags?post=45203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}