相关疑难解决方法(0)

Spring安全方法无法确定模式是MVC还是不是Spring Boot应用程序异常

当我尝试运行应用程序时,它无法启动并抛出此异常。

该方法无法判断这些模式是否是 Spring MVC 模式。如果此端点是 Spring MVC 端点,请使用 requestMatchers(MvcRequestMatcher); 否则,请使用 requestMatchers(AntPathRequestMatcher)。

我是 Spring Security 的新手。请帮我解决这个错误。

这是我的 spring 安全配置类

package com.ronit.SpringSecurityTutorial.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@Configuration
public class SecurityConfiguration {

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    AuthenticationManager authManager(UserDetailsService detailsService) {
        DaoAuthenticationProvider daoProvider = new DaoAuthenticationProvider();
        daoProvider.setUserDetailsService(detailsService);
        return new ProviderManager(daoProvider);
    }

    @SuppressWarnings("removal")
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception …
Run Code Online (Sandbox Code Playgroud)

java eclipse backend spring-security spring-boot

30
推荐指数
2
解决办法
3万
查看次数

在Spring Security Java Config中创建多个HTTP部分

使用Spring Security XML配置,您可以定义多个HTTP元素,以便为应用程序的不同部分指定不同的访问规则.8.6高级命名空间配置中给出的示例定义了应用程序的单独的有状态和无状态部分,前者使用会话和表单登录,后者不使用会话和BASIC身份验证:

<!-- Stateless RESTful service using Basic authentication -->
<http pattern="/restful/**" create-session="stateless">
    <intercept-url pattern='/**' access='ROLE_REMOTE' />
    <http-basic />
</http>

<!-- Empty filter chain for the login page -->
<http pattern="/login.htm*" security="none"/>

<!-- Additional filter chain for normal users, matching all other requests -->
<http>
    <intercept-url pattern='/**' access='ROLE_USER' />
    <form-login login-page='/login.htm' default-target-url="/home.htm"/>
    <logout />
</http>
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何使用Java Config做同样的事情.重要的是我禁用会话并为我的Web服务使用不同的入口点.现在我有以下内容:

@Override
public void configure(WebSecurity security)
{
    security.ignoring().antMatchers("/resource/**", "/favicon.ico");
}

@Override
protected void configure(HttpSecurity security) throws Exception
{
    security
            .authorizeRequests()
                .anyRequest().authenticated() …
Run Code Online (Sandbox Code Playgroud)

java config spring-security

26
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×2

spring-security ×2

backend ×1

config ×1

eclipse ×1

spring-boot ×1