-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAafApplicationBaseGrailsPlugin.groovy
More file actions
86 lines (66 loc) · 2.02 KB
/
AafApplicationBaseGrailsPlugin.groovy
File metadata and controls
86 lines (66 loc) · 2.02 KB
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
import org.codehaus.groovy.grails.commons.GrailsApplication
import org.apache.shiro.SecurityUtils
import aaf.base.identity.Subject
import aaf.base.SMSDeliveryService
class AafApplicationBaseGrailsPlugin {
def version = "0.15.0"
def grailsVersion = "2.5 > *"
def dependsOn = [:]
def pluginExcludes = [
"grails-app/views/error.gsp"
]
def title = "AAF Application Base"
def author = "Bradley Beddoes"
def authorEmail = "bradleybeddoes@aaf.edu.au"
def description = '''\
Base environment for all AAF applications to build from
'''
def documentation = "http://www.aaf.edu.au"
def watchedResources = ["file:./grails-app/**/services/*Service.groovy", "file:./grails-app/controllers/**/*Controller.groovy"]
def doWithWebDescriptor = { xml ->
}
def doWithSpring = {
smsDeliveryService(SMSDeliveryService) {
it.autowire = 'byName'
}
}
def doWithDynamicMethods = { ctx ->
// Supply authenticated subject to filters
application.filtersClasses.each { filter ->
// Should be used after verified call to 'accessControl'
injectAuthn(filter.clazz)
}
// Supply authenticated subject to controllers
application.controllerClasses?.each { controller ->
injectAuthn(controller.clazz)
}
// Supply authenticated subject to services
application.serviceClasses?.each { service ->
injectAuthn(service.clazz)
}
}
def doWithApplicationContext = { applicationContext ->
}
def onChange = { event ->
injectAuthn(event.source)
}
def onConfigChange = { event ->
}
def onShutdown = { event ->
}
// Inject the authenticated Subject object
private void injectAuthn(def clazz) {
clazz.metaClass.getPrincipal = {
def subject = SecurityUtils.getSubject()
}
clazz.metaClass.getSubject = {
def subject = null
def principal = SecurityUtils.subject?.principal
if(principal) {
subject = aaf.base.identity.Subject.get(principal)
log.debug "returning $subject"
}
subject
}
}
}