Commit 06a21a10 authored by Matija Obreza's avatar Matija Obreza
Browse files

Wrapped JPA exception in removeRefreshToken

parent fd0b5516
......@@ -35,6 +35,7 @@ import org.genesys2.server.persistence.domain.OAuthAccessTokenPersistence;
import org.genesys2.server.persistence.domain.OAuthRefreshTokenPersistence;
import org.genesys2.server.service.JPATokenStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.common.util.OAuth2Utils;
......@@ -263,7 +264,11 @@ public class OAuth2JPATokenStoreImpl implements JPATokenStore {
}
private void removeRefreshToken(String tokenId) {
refreshTokenPersistence.delete(tokenId);
try {
refreshTokenPersistence.delete(tokenId);
} catch (EmptyResultDataAccessException e) {
LOG.warn("Could not delete token " + tokenId);
}
}
@Override
......
......@@ -27,6 +27,7 @@ import org.genesys2.server.security.AuthUserDetails;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
......@@ -55,4 +56,14 @@ public abstract class RestController {
return new ExceptionJson(ex);
}
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
public ExceptionJson handleHttpRequestMethodNotSupportedException(Exception ex, HttpServletRequest request, HttpServletResponse response)
throws IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
LOG.warn(request.getRequestURI() + " " + ex.getMessage() + " for "
+ (authentication != null ? ((AuthUserDetails) authentication.getPrincipal()).getUsername() : "null"));
return new ExceptionJson(ex);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment