我在我的 grails 应用程序中使用 Spring Security Facebook 插件。它在身份验证后从 Facebook 页面返回时显示以下错误消息。facebook 用户详细信息未保存在数据库中。请帮助解决此错误并成功验证 Facebook 用户。提前致谢。
FacebookUser.groovy 域类
class FacebookUser {
long uid
String accessToken
Date accessTokenExpires
static belongsTo = [user: User]
static constraints = {
uid unique: true
}
}
spring-security-facebook 应用程序的 Config.groovy 设置
grails.plugins.springsecurity.facebook.domain.classname='com.awnsys.gcx.FacebookUser'
grails.plugins.springsecurity.facebook.domain.appUserConnectionPropertyName = 'user'
grails.plugins.springsecurity.facebook.appId='APPID'
grails.plugins.springsecurity.facebook.secret='secretID'
grails.plugins.springsecurity.facebook.autoCreate.enabled=true
grails.plugins.springsecurity.facebook.autoCreate.roles=['ROLE_USER', 'ROLE_FACEBOOK',]
以下是用户在 facebook 中接受应用程序后从 facebook 重定向时在浏览器中显示的错误消息
Error 500: Internal Server Error
URI : /myapp/j_spring_security_facebook_check
Class : grails.validation.ValidationException
Message : Validation Error(s) occurred during save(): - Field error in object 'com.mydomain.myapp.User' on field 'username': rejected value [facebook_100005487962357]; codes [com.mydomain.myapp.User.username.email.error.com.mydomain.myapp.User.username,com.mydomain.myapp.User.username.email.error.username,com.mydomain.myapp.User.username.email.error.java.lang.String,com.mydomain.myapp.User.username.email.error,user.username.email.error.com.mydomain.myapp.User.username,user.username.email.error.username,user.username.email.error.java.lang.String,user.username.email.error,com.mydomain.myapp.User.username.email.invalid.com.mydomain.myapp.User.username,com.mydomain.myapp.User.username.email.invalid.username,com.mydomain.myapp.User.username.email.invalid.java.lang.String,com.mydomain.myapp.User.username.email.invalid,user.username.email.invalid.com.mydomain.myapp.User.username,user.username.email.invalid.username,user.username.email.invalid.java.lang.String,user.username.email.invalid,email.invalid.com.mydomain.myapp.User.username,email.invalid.username,email.invalid.java.lang.String,email.invalid]; arguments [username,class com.mydomain.myapp.User,facebook_100005487962357]; default message [Property [{0}] of class [{1}] with value [{2}] is not a valid e-mail address]
DefaultFacebookAuthDao.groovy 的第 149 行左右
146: appUser.setProperty(securityConf.userLookup.passwordExpiredPropertyName, false)
147: }
148: AppUserDomainClazz.withTransaction {
149: appUser.save(flush: true, failOnError: true)
150: }
151: }
152: user[appUserConnectionPropertyName] = appUser
DefaultFacebookAuthDao.groovy 的第 148 行左右
145: appUser.setProperty(securityConf.userLookup.accountLockedPropertyName, false)
146: appUser.setProperty(securityConf.userLookup.passwordExpiredPropertyName, false)
147: }
148: AppUserDomainClazz.withTransaction {
149: appUser.save(flush: true, failOnError: true)
150: }
151: }
FacebookAuthProvider.groovy 的第 67 行左右
64: log.error("Can't create user w/o access_token")
65: throw new CredentialsExpiredException("Can't receive access_token from Facebook")
66: }
67: user = facebookAuthDao.create(token)
68: justCreated = true
69: } else {
70: log.error "User $token.uid doesn't exist, and creation of a new user is disabled."
FacebookAuthProvider.groovy 的第 67 行左右
64: log.error("Can't create user w/o access_token")
65: throw new CredentialsExpiredException("Can't receive access_token from Facebook")
66: }
67: user = facebookAuthDao.create(token)
68: justCreated = true69: } else {
70: log.error "User $token.uid doesn't exist, and creation of a new user is disabled."
痕迹
Line | Method
->> 149 | doCall in DefaultFacebookAuthDao.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 687 | withTransaction in org.grails.datastore.gorm.GormStaticApi
| 148 | create . . . . . . . in DefaultFacebookAuthDao.groovy
| 67 | authenticate in FacebookAuthProvider.groovy
| 40 | attemptAuthentication in FacebookAuthRedirectFilter.groovy
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run in java.lang.Thread