{"id":422,"date":"2021-10-18T13:16:28","date_gmt":"2021-10-18T13:16:28","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?p=422"},"modified":"2022-02-15T11:35:11","modified_gmt":"2022-02-15T11:35:11","slug":"complete-application-with-spring-boot-part-8-role-based-authorization-2","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/","title":{"rendered":"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization &#8211; 2)"},"content":{"rendered":"<p>The is Role-Based Authorization 2 and Part 8 of out complete spring boot application. In <a href=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-role-based-authorization\/\" target=\"_blank\" rel=\"noopener\">Part 1<\/a>, we setup the Role model, repository and service.<\/p>\n<p>In this part, we would set up the controller and then create the pages. Let&#8217;s get to work!<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><a href=\"#t1\">Create the RoleController<\/a><\/li>\n<li><a href=\"#t2\">Create the UserEdit Page<\/a><\/li>\n<li><a href=\"#t3\">Write the Controller Method to Show the userEdit page<\/a><\/li>\n<li><a href=\"#t4\">Write the AssignRole\/UnassignRole Controller Methods<\/a><\/li>\n<li><a href=\"#t5\">Restrict Access to\u00a0 Page<\/a><\/li>\n<li><a href=\"#t6\">Update the Authorities Collection<\/a><\/li>\n<li><a href=\"#t7\">Configure Access Denied Page<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Watch the video tutorial\u00a0<a href=\"https:\/\/youtu.be\/HsCfNMiURCY\" target=\"_blank\" rel=\"noopener\">Watch the video tutorial\u00a0<\/a><\/p>\n<h5><strong>1. Create the RoleController<\/strong><\/h5>\n<p>So we would have to create the RoleController as well as a roles page for LIST\/ADD\/EDIT\/DELETE role. Follow the steps:<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create the RoleController based on existing controllers<\/p>\n<p><strong>Step 2<\/strong> &#8211; Create the roles.html page inside the templates folder. Write the markup to display list of roles or just copy, paste and modify from existing page.<\/p>\n<p><strong>Step 3<\/strong> &#8211; Create the js file<\/p>\n<p><strong>Step 5(Optional)<\/strong> &#8211; You could also add a navigation link to the roles page.<\/p>\n<p><strong>Step 5<\/strong>\u00a0&#8211; Test the page. Add a few roles: USER, ADMIN and SUPER-ADMIN<\/p>\n<p>&nbsp;<\/p>\n<h5><strong>2. Create the UserEdit Page<\/strong><\/h5>\n<p>This is a page that would be used for assigning and unassigning roles to users. So follow the steps below:<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create a page called userEdit in the templates folder<\/p>\n<p>This page would contain three sections:<\/p>\n<ul>\n<li>User data<\/li>\n<li>Roles currently assigned to the user<\/li>\n<li>Roles not assigned to user (assignable roles)<\/li>\n<\/ul>\n<p>The layout of this page is given below:<\/p>\n<figure id=\"attachment_424\" aria-describedby=\"caption-attachment-424\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/UserEdit-Layout-Page.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-424 size-medium\" src=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/UserEdit-Layout-Page-300x154.jpg\" alt=\"UserEdit Page Layout\" width=\"300\" height=\"154\" srcset=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/UserEdit-Layout-Page-300x154.jpg 300w, https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/UserEdit-Layout-Page-1024x525.jpg 1024w, https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/UserEdit-Layout-Page-768x394.jpg 768w, https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/UserEdit-Layout-Page-1536x788.jpg 1536w, https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/UserEdit-Layout-Page.jpg 1938w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-424\" class=\"wp-caption-text\">UserEdit Page Layout<\/figcaption><\/figure>\n<p>See the video for\u00a0 the actual markup of this page.<\/p>\n<p><strong>Step 2<\/strong> &#8211; You need to link this page. So open the existing user.html page and add one more column to the users table. The markup for this column is given below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;a<\/span>  <span style=\"color: #0000cc;\">th:href=<\/span><span style=\"background-color: #fff0f0;\">\"@{'\/security\/user\/Edit\/'+${user.id}}\"<\/span>\r\n   <span style=\"color: #0000cc;\">class=<\/span><span style=\"background-color: #fff0f0;\">\"btn btn-primary\"<\/span><span style=\"color: #007700;\">&gt;&lt;i<\/span> <span style=\"color: #0000cc;\">class=<\/span><span style=\"background-color: #fff0f0;\">\"icon_pencil-edit\"<\/span><span style=\"color: #007700;\">&gt;&lt;\/i&gt;<\/span>Manage Roles<span style=\"color: #007700;\">&lt;\/a&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h5><strong>3. Write the Controller Methods to Load the Edit Page<\/strong><\/h5>\n<p>You now need to write the controller method to show the Edit page. I would be written in the RoleController file. This is given below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@GetMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/security\/user\/Edit\/{id}\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> String <span style=\"color: #0066bb; font-weight: bold;\">editEmployee<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer id<span style=\"color: #333333;\">,<\/span> Model model<span style=\"color: #333333;\">){<\/span>\r\n    User user <span style=\"color: #333333;\">=<\/span> userService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findById<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n    model<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">addAttribute<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"user\"<\/span><span style=\"color: #333333;\">,<\/span> user<span style=\"color: #333333;\">);<\/span>\r\n    model<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">addAttribute<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"userRoles\"<\/span><span style=\"color: #333333;\">,<\/span> roleService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getUserRoles<\/span><span style=\"color: #333333;\">(<\/span>user<span style=\"color: #333333;\">));<\/span>\r\n    model<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">addAttribute<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"userNotRoles\"<\/span><span style=\"color: #333333;\">,<\/span> roleService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getUserNotRoles<\/span><span style=\"color: #333333;\">(<\/span>user<span style=\"color: #333333;\">));<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"background-color: #fff0f0;\">\"\/userEdit\"<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h5><strong>4. Write the Controller Methods for (Assign\/Unassign) Roles<\/strong><\/h5>\n<p>In the RoleController, we need to write two more methods for assigning and unassigning roles to users.<\/p>\n<p>The assignRole() method is given below<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/security\/role\/assign\/{userId}\/{roleId}\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> String <span style=\"color: #0066bb; font-weight: bold;\">assignRole<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer userId<span style=\"color: #333333;\">,<\/span> \r\n                         <span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer roleId<span style=\"color: #333333;\">){<\/span>\r\n    roleService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">assignUserRole<\/span><span style=\"color: #333333;\">(<\/span>userId<span style=\"color: #333333;\">,<\/span> roleId<span style=\"color: #333333;\">);<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"background-color: #fff0f0;\">\"redirect:\/user\/Edit\/\"<\/span><span style=\"color: #333333;\">+<\/span>userId<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The unassignRole() method is given below;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/security\/role\/unassign\/{userId}\/{roleId}\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> String <span style=\"color: #0066bb; font-weight: bold;\">unassignRole<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer userId<span style=\"color: #333333;\">,<\/span>\r\n                           <span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer roleId<span style=\"color: #333333;\">){<\/span>\r\n    roleService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">unassignUserRole<\/span><span style=\"color: #333333;\">(<\/span>userId<span style=\"color: #333333;\">,<\/span> roleId<span style=\"color: #333333;\">);<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"background-color: #fff0f0;\">\"redirect:\/user\/Edit\/\"<\/span><span style=\"color: #333333;\">+<\/span>userId<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Now you can fire up the application and assign and unassign some roles!<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t5\">5. Restrict Page Access (HasAuthority and HasAnyAuthority)<\/strong><\/h5>\n<p>Now we want to restrict a page access based on the user&#8217;s role. So now we would like to restrict access to the userEdit page to only users with the &#8216;ADMIN&#8217; role.<\/p>\n<p>To achieve this, open the applicationSecurityConfig file and include this line in the configure section:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">antMatchers<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/security\/user\/Edit\/**\"<\/span><span style=\"color: #333333;\">).<\/span><span style=\"color: #0000cc;\">hasAuthority<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"ADMIN\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n<\/pre>\n<p><em><strong>Note<\/strong><\/em>: To specify multiple authorities, you can use hasAnyAuthority(), then provide multiple authorities separated by comma.<\/p>\n<p>The code means that any route matching the pattern provided will only be accessible to users with role specified in the .hasRoles() part. In this case, ADMIN.<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t6\">6. Update the Authorities Collection<\/strong><\/h5>\n<p>You remember that in the UserPrincipal class, we had a getAuthorities() method that returns a singleton collection of new SimpleGrantedAuthority(&#8220;USER&#8221;). Now we have to adjust that.<\/p>\n<p>We would use the list of roles we stored in our database to create list of authorities, and then return the list.<\/p>\n<p>The new code is shown below, with the previous code commented out.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Override<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> Collection<span style=\"color: #333333;\">&lt;?<\/span> <span style=\"color: #008800; font-weight: bold;\">extends<\/span> GrantedAuthority<span style=\"color: #333333;\">&gt;<\/span> getAuthorities<span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\tList<span style=\"color: #333333;\">&lt;<\/span>GrantedAuthority<span style=\"color: #333333;\">&gt;<\/span> authorities <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ArrayList<span style=\"color: #333333;\">&lt;&gt;();<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">for<\/span><span style=\"color: #333333;\">(<\/span>Role <span style=\"color: #997700; font-weight: bold;\">role:<\/span> user<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getRoles<\/span><span style=\"color: #333333;\">()){<\/span>\r\n\t\tauthorities<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">add<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">new<\/span> SimpleGrantedAuthority<span style=\"color: #333333;\">(<\/span>role<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getDescription<\/span><span style=\"color: #333333;\">()));<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #888888;\">\/\/return Collections.singleton(new SimpleGrantedAuthority(\"USER\"));<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> authorities<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Also remember to autowire the RoleRepository<\/p>\n<p>With this code, when a user want to access a resource, his roles would be checked to determine if he has the permission.<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t7\">7. Configure Access Denied Page<\/strong><\/h5>\n<p>We would need a page that would be displayed if a user requests for an unauthorized resource.<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create an access denied page. I call it accessDenied.html<\/p>\n<p><strong>Step 2<\/strong> &#8211; Create a controller route to serve this page. Here, I use &#8220;\/accessDenied&#8221;<\/p>\n<p><strong>Step 3<\/strong> &#8211; In the configure method of the ApplicationSecurityConfig file, include the line below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">and<\/span><span style=\"color: #333333;\">()<\/span>\r\n<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">exceptionHandling<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">accessDeniedPage<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/accessDenied\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>We are done here! And please do watch the video. <a href=\"https:\/\/youtu.be\/lD7HRqCc3Hw\" target=\"_blank\" rel=\"noopener\">And please do watch the video<\/a> for any clarification. You can also leave me a comment to let me know if you have any challenges.<\/p>\n<p><a href=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/\" target=\"_blank\" rel=\"noopener\">On to Part 2<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>The is Role-Based Authorization 2 and Part 8 of out complete spring boot application. In Part 1, we setup the Role model, repository and service. &hellip; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":431,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[50,48,51,49,19],"class_list":["post-422","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot-tutorials","tag-authorities","tag-authorization","tag-granted-authorities","tag-role","tag-spring-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization - 2) - Learn Spring Boot<\/title>\n<meta name=\"description\" content=\"This is part 2 of series of tutorials that explains how to configure Role-Based Authorization in Spring Boot.\" \/>\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.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization - 2) - Learn Spring Boot\" \/>\n<meta property=\"og:description\" content=\"This is part 2 of series of tutorials that explains how to configure Role-Based Authorization in Spring Boot.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn Spring Boot\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-18T13:16:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-15T11:35:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/Spring-Security-Role-Based-Authorization-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"476\" \/>\n\t<meta property=\"og:image:height\" content=\"242\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\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.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization &#8211; 2)\",\"datePublished\":\"2021-10-18T13:16:28+00:00\",\"dateModified\":\"2022-02-15T11:35:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/\"},\"wordCount\":687,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/10\\\/Spring-Security-Role-Based-Authorization-1.jpg\",\"keywords\":[\"Authorities\",\"Authorization\",\"Granted Authorities\",\"role\",\"Spring Security\"],\"articleSection\":[\"Spring Boot Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/\",\"name\":\"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization - 2) - Learn Spring Boot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/10\\\/Spring-Security-Role-Based-Authorization-1.jpg\",\"datePublished\":\"2021-10-18T13:16:28+00:00\",\"dateModified\":\"2022-02-15T11:35:11+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"description\":\"This is part 2 of series of tutorials that explains how to configure Role-Based Authorization in Spring Boot.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/10\\\/Spring-Security-Role-Based-Authorization-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/10\\\/Spring-Security-Role-Based-Authorization-1.jpg\",\"width\":476,\"height\":242,\"caption\":\"Spring Security Role-Based Authorization\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/complete-application-with-spring-boot-part-8-role-based-authorization-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization &#8211; 2)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\",\"name\":\"Learn Spring Boot\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization - 2) - Learn Spring Boot","description":"This is part 2 of series of tutorials that explains how to configure Role-Based Authorization in Spring Boot.","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.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/","og_locale":"en_US","og_type":"article","og_title":"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization - 2) - Learn Spring Boot","og_description":"This is part 2 of series of tutorials that explains how to configure Role-Based Authorization in Spring Boot.","og_url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/","og_site_name":"Learn Spring Boot","article_published_time":"2021-10-18T13:16:28+00:00","article_modified_time":"2022-02-15T11:35:11+00:00","og_image":[{"width":476,"height":242,"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/Spring-Security-Role-Based-Authorization-1.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization &#8211; 2)","datePublished":"2021-10-18T13:16:28+00:00","dateModified":"2022-02-15T11:35:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/"},"wordCount":687,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/Spring-Security-Role-Based-Authorization-1.jpg","keywords":["Authorities","Authorization","Granted Authorities","role","Spring Security"],"articleSection":["Spring Boot Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/","name":"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization - 2) - Learn Spring Boot","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/Spring-Security-Role-Based-Authorization-1.jpg","datePublished":"2021-10-18T13:16:28+00:00","dateModified":"2022-02-15T11:35:11+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"description":"This is part 2 of series of tutorials that explains how to configure Role-Based Authorization in Spring Boot.","breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/Spring-Security-Role-Based-Authorization-1.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/10\/Spring-Security-Role-Based-Authorization-1.jpg","width":476,"height":242,"caption":"Spring Security Role-Based Authorization"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/complete-application-with-spring-boot-part-8-role-based-authorization-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/spring-boot\/"},{"@type":"ListItem","position":2,"name":"Complete Application with Spring Boot \u2013 Part 8 (Role-Based Authorization &#8211; 2)"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/","name":"Learn Spring Boot","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/comments?post=422"}],"version-history":[{"count":11,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/422\/revisions"}],"predecessor-version":[{"id":447,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/422\/revisions\/447"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media\/431"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media?parent=422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/categories?post=422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/tags?post=422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}