-
Notifications
You must be signed in to change notification settings - Fork 0
AB#72068 Allow requests to admin endpoint #194
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package uk.ac.ox.ctl.admin; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| @Configuration | ||
| @ConfigurationProperties(prefix = "admin") | ||
| public class AdminProperties { | ||
|
|
||
| private List<String> corsOrigins = Collections.emptyList(); | ||
|
|
||
| public List<String> getCorsOrigins() { | ||
| return corsOrigins; | ||
| } | ||
|
|
||
| public void setCorsOrigins(List<String> corsOrigins) { | ||
| this.corsOrigins = corsOrigins; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.security.web.SecurityFilterChain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.util.StringUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.web.cors.CorsConfiguration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.web.cors.CorsConfigurationSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.regex.Pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,12 +56,33 @@ private String getOrDeducePassword(SecurityProperties.User user, PasswordEncoder | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NOOP_PASSWORD_PREFIX + password; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | |
| * Builds a {@link CorsConfigurationSource} for the admin endpoints. | |
| * <p> | |
| * The allowed origins are taken from {@link AdminProperties#getCorsOrigins()}. | |
| * For each configured origin, a corresponding allowed origin is added to the | |
| * CORS configuration. If the special {@link CorsConfiguration#ALL} value | |
| * ({@code "*"}) is present, a warning is logged as this is generally not | |
| * recommended for production environments. | |
| * <p> | |
| * The resulting configuration: | |
| * <ul> | |
| * <li>applies only to {@code /admin/**} paths,</li> | |
| * <li>allows credentials,</li> | |
| * <li>allows all headers, and</li> | |
| * <li>allows all HTTP methods.</li> | |
| * </ul> | |
| * This method is used by {@link #adminConfiguration(HttpSecurity, AdminProperties)} | |
| * to enable CORS handling for the admin security filter chain. | |
| * | |
| * @param adminProperties configuration properties providing the list of | |
| * allowed CORS origins for the admin endpoints | |
| * @return a {@link CorsConfigurationSource} to be used by Spring Security | |
| * when processing CORS requests to {@code /admin/**} | |
| */ |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The corsConfigurationSource method deviates from the established pattern in WebSecurityConfiguration where a similar method is annotated with @bean. For consistency and to follow the existing codebase patterns, consider making this a @bean method and giving it a distinctive name (e.g., "adminCorsConfigurationSource") to avoid bean name conflicts.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ | |
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
|
||
| @WebMvcTest(properties = {"spring.security.user.name=user", "spring.security.user.password=pass1234"}, controllers = AdminController.class, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "uk\\.ac\\.ox\\.ctl\\.(canvasproxy|ltiauth)\\..*")) | ||
| @Import({AdminWebSecurity.class}) | ||
| @Import({AdminWebSecurity.class, AdminProperties.class}) | ||
|
||
| @ImportAutoConfiguration(exclude = { | ||
| OAuth2ClientAutoConfiguration.class | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AdminProperties class lacks documentation explaining its purpose and usage. As this is a configuration class that controls CORS behavior for admin endpoints, it should include class-level and field-level documentation explaining what the corsOrigins property does and providing examples of proper configuration values.