Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more logs to auth related classes #246

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package info.fingo.urlopia.config.authentication;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
Expand All @@ -11,10 +13,13 @@

public class AccessDeniedExceptionHandler implements AccessDeniedHandler
{
private static final Logger LOGGER = LoggerFactory.getLogger(AccessDeniedExceptionHandler.class);

@Override
public void handle(HttpServletRequest request,
HttpServletResponse response,
AccessDeniedException ex) throws IOException, ServletException {
LOGGER.warn("Access denied", ex);
response.setStatus(HttpStatus.FORBIDDEN.value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import info.fingo.urlopia.api.v2.authentication.oauth.OAuthRedirectService;
import info.fingo.urlopia.user.NoSuchUserException;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand All @@ -21,6 +23,7 @@
@RequiredArgsConstructor
@ConditionalOnProperty(name = "ad.configuration.enabled", havingValue = "true", matchIfMissing = true)
public class JwtFilter extends OncePerRequestFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(OncePerRequestFilter.class);
private final JwtTokenValidator jwtTokenValidator;

@Override
Expand All @@ -46,6 +49,7 @@ private Authentication getAuthenticationByToken(String header,
var authorities = accessToken.getAuthorities();
return new UsernamePasswordAuthenticationToken(accountName, null, authorities);
}catch (InvalidTokenException | NoSuchUserException exception){
LOGGER.warn("Invalid authentication token", exception);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return null;
}
Expand Down
Loading