PMT-9: Anlegen des Employee Services #5

Merged
SZUT-Dominik merged 8 commits from task/PMT-9-anlegen-des-employ-service into trunk 2024-09-30 12:37:00 +00:00
2 changed files with 50 additions and 0 deletions
Showing only changes of commit 319f187cae - Show all commits

View file

@ -0,0 +1,12 @@
package de.hmmh.pmt.auth;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;
@Getter
@Setter
@Component
public class JwtToken{
private String token;
}

View file

@ -0,0 +1,38 @@
package de.hmmh.pmt.auth;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import java.io.IOException;
@Component
public class JwtTokenFilter extends OncePerRequestFilter {
@Autowired
private JwtToken token;
@Override
protected void doFilterInternal(
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
) throws ServletException, IOException {
token.setToken(null);
String authHeader = request.getHeader("Authorization");
if (authHeader == null) {
filterChain.doFilter(request, response);
return;
}
if (!authHeader.startsWith("Bearer ")) {
filterChain.doFilter(request, response);
return;
}
token.setToken(authHeader.substring("Bearer ".length()));
filterChain.doFilter(request, response);
}
}