当我使用带有MongoDB数据库的grails spring security facebook插件时,它会继续在these section上抛出OptimisticLockingException。
然后我用这样的FacebookAuthService覆盖它。
class FacebookAuthService {
def create(FacebookAuthToken token) {
FacebookUser fbUser = new FacebookUser(uid: token.uid)
fbUser.accessToken = token.accessToken?.accessToken
fbUser.accessTokenExpires = token.accessToken?.expireAt
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
FacebookProfile fbProfile = facebook.userOperations().userProfile
User user = User.findByUsernameOrFacebookId(fbProfile.email,fbProfile.id)
if(!user){
user = new User()
user.facebookId = fbProfile.id
user.firstname = fbProfile.firstName.toLS()
user.lastname = fbProfile.lastName.toLS()
user.gender = Gender.strToEnum(fbProfile.gender)
user.acceptTerms = true
user.acceptTermsDate = new Date()
user.accountExpired = false
user.passwordExpired = false
user.accountLocked = false
user.enabled = true
user.username = "facebook_$token.uid"
user.password = token.accessToken.accessToken
}else{
user.facebookId = fbProfile.id
}
user.save(flush: true, failOnError: true)
fbUser.user = user
Role role = Role.findByAuthority('ROLE_USER')
if (role && !user.authorities.contains(role)) {
UserRole.create(user, role)
}
fbUser.save(flush: true, failOnError: true)
return fbUser
}
def getAppUser(FacebookUser facebookUser){
return facebookUser?.user
}
Collection<GrantedAuthority> getRoles(User user){
return UserRole.findAllByUser(user)?.role?.collect{ role ->
new GrantedAuthorityImpl(role.authority)
}
}
}
但现在它会在120000 ms后抛出连接等待超时。 Stacktrace如下: 消息:120000 ms后连接等待超时
我知道GPMONGODB驱动程序有bug。并按照那里描述的那样修复它。
请帮我修理
编辑: 我发现了原因 com.the6hours.grails.springsecurity.facebook.FacebookAuthProvider类的authenticate方法不断调用每个请求。那么这个循环可能是什么原因呢?