first part #2434 fix configuration of example app

fix configuration of taskana-rest-spring-example-boot app
to work properly after migration to Spring Boot 3.1
This commit is contained in:
arolfes 2023-11-14 22:16:09 +01:00
parent 459c19dd51
commit 5ec0422acf
8 changed files with 21 additions and 12 deletions

View File

@ -51,7 +51,7 @@ public class CurrentUserContextImpl implements CurrentUserContext {
@Override @Override
@SuppressWarnings("removal") @SuppressWarnings("removal")
public List<String> getGroupIds() { public List<String> getGroupIds() {
// TODO replace with Subject.current() when migrating to newer Version then 17 // TODO replace with Subject.current() when migrating to newer Version than 17
Subject subject = Subject.getSubject(AccessController.getContext()); Subject subject = Subject.getSubject(AccessController.getContext());
LOGGER.trace("Subject of caller: {}", subject); LOGGER.trace("Subject of caller: {}", subject);
if (subject != null) { if (subject != null) {
@ -129,7 +129,7 @@ public class CurrentUserContextImpl implements CurrentUserContext {
@SuppressWarnings("removal") @SuppressWarnings("removal")
private String getUserIdFromJaasSubject() { private String getUserIdFromJaasSubject() {
// TODO replace with Subject.current() when migrating to newer Version then 17 // TODO replace with Subject.current() when migrating to newer Version than 17
Subject subject = Subject.getSubject(AccessController.getContext()); Subject subject = Subject.getSubject(AccessController.getContext());
LOGGER.trace("Subject of caller: {}", subject); LOGGER.trace("Subject of caller: {}", subject);
if (subject != null) { if (subject != null) {

View File

@ -13,6 +13,7 @@ import org.springframework.security.config.Customizer;
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.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.annotation.web.configurers.RequestCacheConfigurer;
import org.springframework.security.config.ldap.LdapPasswordComparisonAuthenticationManagerFactory; import org.springframework.security.config.ldap.LdapPasswordComparisonAuthenticationManagerFactory;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
@ -88,6 +89,7 @@ public class BootWebSecurityConfigurer {
} else { } else {
addLoginPageConfiguration(http); addLoginPageConfiguration(http);
} }
http.requestCache(RequestCacheConfigurer::disable);
return http.build(); return http.build();
} }
@ -123,7 +125,12 @@ public class BootWebSecurityConfigurer {
authorizeHttpRequests -> authorizeHttpRequests.anyRequest().fullyAuthenticated()) authorizeHttpRequests -> authorizeHttpRequests.anyRequest().fullyAuthenticated())
.formLogin( .formLogin(
formLogin -> formLogin ->
formLogin.loginPage("/login").failureUrl("/login?error").defaultSuccessUrl("/")) formLogin
.loginPage("/login")
.failureUrl("/login?error")
.defaultSuccessUrl("/index.html")
.permitAll()
)
.logout( .logout(
logout -> logout ->
logout logout
@ -131,7 +138,9 @@ public class BootWebSecurityConfigurer {
.clearAuthentication(true) .clearAuthentication(true)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login?logout") .logoutSuccessUrl("/login?logout")
.deleteCookies("JSESSIONID")); .deleteCookies("JSESSIONID")
.permitAll()
);
} }
protected JaasApiIntegrationFilter jaasApiIntegrationFilter() { protected JaasApiIntegrationFilter jaasApiIntegrationFilter() {

View File

@ -1,5 +1,5 @@
logging.level.pro.taskana=INFO logging.level.pro.taskana=INFO
logging.level.org.springframework.security=INFO logging.level.org.springframework=INFO
server.servlet.context-path=/taskana server.servlet.context-path=/taskana
taskana.routing.dmn.upload.path=/tmp/routing.dmn taskana.routing.dmn.upload.path=/tmp/routing.dmn
######## Taskana DB ####### ######## Taskana DB #######

View File

@ -19,7 +19,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" "classpath:/static/", "classpath:/public/", "classpath:/templates/"
}; };
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;

View File

@ -5,10 +5,10 @@ import org.springframework.web.bind.annotation.GetMapping;
/** The view controller. */ /** The view controller. */
@Controller @Controller
public class ViewController { public class TaskanaRedirectToIndexHtmlController {
@GetMapping(path = {"", "taskana/**"}) @GetMapping(path = {"", "taskana/**"})
public String index() { public String index() {
return "forward:/index.html"; return "redirect:/index.html";
} }
} }

View File

@ -56,7 +56,7 @@ public class ElytronToJaasFilter extends GenericFilterBean {
@SuppressWarnings("removal") @SuppressWarnings("removal")
private Subject obtainSubject() { private Subject obtainSubject() {
// TODO replace with Subject.current() when migrating to newer Version then 17 // TODO replace with Subject.current() when migrating to newer Version than 17
Subject subject = Subject.getSubject(java.security.AccessController.getContext()); Subject subject = Subject.getSubject(java.security.AccessController.getContext());
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Current JAAS subject: " + subject); logger.debug("Current JAAS subject: " + subject);

View File

@ -68,7 +68,7 @@ public class SpringSecurityToJaasFilter extends GenericFilterBean {
if (authentication.isEmpty() || !authentication.get().isAuthenticated()) { if (authentication.isEmpty() || !authentication.get().isAuthenticated()) {
return Optional.empty(); return Optional.empty();
} }
// TODO replace with Subject.current() when migrating to newer Version then 17 // TODO replace with Subject.current() when migrating to newer Version than 17
return Optional.of(Subject.getSubject(AccessController.getContext())); return Optional.of(Subject.getSubject(AccessController.getContext()));
} }

View File

@ -67,8 +67,8 @@ public class SpringSecurityToJaasFilter extends GenericFilterBean {
if (authentication.isEmpty() || !authentication.get().isAuthenticated()) { if (authentication.isEmpty() || !authentication.get().isAuthenticated()) {
return Optional.empty(); return Optional.empty();
} }
// TODO replace with Subject.current() when migrating to newer Version then 17 // TODO replace with Subject.current() when migrating to newer Version than 17
return Optional.of(Subject.getSubject(AccessController.getContext())); return Optional.ofNullable(Subject.getSubject(AccessController.getContext()));
} }
Optional<Authentication> getCurrentAuthentication() { Optional<Authentication> getCurrentAuthentication() {