使用Session对象在2个webapps之间共享身份验证信息?

时间:2017-06-17 17:18:30

标签: spring spring-security jaas

这是我在SO上制作的earlier post的后续内容,希望在2个EAR之间共享会话信息。相反,我重建了我的EAR,在Wildfly 10上的同一个EAR中运行了两个webapp。我已经启用了两个webapps之间的会话共享,并且可以确认它确实是正在使用的相同会话对象。

我的问题是webapp1是一个使用JAAS进行身份验证的旧版JEE应用程序,而webapp2是一个新的Spring Boot / Spring Security应用程序。

我的用例是我需要通过Webapp1进行身份验证/授权,并让webapp2识别该身份验证。 webapp2中没有身份验证 - 一切都必须通过webapp1发生。

现在,我可以想象这样做的唯一方法是在我的Spring应用程序中创建一个自定义过滤器:

if( SecurityContextHolder.getContext().getAuthentication() == null && request.getUserPrincipal() != null ){
    // some mechanism to retrieve the authentication info and set it in the Spring context
    SecurityContextHolder.getContext().setAuthentication( new PreAuthenticatedAuthenticationToken( username, etc) )
 }
 else{
    // if no request.getUserPrincipal() object, then redirect to webapp1 login page
 }

我不确定我需要为身份验证对象使用什么机制;我怀疑我需要查询我的数据库,以根据getUserPrincipal()对象中的用户名检索用户的角色,并将它们添加到 PreAuthenticatedAuthenticationToken()或类似的东西。

有没有更清洁的机制呢?有没有办法可以使用JassAuthenticationToken从已经由Webapp1实例化的现有LoginContext中检索信息?

通过安全过滤器这样做吗?

0 个答案:

没有答案