custom registrationCode domain class Spring Security UI Plugin - grails

Holla
i want to customize RegistrationCode domain class without changing the ui plugin but i don't find it in s2ui override.
For precision it to include multi tenant for registrated user by tenant

You do this the same way as you would for any artifact in a plugin - create your application class with the same name and package under grails-app and yours will override the one from the plugin.
This works because Grails orders the sources for the classloader(s) with the application's classes before the plugins' classes, so if a class is found from the application it will be loaded and the plugin's corresponding class will be ignored.

Related

Add behavior (relationships) to grails plugin domain classes from main application?

I have a Grails plugin I've created which is intended to support a number of applications. This plugin has an Employee domain object. The problem is that, when used in the main application, domain objects from that application need to refer back to the Employee object. So, my main application might have an Address which belongsTo the Employee class from the plugin.
How can one handle this properly in Grails 2.5.0?
Thanks in advance.
It looks like that your main and plugin depend on each other. In this case you should add the plugin location of one to another:
grails.plugin.location.<PLUGIN-NAME> = "<PATH TO YOUR PLUGIN>" Ex: "../myPlugin" assuming it is located on the same folder structure as the plugin
and in your plugin
grails.plugin.location.<APP-NAME>= "<PATH TO YOUR APP>" EX: "../myApp"

Modify Grail plugin Domain Class data-source in dependent application

I have multiple plugins with Grails domain classes that are stored in separate databases. I want to be able to configure within the dependent project what sources each class comes from. It seems like a similar question is here:
Grails changing datasource at runtime
Is it still not possible to add additionaly sources to a class at runtime? And, I don't necessarily need to do it at runtime either. Just configure the class in the dependent Grails application. The method for setting this up (http://www.grails.org/doc/2.2.1/guide/conf.html#multipleDatasources) requires direct access to the class definitions, and I'd rather avoid having to do that.

Grails Plugin Development - override domain class

Plugins in Grails are great method to modularise an application.The documentation suggest to override the artifacts from the plugin in the application, which uses this plugin.
Is it realy the best approach?
Let's describe it by example: There is a domain class "org.User" defined in the plugin. The application overrides this domain class. If I use "grails run-app" then there are no warnings and it works. But Eclipse (GGTS) complains about "Invalid duplicate class definition of class org.User". For some developers it wouldn't matter, but I like the IDE helping on coding by stuf like "autocomplete".
At the end both classes are compiled an put on the java class loader. The application version of the class is loaded before the version of the plugin. The class resolver finds it first and that's why it works. Please correct me if I'm wrong at this point. Is it realy a good idea to have two versions of a class in one class loader?
What are the alternatives?
You can do like Spring Security Core plugin does, provide the User class as a template, so your application that use this plugin can choose between creating his own class or installing your default User class.
The plugin user template is here, and the script responsible to create this in the application is here.
You will need also a config value to know the class to use, and use it dynamic.
P.S: there are good security plugins like Shiro and Spring Security, maybe it's easier to check them instead of create your own.

grails mybatis-plugin validation location

I cite from mybatis plugin documentation:
"When working with MyBatis plugin your "Domain" classes should be
located in src/groovy and not in grails-app/domain. This is necessary
to avoid conflict with GROM since MyBatis plugin can coexist with
existing GORM Domain classes."
So where should the validation and constraints be located, when I want to use grails with MyBatis plugin ?
You can add a #Validateable annotation to any Groovy class in Grails, and you will be able to validate it... The Plugin currently doesn't check for any validation errors so you will have to implement that code yourself.
From official Grails documentation:
Classes which define the static constraints property and are annotated
with #Validateable can be made validateable by the framework
http://grails.org/doc/2.1.0/guide/validation.html#validationNonDomainAndCommandObjectClasses
You could even write a custom MyBatis Interceptor (see https://github.com/fzilic/Grails-MyBatis/blob/master/src/groovy/org/grails/plugins/mybatis/locking/OptimisticLockingInterceptor.groovy) and register it after the SqlSession is created...
Currently the MyBatis plugin doesn't support registering custom Interceptors in it's configuration, but they could be added to the interceptor chain
def factory = GrailsApplication.mainContext.getBean("sqlSessionFactoryBean_dataSource")
factory.configuration.interceptorChain.addInterceptor(Interceptor)
Support for this might be added in future versions.

Grails Plugin overrides controller and views

I have a modular application where in one module I have spring security ui(s2-ui) setup, with some controllers and views overridden.
In the other module I'm having troubles because grails is not using the spring security ui(s2-ui) configured in the first module but rather a fresh s2-ui installed as a result of the dependency of the first module on s2-ui.
For example, I've customized the register controller and views but this is not being reflected in the 2nd module.
FYI I've set the loadsAfter property to tell my plugin to load after the s2-ui plugin.
If the overridden views and controllers are local to the first plugin, then you need to copy them to the second plugin as well. The second plugin is inheriting the base plugin files from your home folder.

Resources