-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpringSecurityAuth0GrailsPlugin.groovy
87 lines (71 loc) · 2.83 KB
/
SpringSecurityAuth0GrailsPlugin.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
import grails.plugin.springsecurity.SecurityFilterPosition
import grails.plugin.springsecurity.SpringSecurityUtils
import org.apache.commons.codec.binary.Base64
import org.springframework.context.ApplicationContext
import org.springframework.util.Assert
import org.transmart.plugin.auth0.Auth0AuthenticationEntryPoint
import org.transmart.plugin.auth0.Auth0AuthenticationFilter
import org.transmart.plugin.auth0.Auth0AuthenticationProvider
import org.transmart.plugin.auth0.Auth0Config
import org.transmart.plugin.auth0.Auth0Service
class SpringSecurityAuth0GrailsPlugin {
String version = '18.1-SNAPSHOT'
String grailsVersion = '2.3 > *'
String title = 'Spring Security Auth0 Plugin'
String author = 'Burt Beckwith'
String authorEmail = '[email protected]'
String description = 'Auth0 security for Transmart.'
String documentation = 'TODO'
String license = 'APACHE'
def loadAfter = ['springSecurityCore']
def organization = [name: 'TODO', url: 'TODO']
def issueManagement = [url: 'TODO']
def scm = [url: 'TODO']
def doWithSpring = {
def conf = SpringSecurityUtils.securityConfig
if (!conf || !conf.active) {
return
}
SpringSecurityUtils.loadSecondaryConfig 'DefaultAuth0SecurityConfig'
// have to get again after overlaying DefaultAuth0SecurityConfig
conf = SpringSecurityUtils.securityConfig
if (!conf.auth0.active) {
return
}
boolean printStatusMessages = (conf.printStatusMessages instanceof Boolean) ? conf.printStatusMessages : true
if (printStatusMessages) {
println '\nConfiguring Transmart Spring Security Auth0 ...'
}
getRequiredConfigString conf, 'clientId'
getRequiredConfigString conf, 'domain'
String clientSecret = getRequiredConfigString(conf, 'clientSecret')
if (conf.auth0.base64EncodedSecret) {
clientSecret = new Base64(true).decodeBase64(clientSecret)
conf.auth0.clientSecret = clientSecret
}
auth0AuthenticationFilter(Auth0AuthenticationFilter) {
authenticationManager = ref('authenticationManager')
entryPoint = ref('auth0EntryPoint')
}
auth0AuthenticationProvider(Auth0AuthenticationProvider) {
authService = ref('authService')
}
auth0Config(Auth0Config)
auth0EntryPoint(Auth0AuthenticationEntryPoint)
SpringSecurityUtils.registerProvider 'auth0AuthenticationProvider'
SpringSecurityUtils.registerFilter 'auth0AuthenticationFilter',
SecurityFilterPosition.OPENID_FILTER
if (printStatusMessages) {
println '... finished configuring Transmart Spring Security Auth0\n'
}
}
def doWithApplicationContext = { ApplicationContext ctx ->
Auth0Service auth0Service = ctx.auth0Service
auth0Service.autoCreateAdmin()
}
private String getRequiredConfigString(ConfigObject conf, String propertyName) {
String value = conf.auth0[propertyName] ?: ''
Assert.hasText value, 'grails.plugin.springsecurity.auth0.' + propertyName + ' must be set'
value
}
}