我为Spring MVC应用程序实现了CORS。以下是我的Web.xml:
<filter>
<filter-name>simpleCORSFilter</filter-name>
<filter-class>com.tcs.filters.SimpleCORSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>simpleCORSFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
咨询CORS with spring-boot and angularjs not working后,我实施了SimpleCORSFilter.java
课程
现在我在Spring-security.xml文件中实现了以下内容:
<http
use-expressions="true" auto-config="false" create-session="stateless"
disable-url-rewriting="true" entry-point-ref="entryPoint"
authentication-manager-ref="authenticationManager">
<bean id="entryPoint" class="com.tcs.web.EntryPoint" />
但是当它正在执行时,它不会在下面的类中调用&#34;错误/不正确&#34; -password案例或正确密码案例。
因此,CORS配置阻止了对此的调用,但如果我删除了CORS,则调用UnauthorizedEntryPoint。
你能告诉我们如何恰当地调用它吗?
public class EntryPoint implements AuthenticationEntryPoint{
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException{
// here some custom code about user like values etc
String userid = request.getParameter("userId")
response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
"Unauthorized: Authentication token was either missing or invalid.");
}
}