From 8c2ab5d12c4092f96893950f74277c080e7ef879 Mon Sep 17 00:00:00 2001 From: _Bastler Date: Wed, 8 Mar 2023 16:29:14 +0100 Subject: [PATCH] fix misconfigured authentication manager --- .../we/businesslogic/PermissionManager.java | 8 ++++++++ .../PermissionManagementController.java | 8 ++++++-- .../de/bstly/we/security/SecurityConfig.java | 20 ++++++------------- pom.xml | 6 +++--- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java b/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java index 5f8e1f3..bc8ec51 100755 --- a/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java +++ b/core/src/main/java/de/bstly/we/businesslogic/PermissionManager.java @@ -458,6 +458,14 @@ public class PermissionManager implements UserDataProvider { return permissions; } + public void cleanupPermissionStart() { + for (Permission permission : permissionRepository.findAll(qPermission.expires.after(Instant.now()) + .and(qPermission.starts.isNotNull().and(qPermission.starts.before(Instant.now()))))) { + permission.setStarts(null); + permissionRepository.save(permission); + } + } + /* * @see de.bstly.we.businesslogic.UserDataProvider#getId() */ diff --git a/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java b/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java index 3e56f24..d21820b 100644 --- a/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java +++ b/core/src/main/java/de/bstly/we/controller/PermissionManagementController.java @@ -50,14 +50,18 @@ public class PermissionManagementController extends BaseController { @PreAuthorize("hasRole('ROLE_ADMIN')") @GetMapping("/{username}") public List getPermissionsForUser(@PathVariable("username") String username, - @RequestParam("sort") Optional sort) { + @RequestParam("sort") Optional sort, @RequestParam("ignoreStart") Optional ignoreStart) { User user = userManager.getByUsername(username); if (user == null) { throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); } - return permissionManager.getNotExpiresByTargetIgnoreStart(user.getId(), sort.orElse(null)); + if (ignoreStart.orElse(true)) { + return permissionManager.getNotExpiresByTargetIgnoreStart(user.getId(), sort.orElse(null)); + } else { + return permissionManager.getNotExpiresByTarget(user.getId(), sort.orElse(null)); + } } /** diff --git a/core/src/main/java/de/bstly/we/security/SecurityConfig.java b/core/src/main/java/de/bstly/we/security/SecurityConfig.java index 2f28101..41fa8a4 100755 --- a/core/src/main/java/de/bstly/we/security/SecurityConfig.java +++ b/core/src/main/java/de/bstly/we/security/SecurityConfig.java @@ -84,18 +84,6 @@ public class SecurityConfig { public static final String KEEP_PARAM = "keep"; - /** - * Configure authentication. - * - * @param auth the auth - * @throws Exception the exception - */ - @Autowired - public void configureAuthentication(AuthenticationManagerBuilder auth) throws Exception { - localAuthenticationProvider.setPasswordEncoder(passwordEncoder); - auth.authenticationProvider(localAuthenticationProvider); - } - @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http @@ -209,8 +197,12 @@ public class SecurityConfig { @Bean public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception { - return http.getSharedObject(AuthenticationManagerBuilder.class).userDetailsService(localUserDetailsService) - .passwordEncoder(passwordEncoder).and().build(); + AuthenticationManagerBuilder authenticationManagerBuilder = http + .getSharedObject(AuthenticationManagerBuilder.class); + localAuthenticationProvider.setUserDetailsService(localUserDetailsService); + localAuthenticationProvider.setPasswordEncoder(passwordEncoder); + authenticationManagerBuilder.authenticationProvider(localAuthenticationProvider); + return authenticationManagerBuilder.build(); } /** diff --git a/pom.xml b/pom.xml index fdf647c..0ee7b82 100755 --- a/pom.xml +++ b/pom.xml @@ -12,14 +12,14 @@ UTF-8 11 - 2.19.0 - 2.0.5-SNAPSHOT + 2.20.0 + 2.0.6-SNAPSHOT org.springframework.boot spring-boot-starter-parent - 2.7.6 + 2.7.9