我对Grails 2.4.3和Spring Security RC2的升级感到有些麻烦......我可能只是遗漏了一些东西,但感激不尽。
我在这里覆盖了RegisterController:
def register(RegisterCommand command) {
if (command.hasErrors()) {
render view: 'index', model: [command: command]
return
}
String salt = saltSource instanceof NullSaltSource ? null : command.username
//def info = Info.findByName(command.info.toString().replace("[", "").replace("]", ""))
def info = Info.findByName(params.info).toString().replace("[", "").replace("]", "")
def user = lookupUserClass().newInstance(email: command.email, username: command.username,
accountLocked: true, enabled: true, info: info, location: params.location)
RegistrationCode registrationCode = springSecurityUiService.register(user, command.password, salt)
if (registrationCode == null || registrationCode.hasErrors()) {
// null means problem creating the user
flash.error = message(code: 'spring.security.ui.register.miscError')
flash.chainedParams = params
redirect action: 'index'
return
}
String url = generateLink('verifyRegistration', [t: registrationCode.token])
def conf = SpringSecurityUtils.securityConfig
def body = conf.ui.register.emailBody
if (body.contains('$')) {
body = evaluate(body, [user: user, url: url])
}
mailService.sendMail {
to command.email
from conf.ui.register.emailFrom
subject conf.ui.register.emailSubject
html body.toString()
}
render view: 'index', model: [emailSent: true]
}
class RegisterCommand {
String username
String email
String password
String password2
List info = Info.findAll("from Info as d where d.name!=?", ['Super Admin']).toList()
def grailsApplication
static constraints = {
username blank: false, validator: { value, command ->
if (value) {
def User = command.grailsApplication.getDomainClass(
SpringSecurityUtils.securityConfig.userLookup.userDomainClassName).clazz
if (User.findByUsername(value)) {
return 'registerCommand.username.unique'
}
}
}
email blank: false
password blank: false, nullable: false
password2 validator: RegisterController.password2Validator
}
}
以下是我的GSP代码片段
<div class="control-group">
<label class="control-label" for="selectDepartment">Info</label>
<div class="controls form-field-pad">
<g:select name="info" from="${command.info.name.unique()}" labelCode='Info'
labelCodeDefault='Info' value="${info}" noSelection="['':'-Choose your Info-']" data-trigger="change" data-required="true" data-required-message="You must select Info"/>
</div>
</div>
现在,如果我使用对Info的引用删除我的附加代码,那么用户将被正确存储并发送电子邮件...但是我收到以下错误:
register.index: [action:index, controller:register]
| Error 2014-09-18 10:47:57,728 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver - GroovyCastException occurred when processing request: [GET] /my_app/register/index
Cannot cast object 'info' with class 'java.lang.String' to class 'java.util.List'. Stacktrace follows:
Message: Cannot cast object 'info' with class 'java.lang.String' to class 'java.util.List'
Line | Method
->> 27 | index in com.my_app.RegisterController$$EOqD2RUm
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 200 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 49 | doFilter in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
| 82 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
有什么想法吗?提前谢谢!