0
Ich arbeite gerade an Spring Security 4. Alles funktioniert gut, wenn Sie Standard-Login-Methode verwenden. In der Praxis muss ich mich jedoch mit der Ajax-Methode anmelden.Spring Security Ajax Anmelden
feder security.xml
<http use-expressions="true" auto-config="true">
<intercept-url pattern="/resources/**" access="permitAll" />
<form-login
login-processing-url="/resources/login-processing"
default-target-url="http://127.0.0.1:57633/"
/>
<csrf request-matcher-ref="csrfSecurityRequestMatcher"/>
<!-- <csrf disabled="true" /> -->
</http>
Im controllers
verwende ich @PreAuthorize
Anmerkung. In jQuery ist die Ajax-Anforderung wie folgt:
$.ajax({
url:"http://localhost:8080/myapp/resources/login-processing",
data:{username:$("#inputLogin")[0].value,
password:$("#inputPassword")[0].value
},
method:"POST",
success: function(data, textStatus, request) {
console.log(request.getResponseHeader())
}
})
.done(function(data, textStatus, request) {
console.log(request.getResponseHeader("Set-Cookie"))
})
.error(function(error) {
console.log(error)
})
Auch wenn ich gesetzt permitAll
, ist es noch Antwort 403-Fehler mit den folgenden Antwort-Header:
Access-Control-Allow-Headers:x-requested-with
Access-Control-Allow-Methods:POST, GET, OPTIONS, DELETE
Access-Control-Allow-Origin:*
Access-Control-Max-Age:3600
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Language:en
Content-Length:1116
Content-Type:text/html;charset=utf-8
Date:Mon, 18 Apr 2016 02:07:26 GMT
Expires:0
Pragma:no-cache
Server:Apache-Coyote/1.1
Set-Cookie:JSESSIONID=974B1629ECE3EB289F35097C9E9D9FDC; Path=/cancercloud/; HttpOnly
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
Was soll ich tun, Ajax Login konfigurieren?
Benutzername oder Passwort möglicherweise falsch? versuche hartcodiert. Haben Sie versucht, "http: // localhost: 8080/myapp/resources/login-processing" in den Namen des Servlets zu ändern? – Gero
Bitte csrf auch in Ajax enthalten – FreezY