GWT和SpringSecurity

时间:2011-02-09 12:02:51

标签: java gwt spring-security

我创建了两个模块

  1. GWTAppAuth
  2. GWTApp
  3. 当我尝试将表单从GWTAppAuth发布到j_spring_security_check时,没有发生任何事情。

    Firebug在控制台中显示

    "Failed to load source for:http://127.0.0.1:8888/j_spring_security_check"
    

    但是,如果我尝试手动访问GWTApp后,它可以工作。有人知道什么事吗?

    看起来Spring Security不会重定向到第二个(GWTApp) 我该如何检查?

    1. 以托管模式运行应用程序
    2. 尝试访问GWTApp.html
    3. Spring安全性将我重定向到GWTAppAuth.html
    4. 按登录按钮
    5. 如果我们查看firebug日志,我们可以在这个地方看到

      "POST //127.0.0.1:8888/j_spring_security_check"
      

      和回复 -

      "Failed to load source for: http://127.0.0.1:8888/j_spring_security_check"
      

      然后是下一条记录 -

      "GET //127.0.0.1:8888/GWT/GWTApp.html?gwt.codesvr=127.0.0.1:9997"
      

      并获取所有需要的资源
      现在我可以手动输入

      "//127.0.0.1:8888/GWT/GWTApp.html" 
      

      现在我可以访问GWTApp.html

2 个答案:

答案 0 :(得分:4)

我找到了解决方案 您应该使用html表单并提交按钮,而不是GWT提供的小部件 例如:

<form action="/j_spring_security_check" method="post">
   <g:Label>
       login
   </g:Label>
   <g:TextBox name="j_username" width="200" />
       <g:Label>
           password
       </g:Label>
       <g:PasswordTextBox name="j_password" width="200" />
       <input name="submit" type="submit" value="Login" />
</form>

或者在使用GWT FormPanel小部件的情况下捕获表单提交已完成的事件:

public class LoginFormB extends Composite {

  private static LoginFormBUiBinder uiBinder = GWT.create(LoginFormBUiBinder.class);

  interface LoginFormBUiBinder extends UiBinder<Widget, LoginFormB> {}

  @UiField
  FormPanel formPanel;

  public LoginFormB() {
    formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent arg0) {
            // Redirect to needed page
            redirect("needed url");
        }
    });
    initWidget(uiBinder.createAndBindUi(this));
  }

  public static native void redirect(String url)/*-{
    $wnd.location = url;
  }-*/;
}

答案 1 :(得分:-1)

我认为您不能在同一个应用程序中直接集成Spring Security和GWT。你需要介于两者之间的东西来粘合它们。

尝试检查这些教程: http://krams915.blogspot.com/2011/01/spring-and-gwt-integration-using-maven.html

http://krams915.blogspot.com/2011/01/spring-and-gwt-security-via-spring.html