Browse Source

minor fix

cloud-keycloak
aidar 3 years ago
parent
commit
52fd6db133
2 changed files with 4 additions and 9 deletions
  1. +1
    -1
      demo-client-app/src/App.js
  2. +3
    -8
      demo-resource-server/src/main/java/ru/digitalbanana/demoresourceserver/config/WebSocketConfig.java

+ 1
- 1
demo-client-app/src/App.js View File

@ -32,7 +32,7 @@ const connect = async (token) => {
stomp.connect( stomp.connect(
// { "X-Authorization": token.split(".").slice(0, 2).join(".") + ".alkdjalskdjals" }, // { "X-Authorization": token.split(".").slice(0, 2).join(".") + ".alkdjalskdjals" },
{ "X-Authorization": token },
{ "Authorization": `Bearer ${token}` },
(frame) => { (frame) => {
console.log("Connected", frame); console.log("Connected", frame);


+ 3
- 8
demo-resource-server/src/main/java/ru/digitalbanana/demoresourceserver/config/WebSocketConfig.java View File

@ -41,14 +41,9 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
public Message<?> preSend(Message<?> message, MessageChannel channel) { public Message<?> preSend(Message<?> message, MessageChannel channel) {
StompHeaderAccessor accessor = StompHeaderAccessor accessor =
MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (StompCommand.CONNECT.equals(accessor.getCommand())) {
List<String> authorization = accessor.getNativeHeader("X-Authorization");
if (authorization == null || authorization.isEmpty()) {
return null;
}
String accessToken = authorization.get(0);
if (accessor!=null && StompCommand.CONNECT.equals(accessor.getCommand())) {
List<String> authorization = accessor.getNativeHeader("Authorization");
String accessToken = authorization != null ? authorization.get(0).split(" ")[1] : "";
Jwt jwt = jwtDecoder.decode(accessToken); Jwt jwt = jwtDecoder.decode(accessToken);
JwtAuthenticationConverter converter = new JwtAuthenticationConverter(); JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
Authentication authentication = converter.convert(jwt); Authentication authentication = converter.convert(jwt);


Loading…
Cancel
Save