Spring Security:将XML转换为Annotation

时间:2016-07-18 19:07:29

标签: spring-mvc

我想将OpenID Connect客户端与Spring Java注释一起使用。

不幸的是,示例Mitre ID Connect client基于XML。

我设法通过 @ImportResource加载XML("类路径:servlet-context.xml") 但是使用纯Java注释解决方案会好得多。

我无法将以下XML内容翻译成Spring Annotation:

<security:http auto-config="false" use-expressions="true"
        disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint"
        pattern="/**">
        <security:custom-filter before="PRE_AUTH_FILTER" ref="openIdConnectAuthenticationFilter" />
        <security:logout />
</security:http>



<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider ref="openIdConnectAuthenticationProvider" />
</security:authentication-manager>


<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
    <property name="loginFormUrl" value="http://localhost:10239/test" />
</bean>



<util:set id="namedAdmins" value-type="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
    <bean class="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
            <constructor-arg name="subject" value="XXX" />
            <constructor-arg name="issuer" value="http://localhost:10239/test" />
        </bean>
    </util:set>

1 个答案:

答案 0 :(得分:0)

bean xml标记类似于@bean注释。见http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch02s02.html

util:set标签类似于返回一组org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority类型的方法。但是,此方法也具有@bean注释。

对于安全相关标签,您可以扩展WebSecurityConfigurerAdapter 见https://www.mkyong.com/spring-security/spring-security-hello-world-annotation-example/