我正在尝试使 Spring 安全配置正常工作,但遇到了一些问题,我不知道该怎么做。我已经成功使用了x509,配置如下
<security:http auto-config="true" use-expressions="true">
<security:x509 subject-principal-regex="CN=(.*?)," user-service-ref="rrportalUserDetailsService" />
<security:intercept-url pattern="/selfRegistration/**" access="hasRole('ROLE_USER')" requires-channel="https"/>
<security:intercept-url pattern="/**" access="permitAll" requires-channel="http"/>
<security:port-mappings>
<security:port-mapping http="8080" https="8443"/>
</security:port-mappings>
</security:http>
问题是证书的 CN 不足以让我正确授权和分配我的角色。我需要从 X509Certificate 的扩展中解析一些项目。我认为 X509PrincipalExtractor 非常适合我的需要,但我无法弄清楚如何正确连接它。
我有这个,但我不确定我需要什么 AuthenticationEntrypoint。我不能只实现自己的提取并将自定义字符串传递给我的 UserDetailsService 吗?
<security:http auto-config="false" entry-point-ref="????" use-expressions="true">
<security:intercept-url pattern="/selfRegistration/**" access="hasRole('ROLE_USER')" requires-channel="https"/>
<security:intercept-url pattern="/**" access="permitAll" requires-channel="http"/>
<security:port-mappings>
<security:port-mapping http="8080" https="8443"/>
</security:port-mappings>
<security:custom-filter position="X509_FILTER" ref="myX509AuthenticationFilter" />
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="rrportalUserDetailsService">
</security:authentication-provider>
</security:authentication-manager>
<bean id="myX509AuthenticationFilter" class="org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="principalExtractor">
<bean class="com.ctc.rrportal.security.rrportalX509PrincipalExtractor" />
</property></bean>
如果有人能指出我正确的方向或指向我的示例配置,我将不胜感激。
感谢大家!