-
Notifications
You must be signed in to change notification settings - Fork 2
/
FreshSecurityGrailsPlugin.groovy
173 lines (141 loc) · 7.66 KB
/
FreshSecurityGrailsPlugin.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import grails.plugins.springsecurity.SecurityConfigType
import java.util.regex.Pattern
import groovy.util.ConfigObject
import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import com.grailsrocks.webprofile.security.*
class FreshSecurityGrailsPlugin {
// the plugin version
def version = "1.0.2-RC1"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.7 > *"
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/domain/test/**/*.*",
"grails-app/views/error.gsp",
"grails-app/views/index.gsp",
"grails-app/conf/PluginConfig.groovy"
]
def loadAfter = ['springSecurityCore', 'emailConfirmation', 'platformCore'] // We must apply our beans AFTER spring-sec declares its own
def title = "Fresh Security Plugin" // Headline display name of the plugin
def author = "Marc Palmer"
def authorEmail = "[email protected]"
def description = '''\
Security that "just works", backed by Spring Security
'''
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/fresh-security"
// Extra (optional) plugin metadata
// License: one of 'APACHE', 'GPL2', 'GPL3'
def license = "APACHE"
// Details of company behind the plugin (if there is one)
def organization = [ name: "Grails Rocks", url: "http://grailsrocks.com/" ]
// Any additional developers beyond the author specified above.
def developers = [ [ name: "Marc Palmer", email: "[email protected]" ]]
// Location of the plugin's issue tracker.
def issueManagement = [ system: "JIRA", url: "http://jira.grails.org/browse/GPFRESHSECURITY" ]
// Online location of the plugin's browseable source code.
def scm = [ url: "http://github.com/grailsrocks/grails-fresh-security" ]
def doWithWebDescriptor = { xml ->
}
def doWithSpring = {
userDetailsService(com.grailsrocks.webprofile.security.FreshSecurityUserDetailsService) {
grailsApplication = ref('grailsApplication')
}
grailsSecurityBridge(com.grailsrocks.webprofile.security.FreshSecurityProvider) {
springSecurityService = ref('springSecurityService')
grailsApplication = ref('grailsApplication')
freshSecurityService = ref('freshSecurityService')
}
}
def doWithDynamicMethods = { ctx ->
}
def doWithConfigOptions = {
'guest.roles'(type:List, defaultValue:['ROLE_GUEST'], validator: { v ->
(v == null) ? 'A role list is required' : null
})
'default.roles'(type:List, defaultValue:['ROLE_USER'], validator: { v ->
(v == null) ? 'A role list is required' : null
})
'signup.allowed'(defaultValue:true)
'signup.command.class.for.identity.mode.userid'(type:String, defaultValue:'com.grailsrocks.webprofile.security.forms.SignupWithUserIdFormCommand',
validator: { v -> v ? null : 'A value is required'})
'signup.command.class.for.identity.mode.email'(type:String, defaultValue:'com.grailsrocks.webprofile.security.forms.SignupWithEmailFormCommand',
validator: { v -> v ? null : 'A value is required'})
'remember.me.allowed'(defaultValue:true, type:Boolean)
'confirm.email.on.signup'(defaultValue:false, type:Boolean, validator: { v ->
if (v) {
def hasEmailConf = PluginManagerHolder.pluginManager.hasGrailsPlugin('email-confirmation')
return hasEmailConf ? null : 'Email-Confirmation plugin must be installed for confirmations to be enabled'
} else {
return null
}
})
'identity.mode'(defaultValue:'userid', type:String, validator: { v -> v in ['email', 'userid'] ? null : 'Must be [email] or [userid]'} )
'password.reset.mode'(defaultValue:'setnew', type:String, validator: { v -> v in ['setnew', 'generate'] ? null : 'Must be [setnew] or [generate]'})
'account.locked.until.email.confirm'(defaultValue:false, type:Boolean)
'post.login.url'(defaultValue:[uri:'/'], type:Map)
'post.signup.url'(defaultValue:[uri:'/'], type:Map)
'bad.confirmation.url'(defaultValue:[uri:'/bad-confirmation'], type:Map)
'user.object.class.name'(defaultValue:'', type:String)
'allow.confirm.bypass'(defaultValue:false, type:Boolean)
'confirm.bypass.pattern'(defaultValue:null, type:Pattern)
}
def doWithConfig = { config ->
application {
// Get our config values and use them to apply to Spring security's config by
// modifying global config
// This needs to be set as the default, but user can override using sconfig
grails.plugins.springsecurity.interceptUrlMap = [
'/admin/**': ['ROLE_ADMIN'],
'/static/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/js/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/css/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/images/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/auth/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/index': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/**': ['IS_AUTHENTICATED_ANONYMOUSLY']
]
grails.plugins.springsecurity.securityConfigType = SecurityConfigType.InterceptUrlMap
grails.plugins.springsecurity.userLookup.userDomainClassName = 'com.grailsrocks.webprofile.security.SecUser'
grails.plugins.springsecurity.userLookup.usernamePropertyName = 'identity'
// @todo these have been hardcoded to "auth", need to pull that from config
grails.plugins.springsecurity.failureHandler.defaultFailureUrl = '/auth/loginFail'
//grails.plugins.springsecurity.adh.errorPage = null
//grails.plugins.springsecurity.failureHandler.useForward = true // force render of 403 response, not redirect to errorPage
//grails.plugins.springsecurity.adh.errorPage = '/auth/denied'
grails.plugins.springsecurity.auth.loginFormUrl = '/auth'
grails.plugins.springsecurity.apf.usernameParameter = "identity"
grails.plugins.springsecurity.apf.passwordParameter = "password"
grails.plugins.springsecurity.rememberMe.parameter = "rememberMe"
// Lock down everything
grails.plugins.springsecurity.rejectIfNoRule = true
if (config.grails.validateable.packages instanceof List) {
config.grails.validateable.packages <<= 'com.grailsrocks.webprofile.security.forms'
} else {
config.grails.validateable.packages = ['com.grailsrocks.webprofile.security.forms']
}
}
// Configure ourselves based on other app config settings
freshSecurity {
// Force confirm email to true if using email as id
if (config.plugin.freshSecurity.identity.mode == 'email') {
account.locked.until.email.confirm = true
confirm.email.on.signup = true
}
if (config.plugin.freshSecurity.account.locked.until.email.confirm) {
confirm.email.on.signup = true
}
}
}
def doWithApplicationContext = { applicationContext ->
}
def onChange = { event ->
}
def onConfigChange = { event ->
// TODO Implement code that is executed when the project configuration changes.
// The event is the same as for 'onChange'.
}
def onShutdown = { event ->
// TODO Implement code that is executed when the application shuts down (optional)
}
}