我正在使用grails app,作为管理员,我可以将订阅者添加到我的应用程序。当我尝试通过subscriber / create添加新订阅者时,邮件将转到提供的电子邮件ID,然后订阅者必须单击提供的链接在电子邮件中但是当用户填写所有信息并点击时,我会收到以下错误。
Cannot cast object 'chand' with class 'java.lang.String' to class 'com.vproc.member.MyUserDetails'. Stacktrace follows:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'chand' with class 'java.lang.String' to class 'com.vproc.member.MyUserDetails'
从 SubscriberService.groovy
获取以下方法中的错误def Subscriber getLoggedinSubscriber(){
if (springSecurityService.principal != null ){
//Getting error in below line.
MyUserDetails userDetails = (MyUserDetails)springSecurityService.principal
Subscriber subscriber = userDetails.currentSubscriber ;
//subscriber.customer.party
return subscriber
}else {
return null;
}
}
MyUserDetailsService.groovy
package com.vrpoc.service.member
import grails.plugin.springsecurity.SpringSecurityUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;
import com.vproc.member.Customer;
import com.vproc.member.MyUserDetails;
import com.vproc.member.Organization;
import com.vproc.member.Person;
import com.vproc.member.Subscriber;
import com.vproc.member.SubscriberRole;
@Transactional
class MyUserDetailsService implements UserDetailsService{
def springSecurityServivce
static final List NO_ROLES = [new GrantedAuthorityImpl(SpringSecurityUtils.NO_ROLE)]
UserDetails loadUserByUsername(String username, boolean loadRoles) throws UsernameNotFoundException {
return loadUserByUsername(username)
}
UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Subscriber.withTransaction {
status ->
Person user = Person.findByUsername(username)
if (!user)
throw new UsernameNotFoundException( 'User not found', username)
def session = RequestContextHolder.currentRequestAttributes().session
def params = RequestContextHolder.currentRequestAttributes().params
def newOrgId = params["orgId"]
List<Subscriber> subscribers = []
List<Organization> orgs = []
def currentSubscriber = null
if ( session["orgs"] == null && newOrgId == null){
subscribers = Subscriber.findAllByParty( user) // get all subscribers for this person
subscribers.each { orgs.add(it.customer.party ) } // get all customer and then orgs for subscribers
session["orgs"] = orgs // add orgs to session
session["currentOrg"] = orgs.get(0);
currentSubscriber = subscribers.get(0)
currentSubscriber.contacts.size()
}else if ( newOrgId){
def currentOrgId = newOrgId
Organization organization = Organization.get(currentOrgId)
session["currentOrg"] = organization;
Customer customer = Customer.findByParty( organization)
currentSubscriber = Subscriber.findByCustomerAndParty( customer, user)
}
println currentSubscriber.customer.party.orgName
/*
def newContextOrgId = session["currentOrgId"]
def currentSubscriber = session["currentSubscriber"]
if ( newContextOrgId == null ){
def customer = Customer.findByParty( Organization.get(newContextOrgId))
def person = Person.get(springSecurityServivce.principal.id );
subscriber = Subscriber.findByPartyAndCustomer( person, customer)
session["currentSubscriber"] = subscriber
} */
def authorities = SubscriberRole.findAllBySubscriber(currentSubscriber).collect {
new GrantedAuthorityImpl(it.role.authority)
} as Set
return new MyUserDetails(user.username, user.password, user.enabled, !user.accountExpired, !user.passwordExpired, !user.accountLocked,
authorities ?: NO_ROLES, user.id, user.firstName , user.lastName, currentSubscriber )
}
}
}
不是:不知道为什么会这样。请告诉我您需要在此处显示更多代码。