use of com.gmoon.springsecurityjwt.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 = request.getHeader(JwtAuthenticationFilter.HEADER_NAME);
try {
User user = jwtUtil.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.springsecurityjwt.user.User in project toy by gmoon92.
the class JwtUtilTest method testDecode.
@Test
@DisplayName("JWT 복호화 검증")
void testDecode() {
// when
String token = jwtUtil.generate(User.create("gmoon", "123", Role.ADMIN));
User user = jwtUtil.decode(token);
// then
assertThat(user).hasFieldOrPropertyWithValue("username", "gmoon").hasFieldOrPropertyWithValue("role", Role.ADMIN);
}
use of com.gmoon.springsecurityjwt.user.User in project toy by gmoon92.
the class TeamControllerTest method testDelete.
@Test
@DisplayName("팀을 삭제한다.")
void testDelete() throws Exception {
// given
User admin = getUserOrElseThrow("admin");
// when
ResultActions result = verify(delete(URL_OF_TEAM), admin);
// then
result.andExpect(status().isOk());
}
use of com.gmoon.springsecurityjwt.user.User in project toy by gmoon92.
the class TeamControllerTest method testGet.
@Test
@DisplayName("팀을 조회한다.")
void testGet() throws Exception {
// given
User admin = getUserOrElseThrow("admin");
// when
ResultActions result = verify(get(URL_OF_TEAM), admin);
// then
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.id").value(WEB_TEAM_ID));
}
use of com.gmoon.springsecurityjwt.user.User in project toy by gmoon92.
the class JacksonUtilsTest method testToString.
@Test
void testToString() {
// given
User user = User.create("gmoon", "123", Role.ADMIN);
// when
String jsonString = JacksonUtils.toString(user);
// then
assertThat(jsonString).contains("username", "gmoon", "authorities", "ADMIN");
}
Aggregations