added liquibase db
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
package com.krylov.refound.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
|
||||
public class JwtHandshakeInterceptor implements HandshakeInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean beforeHandshake(
|
||||
ServerHttpRequest request,
|
||||
ServerHttpResponse response,
|
||||
WebSocketHandler wsHandler,
|
||||
Map<String, Object> attributes
|
||||
) throws Exception {
|
||||
|
||||
List<String> auth = request.getHeaders().get("Authorization");
|
||||
|
||||
if (auth == null || auth.isEmpty()) {
|
||||
return false; // запретить подключение
|
||||
}
|
||||
|
||||
String token = auth.get(0).replace("Bearer ", "");
|
||||
|
||||
// 🔥 проверяем JWT
|
||||
String userEmail = JwtUtils.validateTokenAndGetEmail(token);
|
||||
|
||||
if (userEmail == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
attributes.put("userEmail", userEmail);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterHandshake(
|
||||
ServerHttpRequest request,
|
||||
ServerHttpResponse response,
|
||||
WebSocketHandler wsHandler,
|
||||
Exception exception
|
||||
) { }
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.krylov.refound.util;
|
||||
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class JwtUtils {
|
||||
private static final String SECRET = "SECRET_KEY"; // заменить на env var
|
||||
|
||||
public static String validateTokenAndGetEmail(String token) {
|
||||
try {
|
||||
return Jwts.parserBuilder()
|
||||
.setSigningKey(Keys.hmacShaKeyFor(SECRET.getBytes()))
|
||||
.build()
|
||||
.parseClaimsJws(token)
|
||||
.getBody()
|
||||
.getSubject();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.krylov.refound.util;
|
||||
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
public class SecurityUtils {
|
||||
public static String getCurrentUserEmail() {
|
||||
return SecurityContextHolder.getContext()
|
||||
.getAuthentication()
|
||||
.getName();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user