A sample application showing how to use X.509 browser certificates to authenticate.
Items of note:
-
X.509 is enabled by adding
useX509 = trueinapplication.groovy -
two users (“dianne” and “scott”) are created in <code>BootStrap.groovy</code>, both with password "not_used" since it’s unused with certificate authentication
-
add the
dianne.p12and/orscott.p12certificate to your browser to authenticate as that person -
you must use SSL with X.509 authentication; I tested by building a WAR file and deploying it to Tomcat 8, and configuring
run-appsimilarly is left as an exercise for the reader-
To test, run
grails warand copy build/libs/x509-0.1.war to the Tomcat webapps folder, renaming the war to ROOT.war so it uses the default context -
be sure to access the application with SSL URLs, e.g. https://localhost:8443/secure/index
-
-
configure
server.jksas the keystore and truststore;server.xmlis an example Tomcat 8 config file that does this, expecting thatserver.jksis in theconfdirectory -
secured.SecureControllerhas two annotated actions;/securerequiresROLE_USER(orROLE_ADMINsince hierarchical roles are configured) and/secure/adminrequiresROLE_ADMIN -
debug/trace logging for the plugin and Spring Security is configured but commented out in
logback.groovy -
the application is intentionally stripped-down:
-
there are no static resources
-
the GSPs are very minimal
-
all unused attributes were removed from the
grails.plugin.springsecurityblock inapplication.groovy
-
-
as in all of the demo apps,
main.gspwas renamed toapplication.gspsince that’s the default name if none is specified, and the<meta>tag specifying the layout was removed from the GSPs-
note that this requires configuring the
grails.plugin.springsecurity.gsp.layoutAuthandgrails.plugin.springsecurity.gsp.layoutDeniedproperties inapplication.groovy
-