0
我是vaadin 7的新手。我發現Spring Security Vaadin集成存在一些問題。我正在使用JSP登錄表單登錄到我的應用程序。我無法登錄到我的應用程序,我無法找到問題。將Spring Security與Vaadin 7集成
的web.xml
<display-name>Vaadin Web Application</display-name>
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>com.vaadin.ui.application.spring.ApplicationContextListener</listener-class>
</listener>
<servlet>
<servlet-name>TestApp</servlet-name>
<servlet-class>com.vaadin.ui.application.spring.SpringApplicationServlet</servlet-class>
<init-param>
<param-name>closeIdleSessions</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<description>Vaadin UIProvider class name</description>
<param-name>UIProvider</param-name>
<param-value>com.vaadin.ui.application.spring.ApplicationUIProvider</param-value>
</init-param>
<init-param>
<description>Vaadin application bean to start</description>
<param-name>UIBean</param-name>
<param-value>TestApplication</param-value>
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>com.vaadin.ui.application.AppWidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/home/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/schema/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>loginform.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>100</session-timeout>
</session-config>
SpringApplicationServlet.java
@Component
public class SpringApplicationServlet extends VaadinServlet {
private WebApplicationContext applicationContext;
private Class<? extends UI> applicationClass;
private String applicationBean;
private LocaleResolver localeResolver;
@SuppressWarnings("unchecked")
@Override
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
applicationBean = servletConfig.getInitParameter("applicationBean");
if (applicationBean == null) {
throw new ServletException(
"ApplicationBean not specified in servlet parameters");
}
applicationContext = WebApplicationContextUtils
.getWebApplicationContext(servletConfig.getServletContext());
applicationClass = (Class<? extends UI>) applicationContext
.getType(applicationBean);
initLocaleResolver(applicationContext);
}
private void initLocaleResolver(ApplicationContext context) {
try {
this.localeResolver = (LocaleResolver) context.getBean(
DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME,
LocaleResolver.class);
} catch (NoSuchBeanDefinitionException ex) {
this.localeResolver = new SessionLocaleResolver();
}
}
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
final Locale locale = localeResolver.resolveLocale(request);
LocaleContextHolder.setLocale(locale);
ServletRequestAttributes requestAttributes = new ServletRequestAttributes(
request);
RequestContextHolder.setRequestAttributes(requestAttributes);
try {
super.service(new HttpServletRequestWrapper(request) {
@Override
public Locale getLocale() {
return locale;
}
}, response);
} finally {
if (!locale.equals(LocaleContextHolder.getLocale())) {
localeResolver.setLocale(request, response,
LocaleContextHolder.getLocale());
}
LocaleContextHolder.resetLocaleContext();
RequestContextHolder.resetRequestAttributes();
}
}
protected UI getNewApplication(HttpServletRequest request)
throws ServletException {
return (UI) applicationContext.getBean(applicationBean);
}
protected Class<? extends UI> getApplicationClass()
throws ClassNotFoundException {
return applicationClass;
}
請幫我出一些示例代碼得到這個工作。
問候
Abhilash
請向我們展示您的代碼,並告訴我們您嘗試了什麼。 – LaurentG