这是我的情景:SpringSecurity - 自定义自动认证
- 一个web应用程序对于许多应用进行SSO一个排序的
- 登录的用户不是点击一个链接和应用发出后与用户信息(名称,pwd [无用],角色)对正确的应用程序
- 我在这些应用程序之一实施SpringSecurity受益于其权力(权限在会话中,其类提供的方法等)
所以,我需要开发一个自定义过滤器 - 我想 - 这是能够检索请求的用户信息,从数据库中检索,通过自定义DetailsUserService,关于用户(电子邮件等的进一步信息... ),然后根据从请求中检索的角色执行该用户的身份验证。
我在看Pre-Authentication过滤器,但我不确定它是否是正确的选择。似乎这些对象预计会在委托人已经在会议中使用,并被一些以前的认证机制所采用(是不是?)。
我认为,一旦确定正确的过滤器,我应该需要类似中执行:
GrantedAuthority[] ga= new GrantedAuthority[1];
ga[0] = new GrantedAuthorityImpl(myUser.getRole());
SecurityContext sc = SecurityContextHolder.getContext();
Authentication a = new UsernamePasswordAuthenticationToken(userName, userPwd, ga);
a = authenticationManager.authenticate(a);
sc.setAuthentication(a);
它是正确的方向来解决我的问题呢?你有什么建议可以帮助我找到缺失的东西吗?
谢谢大家,
卢卡
此外:
Xearxess嗨!对不起,再次打扰你,但似乎根据SpringSecurity 2.0.4的代码翻译比我想象的更困难:S问题是XML ...我尝试了不同的配置,但我总是跑进命名空间问题,缺少属性等等...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd">
<security:http>
<security:intercept-url pattern="/**" access="isAuthenticated()" />
<security:logout logout-url="/logout" logout-success-url="http://milan-ias-vs.usersad.everis.int/DMTest/" invalidate-session="true" />
<security:custom-filter position="PRE_AUTH_FILTER" ref="preAuthenticatedProcessingFilter" />
</security:http>
<bean id="preAuthenticatedProcessingFilter" class="it.novartis.ram.authentication.PreAuthenticatedProcessingFilter">
<custom-filter position="PRE_AUTH_FILTER"/>
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
<property name="preAuthenticatedUserDetailsService">
<bean class="it.novartis.ram.authentication.PreAuthenticatedUserDetailsService" />
</property>
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="preauthAuthProvider" />
</security:authentication-manager>
</beans>
引用CUSTOM-FILTER元素的2行是两个不同的尝试,它们都被标记为错误。如何将我的过滤器的位置指定为属性?
此外,身份验证管理器定义上的身份验证提供程序引用标记为错误。我认为我需要将它指定为属性,对吧?
希望你能给我最后一次推;) 再次感谢您,
卢卡
非常感谢Xaerxess!不幸的是,我们坚持使用Spring 2.5.6和Spring Security 2.0.4,但您的建议将对我有所帮助;) – Dolfiz
很遗憾,Spring 3更好,通用并且具有很好的文档。但是上面的大量代码可以回溯到2.X(例如没有泛型)。 – Xaerxess
确实很可惜!但是你写的代码会帮助我。再次感谢您和宝宝共度美好时光;) – Dolfiz