使用事务包装Spring Security自定义身份验证提供程序

lim*_*imc 5 java spring hibernate spring-security

在我的自定义身份验证提供程序中,我能够通过我的Service API获取域对象,但是当我从一个域对象爬到另一个域对象以获得某些值来执行其他检查时,Spring抱怨Hibernate会话不存在: -

domain.getAnotherDomain().getProperty(); // epic FAIL
Run Code Online (Sandbox Code Playgroud)

我有以下AOP事务用事务包装我的所有项目API,我很确定我的自定义身份验证提供程序属于以下模式: -

<tx:advice id="txAdvice">
    <tx:attributes>
        <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:advisor pointcut="execution(* my.project..*.*(..))" advice-ref="txAdvice" />
</aop:config>
Run Code Online (Sandbox Code Playgroud)

我也配置了OpenSessionInView过滤器,但我认为无论如何都不适用于Spring Security.

我想我可以创建一个特定的服务API来执行所有必需的检查,但我很好奇为什么我无法使用正确的事务包装我的自定义身份验证提供程序.

任何解释?谢谢.

lim*_*imc 3

我的解决方案是创建一个服务 API 来执行检查,以避免自定义身份验证提供程序中出现延迟加载错误。