update deps, fix null pointer

This commit is contained in:
_Bastler 2022-11-30 15:17:30 +01:00
parent 3586bdbbcf
commit 74394f0582
8 changed files with 199 additions and 51 deletions

View File

@ -9,6 +9,7 @@ import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -46,9 +47,22 @@ public class PermissionManager implements UserDataProvider {
* @return the list * @return the list
*/ */
public List<Permission> get(Long target, String name) { public List<Permission> get(Long target, String name) {
return get(target, name, null);
}
/**
* Gets the.
*
* @param target the target
* @param name the name
* @param sort the sort
* @return the list
*/
public List<Permission> get(Long target, String name, String sort) {
if (target != null && StringUtils.hasText(name)) { if (target != null && StringUtils.hasText(name)) {
return Lists.newArrayList( return Lists.newArrayList(
permissionRepository.findAll(qPermission.target.eq(target).and(qPermission.name.eq(name)))); permissionRepository.findAll(qPermission.target.eq(target).and(qPermission.name.eq(name)),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -61,10 +75,27 @@ public class PermissionManager implements UserDataProvider {
* @return the not expires * @return the not expires
*/ */
public List<Permission> getNotExpires(Long target, String name) { public List<Permission> getNotExpires(Long target, String name) {
return getNotExpires(target, name, null);
}
/**
* Gets the not expires.
*
* @param target the target
* @param name the name
* @param sort the sort
* @return the not expires
*/
public List<Permission> getNotExpires(Long target, String name, String sort) {
if (target != null && StringUtils.hasText(name)) { if (target != null && StringUtils.hasText(name)) {
return Lists.newArrayList(permissionRepository.findAll(qPermission.target.eq(target) return Lists
.and(qPermission.name.eq(name)).and(qPermission.expires.after(Instant.now()) .newArrayList(
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now())))))); permissionRepository.findAll(
qPermission.target.eq(target).and(qPermission.name.eq(name))
.and(qPermission.expires.after(Instant.now())
.and(qPermission.starts.isNull()
.or(qPermission.starts.before(Instant.now())))),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -76,8 +107,20 @@ public class PermissionManager implements UserDataProvider {
* @return the all by target * @return the all by target
*/ */
public List<Permission> getAllByTarget(Long target) { public List<Permission> getAllByTarget(Long target) {
return getAllByTarget(target, null);
}
/**
* Gets the all by target.
*
* @param target the target
* @param sort the sort
* @return the all by target
*/
public List<Permission> getAllByTarget(Long target, String sort) {
if (target != null) { if (target != null) {
return Lists.newArrayList(permissionRepository.findAll(qPermission.target.eq(target))); return Lists.newArrayList(permissionRepository.findAll(qPermission.target.eq(target),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -89,10 +132,26 @@ public class PermissionManager implements UserDataProvider {
* @return the not expires by target * @return the not expires by target
*/ */
public List<Permission> getNotExpiresByTarget(Long target) { public List<Permission> getNotExpiresByTarget(Long target) {
return getNotExpiresByTarget(target, null);
}
/**
* Gets the not expires by target.
*
* @param target the target
* @param sort the sort
* @return the not expires by target
*/
public List<Permission> getNotExpiresByTarget(Long target, String sort) {
if (target != null) { if (target != null) {
return Lists.newArrayList(permissionRepository return Lists
.findAll(qPermission.target.eq(target).and(qPermission.expires.after(Instant.now()) .newArrayList(
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now())))))); permissionRepository.findAll(
qPermission.target.eq(target)
.and(qPermission.expires.after(Instant.now())
.and(qPermission.starts.isNull()
.or(qPermission.starts.before(Instant.now())))),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -104,10 +163,26 @@ public class PermissionManager implements UserDataProvider {
* @return the not expires by name * @return the not expires by name
*/ */
public List<Permission> getNotExpiresByName(String name) { public List<Permission> getNotExpiresByName(String name) {
return getNotExpiresByName(name, null);
}
/**
* Gets the not expires by name.
*
* @param name the name
* @param sort the sort
* @return the not expires by name
*/
public List<Permission> getNotExpiresByName(String name, String sort) {
if (name != null) { if (name != null) {
return Lists.newArrayList( return Lists
permissionRepository.findAll(qPermission.name.eq(name).and(qPermission.expires.after(Instant.now()) .newArrayList(
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now())))))); permissionRepository.findAll(
qPermission.name.eq(name)
.and(qPermission.expires.after(Instant.now())
.and(qPermission.starts.isNull()
.or(qPermission.starts.before(Instant.now())))),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -119,9 +194,21 @@ public class PermissionManager implements UserDataProvider {
* @return the not expires by target ignore start * @return the not expires by target ignore start
*/ */
public List<Permission> getNotExpiresByTargetIgnoreStart(Long target) { public List<Permission> getNotExpiresByTargetIgnoreStart(Long target) {
return getNotExpiresByTargetIgnoreStart(target, null);
}
/**
* Gets the not expires by target ignore start.
*
* @param target the target
* @param sort the sort
* @return the not expires by target ignore start
*/
public List<Permission> getNotExpiresByTargetIgnoreStart(Long target, String sort) {
if (target != null) { if (target != null) {
return Lists.newArrayList(permissionRepository return Lists.newArrayList(permissionRepository.findAll(
.findAll(qPermission.target.eq(target).and(qPermission.expires.after(Instant.now())))); qPermission.target.eq(target).and(qPermission.expires.after(Instant.now())),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -185,7 +272,7 @@ public class PermissionManager implements UserDataProvider {
public Permission update(Permission permission) { public Permission update(Permission permission) {
Assert.isTrue(permissionRepository.existsById(permission.getId()), Assert.isTrue(permissionRepository.existsById(permission.getId()),
"Permission '" + permission.getName() + "' for target + '" + permission.getTarget() + "' not exists!"); "Permission '" + permission.getName() + "' for target + '" + permission.getTarget() + "' not exists!");
Permission updatePermission = permissionRepository.getById(permission.getId()); Permission updatePermission = permissionRepository.findById(permission.getId()).orElse(new Permission());
updatePermission.setStarts(permission.getStarts()); updatePermission.setStarts(permission.getStarts());
updatePermission.setExpires(permission.getExpires()); updatePermission.setExpires(permission.getExpires());
updatePermission.setAddon(permission.isAddon()); updatePermission.setAddon(permission.isAddon());

View File

@ -6,8 +6,10 @@ package de.bstly.we.businesslogic;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -50,7 +52,19 @@ public class QuotaManager implements UserDataProvider {
* @return the all by name * @return the all by name
*/ */
public List<Quota> getAllByName(String name) { public List<Quota> getAllByName(String name) {
return Lists.newArrayList(quotaRepository.findAll(qQuota.name.eq(name))); return getAllByName(name, null);
}
/**
* Gets the all by name.
*
* @param name the name
* @param sort the sort
* @return the all by name
*/
public List<Quota> getAllByName(String name, String sort) {
return Lists.newArrayList(
quotaRepository.findAll(qQuota.name.eq(name), Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
/** /**
@ -60,8 +74,20 @@ public class QuotaManager implements UserDataProvider {
* @return the all by target * @return the all by target
*/ */
public List<Quota> getAllByTarget(Long target) { public List<Quota> getAllByTarget(Long target) {
return getAllByTarget(target, null);
}
/**
* Gets the all by target.
*
* @param target the target
* @param sort the sort
* @return the all by target
*/
public List<Quota> getAllByTarget(Long target, String sort) {
if (target != null) { if (target != null) {
return Lists.newArrayList(quotaRepository.findAll(qQuota.target.eq(target))); return Lists.newArrayList(quotaRepository.findAll(qQuota.target.eq(target),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -73,8 +99,20 @@ public class QuotaManager implements UserDataProvider {
* @return the not expires by target * @return the not expires by target
*/ */
public List<Quota> getNotExpiresByTarget(Long target) { public List<Quota> getNotExpiresByTarget(Long target) {
return getNotExpiresByTarget(target, null);
}
/**
* Gets the not expires by target.
*
* @param target the target
* @param sort the sort
* @return the not expires by target
*/
public List<Quota> getNotExpiresByTarget(Long target, String sort) {
if (target != null) { if (target != null) {
return Lists.newArrayList(quotaRepository.findAll(qQuota.target.eq(target).and(qQuota.value.gt(0)))); return Lists.newArrayList(quotaRepository.findAll(qQuota.target.eq(target).and(qQuota.value.gt(0)),
Sort.by(StringUtils.hasText(sort) ? sort : "id")));
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }

View File

@ -4,6 +4,7 @@
package de.bstly.we.controller; package de.bstly.we.controller;
import java.util.List; import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -41,36 +43,40 @@ public class PermissionManagementController extends BaseController {
* Gets the permissions for user. * Gets the permissions for user.
* *
* @param username the username * @param username the username
* @param sort the sort
* @return the permissions for user * @return the permissions for user
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/{username}") @GetMapping("/{username}")
public List<Permission> getPermissionsForUser(@PathVariable("username") String username) { public List<Permission> getPermissionsForUser(@PathVariable("username") String username,
@RequestParam("sort") Optional<String> sort) {
User user = userManager.getByUsername(username); User user = userManager.getByUsername(username);
if (user == null) { if (user == null) {
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
} }
return permissionManager.getNotExpiresByTargetIgnoreStart(user.getId()); return permissionManager.getNotExpiresByTargetIgnoreStart(user.getId(), sort.orElse(null));
} }
/** /**
* Gets the all permissions for user. * Gets the all permissions for user.
* *
* @param username the username * @param username the username
* @param sort the sort
* @return the all permissions for user * @return the all permissions for user
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/{username}/all") @GetMapping("/{username}/all")
public List<Permission> getAllPermissionsForUser(@PathVariable("username") String username) { public List<Permission> getAllPermissionsForUser(@PathVariable("username") String username,
@RequestParam("sort") Optional<String> sort) {
User user = userManager.getByUsername(username); User user = userManager.getByUsername(username);
if (user == null) { if (user == null) {
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
} }
return permissionManager.getAllByTarget(user.getId()); return permissionManager.getAllByTarget(user.getId(), sort.orElse(null));
} }
/** /**

View File

@ -4,6 +4,7 @@
package de.bstly.we.controller; package de.bstly.we.controller;
import java.util.List; import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.beust.jcommander.internal.Lists; import com.beust.jcommander.internal.Lists;
@ -41,48 +43,53 @@ public class QuotaManagementController extends BaseController {
* Gets the quotas for user. * Gets the quotas for user.
* *
* @param username the username * @param username the username
* @param sort the sort
* @return the quotas for user * @return the quotas for user
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/{username}") @GetMapping("/{username}")
public List<Quota> getQuotasForUser(@PathVariable("username") String username) { public List<Quota> getQuotasForUser(@PathVariable("username") String username,
@RequestParam("sort") Optional<String> sort) {
User user = userManager.getByUsername(username); User user = userManager.getByUsername(username);
if (user == null) { if (user == null) {
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
} }
return quotaManager.getNotExpiresByTarget(user.getId()); return quotaManager.getNotExpiresByTarget(user.getId(), sort.orElse(null));
} }
/** /**
* Gets the all quotas for user. * Gets the all quotas for user.
* *
* @param username the username * @param username the username
* @param sort the sort
* @return the all quotas for user * @return the all quotas for user
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/{username}/all") @GetMapping("/{username}/all")
public List<Quota> getAllQuotasForUser(@PathVariable("username") String username) { public List<Quota> getAllQuotasForUser(@PathVariable("username") String username,
@RequestParam("sort") Optional<String> sort) {
User user = userManager.getByUsername(username); User user = userManager.getByUsername(username);
if (user == null) { if (user == null) {
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
} }
return quotaManager.getAllByTarget(user.getId()); return quotaManager.getAllByTarget(user.getId(), sort.orElse(null));
} }
/** /**
* Gets the quotas by name. * Gets the quotas by name.
* *
* @param name the name * @param name the name
* @param sort the sort
* @return the quotas by name * @return the quotas by name
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/byname/{name}") @GetMapping("/byname/{name}")
public List<Quota> getQuotasByName(@PathVariable("name") String name) { public List<Quota> getQuotasByName(@PathVariable("name") String name, @RequestParam("sort") Optional<String> sort) {
return quotaManager.getAllByName(name); return quotaManager.getAllByName(name, sort.orElse(null));
} }
/** /**

View File

@ -74,13 +74,17 @@ public class UserManagementController extends BaseController {
* *
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param sort the sort
* @param descending the descending
* @return the users * @return the users
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping @GetMapping
public Page<User> getUsers(@RequestParam("page") Optional<Integer> pageParameter, public Page<User> getUsers(@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter) { @RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("sort") Optional<String> sort,
return userManager.get(pageParameter.orElse(0), sizeParameter.orElse(10), "username", true); @RequestParam("descending") Optional<Boolean> descending) {
return userManager.get(pageParameter.orElse(0), sizeParameter.orElse(10), sort.orElse("username"),
descending.orElse(false));
} }
/** /**

View File

@ -11,13 +11,14 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.RememberMeServices; import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
@ -48,7 +49,7 @@ import dev.samstevens.totp.code.HashingAlgorithm;
*/ */
@EnableWebSecurity @EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) @EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter { public class SecurityConfig {
@Autowired @Autowired
private LocalUserDetailsService localUserDetailsService; private LocalUserDetailsService localUserDetailsService;
@ -92,13 +93,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
auth.authenticationProvider(localAuthenticationProvider); auth.authenticationProvider(localAuthenticationProvider);
} }
/* @Bean
* @see org.springframework.security.config.annotation.web.configuration. public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
* WebSecurityConfigurerAdapter#configure(org.springframework.security.config.
* annotation.web.builders.HttpSecurity)
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http http
// anonymous // anonymous
.anonymous().authenticationFilter(localAnonymousAuthenticationFilter()).and() .anonymous().authenticationFilter(localAnonymousAuthenticationFilter()).and()
@ -115,11 +111,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// remember me // remember me
.rememberMe().rememberMeServices(rememberMeServices()).and() .rememberMe().rememberMeServices(rememberMeServices()).and()
// form totp // form totp
.addFilterBefore(formSecondFactorAuthenticationFilter(), LocalAnonymousAuthenticationFilter.class) .addFilterBefore(formSecondFactorAuthenticationFilter(http), LocalAnonymousAuthenticationFilter.class)
// rest login // rest login
.addFilterBefore(restAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) .addFilterBefore(restAuthenticationFilter(http), UsernamePasswordAuthenticationFilter.class)
// rest totp // rest totp
.addFilterAfter(restSecondFactorAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) .addFilterAfter(restSecondFactorAuthenticationFilter(http), UsernamePasswordAuthenticationFilter.class)
// Logout // Logout
.logout().logoutUrl("/auth/logout").logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler()) .logout().logoutUrl("/auth/logout").logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler())
.and() .and()
@ -137,6 +133,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// cors // cors
http.cors().configurationSource(corsConfigurationSource()); http.cors().configurationSource(corsConfigurationSource());
} }
return http.build();
} }
/** /**
@ -206,6 +204,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return restAuthenticationSuccessHandler; return restAuthenticationSuccessHandler;
} }
@Bean
public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception {
return http.getSharedObject(AuthenticationManagerBuilder.class).userDetailsService(localUserDetailsService)
.passwordEncoder(passwordEncoder).and().build();
}
/** /**
* Form second factor authentication filter. * Form second factor authentication filter.
* *
@ -213,10 +217,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
* @throws Exception the exception * @throws Exception the exception
*/ */
@Bean @Bean
public FormSecondFactorAuthenticationFilter formSecondFactorAuthenticationFilter() throws Exception { public FormSecondFactorAuthenticationFilter formSecondFactorAuthenticationFilter(HttpSecurity http)
throws Exception {
FormSecondFactorAuthenticationFilter formSecondFactorAuthenticationFilter = new FormSecondFactorAuthenticationFilter( FormSecondFactorAuthenticationFilter formSecondFactorAuthenticationFilter = new FormSecondFactorAuthenticationFilter(
"/auth/login/2fa"); "/auth/login/2fa");
formSecondFactorAuthenticationFilter.setAuthenticationManager(authenticationManager()); formSecondFactorAuthenticationFilter.setAuthenticationManager(authenticationManager(http));
formSecondFactorAuthenticationFilter.setAuthenticationSuccessHandler(formAuthenticationSuccessHandler()); formSecondFactorAuthenticationFilter.setAuthenticationSuccessHandler(formAuthenticationSuccessHandler());
formSecondFactorAuthenticationFilter.setRememberMeServices(rememberMeServices()); formSecondFactorAuthenticationFilter.setRememberMeServices(rememberMeServices());
return formSecondFactorAuthenticationFilter; return formSecondFactorAuthenticationFilter;
@ -229,9 +234,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
* @throws Exception the exception * @throws Exception the exception
*/ */
@Bean @Bean
public RestAuthenticationFilter restAuthenticationFilter() throws Exception { public RestAuthenticationFilter restAuthenticationFilter(HttpSecurity http) throws Exception {
RestAuthenticationFilter restAuthenticationFilter = new RestAuthenticationFilter("/auth/restlogin"); RestAuthenticationFilter restAuthenticationFilter = new RestAuthenticationFilter("/auth/restlogin");
restAuthenticationFilter.setAuthenticationManager(authenticationManager()); restAuthenticationFilter.setAuthenticationManager(authenticationManager(http));
restAuthenticationFilter.setAuthenticationSuccessHandler(restAuthenticationSuccessHandler()); restAuthenticationFilter.setAuthenticationSuccessHandler(restAuthenticationSuccessHandler());
restAuthenticationFilter.setAuthenticationFailureHandler(restAuthenticationFailureHandler); restAuthenticationFilter.setAuthenticationFailureHandler(restAuthenticationFailureHandler);
return restAuthenticationFilter; return restAuthenticationFilter;
@ -244,10 +249,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
* @throws Exception the exception * @throws Exception the exception
*/ */
@Bean @Bean
public RestSecondFactorAuthenticationFilter restSecondFactorAuthenticationFilter() throws Exception { public RestSecondFactorAuthenticationFilter restSecondFactorAuthenticationFilter(HttpSecurity http)
throws Exception {
RestSecondFactorAuthenticationFilter restSecondFactorAuthenticationFilter = new RestSecondFactorAuthenticationFilter( RestSecondFactorAuthenticationFilter restSecondFactorAuthenticationFilter = new RestSecondFactorAuthenticationFilter(
"/auth/restlogin/2fa"); "/auth/restlogin/2fa");
restSecondFactorAuthenticationFilter.setAuthenticationManager(authenticationManager()); restSecondFactorAuthenticationFilter.setAuthenticationManager(authenticationManager(http));
restSecondFactorAuthenticationFilter.setAuthenticationSuccessHandler(restAuthenticationSuccessHandler()); restSecondFactorAuthenticationFilter.setAuthenticationSuccessHandler(restAuthenticationSuccessHandler());
restSecondFactorAuthenticationFilter.setAuthenticationFailureHandler(restAuthenticationFailureHandler); restSecondFactorAuthenticationFilter.setAuthenticationFailureHandler(restAuthenticationFailureHandler);
restSecondFactorAuthenticationFilter.setRememberMeServices(rememberMeServices()); restSecondFactorAuthenticationFilter.setRememberMeServices(rememberMeServices());

View File

@ -378,7 +378,7 @@ public class OidcTokenManager implements SmartInitializingSingleton {
do { do {
page = oidcTokenRepository.findAll(predicate.getValue(), pageable); page = oidcTokenRepository.findAll(predicate.getValue(), pageable);
for (OidcToken oidcToken : page.getContent()) { for (OidcToken oidcToken : page.getContent()) {
if (oidcToken.getCreated() if (oidcToken.getExpiresIn() != null && oidcToken.getCreated()
.isBefore(Instant.now().minus(oidcToken.getExpiresIn(), ChronoUnit.SECONDS))) { .isBefore(Instant.now().minus(oidcToken.getExpiresIn(), ChronoUnit.SECONDS))) {
logger.debug( logger.debug(
"delete expired OidcToken: " + oidcToken.getId() + " [" + oidcToken.getAccessToken() + "]"); "delete expired OidcToken: " + oidcToken.getId() + " [" + oidcToken.getAccessToken() + "]");

View File

@ -12,14 +12,14 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version> <java.version>11</java.version>
<log4j2.version>2.17.2</log4j2.version> <log4j2.version>2.19.0</log4j2.version>
<revision>1.9.2-SNAPSHOT</revision> <revision>2.0.0-SNAPSHOT</revision>
</properties> </properties>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version> <version>2.7.6</version>
<relativePath /> <relativePath />
</parent> </parent>