Spring security 身份验证后重定向

Spring security 身份验证后重定向,spring-security,vaadin,Spring Security,Vaadin,在我将spring-security集成到vaadin中之后,当然需要在成功的身份验证之后重定向用户 我使用两个servlet集成了spring security,一个用于vaadin,另一个用于spring security。 这里是我的web.xml <?xml version="1.0"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSch

在我将
spring-security
集成到
vaadin
中之后,当然需要在成功的身份验证之后重定向用户

我使用两个servlet集成了
spring security
,一个用于
vaadin
,另一个用于
spring security
。 这里是我的
web.xml

<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/pmc-web-context.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>

    <servlet>
        <servlet-name>another-pmc-servlet</servlet-name>
        <servlet-class>ru.xpoft.vaadin.SpringVaadinServlet</servlet-class>
        <init-param>
            <param-name>beanName</param-name>
            <param-value>pmcVaadin</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>another-pmc-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <!-- Spring Security -->
    <servlet>
        <servlet-name>login-pmc-servlet</servlet-name>
        <servlet-class>ru.xpoft.vaadin.SpringVaadinServlet</servlet-class>
        <init-param>
            <param-name>beanName</param-name>
            <param-value>loginVaadin</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>login-pmc-servlet</servlet-name>
        <url-pattern>/login/*</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

但是如何使它重定向到所有组件(ui bean name
pmcVaadin
)所需的me
vaadin
页面?因为当我这样做时,它再次被截获,并再次显示我的登录信息。

首先缩短并清理你的“createLayout”方法

尝试:

<http auto-config="true">
    <intercept-url pattern="/*" access="ROLE_USER"/>
    <form-login login-page="/login/" default-target-url="/*" authentication-failure-url="/login/?login_error=true"/>
</http>

<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="user" password="pass" authorities="ROLE_USER"/>
            <user name="admin" password="admin" authorities="ROLE_ADMIN, ROLE_USER"/>
        </user-service>
    </authentication-provider>
</authentication-manager>
public class LoginForm extends Window {

    private TextField login;
    private TextField password;

    private Button enter;

    private HorizontalLayout buttonLayout;
    private FormLayout formLayout;

    private Image facebookIcon;

    @Override
    public void attach() {
        setCaption(StringValues.LOGIN_FORM_CAPTION);
        setSizeUndefined();
        setResizable(false);
        setModal(true);
        setContent(createLayout());

        super.attach();
    }

    private FormLayout createLayout() {
        login = new TextField("Login");
        password = new TextField("Password");

        enter = new Button("Enter(close)");
        final LoginUi ui = (LoginUi) LoginUi.getCurrent();
        enter.addClickListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                String loginValue = login.getValue();
                String passwordValue = password.getValue();
                AuthenticationService authenticationService = ui.getAuthenticationService();
                String result = authenticationService.authorize(loginValue, passwordValue);
                if (StringUtils.isBlank(result)) {
                    LoginForm.this.close();
                }

                ui.getPage().setLocation("localhost:8080/pmc-web/");
            }

        });

        buttonLayout = new HorizontalLayout();

        String pathToFile = VaadinService.getCurrent().getBaseDirectory()
                .getAbsolutePath() + "\\WEB-INF\\images\\facebook_icon.png";
        FileResource resource = new FileResource(new File(pathToFile));

        facebookIcon = new Image(null, resource);
        facebookIcon.addClickListener(new MouseEvents.ClickListener() {

            @Override
            public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
                try {
                    ui.getPage().setLocation(ui.getAuthenticationService()
                        .redirect(ui.getProperty("oauth.application"), ui.getProperty("oauth.callback")));
                } catch (Exception e) {
                    Notification.show(e.getMessage());
                }

            }

        });

        buttonLayout.addComponent(facebookIcon);
        buttonLayout.addComponent(enter);
        buttonLayout.setComponentAlignment(enter, Alignment.BOTTOM_LEFT);

        formLayout = new FormLayout(login, password, buttonLayout);
        formLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_LEFT);
        formLayout.setMargin(true);

        return formLayout;
    }

}
ui.getNavigator().navigateTo("pmc-web");