Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从自定义身份验证提供程序类更改Json格式的BadCredentialsException、UserNameNotFound异常消息_Java_Angularjs_Json_Spring_Spring Security - Fatal编程技术网

Java 如何从自定义身份验证提供程序类更改Json格式的BadCredentialsException、UserNameNotFound异常消息

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

我尝试了不同的方法,但到目前为止都没有效果,仍然无法以json格式从我的自定义身份验证提供程序发送异常响应

我尝试过的事情

1.customAuthenticationFailureHandler

2客户点

3.1拒绝接受

我在前端有angular js,如果身份验证失败,我想要一条json消息,但现在我想到了BadCredentialsException、UsernotFoundException,并在rest客户端中获取HTML数据


任何帮助…

好的,所以我得到了问题的答案

您必须编写实现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>