hibernate - No session found for current thread in Custom AuthenticationProvider -
i'm new in grails , i'm trying make own authenticationprovider security core plugin, problem i'm getting follow error when try return token
could not obtain current hibernate session; nested exception org.hibernate.hibernateexception: no session found current thread
this authenticationprovider code:
@component public class mycustomauthenticationprovider implements authenticationprovider { @override public authentication authenticate(authentication authentication) throws authenticationexception { string name = authentication.getname(); string password = authentication.getcredentials().tostring() def user user user.withtransaction { status ->user = user.findbyusername(name); if(! user.springsecurityservice.ispasswordvalid(user.getpassword(),password,null)){ throw new badcredentialsexception("bad credentials"); } // here comes problem when try return new usernamepasswordauthenticationtoken(user, user.getpassword(), user.getauthorities1()) ; } } @override public boolean supports(class<?> authentication) { return authentication.equals(usernamepasswordauthenticationtoken.class); } } my bean declaration (in resources.groovy file) is:
beans = { mycustomauthenticationprovider (com.security.mycustomauthenticationprovider) { } }
pretty sure, user.getauthorities1() call being lazily loaded outside of session.
you need initialize before session closed. 1 solution replace user.findbyusername(name) call different method initializes property.
Comments
Post a Comment