1

我正在尝试使用此表单使用 extjs 表单登录:

{
            xtype : 'form',
            name: 'authenticationBox',
            width: 250,
            bodyPadding:5,
            fieldDefaults: {
                msgTarget: 'side',
                labelWidth: 75
            },
            defaultType: 'textfield',
            url:'j_spring_security_check',
            items:[{
                fieldLabel: 'Login',
                name: 'j_username',
                allowBlank:false
            },{
                fieldLabel: 'Password',
                inputType: 'password',
                name: 'j_password',
                allowBlank:false
            }],
            buttons: [{
                text: 'Reset',
                action: 'reset'
            },{
                text: 'Submit',
                action:'auth'
            }]
    }

按钮处理程序是:

 onSubmitLogin : function(button){
    var me = this,
        form = button.up().up().getForm();// get the basic form
    if (form.isValid()) { // make sure the form contains valid data before submitting
        form.submit({
            success: function(form, action) {
               Ext.Msg.alert('Success', action.result.msg);
            },
            failure: function(form, action) {
             console.log(action.result);
             //var msg = action.result.msg;
                Ext.Msg.alert('Failed', 'failed');
            }
        });
    } else { // display error alert if the data is invalid
        Ext.Msg.alert('Invalid Data', 'Please correct form errors.');
    }
}

我的安全上下文 xml 是:

    <http auto-config="true" disable-url-rewriting="true"
    use-expressions="true">
    <intercept-url pattern="/login" access="permitAll" />
    <intercept-url pattern="/public" access="permitAll" />
    <intercept-url pattern="/logout" access="permitAll" />
    <intercept-url pattern="/accessdenied" access="permitAll" />
    <intercept-url pattern="/home" access="authenticated" />
    <form-login login-page="/login" default-target-url="/home"
        authentication-failure-url="/accessdenied"/>
    <logout logout-success-url="/logout" />
</http> 

<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="vitorn" password="password1" authorities="ROLE_USER" />
        </user-service>
    </authentication-provider>
</authentication-manager>

我有这个控制器:

    @RequestMapping(value = "/"+HOME_PAGE_NAME)
public ModelAndView showHomePage() {
    logger.info("trying to show home!");
    String username = getUsername();
    if(!username.equals(ANONYMOUS_USER)){
        logger.info("authenticated - show home!");
        return new ModelAndView(HOME_PAGE_NAME);
    }

    //ModelAndView model = new ModelAndView(LOGIN_PAGE_NAME);
    return new ModelAndView(LOGIN_PAGE_NAME);
}

@RequestMapping(value="/login", method = RequestMethod.GET)
public ModelAndView openLoginPage() {
    logger.info("trying to show login!");

    ModelAndView model = new ModelAndView(LOGIN_PAGE_NAME);
    return model;
}

当我在谷歌浏览器上登录时,我在网络中看到我的帖子,其值为 j_username:vitorn j_password:password1 但没有任何响应,并且在我看到重定向到主页后出现此错误:未捕获的 Ext.JSON.decode(): You're试图解码无效的 JSON 字符串:

我已经阅读了许多教程但没有成功。成功登录后我可以更改自动重定向到主页吗?

4

1 回答 1

0

您可以在这里找到帮助:将 spring security3 与 extjs 集成 http://javajeedevelopment.blogspot.fr/2011/02/integrating-spring-security-3-with.html

于 2013-11-20T16:00:53.007 回答