Java SpringSecurityVaadin授权管理器bean

Java SpringSecurityVaadin授权管理器bean,java,spring-security,vaadin,Java,Spring Security,Vaadin,我是瓦丁和春天安全的新手。最近几天,我在谷歌上搜索如何将spring安全性集成到vaadin应用程序(而不是servlet)中的正确示例,以便用户可以使用LoginForm vaadin组件对自己进行身份验证。以下是我在onlogin事件中使用的代码片段: login = new LoginForm(); login.addListener(new LoginForm.LoginListener() { private static final long serialVersionUID

我是瓦丁和春天安全的新手。最近几天,我在谷歌上搜索如何将spring安全性集成到vaadin应用程序(而不是servlet)中的正确示例,以便用户可以使用LoginForm vaadin组件对自己进行身份验证。以下是我在onlogin事件中使用的代码片段:

login = new LoginForm();
login.addListener(new LoginForm.LoginListener() {
    private static final long serialVersionUID = 1L;

    @Override
    public void onLogin(LoginEvent event) {
        if (event.getLoginParameter("username").isEmpty() || event.getLoginParameter("password").isEmpty()) {
            getWindow().showNotification("Please enter username and/or password", Notification.TYPE_ERROR_MESSAGE);
        } else {
            SpringContextHelper helper = new SpringContextHelper(getApplication());
            authenticationManager = (ProviderManager)helper.getBean("authenticationManager");

            try {
                UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(event.getLoginParameter("username"), event.getLoginParameter("password"));   
                Authentication authentication = authenticationManager.authenticate(token);
                SecurityContextHolder.getContext().setAuthentication(authentication);
                authentication.getDetails();
            } catch (Exception e) {
                getWindow().showNotification(e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
            }
        }                   
    }
});
当我尝试使用applicationContext.xml文件中描述的凭据登录时,我在此行遇到了一个错误Null指针异常:

 authenticationManager = (ProviderManager)helper.getBean("authenticationManager");
我知道错误是由getBean(“authenticationManager”)抛出的;方法,因为它无法定位“**authenticationManager”“**bean。问题是:在这种情况下,“**authenticationManager”**是什么。它是一个用特殊方法实现某种Spring安全框架接口的类还是bean。是否有人可以提供此类bean的示例(类、pojo等)。我在web.xml中描述了侦听器和上下文参数,正如我在internet上的示例中所发现的那样

WEB.XML

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/applicationContext*.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>
<beans:beans xmlns="http://www.springframework.org/schema/security"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<http>
   <intercept-url pattern="/**" access="ROLE_USER" />
   <form-login />
   <logout />
</http>

<authentication-manager alias="authenticationManager">
    <authentication-provider>
      <user-service>
        <user name="userrrr" password="passsssword" authorities="ROLE_USER, ROLE_ADMIN" />
        <user name="otheruser" password="otherpasss" authorities="ROLE_USER" />
      </user-service>
    </authentication-provider>
</authentication-manager>

尝试org.springframework.security.authentication.AuthenticationManager界面,而不是ProviderManager

authenticationManager = (AuthenticationManager)helper.getBean("authenticationManager");

编辑。在您的配置中将alias=“authenticationManager”替换为id=“authenticationManager”。

没有名为“authenticationManager”的bean“已提供。从这个错误中,我看到我必须创建authenticationManager bean。但是我不知道如何实现这样的bean。应该使用什么样的接口和方法?由Spring Security提供。请参阅您的配置:authentication manager alias=“authenticationManager”。通常,您不需要自定义实现。Spring Security为您提供默认设置(ProviderManager)。您需要将alias=“authenticationManager”替换为id=“authenticationManager”。我想它会成功的。我得到了同样的错误:((没有提供名为“authenticationManager”的bean)。也许我必须在pom文件中包含一些包。但是我已经将所有相关的Spring安全包添加到pom中。我还将别名改为id
authenticationManager = (AuthenticationManager)helper.getBean("authenticationManager");