将Spring Security与Vaadin 7集成

时间:2013-07-03 11:40:34

标签: spring-security vaadin

我是vaadin 7的新手。我发现Spring Security Vaadin Integration存在一些问题。我正在使用JSP登录表单登录我的应用程序。我无法登录我的应用程序,我无法找到问题。

的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

1 个答案:

答案 0 :(得分:0)

你没有写出你有什么错误。无论如何,我看到一个缺陷:servlet注册为: TestApp 但映射为:测试