WebSocket trong ứng dụng của mùa xuân Boot - Bắt 403 ForbiddenWebSocket trong ứng dụng của mùa xuân Boot - Bắt 403 Forbidden
tôi có thể kết nối với WebSocket từ khách hàng sử dụng sockjs/stompjs khi tôi chạy này trong nhật thực (không khởi động mùa xuân).
Nhưng khi tôi tạo một bình khởi động Spring (gradlew build) cho mã websocket và chạy java -jar websocket-code.jar, tôi nhận được lỗi 403 khi kết nối với websocket.
Tôi không có xác thực cho các ổ cắm web. Tôi có bộ lọc CORS và nghĩ rằng có tất cả tiêu đề ngay trong yêu cầu/phản hồi.
Dưới đây là build.gradle tôi
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'war'
sourceCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
compile "org.springframework:spring-web:$spring_version"
compile "org.springframework:spring-webmvc:$spring_version"
compile "org.springframework:spring-websocket:$spring_version"
compile "org.springframework:spring-messaging:$spring_version"
compile "org.springframework.boot:spring-boot-starter-websocket"
compile "org.springframework.boot:spring-boot-starter-web"
compile "com.fasterxml.jackson.core:jackson-databind:2.6.2"
compile "com.fasterxml.jackson.core:jackson-core:2.6.2"
compile "com.fasterxml.jackson.core:jackson-annotations:2.6.2"
compile "org.springframework.amqp:spring-rabbit:1.3.5.RELEASE"
compile("org.springframework:spring-tx")
compile("org.springframework.boot:spring-boot-starter-web:1.2.6.RELEASE")
compile("org.springframework.boot:spring-boot-starter-jetty:1.2.6.RELEASE")
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile "org.springframework:spring-test:$spring_version"
}
task wrapper(type: Wrapper) {
gradleVersion = '2.5'
}
Cập nhật:
gia tăng một bộ lọc CORS với response.setHeader ("Access-Control-Allow-Origin", "http://localhost:8089");
Trong firebug đứng về phía khách hàng
Request Headers
Origin
http://localhost:8089
Response Headers
Access-Control-Allow-Origin
http://localhost:8089
Server Logs
2015-10-02 16:57:31.372 DEBUG 1848 --- [qtp374030679-14] o.s.w.s.s.t.h.DefaultSockJsService : Request rejected, Origin header value http://localhost:8089 not allowed
xứ Tôi yêu cầu từ nằm trong Allow-nguồn gốc danh sách. Vẫn nhận được thông báo Yêu cầu bị từ chối trong nhật ký.
Bạn không chắc chắn nếu các tính năng này vẫn hoạt động nữa. Đối với tôi nói rằng lớp ổ cắm web yêu cầu thông tin xác thực là đúng và ngay cả khi tôi đặt thiết lập của tôi cho phép nguồn gốc của tôi trong CORS. Tôi vẫn bị phạt 403 – numerical25