-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSpringSecurityMockGrailsPlugin.groovy
124 lines (108 loc) · 4.63 KB
/
SpringSecurityMockGrailsPlugin.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
112
113
114
115
116
117
118
119
120
121
122
123
124
import edu.umn.auth.MockAuthenticationEntryPoint
import edu.umn.auth.MockAuthenticationProvider
import edu.umn.auth.MockAuthenticationFilter
import edu.umn.auth.MockUserDetailsService
import org.codehaus.groovy.grails.plugins.springsecurity.GormUserDetailsService
import org.codehaus.groovy.grails.plugins.springsecurity.SecurityFilterPosition
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
/*
* Grails Spring Security Mock Plugin - Fake Authentication for Spring Security
* Copyright (C) 2012 Aaron J. Zirbes
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class SpringSecurityMockGrailsPlugin {
// the plugin version
def version = "1.0.3"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.7 > *"
// the other plugins this plugin depends on
def dependsOn = [springSecurityCore: '1.2.7.3 > *']
// Make sure this loads AFTER the Spring Security LDAP plugin.
def loadAfter = ['springSecurityLdap']
// resources that are excluded from plugin packaging
def pluginExcludes = [
'grails-app/domain/**',
'docs/**',
'lib/**',
'src/docs/**',
'test/**' ]
def author = "Aaron J. Zirbes"
def authorEmail = "[email protected]"
def title = "Mock authentication support for Spring Security"
def description = "Mock authentication support for Spring Security"
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/spring-security-mock"
def license = "GPLv3"
def developers = [ [ name: "Aaron J. Zirbes", email: "[email protected]" ] ]
def issueManagement = [
system: "GitHub",
url: "https://github.com/aaronzirbes/grails-spring-security-mock/issues"
]
def scm = [ url: "https://github.com/aaronzirbes/grails-spring-security-mock" ]
def doWithSpring = {
// plug in mock artifacts in to spring security
def conf = SpringSecurityUtils.securityConfig
if (!conf || !conf.active) { return }
SpringSecurityUtils.loadSecondaryConfig 'DefaultMockSecurityConfig'
conf = SpringSecurityUtils.securityConfig
if (!conf.mock.active) { return }
println 'Configuring Spring Security Mock ...'
// mock authentication entry point
authenticationEntryPoint(MockAuthenticationEntryPoint) {
rejectIfNoRule = conf.rejectIfNoRule ?: false
}
// setup user details service
if (conf.userLookup.enabled) {
// if configured, load the user details from GORM objects
userDetailsService(GormUserDetailsService) {
grailsApplication = ref('grailsApplication')
}
} else {
// mock user details service
userDetailsService(MockUserDetailsService) {
// Load LDAP if configured
if (
conf.ldap.active &&
conf.ldap.authorities.retrieveGroupRoles &&
conf.ldap.usernameMapper.userDnBase
) {
userDnBase = conf.ldap.usernameMapper.userDnBase
ldapAuthoritiesPopulator = ref('ldapAuthoritiesPopulator')
}
// Load user attributes
fullName = conf.mock.fullName
email = conf.mock.email
mockRoles = conf.mock.roles
}
}
// mock authentication provider
mockAuthenticationProvider(MockAuthenticationProvider) {
userDetailsService = ref('userDetailsService')
}
// mock authentication filter
mockAuthenticationFilter(MockAuthenticationFilter) {
authenticationDetailsSource = ref('authenticationDetailsSource')
authenticationFailureHandler = ref('authenticationFailureHandler')
authenticationManager = ref('authenticationManager')
authenticationSuccessHandler = ref('authenticationSuccessHandler')
rememberMeServices = ref('rememberMeServices')
sessionAuthenticationStrategy = ref('sessionAuthenticationStrategy')
mockUsername = conf.mock.username
}
SpringSecurityUtils.registerProvider 'mockAuthenticationProvider'
SpringSecurityUtils.registerFilter 'mockAuthenticationFilter', SecurityFilterPosition.CAS_FILTER.getOrder() + 13
println '...finished configuring Spring Security Mock'
}
}