Grails: Conditionally Load Spring Security LDAP Plugin - grails

I have an app that runs in multiple production environments. In one environment we want to authenticate with LDAP, in the other we do not. If the Spring Security LDAP plugin is included in BuildConfig.groovy, the non-LDAP environment fails to authenticate because LDAP is not configured.
I tried
environments {
devldap {
plugins {
compile ":spring-security-ldap:2.0-RC2"
}
}
}
but the LDAP plugin still builds with the non-LDAP environment and causes the non-LDAP environment (in this case development) to fail to authenticate if I don't include the LDAP configuration because it can't connect to LDAP.
I've tried
grails clean
grails refresh-dependencies
but the LDAP plugin only uninstalls if I completely comment it out.
How can I conditionally include/exclude a plugin in my build?

I see this question is a bit old now, however I do a similar thing with the Melody plugin. There is no value in this being installed during TEST - and can get in the way - so I do the following:
plugins {
// other plugins ...
if( Environment.current != Environment.TEST )
compile ":grails-melody:1.56.0"
// other plugins ...
}
So when I run 'test-app' I see the plugin 'uninstalled' and then when I do 'run-app' I see it installed and it's available.
NOTE: I recently got caught out by forgetting to also do an import grails.util.Environment. If you do that, you'll find that Environment.current == [:] as does Environment.TEST etc. I believe this is due to the builder behind the config file.

Related

"Another unnamed CacheManager already exists in the same VM"-error when deploying Grails 3.1.4 app to Elastic Beanstalk

Ever since about a week ago after doing a prod dbm-update I started getting this error when deploying the WAR-file to EB (run-app works fine both in dev and prod setting):
Caused by: org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following: 1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary 2. Shutdown the earlier cacheManager before creating new one with same name.
Grails 2.5.0 release notes suggested setting beans.cacheManager.shared to true. Didn't help.
Other people facing similar issues suggested replacing Hibernate cache factory_class from org.hibernate.cache.ehcache.EhCacheRegionFactory to org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory - this post. I think it eliminated the unnamed cacheManager issue, but created another one:
Caused by: java.io.FileNotFoundException: class path resource [db/changelog/db.changelog-master.yaml] cannot be resolved to URL because it does not exist
Setting "liquibase.checkChangeLogLocation = false" and "liquibase.enabled = false" triggers yet another:
Caused by: org.grails.core.exceptions.GrailsConfigurationException: Error configuring dynamic methods for plugin [springSecurityCore:3.0.4]: null
I'm using: Grails 3.1.4 with the AngularJS profile, Spring Security 3.0.4, Spring Security Rest 2.0.0.M2, Database Migration 2.0.0.RC4
I've also tried:
switching to Spring Security 3.0.2, 3.0.3
termimating the EC2 instance
re-building the entire EB environment and creating a new database
setting hibernate use_second_level_cache to false
downgrading to Grails 3.1.0
setting sourceSets { main { resources { srcDir 'grails-app/migrations'}}}
I'm running out of ideas and nothing has helped so far. Does anyone have an idea? Or is facing similar problems?
Did you recently upgrade to Hibernate 5.1.0.Final ? If so, then you might have the same issue as this one. No solution seems to have been found, but you might want to downgrade to Hibernate 5.0.9.Final to avoid this issue for now.
It turned out to be an issue with the Grails 3 AWS SDK plugin. I reverted all my changes and just replaced the plugin with the AWS SDK for Java through Gradle.
You can see from the plugin page that it supports Grails up to 3.1.1, but downgrading from 3.1.4 to 3.1.1 didn't make any difference either. But yes, using AWS SDK without the plugin worked. Woo!
I used Spring Security Core plugin v3.0.4 and got this error too on Grails v3.1.4. Upgrading the SSC pluign to v3.1.1. fixed the issue for me.

Grails 3 app is 404 in JBoss EAP 6

If I create a new web profile app, and generate-all, it runs fine in my local and deploys without error to JBoss. But when I try to access the app all URLs return 404. I know the app started up successfully, because it created tables in the database.
Here's what I'm doing.
grails 3.1.4> create-app demo
create-domain-class Book
create-domain-class Author
Edit domain classes
generate-all *
change tomcat dependency from compile to provided in build.gradle
change dataSource in application.yml to use my JNDI Oracle connection
Add server: contextPath: /demo to application.yml
run-app -> Works
gradle war
Deploy to JBoss EAP 6.4.0.GA
JBoss says deployment and activation of the app was successful. There are no errors of any sort in any JBoss log file. And dbCreate: update made the DDL changes to my Oracle database, so I know it got that far. But all URLs for the app return 404.
This is a known bug: Issue-9481
It has been added to grails 3.1.5 milestone.

Grails 2.5.0 endpoints located sans application context

I am upgrading an existing Grails 2.2.4 app to 2.5.0.
For some reason, endpoints whose URLs included the app context in 2.2.4 no longer include the app context in 2.5.0.
e.g., for app context = app, old endpoint in 2.2.4 was:
/app/a/b/c
but in 2.5.0 is now:
/a/b/c
I have tried many things to fix this, including:
in application.properties:
app.name=app
app.context=/app
in Config.groovy, for testing on localhost:8080:
grails.app.context = "/${appName}"
grails.serverURL = http://localhost:8080 and grails.serverURL = http://localhost:8080/${appName}, at different times
app.grails.serverURL = http://localhost:8080 and app.grails.serverURL = http://localhost:8080/${appName}, at different times
I've verified that "${appName}" == 'app'.
I have upgraded all of the plugins to the newest version, but I'm continuing to use the resources plugin instead of the asset-pipeline plugin.
I am not using scaffolding.
Any suggestions?
UrlMappings.groovy contained some mappings with (parseRequest:true), which is no longer supported by Grails. Removing that fixed it.

Grails mail delivery works fine locally but fails on live server (Jelastic) with same Config

I have a grails 2.2.1 app with mail plugin 1.0.1.
Mail delivery via Gmail smtp server works fine when I run the app locally (grails dev run-app), but fails on the production server (which is on the Jelastic cloud platform), which I deploy as a war file.
Config.groovy:
// Mail
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "aut********#gmail.com" // *** = just blacked out
password = "sun1******" // *** = just blacked out
props = ["mail.smtp.auth":"true",
"mail.smtp.starttls.required": "false",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
But I only have one mail plugin configuration, and therefore assume that the config applies for both development and production environment.
In fact, when I unzip the war file and check the class (in my case: Config$_run_closure2_closure8_closure13.class) via Decompiler, I can see the correct config values in there:
Enlarged: http://i.troll.ws/638ef33d.png
Error message:
Caused by: org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 d47sm23030880eem.9 - gsmtp
at grails.plugin.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:104)
at grails.plugin.mail.MailService.sendMail(MailService.groovy:41)
at MailGrailsPlugin$_configureSendMail_closure6.doCall(MailGrailsPlugin.groovy:170)
at com.oritrack.core.ApiController.register(ApiController.groovy:212)
... 5 more
Caused by: javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 d47sm23030880eem.9 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
at javax.mail.Service.connect(Service.java:291)
... 9 more
It is so weird that the authentication fails; so it's at least trying to connect to the right server; and the username/password in the Config.groovy is the only set of mail plugin config that I have in there. If it runs locally, it gotta run elsewhere.
When something works in development and not in production the usual culprit (from my experience) is dependencies. Check your WAR for multiple version of the same jar e.g. java-mail-1.0.jar and java-mail-1.2.jar. Don't limit your search to java-mail.jar, that was just an example.
If you find multiple versions of one jar, try removing one and deploying your war and if it works... huzzah!
To find what plugin is bringing in the jar use "grails dependency-report". Once you find out what is bringing in the jar you can remove it by doing something like this in BuildConfig.groovy using the excludes syntax.
dependencies {
compile("org.apache.shiro:shiro-quartz:1.1.0") {
excludes("quartz")
}
runtime('org.codehaus.groovy.modules.http-builder:http-builder:0.5.0') {
excludes 'xalan'
excludes 'xml-apis'
excludes 'groovy'
}
}
I have solved some very strange errors like this, one of them including http authentication that was failing due to multiple http-client jars.

Grails resources plugin and cloudfoundry

I tried to deploy my app to cloudfoundry, everything goes smooth however none of my static resources that use the resources plugin can be found.
In the logs i get lots of errors like the below
2012-01-31 13:36:41,352 [http-46220-3] WARN util.ResourceMetaStore -
Cannot locate resource [/static/css/jquery-ui-1.8.17.custom.css]
I first thought that this is due to cloudfoundry not having any disk space allocated but based on this thread it should work out of the box
http://grails.1312388.n4.nabble.com/Cloud-foundry-and-resources-plugin-with-js-css-td4243619.html
The test application i am running is running on one instance and i am using version 1.1.6 of the resources plugin.
Anybody else experiencing similar problems?
Make sure you are not missing the following line in your Config.groovy
grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']
I had the similar problem on heroku platform. It seems that problem is related with resources plugin and load balancing. My be the following will be useful:
Heroku, Grails: Missing resources if using multiple web dynos
Can you confirm 100% that this works in "production" environment locally?
I have a Grails 2.0 application on Cloud Foundry (http://tripplanner-ali.cloudfoundry.com/trip/create). It is using the resources plugin (1.1.5) along with cloud-support and cloud-foundry and jquery of course. I would suggest you to have your STS setup with Grails 2.0 if you haven't done so and try to create a sample application and deploy it to CF. Here is where you can get STS with Grails 2.0 working (http://static.springsource.org/sts/docs/2.7.0/reference/html/grails/grails20.html).
Once you have this setup, All you have to do is create a new Grails project and you will get the resources plugin along with jquery by default.

Resources