update
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
package com.example.vue.config.security;
|
||||||
|
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
|
||||||
|
System.out.println("hello");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ import com.example.vue.domain.user.User;
|
|||||||
import com.example.vue.util.JwtUtil;
|
import com.example.vue.util.JwtUtil;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import io.jsonwebtoken.JwtException;
|
import io.jsonwebtoken.JwtException;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
@@ -35,6 +35,8 @@ public class JwtAuthenticationFilter extends BasicAuthenticationFilter {
|
|||||||
@Override
|
@Override
|
||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||||
|
|
||||||
|
// throw new BadCredentialsException("Hello");
|
||||||
|
|
||||||
Authentication authentication = getAuthentication(request);
|
Authentication authentication = getAuthentication(request);
|
||||||
|
|
||||||
if (authentication != null) {
|
if (authentication != null) {
|
||||||
@@ -55,7 +57,7 @@ public class JwtAuthenticationFilter extends BasicAuthenticationFilter {
|
|||||||
|
|
||||||
String token = authorizationHeader.substring("Bearer ".length());
|
String token = authorizationHeader.substring("Bearer ".length());
|
||||||
|
|
||||||
Claims claims = null;
|
Claims claims;
|
||||||
try {
|
try {
|
||||||
claims = jwtUtil.getClaims(token);
|
claims = jwtUtil.getClaims(token);
|
||||||
} catch (JwtException e) {
|
} catch (JwtException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user