我使用基本的auth和spring安全性(JWT令牌) (Springboot)的组合。
我有以下设置: web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>det</display-name>
<description>det</description>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<security-constraint>
<web-resource-collection>
<web-resource-name>images</web-resource-name>
<url-pattern>/images/*</url-pattern>
</web-resource-collection>
<!-- OMIT auth-constraint -->
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Application</web-resource-name>
<url-pattern>/login</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>User</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>因此,登录服务返回一个JWT令牌。然后spring安全性接管并使用令牌来验证rest服务的使用。
这一切都有效。我只有一个问题。当用户发送错误的凭据时,我得到一个401错误,弹出窗口就会出现。我想避免这件事。我尝试使用一个过滤器来更改响应代码,但是它似乎没有被触发。
我该怎么解决这个问题。
发布于 2022-01-19 13:45:41
我找到了解决方案,对401个错误使用了一个错误servlet,并从响应头中删除了WWW-身份验证值。
https://stackoverflow.com/questions/70769858
复制相似问题