-
Notifications
You must be signed in to change notification settings - Fork 20
Upgrade Spring Boot and Java #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
Open
domonkos-ess
wants to merge
7
commits into
master
Choose a base branch
from
spring-boot-and-java-upgrade
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
86f2d87
Uplift Spring Boot and Java versions
f463752
Update Docker related files
f879baf
Update readme
e40f890
Update Github workflow files
d128c30
Undo elaticsearch upgrade
4862b42
Correct demo auth config
aa26c17
Resolve Sonar issues
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| # syntax=docker/dockerfile:1 | ||
|
|
||
| FROM eclipse-temurin:17-jdk AS builder | ||
| FROM eclipse-temurin:21-jdk AS builder | ||
| WORKDIR /build | ||
| RUN apt-get update && apt-get install -y maven | ||
| COPY . . | ||
| RUN mvn --batch-mode --update-snapshots clean package -DskipTests | ||
|
|
||
| FROM eclipse-temurin:17-jre AS runner | ||
| FROM eclipse-temurin:21-jre AS runner | ||
| WORKDIR /app | ||
| COPY --from=builder /build/target/ChannelFinder-*.jar ./channelfinder.jar | ||
| CMD ["java", "-jar", "/app/channelfinder.jar", "--spring.config.name=application"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,50 @@ | ||
| package org.phoebus.channelfinder.configuration; | ||
|
|
||
| import static org.springframework.security.config.Customizer.withDefaults; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.commons.lang3.ArrayUtils; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.*; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.core.type.AnnotatedTypeMetadata; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
| import org.springframework.security.authentication.AuthenticationManager; | ||
| import org.springframework.security.authentication.AuthenticationProvider; | ||
| import org.springframework.security.authentication.ProviderManager; | ||
| import org.springframework.security.authentication.dao.DaoAuthenticationProvider; | ||
| import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.builders.WebSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; | ||
| import org.springframework.security.config.http.SessionCreationPolicy; | ||
| import org.springframework.security.core.userdetails.User; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.security.ldap.DefaultSpringSecurityContextSource; | ||
| import org.springframework.security.ldap.authentication.BindAuthenticator; | ||
| import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; | ||
| import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator; | ||
| import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
|
|
||
| @Configuration | ||
| public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
|
|
||
| @Override | ||
| protected void configure(HttpSecurity http) throws Exception { | ||
| http.csrf().disable(); | ||
| http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); | ||
| http.authorizeRequests().anyRequest().authenticated(); | ||
| http.httpBasic(); | ||
| public class WebSecurityConfig { | ||
|
|
||
| @Bean | ||
| public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
| return http.csrf(csrf -> csrf.disable()) | ||
| .sessionManagement( | ||
| session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
| .authorizeHttpRequests(auth -> auth.anyRequest().authenticated()) | ||
| .httpBasic(withDefaults()) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public void configure(WebSecurity web) throws Exception { | ||
| @Bean | ||
| public WebSecurityCustomizer ignoringCustomizer() { | ||
| // Authentication and Authorization is only needed for non search/query operations | ||
| web.ignoring().antMatchers(HttpMethod.GET, "/**"); | ||
| return web -> web.ignoring().requestMatchers(HttpMethod.GET, "/**"); | ||
| } | ||
|
|
||
| /** External LDAP configuration properties */ | ||
|
|
@@ -83,71 +99,99 @@ public void configure(WebSecurity web) throws Exception { | |
| @Value("${file.auth.enabled:true}") | ||
| boolean file_enabled; | ||
|
|
||
| @Override | ||
| public void configure(AuthenticationManagerBuilder auth) throws Exception { | ||
| @Bean | ||
| public AuthenticationManager authenticationManager( | ||
| AuthenticationConfiguration configuration, List<AuthenticationProvider> providers) { | ||
| return new ProviderManager(providers); | ||
| } | ||
|
|
||
| if (ldap_enabled) { | ||
| DefaultSpringSecurityContextSource contextSource = | ||
| new DefaultSpringSecurityContextSource(ldap_url); | ||
| contextSource.afterPropertiesSet(); | ||
| @Bean | ||
| @ConditionalOnProperty(name = "ldap.enabled", havingValue = "true") | ||
| public AuthenticationProvider ldapAuthProvider() { | ||
|
|
||
| DefaultLdapAuthoritiesPopulator myAuthPopulator = | ||
| new DefaultLdapAuthoritiesPopulator(contextSource, ldap_groups_search_base); | ||
| myAuthPopulator.setGroupSearchFilter(ldap_groups_search_pattern); | ||
| myAuthPopulator.setSearchSubtree(true); | ||
| myAuthPopulator.setIgnorePartialResultException(true); | ||
| DefaultSpringSecurityContextSource contextSource = | ||
| new DefaultSpringSecurityContextSource(ldap_url); | ||
| contextSource.afterPropertiesSet(); | ||
|
|
||
| auth.ldapAuthentication() | ||
| .userDnPatterns(ldap_user_dn_pattern) | ||
| .ldapAuthoritiesPopulator(myAuthPopulator) | ||
| .contextSource(contextSource); | ||
| } | ||
| DefaultLdapAuthoritiesPopulator authPopulator = | ||
| new DefaultLdapAuthoritiesPopulator(contextSource, ldap_groups_search_base); | ||
| authPopulator.setGroupSearchFilter(ldap_groups_search_pattern); | ||
| authPopulator.setSearchSubtree(true); | ||
| authPopulator.setIgnorePartialResultException(true); | ||
|
|
||
| if (embedded_ldap_enabled) { | ||
| DefaultSpringSecurityContextSource contextSource = | ||
| new DefaultSpringSecurityContextSource(embedded_ldap_url); | ||
| contextSource.afterPropertiesSet(); | ||
|
|
||
| DefaultLdapAuthoritiesPopulator myAuthPopulator = | ||
| new DefaultLdapAuthoritiesPopulator(contextSource, embedded_ldap_groups_search_base); | ||
| myAuthPopulator.setGroupSearchFilter(embedded_ldap_groups_search_pattern); | ||
| myAuthPopulator.setSearchSubtree(true); | ||
| myAuthPopulator.setIgnorePartialResultException(true); | ||
|
|
||
| auth.ldapAuthentication() | ||
| .userDnPatterns(embedded_ldap_user_dn_pattern) | ||
| .ldapAuthoritiesPopulator(myAuthPopulator) | ||
| .groupSearchBase("ou=Group") | ||
| .contextSource(contextSource); | ||
| } | ||
| BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource); | ||
| bindAuthenticator.setUserDnPatterns(new String[] {ldap_user_dn_pattern}); | ||
|
|
||
| return new LdapAuthenticationProvider(bindAuthenticator, authPopulator); | ||
| } | ||
|
|
||
| @Bean | ||
| @ConditionalOnProperty(name = "embedded_ldap.enabled", havingValue = "true") | ||
| public AuthenticationProvider embeddedLdapAuthProvider() { | ||
|
|
||
| DefaultSpringSecurityContextSource contextSource = | ||
| new DefaultSpringSecurityContextSource(embedded_ldap_url); | ||
| contextSource.afterPropertiesSet(); | ||
|
|
||
| DefaultLdapAuthoritiesPopulator authPopulator = | ||
| new DefaultLdapAuthoritiesPopulator(contextSource, embedded_ldap_groups_search_base); | ||
| authPopulator.setGroupSearchFilter(embedded_ldap_groups_search_pattern); | ||
| authPopulator.setSearchSubtree(true); | ||
| authPopulator.setIgnorePartialResultException(true); | ||
|
|
||
| if (demo_auth_enabled) { | ||
| // read from configuration, no default content | ||
| // interpret users, pwds, roles | ||
| // user may have multiple roles | ||
|
|
||
| if (demo_auth_users != null | ||
| && demo_auth_pwds != null | ||
| && demo_auth_roles != null | ||
| && demo_auth_users.length > 0 | ||
| && demo_auth_users.length == demo_auth_pwds.length | ||
| && demo_auth_pwds.length == demo_auth_roles.length) { | ||
|
|
||
| for (int i = 0; i < demo_auth_users.length; i++) { | ||
| String[] userroles = demo_auth_roles[i].split(demo_auth_delimiter_roles); | ||
| if (userroles != null && userroles.length > 0) { | ||
| auth.inMemoryAuthentication() | ||
| .withUser(demo_auth_users[i]) | ||
| .password(encoder().encode(demo_auth_pwds[i])) | ||
| .roles(userroles); | ||
| } | ||
| } | ||
| } | ||
| BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource); | ||
| bindAuthenticator.setUserDnPatterns(new String[] {embedded_ldap_user_dn_pattern}); | ||
|
|
||
| return new LdapAuthenticationProvider(bindAuthenticator, authPopulator); | ||
| } | ||
|
|
||
| @Bean | ||
| @Conditional(EmbeddedLdapCondition.class) | ||
| public AuthenticationProvider demoAuthProvider() { | ||
|
|
||
| InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); | ||
| PasswordEncoder encoder = encoder(); | ||
|
|
||
| for (int i = 0; i < demo_auth_users.length; i++) { | ||
| String[] userroles = demo_auth_roles[i].split(demo_auth_delimiter_roles); | ||
|
|
||
| manager.createUser( | ||
| User.withUsername(demo_auth_users[i]) | ||
| .password(encoder.encode(demo_auth_pwds[i])) | ||
| .roles(userroles) | ||
| .build()); | ||
| } | ||
|
|
||
| DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); | ||
| provider.setUserDetailsService(manager); | ||
| provider.setPasswordEncoder(encoder); | ||
| return provider; | ||
| } | ||
|
|
||
| @Bean | ||
| public PasswordEncoder encoder() { | ||
| return new BCryptPasswordEncoder(); | ||
| } | ||
|
|
||
| private static class EmbeddedLdapCondition implements Condition { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems mixed up with demo auth and embedded ldap. They should be separate beans. |
||
|
|
||
| @Override | ||
| public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
|
|
||
| Environment environment = context.getEnvironment(); | ||
|
|
||
| Boolean isDemoAuthEnabled = | ||
| environment.getProperty("demo_auth.enabled", Boolean.class, false); | ||
| String[] demoAuthPwds = environment.getProperty("demo_auth.pwds", String[].class); | ||
| String[] demoAuthRoles = environment.getProperty("demo_auth.roles", String[].class); | ||
| String[] demoAuthUsers = environment.getProperty("demo_auth.users", String[].class); | ||
|
|
||
| return isDemoAuthEnabled | ||
| && !ArrayUtils.isEmpty(demoAuthUsers) | ||
| && !ArrayUtils.isEmpty(demoAuthPwds) | ||
| && !ArrayUtils.isEmpty(demoAuthRoles) | ||
| && demoAuthUsers.length == demoAuthPwds.length | ||
| && demoAuthPwds.length == demoAuthRoles.length; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Don't you need to update also this? (maven wrapper)
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.
Should I upgrade it to 3.9+?
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.
Let's keep it out of scope - please create a backlog task re maven version