@Test public void getTokenFromHttpServletRequest() { final String expectedToken = "An AccessToken"; when(request.getHeader("Authorization")).thenReturn("Bearer " + expectedToken); String actualToken = jwtTool.getTokenFromHttpServletRequest(request); assertEquals(expectedToken, actualToken); }
public String getTokenFromHttpServletRequest(HttpServletRequest servletRequest) { return Optional .ofNullable(servletRequest.getHeader("Authorization")) .filter(authHeader -> authHeader.startsWith("Bearer ")) .map(token -> token.substring(7)) .orElse(null); }
JwtTool { public String getTokenFromHttpServletRequest(HttpServletRequest servletRequest) { return Optional .ofNullable(servletRequest.getHeader("Authorization")) .filter(authHeader -> authHeader.startsWith("Bearer ")) .map(token -> token.substring(7)) .orElse(null); } }
JwtTool { public String getTokenFromHttpServletRequest(HttpServletRequest servletRequest) { return Optional .ofNullable(servletRequest.getHeader("Authorization")) .filter(authHeader -> authHeader.startsWith("Bearer ")) .map(token -> token.substring(7)) .orElse(null); } @Autowired  JwtTool(@Value("${accessTokenValidTimeInMinutes}") Integer accessTokenValidTimeInMinutes,
                   @Value("${refreshTokenValidTimeInMinutes}") Integer refreshTokenValidTimeInMinutes,
                   @Value("${tokenKey}") String accessTokenKey); }
JwtTool { public String getTokenFromHttpServletRequest(HttpServletRequest servletRequest) { return Optional .ofNullable(servletRequest.getHeader("Authorization")) .filter(authHeader -> authHeader.startsWith("Bearer ")) .map(token -> token.substring(7)) .orElse(null); } @Autowired  JwtTool(@Value("${accessTokenValidTimeInMinutes}") Integer accessTokenValidTimeInMinutes,
                   @Value("${refreshTokenValidTimeInMinutes}") Integer refreshTokenValidTimeInMinutes,
                   @Value("${tokenKey}") String accessTokenKey); String createAccessToken(String email, ROLE role); String createRefreshToken(User user); String getEmailOutOfAccessToken(String token); boolean isTokenValid(String token, String tokenKey); String getAccessTokenKey(); String getTokenFromHttpServletRequest(HttpServletRequest servletRequest); String generateTokenKey(); }
JwtTool { public String getTokenFromHttpServletRequest(HttpServletRequest servletRequest) { return Optional .ofNullable(servletRequest.getHeader("Authorization")) .filter(authHeader -> authHeader.startsWith("Bearer ")) .map(token -> token.substring(7)) .orElse(null); } @Autowired  JwtTool(@Value("${accessTokenValidTimeInMinutes}") Integer accessTokenValidTimeInMinutes,
                   @Value("${refreshTokenValidTimeInMinutes}") Integer refreshTokenValidTimeInMinutes,
                   @Value("${tokenKey}") String accessTokenKey); String createAccessToken(String email, ROLE role); String createRefreshToken(User user); String getEmailOutOfAccessToken(String token); boolean isTokenValid(String token, String tokenKey); String getAccessTokenKey(); String getTokenFromHttpServletRequest(HttpServletRequest servletRequest); String generateTokenKey();  }