Współdzielenie zasobów między źródłami z Spring Security

Próbuję sprawić, by CORS ładnie grał z Spring Security, ale nie jest zgodny. Wprowadziłem zmiany opisane wTen artykuł i zmiana tej liniiapplicationContext-security.xml ma żądania POST i GET działające dla mojej aplikacji (tymczasowo ujawnia metody kontrolera, więc mogę testować CORS):

Przed:<intercept-url pattern="/**" access="isAuthenticated()" />Po:<intercept-url pattern="/**" access="permitAll" />

Niestety następujący adres URL, który umożliwia logowanie Spring Security przez AJAX, nie odpowiada:http://localhost:8080/mutopia-server/resources/j_spring_security_check. Wykonuję żądanie AJAX zhttp://localhost:80 dohttp://localhost:8080.

W Chrome

Podczas próby uzyskania dostępuj_spring_security_check dostaję(pending) w Chrome dla żądania wstępnej opcji OPTIONS i wywołanie AJAX zwraca kod statusu HTTP 0 i komunikat „błąd”.

W Firefoksie

Wstępna inspekcja powiodła się z kodem stanu HTTP 302 i nadal otrzymuję wywołanie zwrotne błędu dla mojego żądania AJAX bezpośrednio potem ze statusem HTTP 0 i komunikatem „błąd”.

Kod żądania 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);

Uwaga - mogę POST na dowolny inny adres URL w mojej aplikacji za pośrednictwem CORS z wyjątkiem logowania Spring Security. Przeglądałem wiele artykułów, więc każdy wgląd w ten dziwny problem byłby bardzo mile widziany

questionAnswers(8)

yourAnswerToTheQuestion