Springboot在网络上工作,但在邮递员中不起作用吗?

发布于 2025-02-12 08:43:33 字数 714 浏览 1 评论 0原文

我正在尝试构建具有春季安全性的真正基本的用户/角色CRUD。

我创建了两种帐户类型:管理员和用户。

进入此URL后:http:// localhost:8080/api/v1/员工首先登录,然后得到结果

当我尝试通过Postman连接时,问题开始。我无法超越登录。

无论如何我都无法超越登录。我尝试了其他控制器,但同样的事情也发生了。

我做错了吗?我错过了一步吗?

I'm trying to build to build a really basic user/role CRUD with spring security.

I created 2 types of accounts: admin and user.

After I go to this URL: http://localhost:8080/api/v1/employees first I get login and after that I get the result
Sign in

Result of URL

The problem start when I try to connect via postman. I can't get past the login.
Login fail

I can't get past the login no matter what. I tried other controller but the same thing happens.

Am I doing something wrong? Am I missing a step?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2025-02-19 08:43:33

昨天我遇到了这个问题,很可能是同一回事。

我禁用了websecurityConfigurerAdapter的类中的CSRF,以使其工作。如果您要进入生产,则可能应该使其启用。

我的websecurityconfig类:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .antMatchers("/").permitAll();
    }
}

我不完全了解CSRF保护是如何保护的,因此如果您尝试从浏览器登录,可能会有问题。输出.csrf()。disable()

I had this problem yesterday, it's most likely the same thing.

I disabled csrf in the class that extends WebSecurityConfigurerAdapter to get it to work. If you're moving into production, you should probably leave it enabled.

My WebSecurityConfig class:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .antMatchers("/").permitAll();
    }
}

I don't fully understand how the csrf protection so there might be issues if you try to log in from a browser. Uncomment out the .csrf().disable() when you want to run in from a browser

花间憩 2025-02-19 08:43:33

要在Postman中打电话,您需要在调用端点时通过适当的授权(令牌标头/cookie)。在您当前的情况下,Postman要么向您显示一个登录页面,即您看到的HTML,或者是错误页面,因为未经授权

To make a call in Postman, you need to pass a proper authorization (token header/cookie) when calling an endpoint. In your current case, Postman either shows you a login page which is that HTML you see, or an error page because unauthorized

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文