use of com.gmoon.resourceserver.user.User in project toy by gmoon92.
the class JwtVerifyFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
String token = getToken(request);
try {
User user = jwtUtils.decode(token);
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
chain.doFilter(request, response);
} catch (JWTVerificationException e) {
SecurityContextHolder.clearContext();
getAuthenticationEntryPoint().commence(request, response, new JwtVerifyException(e));
}
}
use of com.gmoon.resourceserver.user.User in project Toy by gmoon92.
the class JwtAuthenticationFilter method successfulAuthentication.
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {
User user = (User) authentication.getPrincipal();
String token = jwtUtils.generate(user);
response.setHeader(HttpHeaders.AUTHORIZATION, token);
}
use of com.gmoon.resourceserver.user.User in project Toy by gmoon92.
the class JwtVerifyFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
String token = getToken(request);
try {
User user = jwtUtils.decode(token);
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
chain.doFilter(request, response);
} catch (JWTVerificationException e) {
SecurityContextHolder.clearContext();
getAuthenticationEntryPoint().commence(request, response, new JwtVerifyException(e));
}
}
use of com.gmoon.resourceserver.user.User in project toy by gmoon92.
the class JwtAuthenticationFilter method successfulAuthentication.
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {
User user = (User) authentication.getPrincipal();
String token = jwtUtils.generate(user);
response.setHeader(HttpHeaders.AUTHORIZATION, token);
}
use of com.gmoon.resourceserver.user.User in project toy by gmoon92.
the class BaseIntegrationTest method beforeAll.
@BeforeAll
static void beforeAll(@Autowired UserRepository repository, @Autowired JwtUtils jwtUtils) {
User admin = repository.findByUsername("admin");
TOKEN_OF_ADMIN = new Token(jwtUtils.generate(admin));
}
Aggregations