当前位置: 首页 > 知识库问答 >
问题:

为什么Spring Security应用程序重定向到登录页面,虽然我们没有提供Spring Security配置?

巫马劲
2023-03-14

我不提供任何Spring Security配置和每个请求URL重定向到登录页面。我使用“Spring Initializr”创建了一个Spring Boot应用程序,该应用程序具有所需的Spring Security性依赖项。

@SpringBootApplication
public class SpringbootJwtExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootJwtExampleApplication.class, args);
    }

}

public interface VehicleRepository extends JpaRepository<Vehicle, Long> {
}


@Data
@Entity
public class Vehicle {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
}


@RestController
@RequestMapping("/v1/vehicles")
public class VehicleController {

    @Autowired
    private VehicleRepository vehicleRepository;

    @GetMapping("")
    public ResponseEntity getAll(){
        return ok(vehicleRepository.findAll());
    }
}

共有1个答案

施永贞
2023-03-14

根据Spring Security文档,WebSecurityConfigurerAdapter类提供以下默认配置:

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .and()
        .httpBasic();
}

要重写这些默认值,请编写您自己的WebSecurityConfig,例如:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // Your own rules
    }
}
 类似资料:
  • 设置如下:嵌入式Jetty 9.3.0.M0运行一个GuiceServlet 3.0,它反过来使用Jersey 1.18.1进行映射和它可以做的所有其他漂亮的事情。Shiro 1.2.3被添加到此设置中以提供安全性。在一般情况下配置Shiro和ShiroWebModule中的FilterChain时,设置工作正常。 当使用Shiro的AOP特性用Shiro的注释来注释我的方法时,对被注释方法的UR

  • 记录器文件中的日志- org.springframework.Security.Access.event.loggerlistener-安全授权失败,原因是:org.springframework.Security.Access.accessdeniedexception:访问被拒绝;通过身份验证的主体:org.springframework.security.authentication.ano

  • 我现在一直在努力使用我的登录页面来让组件呈现Loggedin组件。我的前端是Reactjs,后端是NodeJS。我对nodejs、expression和react都是新手。 在loginform组件上,我使用fetch进行了一次post,它将用户名和密码传递给后端的相应endpoint。没问题。在后端,它读取我存储用户(不使用任何数据库)的jsonfile来查找匹配项,如果用户名和密码都匹配,则它

  • 本文向大家介绍SpringSecurity 默认表单登录页展示流程源码,包括了SpringSecurity 默认表单登录页展示流程源码的使用技巧和注意事项,需要的朋友参考一下 SpringSecurity 默认表单登录页展示流程源码 本篇主要讲解 SpringSecurity提供的默认表单登录页 它是如何展示的的流程, 涉及 1.FilterSecurityInterceptor, 2.Excep

  • 我在Laravel框架中的HomeController.php中有一段代码,但是我无法访问它重定向到登录页面的索引/主页。我犯了什么大错?

  • 我在地址栏中输入的任何链接都会将我重定向到登录页面。我该怎么防止呢? 例如如果我加上http://localhost:8080/asdasdsa 我的安全配置: