Apache Shiro - 浏览器 URL 仅在使用网站导航时有效

Apache Shiro - Browser URL only works when using the website to navigate

我在后端使用 Java (maven),在 Shiro 的前端使用 Angular 2。只要我使用该网站,我就可以导航到不同的 URL。手动输入 URL 会导致 404 错误。

我不确定问题出在 Angular(因为它使用单个 index.html 页面)还是出在 shiro.ini 中的 [URL] 部分。

[URL] 部分留空或添加 /index.html = anon 继续导致同样的问题。

此外,使用 authc 会将我重定向到 login.jsp。

我怎样才能允许访问每条路线而不考虑用户status/role?

这可能是服务器端问题(不是 Shiro)。首先要检查的几件事是您是否使用 HTML5 模式(这听起来像是基于您的问题)。如果您是,则必须处理 angular 路由(并将它们转发到您的 index.html 页面)

您可以使用 rewrite servlet to handle this. Here is one example of this.

有几种不同的方法来处理转发,您也可以只编写一个简单的 servlet 或过滤器。