Java 如何从自定义身份验证提供程序类更改Json格式的BadCredentialsException、UserNameNotFound异常消息
我尝试了不同的方法,但到目前为止都没有效果,仍然无法以json格式从我的自定义身份验证提供程序发送异常响应 我尝试过的事情 1.customAuthenticationFailureHandler 2客户点 3.1拒绝接受 我在前端有angular js,如果身份验证失败,我想要一条json消息,但现在我想到了BadCredentialsException、UsernotFoundException,并在rest客户端中获取HTML数据Java 如何从自定义身份验证提供程序类更改Json格式的BadCredentialsException、UserNameNotFound异常消息,java,angularjs,json,spring,spring-security,Java,Angularjs,Json,Spring,Spring Security,我尝试了不同的方法,但到目前为止都没有效果,仍然无法以json格式从我的自定义身份验证提供程序发送异常响应 我尝试过的事情 1.customAuthenticationFailureHandler 2客户点 3.1拒绝接受 我在前端有angular js,如果身份验证失败,我想要一条json消息,但现在我想到了BadCredentialsException、UsernotFoundException,并在rest客户端中获取HTML数据 任何帮助…好的,所以我得到了问题的答案 您必须编写实现Au
任何帮助…好的,所以我得到了问题的答案 您必须编写实现AuthenticationEntryPoint接口的customAuthenticationEntryPoint类 在securtiy-config.xml文件中 您必须添加入口点ref=“restAuthenticationEntryPoint”
这里要注意的主要一点是,您必须在http和http基本标记中提供入口点ref
<http auto-config='true' use-expressions="true"
entry-point-ref="restAuthenticationEntryPoint">
<http-basic entry-point-ref="restAuthenticationEntryPoint"/>
<intercept-url pattern="/user" access="hasRole('ROLE_USER')" />
<access-denied-handler ref="securityAccessDeniedHandler" />
<form-login authentication-success-handler-ref="mySuccessHandler"
authentication-failure-handler-ref="authenticationFailureHandler" /></http>