Spring 安全 4 和 CDI
Spring Security 4 & CDI
我想在 CDI/EJB 环境中使用 SpringSecurity4。
这可能吗? Spring安全可以不使用Spring吗?
我想做的是 Spring安全与我的 EJB 和 CDI 组件。
Spring 安全基本上是一个过滤机,过滤所有传入的请求。但是,它的很多功能都是 Spring-core 依赖的。它 is possible 在 CDI 应用程序中利用 Spring,但 Spring 的核心是重量级的,与 CDI 相比它的功能很有趣。那将是降级,使用 CDI 没有意义。
你可以看看 JEE 世界的一些安全项目。
- Apache DeltaSpike 并且它是安全模块。
- Keycloak - The absolute solution. Keycloak goes far, far beyond Spring security's functionality. It is an evolution of old PicketLink libraries developed by JBoss, but those are discontinued and merged into Keycloak instead. An example how simple usage of Keycloak is can be found here.
使用@WebFilter 和@Inject 编写自己的安全拦截器也不难:),GitHub:
上有几个项目
我正在使用 CDI 的 Spring 安全性,但我可以说它不是很健康,因为 Spring 安全性基于 spring 并且 spring 与CDI 豆。
这是发生在我身上的事情。我自定义了 spring 安全性的 AuthenticationProvider,以便通过我的身份验证服务器对用户进行身份验证。在实现此机制时,我通过使用 (@Inject) 注释注入它们来使用预定义的 CDI bean。此时 spring 以某种方式拦截了注入并创建了它自己的 bean,这意味着您不能使用之前为 CDI bean 设置的任何值。
为了解决这个问题,我做了一些这样的技巧:
@Inject
private LoginController loginController;
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//Here, the injected bean is empty, I am requesting my old bean from CDI and assign it back.
LoginController bm = (LoginController) CDI.current().select(LoginController.class).get();
loginController = bm;
我不知道这是否是您正在寻找的答案,但我希望这对您有所帮助...
我想在 CDI/EJB 环境中使用 SpringSecurity4。 这可能吗? Spring安全可以不使用Spring吗?
我想做的是 Spring安全与我的 EJB 和 CDI 组件。
Spring 安全基本上是一个过滤机,过滤所有传入的请求。但是,它的很多功能都是 Spring-core 依赖的。它 is possible 在 CDI 应用程序中利用 Spring,但 Spring 的核心是重量级的,与 CDI 相比它的功能很有趣。那将是降级,使用 CDI 没有意义。
你可以看看 JEE 世界的一些安全项目。
- Apache DeltaSpike 并且它是安全模块。
- Keycloak - The absolute solution. Keycloak goes far, far beyond Spring security's functionality. It is an evolution of old PicketLink libraries developed by JBoss, but those are discontinued and merged into Keycloak instead. An example how simple usage of Keycloak is can be found here.
使用@WebFilter 和@Inject 编写自己的安全拦截器也不难:),GitHub:
上有几个项目我正在使用 CDI 的 Spring 安全性,但我可以说它不是很健康,因为 Spring 安全性基于 spring 并且 spring 与CDI 豆。
这是发生在我身上的事情。我自定义了 spring 安全性的 AuthenticationProvider,以便通过我的身份验证服务器对用户进行身份验证。在实现此机制时,我通过使用 (@Inject) 注释注入它们来使用预定义的 CDI bean。此时 spring 以某种方式拦截了注入并创建了它自己的 bean,这意味着您不能使用之前为 CDI bean 设置的任何值。
为了解决这个问题,我做了一些这样的技巧:
@Inject
private LoginController loginController;
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//Here, the injected bean is empty, I am requesting my old bean from CDI and assign it back.
LoginController bm = (LoginController) CDI.current().select(LoginController.class).get();
loginController = bm;
我不知道这是否是您正在寻找的答案,但我希望这对您有所帮助...