Java Code Examples for org.springframework.util.StringUtils.substringMatch()

The following are Jave code examples for showing how to use substringMatch() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: springuni-particles   File: JwtAuthenticationFilter.java   View Source Code Vote up 6 votes
private Authentication getAuthentication(HttpServletRequest request) {
  String authorizationHeader = request.getHeader(AUTHORIZATION_HEADER);
  if (StringUtils.isEmpty(authorizationHeader)) {
    LOGGER.debug("Authorization header is empty.");
    return null;
  }

  if (!StringUtils.substringMatch(authorizationHeader, 0, TOKEN_PREFIX)) {
    LOGGER.debug("Token prefix {} in Authorization header was not found.", TOKEN_PREFIX);
    return null;
  }

  String jwtToken = authorizationHeader.substring(TOKEN_PREFIX.length() + 1);

  try {
    return jwtTokenService.parseJwtToken(jwtToken);
  } catch (AuthenticationException e) {
    LOGGER.warn(e.getMessage());
    return null;
  }
}