forked from benlucchesi/grails-cookie-session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCookieSessionGrailsPlugin.groovy
111 lines (91 loc) · 4.42 KB
/
CookieSessionGrailsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Ben Lucchesi
* ben@granicus.com or benlucchesi@gmail.com
*/
import org.springframework.web.filter.DelegatingFilterProxy
import grails.util.Environment
import com.granicus.grails.plugins.cookiesession.JavaSessionSerializer
import com.granicus.grails.plugins.cookiesession.KryoSessionSerializer
import com.granicus.grails.plugins.cookiesession.CookieSessionFilter
import com.granicus.grails.plugins.cookiesession.CookieSessionRepository
import com.granicus.grails.plugins.cookiesession.ExceptionCondenser
import com.granicus.grails.plugins.cookiesession.SecurityContextSessionPersistenceListener
import org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean
class CookieSessionGrailsPlugin {
def version = "2.0.13"
def grailsVersion = "1.2.4 > *"
def title = "Cookie Session Plugin" // Headline display name of the plugin
def author = "Ben Lucchesi"
def authorEmail = "benlucchesi@gmail.com"
def description = "The Cookie Session plugin enables grails applications to store session data in http cookies between requests instead of in memory on the server. This allows application deployments to be more stateless which supports simplified scaling architectures and fault tolerance."
def documentation = "http://github.com/benlucchesi/grails-cookie-session-v2"
def license = "APACHE"
// Online location of the plugin's browseable source code.
def scm = [url: 'http://github.com/benlucchesi/grails-cookie-session-v2']
//def loadAfter = ['controllers']
def getWebXmlFilterOrder() {
//[cookieSessionFilter: -100]
def filterManager = getClass().getClassLoader().loadClass('grails.plugin.webxml.FilterManager')
[cookieSessionFilter: filterManager.GRAILS_WEB_REQUEST_POSITION - 1]
}
def doWithWebDescriptor = { xml ->
if ( !application.config.grails.plugin.cookiesession.enabled ) {
return
}
// add the filter after the last context-param
def contextParam = xml.'context-param'
contextParam[contextParam.size() - 1] + {
'filter' {
'filter-name'('cookieSessionFilter')
'filter-class'(DelegatingFilterProxy.name)
}
}
// will be repositioned with getWebXmlFilterOrder()
def filter = xml.'filter'
filter[filter.size() - 1] + {
'filter-mapping' {
'filter-name'('cookieSessionFilter')
'url-pattern'('/*')
}
}
}
def doWithSpring = {
if ( !application.config.grails.plugin.cookiesession.enabled ) {
return
}
sessionRepository(CookieSessionRepository){
grailsApplication = ref("grailsApplication")
}
cookieSessionFilter(CookieSessionFilter) {
sessionRepository = ref("sessionRepository")
}
if( application.config.grails.plugin.cookiesession.containsKey("condenseexceptions") && application.config.grails.plugin.cookiesession["condenseexceptions"] == true )
exceptionCondenser(ExceptionCondenser)
// ALWAYS CONFIGURED!
javaSessionSerializer(JavaSessionSerializer){
grailsApplication = ref("grailsApplication")
}
if( application.config.grails.plugin.cookiesession.containsKey("serializer") && application.config.grails.plugin.cookiesession["serializer"] == "kryo" )
kryoSessionSerializer(KryoSessionSerializer){
grailsApplication = ref("grailsApplication")
}
if( application.config.grails.plugin.cookiesession.containsKey("springsecuritycompatibility") && application.config.grails.plugin.cookiesession["springsecuritycompatibility"] == true )
securityContextSessionPersistenceListener(SecurityContextSessionPersistenceListener){
grailsApplication = ref("grailsApplication")
}
}
}