Spring 3.0 Security http GET login

2019-09-08 12:04发布

问题:

I have following spring security configuration, How do i change to it login to work based on http GET instead of POST, so that login url will be something like: *http://localhost/myapp/j_security_check?j_username=scott&j_password=tiger&landing=some.html*

   <http auto-config="true" lowercase-comparisons="false">
    <intercept-url pattern="/images/**" filters="none"/>
    <intercept-url pattern="/styles/**" filters="none"/>
    <intercept-url pattern="/scripts/**" filters="none"/>
    <!--  Temp Below for testing reports -->
    <intercept-url pattern="/admin/**" access="ROLE_ADMIN"/>
    <intercept-url pattern="/passwordHint*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
    <intercept-url pattern="/signup*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
    <intercept-url pattern="/unauthorized*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
    <intercept-url pattern="/**/*.action*" access="ROLE_ADMIN,ROLE_USER"/> 
    <logout success-handler-ref="logoutHandler" invalidate-session="true" logout-url="/logout"/>
    <form-login login-page="/login" authentication-success-handler-ref="authSuccessHandler" 
                authentication-failure-handler-ref="authFailureHandler" authentication-failure-url="/login?error=true"
                login-processing-url="/j_security_check"/>
    <remember-me user-service-ref="userDao" key="e37f4b31-0c45-11dd-bd0b-0800200c9a66"/>        
</http>

回答1:

I end up introducing additional static jsp page with jquery submit form to j_security_check

<script type="text/javascript">
$(function() {
    function getUrlParams() {
        var params = {};
        window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, value) {
            params[key] = value;
        });

        return params;
    }
    $('#j_username').val(getUrlParams()['user']);
    $('#j_password').val(getUrlParams()['password']);
    $('#urlLoginForm').submit();
});
</script>

</head>

<form method="post" id="urlLoginForm" action="<c:url value='/j_security_check'/>">
<input type="hidden" id="j_username" name="j_username" /> 
<input type="hidden" id="j_password" name="j_password" />
</form>