Skip to content

Commit

Permalink
added exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
melistik committed Sep 5, 2018
1 parent 8883770 commit 422ac88
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.MalformedJwtException;
import io.rocketbase.commons.config.JwtProperties;
import io.rocketbase.commons.dto.ErrorResponse;
import io.rocketbase.commons.model.AppUser;
import io.rocketbase.commons.security.CustomAuthoritiesProvider;
import io.rocketbase.commons.security.JwtTokenService;
import io.rocketbase.commons.service.AppUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
Expand Down Expand Up @@ -44,9 +46,15 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
String authToken = getAuthToken(request);
String username = getValidatedUsername(authToken);

tryToAuthenticate(authToken, username, request);

chain.doFilter(request, response);
try {
tryToAuthenticate(authToken, username, request);
chain.doFilter(request, response);
} catch (Exception e) {
int status = HttpStatus.BAD_REQUEST.value();
response.setStatus(status);
response.getWriter().write(String.format("{\"status\": %d, \"message\": \"%s\"}", status,
e.getMessage().replace("\"", "\\")));
}
}

protected String getAuthToken(HttpServletRequest request) {
Expand Down

0 comments on commit 422ac88

Please sign in to comment.