Ale*_*Man 6 java spring annotations siteminder spring-4
我正在将基于旧版本的Spring应用程序转换为基于注释的Spring4应用程序.作为第一步,我将所有xmls转换为基于java配置的注释.应用程序运行正常,但唯一的问题是站点管理器xml配置.我不知道如何将web.xml中的以下siteminder配置转换为基于java的.
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>SiteMinderRealm</realm-name>
</login-config>
Run Code Online (Sandbox Code Playgroud)
上面的siteminder配置在web.xml中,
谁能告诉我如何在AppInitializer.java中为上面的xml编写基于java的配置
我的web.xml及其相应的替代AppInitializer.java代码如下所示
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>SpringWebMVCApp</display-name>
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.helloworld.config.AppConfig</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/rest/</url-pattern>
</servlet-mapping>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>SiteMinderRealm</realm-name>
</login-config>
</web-app>
Run Code Online (Sandbox Code Playgroud)
AppInitializer.java
public class AppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/rest/");
}
private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(AppConfig.class);
return context;
}
}
Run Code Online (Sandbox Code Playgroud)
更新1
public class AppInitializer extends WebSecurityConfigurerAdapter implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/rest/");
}
private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(AppConfig.class);
return context;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().realmName("SiteMinderRealm").and().x509();
}
}
Run Code Online (Sandbox Code Playgroud)
你试过配置WebSecurityConfigurerAdapter吗?像这样的东西:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().realmName("SiteMinderRealm").and().x509();
}
}
Run Code Online (Sandbox Code Playgroud)