Обмен ресурсами между источниками с помощью Spring Security

Я пытаюсь заставить CORS хорошо играть с Spring Security, но он не соответствует. Я сделал изменения, описанные вэта статья и изменяя эту строку вapplicationContext-security.xml получил запросы POST и GET для моего приложения (временно предоставляет методы контроллера, чтобы я мог проверить CORS):

До:<intercept-url pattern="/**" access="isAuthenticated()" />После:<intercept-url pattern="/**" access="permitAll" />

К сожалению, следующий URL, который позволяет входить в Spring Security через AJAX, не отвечает:http://localhost:8080/mutopia-server/resources/j_spring_security_check, Я делаю запрос AJAX отhttp://localhost:80 вhttp://localhost:8080.

В Chrome

При попытке доступаj_spring_security_check я получил(pending) в Chrome для запроса предварительной проверки OPTIONS и вызова AJAX возвращается с кодом состояния HTTP 0 и сообщением «ошибка».

В Firefox

Предварительная проверка завершается успешно с кодом состояния HTTP 302, и я все еще получаю обратный вызов ошибки для моего запроса AJAX непосредственно после этого с состоянием HTTP 0 и сообщением «ошибка».

Код запроса AJAX
function get(url, json) {
    var args = {
        type: 'GET',
        url: url,
        // async: false,
        // crossDomain: true,
        xhrFields: {
            withCredentials: false
        },
        success: function(response) {
            console.debug(url, response);
        },
        error: function(xhr) {
            console.error(url, xhr.status, xhr.statusText);
        }
    };
    if (json) {
        args.contentType = 'application/json'
    }
    $.ajax(args);
}

function post(url, json, data, dataEncode) {
    var args = {
        type: 'POST',
        url: url,
        // async: false,
        crossDomain: true,
        xhrFields: {
            withCredentials: false
        },
        beforeSend: function(xhr){
            // This is always added by default
            // Ignoring this prevents preflight - but expects browser to follow 302 location change
            xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
            xhr.setRequestHeader("X-Ajax-call", "true");
        },
        success: function(data, textStatus, xhr) {
            // var location = xhr.getResponseHeader('Location');
            console.error('success', url, xhr.getAllResponseHeaders());
        },
        error: function(xhr) {
            console.error(url, xhr.status, xhr.statusText);
            console.error('fail', url, xhr.getAllResponseHeaders());
        }
    }
    if (json) {
        args.contentType = 'application/json'
    }
    if (typeof data != 'undefined') {
        // Send JSON raw in the body
        args.data = dataEncode ? JSON.stringify(data) : data;
    }
    console.debug('args', args);
    $.ajax(args);
}

var loginJSON = {"j_username": "username", "j_password": "password"};

// Fails
post('http://localhost:8080/mutopia-server/resources/j_spring_security_check', false, loginJSON, false);

// Works
post('http://localhost/mutopia-server/resources/j_spring_security_check', false, loginJSON, false);

// Works
get('http://localhost:8080/mutopia-server/landuses?projectId=6', true);

// Works
post('http://localhost:8080/mutopia-server/params', true, {
    "name": "testing",
    "local": false,
    "generated": false,
    "project": 6
}, true);

Пожалуйста, обратите внимание - я могу POST на любой другой URL в моем приложении через CORS, кроме входа в Spring Security. Я просмотрел много статей, поэтому любая оценка этого странного вопроса будет принята с благодарностью.

Ответы на вопрос(8)

Ваш ответ на вопрос