简体   繁体   English

JAAS如何加载实现LoginModule的类?

[英]How does JAAS load a class implementing LoginModule?

Is this done via Reflection, or ServiceLoader? 这是通过反射或ServiceLoader完成的吗? I am asking, because I have a custom LoginModule which is supposed to use Spring, but despite having @Autowired , the respective bean is not getting populated properly (with the bean defined in the context, which is clearly on the classpath). 我问,因为我有一个应该使用Spring的自定义LoginModule,但是尽管具有@Autowired ,但相应的bean却没有正确填充(使用在上下文中定义的bean,它显然在类路径中)。 This leads me to think that the LoginModule implementing class is being loaded using reflection and thus circumventing Spring completely. 这使我认为LoginModule实现类是使用反射加载的,从而完全规避了Spring。 Is this the case? 是这样吗 Can I still somehow use Spring, if so? 如果可以,我还能以某种方式使用Spring吗?

To answer my own question: yes, this is done using reflection, which effectively goes around Spring and gives you an instantiated object that doesn't have anything @Autowired . 要回答我自己的问题:是的,这是使用反射完成的,它有效地绕过Spring,并为您提供了一个实例化的对象,该对象没有任何@Autowired

However, you could manually initialize your beans in your LoginModule 's initialize() method. 但是,您可以在LoginModuleinitialize()方法中手动初始化bean。 The LoginModule class should implement org.springframework.context.ApplicationContextAware and you must have a private static ApplicationContext context . LoginModule类应实现org.springframework.context.ApplicationContextAware并且您必须具有private static ApplicationContext context This way the context is injected for you and you can load the beans from there on. 这样,为您注入了context ,您可以从那里加载bean。

Far from optimal, but it seems to be doing the trick. 远非最佳,但似乎可以解决问题。 If anybody has a better solution, please share it, as I would be happy to hear it! 如果有人有更好的解决方案,请分享,因为我很高兴听到!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM