{"id":74737,"date":"2019-07-18T11:00:16","date_gmt":"2019-07-18T08:00:16","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=74737"},"modified":"2019-07-18T09:02:57","modified_gmt":"2019-07-18T06:02:57","slug":"grails-spring-security-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/","title":{"rendered":"Grails Spring Security Tutorial"},"content":{"rendered":"<p>There are many security features in Spring Security such as authentication, authorization, instance-based control, and others. Grails developers use Spring security to secure the application.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#overview\">1. Overview<\/a><\/dt>\n<dt><a href=\"#grails\">2. Grails Spring Security<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#prerequisites\">2.1. Prerequisites<\/a><\/dt>\n<dt><a href=\"#software\">2.2. Download<\/a><\/dt>\n<dt><a href=\"#setup\">2.3. Setup<\/a><\/dt>\n<dt><a href=\"#run_gradle\">2.4. Running Gradle<\/a><\/dt>\n<dt><a href=\"#run_grails\">2.5. Running Grails<\/a><\/dt>\n<dt><a href=\"#hello_world\">2.6. HelloWorld in Grails<\/a><\/dt>\n<dt><a href=\"#testing\">2.7. Testing Grails Application<\/a><\/dt>\n<dt><a href=\"#ide\">2.8. Grails IDE Integration<\/a><\/dt>\n<dt><a href=\"#build\">2.9. Building with Gradle<\/a><\/dt>\n<dt><a href=\"#deploy\">2.10. Deploying a Grails App<\/a><\/dt>\n<dt><a href=\"#spring_security\">2.11. Grails Spring Security<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#download\">3. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<p>&nbsp;<\/p>\n<h2 class=\"wp-block-heading\"><a name=\"introduction\"><\/a>1. Overview<\/h2>\n<p>This is an in-depth article on Grails Spring Security. Grails opensource framework is used for designing and developing full-stack applications. Spring security plugin provides spring security for Grails application. The plugin can be customized for various configuration options.  Interfaces are used for extensibility.<\/p>\n<h2 class=\"wp-block-heading\"><a name=\"grails\"><\/a>2. Grails Spring Security<\/h2>\n<h3 class=\"wp-block-heading\"><a name=\"prerequisites\"><\/a>2.1 Prerequisites<\/h3>\n<p>Java 8 is required on the linux, windows or mac operating system. Gradle 5.4.1 version can be used for building gradle projects. Grails 3.3.10 is used for creating Grails Helloworld projects. Apache tomcat 9.0 is used as a servlet container to deploy Grails Helloworld example.<\/p>\n<h3 class=\"wp-block-heading\"><a name=\"software\"><\/a>2.2 Download<\/h3>\n<p>You can download Java 8 from the Oracle web&nbsp;<a href=\"https:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jdk8-downloads-2133151.html\">site<\/a>&nbsp;. Likewise, Gradle 5.4.1 can be downloaded from this&nbsp;<a href=\"https:\/\/gradle.org\/next-steps\/?version=5.4.1&amp;format=bin\">website<\/a>. Grails binary distribution can be downloaded from&nbsp;<a href=\"https:\/\/github.com\/grails\/grails-core\/releases\/tag\/v3.3.10\">github site<\/a>. Similarly, Apache Tomcat 9.0 can be downloaded from the apache&nbsp;<a href=\"https:\/\/tomcat.apache.org\/download-90.cgi\">website<\/a>.<\/p>\n<h3 class=\"wp-block-heading\"><a name=\"setup\"><\/a>2.3 Setup<\/h3>\n<h4 class=\"wp-block-heading\">2.3.1 Java Setup<\/h4>\n<p>You can set the environment variables for JAVA_HOME and PATH. They can be set as shown below<em>.<\/em><\/p>\n<p><span style=\"text-decoration: underline\"><em>Java Environment<\/em><\/span><\/p>\n<pre class=\"brush:plain\">JAVA_HOME=\u201d\/jboss\/jdk1.8.0_73\u2033\nexport JAVA_HOME\nPATH=$JAVA_HOME\/bin:$PATH\nexport PATH\n<\/pre>\n<h4 class=\"wp-block-heading\">2.3.2 Grails Setup<\/h4>\n<p>You can set the Grails home in the PATH as shown below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Grails Environment<\/em><\/span><\/p>\n<pre class=\"brush:plain\">export GRAILS_HOME=\/path\/to\/grails\nexport PATH=\"$PATH:$GRAILS_HOME\/bin\"\n<\/pre>\n<h4 class=\"wp-block-heading\">2.3.3 Gradle Setup<\/h4>\n<p>The environment variables for Gradle are set as below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Gradle Environment<\/em><\/span><\/p>\n<pre class=\"brush:plain\">GRADLE_HOME=\"\/opt\/gradle\/gradle-5.4.1\/bin\"\nexport GRADLE_HOME=$GRADLE_HOME\/bin\/\nexport PATH=$PATH:$GRADLE_HOME\n<\/pre>\n<h3 class=\"wp-block-heading\"><a name=\"run_gradle\"><\/a>2.4 Running Gradle<\/h3>\n<p>You can check the version of the gradle by using the command gradle \u2013-version. The command for running Gradle is as below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Gradle Version<\/em><\/span><\/p>\n<pre class=\"brush:plain\">gradle --version\n<\/pre>\n<p>The output of the executed Gradle command is shown below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"520\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_command.jpg.webp\" alt=\"Grails Spring Security - Gradle Version\" class=\"wp-image-73312\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_command.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_command-300x190.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_command-768x487.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Gradle Version<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\"><a name=\"run_grails\"><\/a>2.5 Running Grails<\/h3>\n<p>You can check the version of the Grails by using the command \u201cgrails \u2013v\u201d. The command for running Grails is as below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Grails Version<\/em><\/span><\/p>\n<pre class=\"brush:plain\">grails -v\n<\/pre>\n<p>The output of the executed Grails command is shown below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"674\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_version.jpg.webp\" alt=\"Grails Spring Security - Grails Version\" class=\"wp-image-73314\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_version.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_version-300x247.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_version-768x631.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails Version<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\"><a name=\"hello_world\"><\/a>2.6 Hello World in Grails<\/h3>\n<p>Grails framework is used for full-stack application development. It is an  opensource framework. It cuts down the challenges in creating web applications using Java. You can create a Grails application by using the command below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Hello World<\/em><\/span><\/p>\n<pre class=\"brush:plain\">grails create-app HelloWorld\n<\/pre>\n<p>The output of the executed Grails command is shown below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"674\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_create_app.jpg.webp\" alt=\"Grails Spring Security - Grails CreateApp\" class=\"wp-image-73330\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_create_app.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_create_app-300x247.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_create_app-768x631.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails CreateApp<\/figcaption><\/figure>\n<p>\u201cCreateApp\u201d command creates the HelloWorld folder. The folder contains the Gradle build based project for Grails. Folder structure is shown below:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"520\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_folder.jpg.webp\" alt=\"Grails Spring Security - HelloWorld\" class=\"wp-image-73332\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_folder.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_folder-300x190.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_folder-768x487.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>HelloWorld Project<\/figcaption><\/figure>\n<p>Controllers are generated by using commands such as create-controller or generate-controller. You can create a controller by using the command below inside the HelloWorld folder:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Create Controller<\/em><\/span><\/p>\n<pre class=\"brush:plain\">grails create-controller Hello\n<\/pre>\n<p>A controller has action methods which are public. These methods map to a URI of a page. You can add the code to show \u201cGreetings\u201d inside the generated controller code. The code implementation of the&nbsp;<code>HelloController<\/code>&nbsp;Class is shown below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Hello Controller<\/em><\/span><\/p>\n<pre class=\"brush:java\">package helloworld\n \nclass HelloController {\n \n    def index() { \n         \n        render \"Greetings\"\n     \n    }\n}\n<\/pre>\n<p>You can run the Grails app in grails console using the command below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Run App<\/em><\/span><\/p>\n<pre class=\"brush:plain\">run-app\n<\/pre>\n<p>The snap shot of the grails console is shown below:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"674\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/run-app-1.jpg.webp\" alt=\"Grails Spring Security - Grails run-app\" class=\"wp-image-73336\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/run-app-1.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/run-app-1-300x247.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/run-app-1-768x631.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails run-app<\/figcaption><\/figure>\n<p>You can access the Grails app in the browser from this URL:&nbsp;<a href=\"http:\/\/localhost:8080\/\">http:\/\/localhost:8080\/<\/a>&nbsp;. The page rendered is shown below:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"881\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_local_running.jpg.webp\" alt=\"Grails Spring Security - Grails App\" class=\"wp-image-73338\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_local_running.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_local_running-279x300.jpg 279w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_local_running-768x825.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails App Running<\/figcaption><\/figure>\n<p>You can select the Hello Controller and click on the link. The following page shows up:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"881\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_hello_index.jpg.webp\" alt=\"Grails Spring Security - Grails Hello Controller\" class=\"wp-image-73341\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_hello_index.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_hello_index-279x300.jpg 279w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_hello_index-768x825.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails Hello Controller<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\"><a name=\"testing\"><\/a>2.7 Testing Grails Application<\/h3>\n<p>Grails Framework has features for automated testing. Unit testing and functional testing can be done using the framework. You can modify the HelloWorld\/src\/test\/groovy\/helloworld\/HelloControllerSpec.Groovy to test the index method. The code implemented for&nbsp;<code>HelloControllerSpec<\/code>&nbsp;is shown below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Unit Test<\/em><\/span><\/p>\n<pre class=\"brush:java\">package helloworld\n \nimport grails.testing.web.controllers.ControllerUnitTest\nimport spock.lang.Specification\n \nclass HelloControllerSpec extends Specification implements ControllerUnitTest {\n \n    def setup() {\n    }\n \n    def cleanup() {\n    }\n \n    void \"test something\"() {\n         \n        when:\n        controller.index()\n         \n        then:\n        response.text == 'Greetings'\n \n    }\n}\n<\/pre>\n<p>You can run test the Grails app using the command below:<em> <\/em><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>Test Grails App<\/em><\/span><\/p>\n<pre class=\"brush:plain\">grails test-app\n<\/pre>\n<p>The output of the executed grails command is shown below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"688\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_testing.jpg.webp\" alt=\"Grails Spring Security - Grails Testing\" class=\"wp-image-73348\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_testing.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_testing-300x252.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_testing-768x644.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails Testing<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\"><a name=\"ide\"><\/a>2.8 Grails IDE Integration<\/h3>\n<p>You can configure the Groovy Eclipse plugin from the&nbsp;<a href=\"https:\/\/dist.springsource.org\/release\/GRECLIPSE\/e4.7\">distribution site<\/a>. The screen shot below shows the configuration of Groovy Eclipse plugin from Help-&gt; Install-&gt; New Software.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"834\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groove_eclipse.jpg.webp\" alt=\"Grails Spring Security - Groovy Eclipse\" class=\"wp-image-73356\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groove_eclipse.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groove_eclipse-295x300.jpg 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groove_eclipse-768x781.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groove_eclipse-70x70.jpg 70w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Groovy Eclipse<\/figcaption><\/figure>\n<p>The groovy version is set from Eclipse\u2019s Preferences -&gt; Groovy -&gt;Compiler. The setting of the groovy version 2.4.16 is shown below:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"834\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groovy_version_configuration_eclipse.jpg.webp\" alt=\"Grails Spring Security - Groovy Version\" class=\"wp-image-73357\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groovy_version_configuration_eclipse.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groovy_version_configuration_eclipse-295x300.jpg 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groovy_version_configuration_eclipse-768x781.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/groovy_version_configuration_eclipse-70x70.jpg 70w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Groovy Version- Eclipse<\/figcaption><\/figure>\n<p>Spock plugin can be installed with eclipse from this&nbsp;<a href=\"https:\/\/marketplace.eclipse.org\/content\/spock-plugin\">site<\/a>. The screenshot shows the spock plugin installation.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"833\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/spock_plugin_eclipse.jpg.webp\" alt=\"Grails Spring Security - Spocky Plugin\" class=\"wp-image-73358\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/spock_plugin_eclipse.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/spock_plugin_eclipse-295x300.jpg 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/spock_plugin_eclipse-768x780.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/spock_plugin_eclipse-70x70.jpg 70w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Spocky Plugin \u2013 Eclipse<\/figcaption><\/figure>\n<p>You need to install SpringSource Tool Suite Grails Support(STS) from the distribution&nbsp;<a href=\"https:\/\/dist.springsource.com\/snapshot\/TOOLS\/nightly\/e4.7\">site<\/a>. You need to also ensure that Buildship gradle Integration plugin is installed. The snapshot below shows the installed gradle version.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"832\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_gradle.jpg.webp\" alt=\"Grails Spring Security - Gradle plugin \" class=\"wp-image-73359\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_gradle.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_gradle-296x300.jpg 296w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_gradle-768x779.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_gradle-70x70.jpg 70w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Eclipse \u2013 Gradle plugin<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\"><a name=\"build\"><\/a>2.9 Building with Gradle<\/h3>\n<p>You can import the project HelloWorld which was a Gradle project created in section 2.6. The snapshot below shows the import wizard from the Eclipse menu File-&gt; Import.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"615\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_import_gradle.jpg.webp\" alt=\"Grails Spring Security -  Import Gradle Project\" class=\"wp-image-73360\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_import_gradle.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_import_gradle-300x225.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/eclipse_import_gradle-768x576.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Eclipse \u2013 Import Gradle Project<\/figcaption><\/figure>\n<p>After the import, Gradle Grails project can be viewed in the eclipse. The screen shot below shows the imported project.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"616\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_eclipse.jpg.webp\" alt=\"Grails Spring Security - Eclipse Project\" class=\"wp-image-73361\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_eclipse.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_eclipse-300x225.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_eclipse-768x577.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Gradle Grails Eclipse Project<\/figcaption><\/figure>\n<p>From the Gradle tasks view, You can see all the gradle tasks. To execute the grails app, click on bootRun. The screenshot below shows the gradle tasks view.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"852\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_tasks_view.jpg.webp\" alt=\"Grails Spring Security - Gradle Tasks Eclipse View\" class=\"wp-image-73362\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_tasks_view.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_tasks_view-289x300.jpg 289w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_tasks_view-768x798.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Gradle Tasks Eclipse View<\/figcaption><\/figure>\n<p>The grails app can be accessed at http:\/\/localhost:8080 when the gradle runs the Grails app on eclipse. The snapshot of the Grails app and Gradle task execution is shown below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"824\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/browser_grails_app_eclipse.jpg.webp\" alt=\"\" class=\"wp-image-73363\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/browser_grails_app_eclipse.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/browser_grails_app_eclipse-150x150.jpg 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/browser_grails_app_eclipse-300x300.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/browser_grails_app_eclipse-768x772.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/browser_grails_app_eclipse-70x70.jpg 70w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails App Running \u2013 Eclipse<\/figcaption><\/figure>\n<p>The HelloController can be accessed and the page renders to show the \u201cGreetings\u201d message. The rendered page is shown below:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"815\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/hello_index_eclipse_grails.jpg.webp\" alt=\"\" class=\"wp-image-73364\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/hello_index_eclipse_grails.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/hello_index_eclipse_grails-150x150.jpg 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/hello_index_eclipse_grails-300x298.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/hello_index_eclipse_grails-768x763.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/hello_index_eclipse_grails-70x70.jpg 70w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Hello Controller \u2013 Eclipse<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\"><a name=\"deploy\"><\/a>2.10 Deploying a Grails App<\/h3>\n<p>War file is deployed on the typical servlet containers such as Tomcat, Jetty, etc. war command is used for generating a war file. You can deploy a Grails app on to a container which supports Java Servlet 3.0 specification. The command to create a war file is shown below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Deploying Grails App<\/em><\/span><\/p>\n<pre class=\"brush:plain\">grails war\n<\/pre>\n<p>The output of the executed grails command is shown below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"534\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_war.jpg.webp\" alt=\"\" class=\"wp-image-73366\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_war.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_war-300x195.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grails_war-768x500.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails War command<\/figcaption><\/figure>\n<p>The war file from build\/libs can be deployed on apache tomcat. The startup script of the tomcat is executed. The screen shot shows the execution of the script and the browser rendering the page at http:\/\/localhost:8080.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"727\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_deploy.jpg.webp\" alt=\"\" class=\"wp-image-73381\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_deploy.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_deploy-300x266.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/gradle_grails_deploy-768x681.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails Deploy<\/figcaption><\/figure>\n<p>The controller page is accessed by clicking on the link. The page renders as shown below in the screen shot.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"802\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grade_grails_controller_deploy.jpg.webp\" alt=\"\" class=\"wp-image-73383\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grade_grails_controller_deploy.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grade_grails_controller_deploy-300x293.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/grade_grails_controller_deploy-768x751.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Gradle Grails Controller<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\"><a name=\"spring_security\"><\/a>2.11 Grails Spring Security<\/h3>\n<h4 class=\"wp-block-heading\">2.11.1  Role Based Security<\/h4>\n<p>This section talks about the configuration and extension of spring security plugin for Grails apps. The configuration can be maintained in conf\/application.yml. It can also be maintained in conf\/application.groovy.  application.yml can have the application-specific values and the defualt values can be in the DefaultSecurityConfig.groovy. The application-specific values are overridden with defaults and the settings are merged with the default configuration. The application.yml used is shown below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>application.yml<\/em><\/span><\/p>\n<pre class=\"brush:plain\">---\ngrails:\n    profile: web\n    codegen:\n        defaultPackage: com.app.security\n    spring:\n        transactionManagement:\n            proxies: false\n    gorm:\n        reactor:\n            # Whether to translate GORM events into Reactor events\n            # Disabled by default for performance reasons\n            events: false\ninfo:\n    app:\n        name: '@info.app.name@'\n        version: '@info.app.version@'\n        grailsVersion: '@info.app.grailsVersion@'\nspring:\n    main:\n        banner-mode: \"off\"\n    groovy:\n        template:\n            check-template-location: false\n\n# Spring Actuator Endpoints are Disabled by Default\nendpoints:\n    enabled: false\n    jmx:\n        enabled: true\n\n---\ngrails:\n    mime:\n        disable:\n            accept:\n                header:\n                    userAgents:\n                        - Gecko\n                        - WebKit\n                        - Presto\n                        - Trident\n        types:\n            all: '*\/*'\n            atom: application\/atom+xml\n            css: text\/css\n            csv: text\/csv\n            form: application\/x-www-form-urlencoded\n            html:\n              - text\/html\n              - application\/xhtml+xml\n            js: text\/javascript\n            json:\n              - application\/json\n              - text\/json\n            multipartForm: multipart\/form-data\n            pdf: application\/pdf\n            rss: application\/rss+xml\n            text: text\/plain\n            hal:\n              - application\/hal+json\n              - application\/hal+xml\n            xml:\n              - text\/xml\n              - application\/xml\n    urlmapping:\n        cache:\n            maxsize: 1000\n    controllers:\n        defaultScope: singleton\n    converters:\n        encoding: UTF-8\n    views:\n        default:\n            codec: html\n        gsp:\n            encoding: UTF-8\n            htmlcodec: xml\n            codecs:\n                expression: html\n                scriptlets: html\n                taglib: none\n                staticparts: none\nendpoints:\n    jmx:\n        unique-names: true\n\n---\nhibernate:\n    cache:\n        queries: false\n        use_second_level_cache: false\n        use_query_cache: false\ndataSource:\n    pooled: true\n    jmxExport: true\n    driverClassName: org.h2.Driver\n    username: sa\n    password: ''\n\nenvironments:\n    development:\n        dataSource:\n            dbCreate: create-drop\n            url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE\n    test:\n        dataSource:\n            dbCreate: create-drop\n            url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE\n    production:\n        dataSource:\n            dbCreate: none\n            url: jdbc:h2:.\/prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE\n            properties:\n                jmxEnabled: true\n                initialSize: 5\n                maxActive: 50\n                minIdle: 5\n                maxIdle: 25\n                maxWait: 10000\n                maxAge: 600000\n                timeBetweenEvictionRunsMillis: 5000\n                minEvictableIdleTimeMillis: 60000\n                validationQuery: SELECT 1\n                validationQueryTimeout: 3\n                validationInterval: 15000\n                testOnBorrow: true\n                testWhileIdle: true\n                testOnReturn: false\n                jdbcInterceptors: ConnectionState\n                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED\n---\ngrails:\n    plugin:\n        springsecurity:\n            apf:\n                storeLastUsername: true\n            useSwitchUserFilter: true\n            switchUser:\n                targetUrl: \/secure\/\n            adh:\n                errorPage: null # to trigger a 403\n            userLookup:\n                userDomainClassName: org.app.security.auth.LoginUser\n                authorityJoinClassName: org.app.security.auth.LoginUserRole\n            authority:\n                className: org.app.security.auth.LoginRole\n            controllerAnnotations:\n                staticRules:\n                    -\n                        pattern: \/\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/dbconsole\/*\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/error\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/index\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/index.gsp\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/shutdown\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/assets\/**\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/**\/js\/**\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/**\/css\/**\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/**\/images\/**\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/**\/favicon.ico\n                        access:\n                            - permitAll\n                    -\n                        pattern: \/login\/impersonate\n                        access:\n                            - ROLE_SUPERVISOR\n\n<\/pre>\n<p>resources.groovy is configured for LoginPasswordEncoderListener . Sample resources.groovy is shown below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>resources.groovy<\/em><\/span><\/p>\n<pre class=\"brush:plain\">import com.app.security.auth.LoginPasswordEncoderListener\n\nbeans = {\n    userPasswordEncoderListener(LoginPasswordEncoderListener)\n}\n<\/pre>\n<p>Authentication can be done in Grails using spring security. The authentication object checks if the present user can execute a secured action. The action can be  URL access, domain object securing, method level security and etc., The authentication can be pluggable using spring security. There exists an overlap between login authentication and user representation.  <code>LoginUserDataService<\/code> will have an implementation of the method of <code>findLoginUserUsername<\/code> with <code>parameter<\/code> username. <code>LoginUserDataService<\/code> class code is shown below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>LoginUserService.groovy<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.app.security.auth\n\nimport grails.gorm.services.Service\nimport groovy.transform.CompileStatic\nimport com.app.security.LoginUser\n\n@CompileStatic\n@Service(LoginUser)\ninterface LoginUserDataService {\n\n    LoginUser save(String username, String password, boolean enabled)\n\n    List findLoginUserUsername()\n}\n<\/pre>\n<p><code>LoginUser<\/code> class has properties username, password and enabled. Authorities property is implemented as a method named <code>getAuthorities<\/code>. Sample code is shown below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>LoginUser<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.app.security\n\nimport groovy.transform.EqualsAndHashCode\nimport groovy.transform.ToString\nimport grails.compiler.GrailsCompileStatic\n\n@GrailsCompileStatic\n@EqualsAndHashCode(includes='username')\n@ToString(includes='username', includeNames=true, includePackage=false)\nclass LoginUser implements Serializable {\n\tprivate static final long serialVersionUID = 1\n\n\tString username\n\tString password\n\tboolean enabled = true\n\tboolean accountExpired\n\tboolean accountLocked\n\tboolean passwordExpired\n\n\tSet getAuthorities() {\n\t\t(LoginUserRole.findAllByUser(this) as List)*.role as Set\n\t}\n\n\tstatic constraints = {\n\t\tpassword blank: false, password: true\n\t\tusername blank: false, unique: true\n\t}\n\n\tstatic mapping = {\n\t\tpassword column: '`password`'\n\t}\n}<\/pre>\n<p>Authority class helps in presenting the user roles in the web app. URL are restricted to the users by assigning access rights. Users can have multiple roles with different access rights in the application. Default user role is a virtual role named ROLE_NO_ROLES. Typically this role does not have any secure resources for this role. A <code>LoginRole<\/code> class code sample is shown below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>LoginRole.groovy<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.app.security\n\n\nimport groovy.transform.EqualsAndHashCode\nimport groovy.transform.ToString\nimport grails.compiler.GrailsCompileStatic\n\n@GrailsCompileStatic\n@EqualsAndHashCode(includes='authority')\n@ToString(includes='authority', includeNames=true, includePackage=false)\nclass LoginRole implements Serializable {\n\n\tprivate static final long serialVersionUID = 1\n\tString authority\n\n\tstatic constraints = {\n\t\tauthority blank: false, unique: true\n\t}\n\n\tstatic mapping = {\n\t\tcache true\n\t}\n}\n<\/pre>\n<p>A Role class will have authority, constraints, and mapping. The role names can be configured with names starting with  \u201cROLE_\u201d.  Person and Authority have many to many relationship to each other. A <code>LoginUserRole<\/code> represents the relationship for users having more than one role. The <code>LoginUserRole<\/code> code is shown as below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>LoginUserRole.groovy<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.app.security\n\nimport grails.gorm.DetachedCriteria\nimport groovy.transform.ToString\n\nimport org.codehaus.groovy.util.HashCodeHelper\nimport grails.compiler.GrailsCompileStatic\n\n@SuppressWarnings(['FactoryMethodName', 'Instanceof'])\n@GrailsCompileStatic\n@ToString(cache=true, includeNames=true, includePackage=false)\nclass LoginUserRole implements Serializable {\n\n\tprivate static final long serialVersionUID = 1\n\n\tLoginUser user\n\tLoginRole role\n\n\t@Override\n\tboolean equals(other) {\n\t\tif (other instanceof LoginUserRole) {\n\t\t\tother.userId == user?.id &amp;&amp; other.roleId == role?.id\n\t\t}\n\t}\n\n\t@Override\n\tint hashCode() {\n\t\tint hashCode = HashCodeHelper.initHash()\n\t\tif (user) {\n\t\t\thashCode = HashCodeHelper.updateHash(hashCode, user.id)\n\t\t}\n\t\tif (role) {\n\t\t\thashCode = HashCodeHelper.updateHash(hashCode, role.id)\n\t\t}\n\t\thashCode\n\t}\n\n\tstatic LoginUserRole get(long userId, long roleId) {\n\t\tcriteriaFor(userId, roleId).get()\n\t}\n\n\tstatic boolean exists(long userId, long roleId) {\n\t\tcriteriaFor(userId, roleId).count()\n\t}\n\n\tprivate static DetachedCriteria criteriaFor(long userId, long roleId) {\n\t\tLoginUserRole.where {\n\t\t\tuser == LoginUser.load(userId) &amp;&amp;\n\t\t\t\t\trole == Role.load(roleId)\n\t\t}\n\t}\n\n\tstatic LoginUserRole create(Login user, LoginRole role, boolean flush = false) {\n\t\tdef instance = new LoginUserRole(user: user, role: role)\n\t\tinstance.save(flush: flush)\n\t\tinstance\n\t}\n\n\tstatic boolean remove(Login u, LoginRole r) {\n\t\tif (u != null &amp;&amp; r != null) {\n\t\t\tLoginUserRole.where { user == u &amp;&amp; role == r }.deleteAll()\n\t\t}\n\t}\n\n\tstatic int removeAll(Login u) {\n\t\tu == null ? 0 : LoginUserRole.where { user == u }.deleteAll() as int\n\t}\n\n\tstatic int removeAll(LoginRole r) {\n\t\tr == null ? 0 : LoginUserRole.where { role == r }.deleteAll() as int\n\t}\n\n\tstatic constraints = {\n\t\trole validator: { LoginRole r, LoginUserRole ur -&gt;\n\t\t\tif (ur.user?.id) {\n\t\t\t\tLoginUserRole.withNewSession {\n\t\t\t\t\tif (LoginUserRole.exists(ur.user.id, r.id)) {\n\t\t\t\t\t\treturn ['userRole.exists']\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic mapping = {\n\t\tid composite: ['user', 'role']\n\t\tversion false\n\t}\n}\n<\/pre>\n<p>The command below executes the above code snippets:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Grails Run App<\/em><\/span><\/p>\n<pre class=\"brush:plain\">grails run-app\n<\/pre>\n<p>The output of the executed command is shown below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"593\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_spring.jpg\" alt=\"\" class=\"wp-image-74811\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_spring.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_spring-300x217.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_spring-768x555.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Grails Run App<\/figcaption><\/figure>\n<p>The screen shot below shows the execution of the sample code and the browser rendering the page at http:\/\/localhost:8080.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"720\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_demo.jpg\" alt=\"\" class=\"wp-image-74812\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_demo.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_demo-300x263.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grails_demo-768x674.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>Login Security Demo<\/figcaption><\/figure>\n<h4 class=\"wp-block-heading\">2.11.2  Security Group<\/h4>\n<p>A security group can consist of multiple users. The access rights can be assigned to a group. The application will have multiple groups of users having different levels of access.<\/p>\n<h4 class=\"wp-block-heading\">2.11.3  Hierarchical Roles<\/h4>\n<p>Roles can be hierarchical to minimize the clutter in application request mappings. The configuration options for the hierarchical roles can be role Hierarchy and roleHierarchy entry class name. Sample hierarchy can be as shown below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Role Hierarchy<\/em><\/span><\/p>\n<pre class=\"brush:plain\">grails.plugin.springsecurity.roleHierarchy = '''\n   ROLE_SUPER_ADMIN &gt; ROLE_FINANCE_ADMIN\n   ROLE_FINANCE_ADMIN &gt; ROLE_OPERATIONS_ADMIN\n   ROLE_OPERATIONS_ADMIN &gt; ROLE_ADMIN\n'''\n<\/pre>\n<h2 class=\"wp-block-heading\"><a name=\"download\"><\/a>3. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:<a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/grailsspringsecurity-1.zip\"> <strong>Grails Spring Security Tutorial<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>There are many security features in Spring Security such as authentication, authorization, instance-based control, and others. Grails developers use Spring security to secure the application. Table Of Contents 1. Overview 2. Grails Spring Security 2.1. Prerequisites 2.2. Download 2.3. Setup 2.4. Running Gradle 2.5. Running Grails 2.6. HelloWorld in Grails 2.7. Testing Grails Application 2.8. &hellip;<\/p>\n","protected":false},"author":31,"featured_media":27333,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1528],"tags":[1701],"class_list":["post-74737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-grails","tag-spring-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Grails Spring Security Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about Grails? Then check out our detailed example on Grails Spring Security!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Grails Spring Security Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about Grails? Then check out our detailed example on Grails Spring Security!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/bhagvank\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-18T08:00:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-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=\"Bhagvan Kommadi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bhaggu\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bhagvan Kommadi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/\"},\"author\":{\"name\":\"Bhagvan Kommadi\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/4575ae335b8ff016be62c3b927d5d5e6\"},\"headline\":\"Grails Spring Security Tutorial\",\"datePublished\":\"2019-07-18T08:00:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/\"},\"wordCount\":1458,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"keywords\":[\"Spring Security\"],\"articleSection\":[\"Grails\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/\",\"name\":\"Grails Spring Security Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"datePublished\":\"2019-07-18T08:00:16+00:00\",\"description\":\"Interested to learn more about Grails? Then check out our detailed example on Grails Spring Security!\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JVM Languages\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Groovy\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Grails\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/grails\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Grails Spring Security Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/4575ae335b8ff016be62c3b927d5d5e6\",\"name\":\"Bhagvan Kommadi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/bhagvan.-kommadi-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/bhagvan.-kommadi-96x96.jpg\",\"caption\":\"Bhagvan Kommadi\"},\"description\":\"Bhagvan Kommadi is the Founder of Architect Corner &amp; has around 20 years\u2019 experience in the industry, ranging from large scale enterprise development to helping incubate software product start-ups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is member of IFX forum,Oracle JCP and participant in Java Community Process. He founded Quantica Computacao, the first quantum computing startup in India. Markets and Markets have positioned Quantica Computacao in \u2018Emerging Companies\u2019 section of Quantum Computing quadrants. Bhagvan has engineered and developed simulators and tools in the area of quantum technology using IBM Q, Microsoft Q# and Google QScript. He has reviewed the Manning book titled : \\\"Machine Learning with TensorFlow\u201d. He is also the author of Packt Publishing book - \\\"Hands-On Data Structures and Algorithms with Go\\\".He is member of IFX forum,Oracle JCP and participant in Java Community Process. He is member of the MIT Technology Review Global Panel.\",\"sameAs\":[\"http:\/\/www.architectcorner.com\",\"https:\/\/www.facebook.com\/bhagvank\",\"https:\/\/in.linkedin.com\/pub\/bhagvan-kommadi\/0\/3a6\/b46\",\"https:\/\/x.com\/bhaggu\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/bhagvan-kommadi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Grails Spring Security Tutorial - Java Code Geeks","description":"Interested to learn more about Grails? Then check out our detailed example on Grails Spring Security!","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:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Grails Spring Security Tutorial - Java Code Geeks","og_description":"Interested to learn more about Grails? Then check out our detailed example on Grails Spring Security!","og_url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/bhagvank","article_published_time":"2019-07-18T08:00:16+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","type":"image\/jpeg"}],"author":"Bhagvan Kommadi","twitter_card":"summary_large_image","twitter_creator":"@bhaggu","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Bhagvan Kommadi","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/"},"author":{"name":"Bhagvan Kommadi","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/4575ae335b8ff016be62c3b927d5d5e6"},"headline":"Grails Spring Security Tutorial","datePublished":"2019-07-18T08:00:16+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/"},"wordCount":1458,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","keywords":["Spring Security"],"articleSection":["Grails"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/","name":"Grails Spring Security Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","datePublished":"2019-07-18T08:00:16+00:00","description":"Interested to learn more about Grails? Then check out our detailed example on Grails Spring Security!","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-spring-security-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JVM Languages","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/"},{"@type":"ListItem","position":3,"name":"Groovy","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/"},{"@type":"ListItem","position":4,"name":"Grails","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/grails\/"},{"@type":"ListItem","position":5,"name":"Grails Spring Security Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/4575ae335b8ff016be62c3b927d5d5e6","name":"Bhagvan Kommadi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/bhagvan.-kommadi-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/bhagvan.-kommadi-96x96.jpg","caption":"Bhagvan Kommadi"},"description":"Bhagvan Kommadi is the Founder of Architect Corner &amp; has around 20 years\u2019 experience in the industry, ranging from large scale enterprise development to helping incubate software product start-ups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is member of IFX forum,Oracle JCP and participant in Java Community Process. He founded Quantica Computacao, the first quantum computing startup in India. Markets and Markets have positioned Quantica Computacao in \u2018Emerging Companies\u2019 section of Quantum Computing quadrants. Bhagvan has engineered and developed simulators and tools in the area of quantum technology using IBM Q, Microsoft Q# and Google QScript. He has reviewed the Manning book titled : \"Machine Learning with TensorFlow\u201d. He is also the author of Packt Publishing book - \"Hands-On Data Structures and Algorithms with Go\".He is member of IFX forum,Oracle JCP and participant in Java Community Process. He is member of the MIT Technology Review Global Panel.","sameAs":["http:\/\/www.architectcorner.com","https:\/\/www.facebook.com\/bhagvank","https:\/\/in.linkedin.com\/pub\/bhagvan-kommadi\/0\/3a6\/b46","https:\/\/x.com\/bhaggu"],"url":"https:\/\/examples.javacodegeeks.com\/author\/bhagvan-kommadi\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=74737"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74737\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/27333"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=74737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=74737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=74737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}