Skip to content

Commit

Permalink
Fix OAuth2 Logout and Exception Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JREastonMarks committed Jan 29, 2025
1 parent a666225 commit a7914c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ Dockerfile.local
security.properties
*.crt
*.key
*~
*~
*.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cbioportal.security.config;

import java.io.IOException;

import org.springframework.security.web.AuthenticationEntryPoint;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class CustomAuthenticationErrorEntryPoint implements AuthenticationEntryPoint {

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
org.springframework.security.core.AuthenticationException authException)
throws IOException, ServletException {
response.sendRedirect(request.getContextPath() + "/login?error");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public class OAuth2SecurityConfig {
@Value("${spring.security.oauth2.client.jwt-roles-path:resource_access::cbioportal::roles}")
private String jwtRolesPath;

private static final String LOGOUT_URL = "/logout";

private static final String LOGIN_URL = "/login";

@Value("${oauth2.logout.url}")
private String successfullLogoutUrl;

@Bean
@Order(1)
Expand All @@ -66,8 +71,10 @@ public SecurityFilterChain filterChain(HttpSecurity http, ClientRegistrationRepo
.failureUrl(LOGIN_URL + "?logout_failure")
)
.logout(logout -> logout
.logoutSuccessHandler(oidcLogoutSuccessHandler(clientRegistrationRepository))
);
.logoutUrl(LOGOUT_URL)
.logoutSuccessUrl(successfullLogoutUrl)
)
.exceptionHandling(ex -> ex.authenticationEntryPoint(new CustomAuthenticationErrorEntryPoint()));
return http.build();
}

Expand Down

0 comments on commit a7914c0

Please sign in to comment.