【问题标题】:A problem with the Spring MVC and Spring Security configurationSpring MVC 和 Spring Security 配置的问题
【发布时间】:2018-12-16 16:17:38
【问题描述】:

我正在用 Java 做一个 Web 应用程序项目,我在使用 Spring Security 保护应用程序时遇到了问题,即我的配置不起作用,我尝试了几种配置 Spring Security 的方法,但它不能保护应用。 我向任何将帮助我完成此配置的人鞠躬。下面是依赖项和配置类。我请求原谅,我是一个初学者程序员。提前谢谢你

【问题讨论】:

  • 嗨,首先通过这个-meta.stackoverflow.com/questions/285551/…,其次请解释您的问题,可能是您遇到的一些代码和错误,谢谢
  • 请在问题正文中包含代码作为文本(缩进四个空格,以便它显示为代码格式),而不是图像。这使代码更易于阅读,特别是对于视力不佳且拥有辅助技术(例如备用字体或屏幕阅读器)的用户。

标签: java spring


【解决方案1】:

好的,所以问题是我有一个 MVC 和安全配置,但是安全配置根本不起作用,控制台中没有错误。标记 url 地址不起作用。对于我是新用户的组织,我很抱歉。

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {


@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/find").denyAll()
            .anyRequest().authenticated()
            .and().formLogin().and().httpBasic();

}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    super.configure(auth);

    auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}

}

 <!--Spring Security-->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>

【讨论】:

  • 所以,问题是当我运行应用程序并点击任何 url(甚至“/ find”)时,没有一个被阻止,只会继续。我在这方面有问题。
  • 不要添加其他信息作为答案,而是编辑您的问题并在其中添加信息。
猜你喜欢
  • 2011-01-08
  • 2018-02-02
  • 2016-12-17
  • 1970-01-01
  • 2015-11-19
  • 1970-01-01
  • 1970-01-01
  • 2017-01-27
  • 1970-01-01
相关资源
最近更新 更多