Parameter 0 of method filterChain in dorinca_client.config.DorincaSpringSecurityConfig required a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' that could not be found.
My project setup is "simple", as shown below:
@Configuration
// http://docs.spring.io/spring-boot/docs/current/reference/html/howto-security.html
// Switch off the Spring Boot security configuration
//@EnableWebSecurity
public class DorincaSpringSecurityConfig {
@Autowired
private AccessDeniedHandler accessDeniedHandler;
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
// roles admin allow to access /admin/**
// roles user allow to access /user/**
// custom 403 access denied handler
@Bean
protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/", "/css/**", "/js/**", "/gfx/**","/text/**").permitAll()
.antMatchers("/dashboard/**").hasAnyRole("ADMIN")
.antMatchers("/dashboard/**").hasAnyRole("USER")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/", true) // testing forwarding to success page after login success.
.permitAll()
.and()
.logout()
.permitAll()
.and()
.exceptionHandling().accessDeniedHandler(accessDeniedHandler);
return http.build();
}
@Bean
public UserDetailsService users() {
UserDetails user = User.builder()
.username("user")
.password("$2a$12$uCNqI/ReIfRsZ/A/dfTl9O1LQCfiZhJ7AHctjBOQWdR9xSspaMa6m")
.roles("USER")
.build();
UserDetails admin = User.builder()
.username("admin")
.password("$2a$12$uCNqI/ReIfRsZ/A/dfTl9O1LQCfiZhJ7AHctjBOQWdR9xSspaMa6m")
.roles("USER", "ADMIN")
.build();
// return new InMemoryUserDetailsManager(user, admin);
InMemoryUserDetailsManager userDetailsManager = new InMemoryUserDetailsManager();
userDetailsManager.createUser(user);
userDetailsManager.createUser(admin);
return userDetailsManager;
}
@EnableAutoConfiguration
@SpringBootApplication
public class DorincaSpringBootWebApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
return application.sources(DorincaSpringBootWebApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DorincaSpringBootWebApplication.class, args);
}
}
pom.xml:
<dependencies>
<!-- Compile -->
<dependency>
<groupId>dorinca</groupId>
<artifactId>dorinca-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<!-- hot swapping, disable cache for template, enable live reload -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- Optional, for bootstrap -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-08-25 14:02:28.624 ERROR 24801 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method filterChain in dorinca_client.config.DorincaSpringSecurityConfig required a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' in your configuration.
here is my DorincaSpringSecurityConfig class:
package dorinca_client.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.access.AccessDeniedHandler;
@Configuration
// http://docs.spring.io/spring-boot/docs/current/reference/html/howto-security.html
// Switch off the Spring Boot security configuration
@EnableWebSecurity
public class DorincaSpringSecurityConfig {
@Autowired
private AccessDeniedHandler accessDeniedHandler;
// @Bean
// public UserDetailsService userDetailsService() {
// return new ShopmeUserDetailsService();
// }
// @Autowired
// public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//
// auth.inMemoryAuthentication()
// .withUser("user").password("password").roles("USER")
// .and()
// .withUser("admin").password("password").roles("ADMIN");
// }
@Bean
public UserDetailsService users() {
UserDetails user = User.builder()
.username("user")
.password("$2a$12$uCNqI/ReIfRsZ/A/dfTl9O1LQCfiZhJ7AHctjBOQWdR9xSspaMa6m")
.roles("USER")
.build();
UserDetails admin = User.builder()
.username("admin")
.password("$2a$12$uCNqI/ReIfRsZ/A/dfTl9O1LQCfiZhJ7AHctjBOQWdR9xSspaMa6m")
.roles("USER", "ADMIN")
.build();
// return new InMemoryUserDetailsManager(user, admin);
InMemoryUserDetailsManager userDetailsManager = new InMemoryUserDetailsManager();
userDetailsManager.createUser(user);
userDetailsManager.createUser(admin);
return userDetailsManager;
}
/*
//Spring Boot configured this already.
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**");
}*/
}
--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/e19ebadb-d912-453f-b36a-db8b03bed83bn%40googlegroups.com.
14:31:27,875 INFO [stdout] (ServerService Thread Pool -- 110) 2022-08-25 14:31:27.875 INFO 25157 --- [ead Pool -- 110] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
14:31:28,078 INFO [stdout] (ServerService Thread Pool -- 110) 2022-08-25 14:31:28.078 INFO 25157 --- [ead Pool -- 110] d.DorincaSpringBootWebApplication : Started DorincaSpringBootWebApplication in 1.98 seconds (JVM running for 48.037)
14:31:28,100 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 110) Initializing Mojarra 2.3.17.SP01 for context ''
14:31:28,360 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 110) MSC000001: Failed to start service jboss.deployment.unit."dorinca-client-1.2.war".undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.unit."dorinca-client-1.2.war".undertow-deployment: java.lang.RuntimeException: java.lang.ClassCastException: class org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to class io.undertow.websockets.jsr.ServerWebSocketContainer (org.apache.tomcat.websocket.server.WsServerContainer is in unnamed module of loader 'deployment.dorinca-client-1.2.war' @5f255baa; io.undertow.websockets.jsr.ServerWebSocketContainer is in unnamed module of loader 'io.underto...@2.2.17.Final' @33ce90b9)
at org.wildfly.ext...@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:90)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jbos...@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:833)
at org.jbos...@2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: class org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to class io.undertow.websockets.jsr.ServerWebSocketContainer (org.apache.tomcat.websocket.server.WsServerContainer is in unnamed module of loader 'deployment.dorinca-client-1.2.war' @5f255baa; io.undertow.websockets.jsr.ServerWebSocketContainer is in unnamed module of loader 'io.underto...@2.2.17.Final' @33ce90b9)
at io.undert...@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:257)
at org.wildfly.ext...@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:105)
at org.wildfly.ext...@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:87)
... 8 more
Caused by: java.lang.ClassCastException: class org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to class io.undertow.websockets.jsr.ServerWebSocketContainer (org.apache.tomcat.websocket.server.WsServerContainer is in unnamed module of loader 'deployment.dorinca-client-1.2.war' @5f255baa; io.undertow.websockets.jsr.ServerWebSocketContainer is in unnamed module of loader 'io.underto...@2.2.17.Final' @33ce90b9)
at io.underto...@2.2.17.Final//io.undertow.websockets.jsr.Bootstrap$WebSocketListener.contextInitialized(Bootstrap.java:119)
at io.undert...@2.2.17.Final//io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
at io.undert...@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:219)
at io.undert...@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:187)
at io.undert...@2.2.17.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undert...@2.2.17.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.ext...@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.ext...@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.ext...@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at org.wildfly.ext...@26.1.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1544)
at io.undert...@2.2.17.Final//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:255)
... 10 more
14:31:28,372 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "dorinca-client-1.2.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"dorinca-client-1.2.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.ClassCastException: class org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to class io.undertow.websockets.jsr.ServerWebSocketContainer (org.apache.tomcat.websocket.server.WsServerContainer is in unnamed module of loader 'deployment.dorinca-client-1.2.war' @5f255baa; io.undertow.websockets.jsr.ServerWebSocketContainer is in unnamed module of loader 'io.underto...@2.2.17.Final' @33ce90b9)
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: class org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to class io.undertow.websockets.jsr.ServerWebSocketContainer (org.apache.tomcat.websocket.server.WsServerContainer is in unnamed module of loader 'deployment.dorinca-client-1.2.war' @5f255baa; io.undertow.websockets.jsr.ServerWebSocketContainer is in unnamed module of loader 'io.underto...@2.2.17.Final' @33ce90b9)
Caused by: java.lang.ClassCastException: class org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to class io.undertow.websockets.jsr.ServerWebSocketContainer (org.apache.tomcat.websocket.server.WsServerContainer is in unnamed module of loader 'deployment.dorinca-client-1.2.war' @5f255baa; io.undertow.websockets.jsr.ServerWebSocketContainer is in unnamed module of loader 'io.underto...@2.2.17.Final' @33ce90b9)"}}
14:31:28,454 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "dorinca-client-1.2.war" (runtime-name : "dorinca-client-1.2.war")
14:31:28,457 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.deployment.unit."dorinca-client-1.2.war".undertow-deployment: java.lang.RuntimeException: java.lang.ClassCastException: class org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to class io.undertow.websockets.jsr.ServerWebSocketContainer (org.apache.tomcat.websocket.server.WsServerContainer is in unnamed module of loader 'deployment.dorinca-client-1.2.war' @5f255baa; io.undertow.websockets.jsr.ServerWebSocketContainer is in unnamed module of loader 'io.underto...@2.2.17.Final' @33ce90b9)
WFLYCTL0448: 1 additional services are down due to their dependencies being missing or failed