An update of the demo app from Greach 2015 (“hacking_madrid”) which was an update of the demo app from GGX 2011 (“hacking_london”). Updated to Grails 3 and spring-security-core 3.0.3
Adds an “organization” drop-down to the login page in addition to username and password, and a customized Authentication class, servlet filter, and AuthenticationProvider.
Items of note:
-
grails-app/views/login/auth.gspis the same asauth.gspfrom the core plugin, with the addition of a<g:select>to select the user’s Organization during login -
hacking.extralogin.OrganizationAuthenticationextendsUsernamePasswordAuthenticationTokento add aString organizationNameproperty -
hacking.extralogin.ui.OrganizationFilterextends the core plugin’sGrailsUsernamePasswordAuthenticationFilterand is registered as theauthenticationProcessingFilterbean to process form logins; it createsOrganizationAuthenticationinstances from POST parameters for authentication -
hacking.extralogin.auth.OrganizationAuthenticationProvideruses the data inOrganizationAuthenticationto authenticate-
It’s based on
DaoAuthenticationProviderbut directly accesses the database using GORM instead of delegating to aUserDetailsService
-
-
two new domain classes,
OrganizationandOrgUserare used to persist the user/organization relationship-
OrgUser is the many-to-many join class which uses two 1-to-many relationships instead of the traditional GORM
static hasManymapped collections
-
-
BootStrap.groovy creates test data:
-
two
Organizationinstances, “Org1” and “Org2” -
a user with
ROLE_ADMIN(“admin”/“password”) in “Org1” -
a user with
ROLE_USER(“user”/“password”) in “Org2” -
a user with
ROLE_USERandenabledset to false (“disabled”/“password”) in “Org1”
-
-
rather than copying and pasting the entire bean definitions into
resources.groovyto override the bean class for theauthenticationProcessingFilteranddaoAuthenticationProviderbeans,hacking.HackingBeanFactoryPostProcessoris registered inresources.groovyand updates the bean class in the bean definition. This approach retains all of the dependency injections and configuration updates and helps prevent the app from breaking if updated to a newer version of the plugin that has different dependencies and/or config options for the beans -
NoStackBadCredentialsExceptionis thrown as needed instead ofBadCredentialsException; it’s similar to the core plugin’sNoStackUsernameNotFoundExceptionwhich avoids filling in the stack trace to reduce creation cost -
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 -
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
-