我是Spring Security中的開發成功和失敗處理程序。AuthenticationFailureHandler內部的Spring Mobile未找到
取決於設備類型我必須顯示一個html視圖或發送一個json響應。爲此我使用Spring Mobile,但是當我用HtttpServletRequest創建Device對象時沒有找到。一些想法?
的web.xml
<filter>
<filter-name>deviceResolverRequestFilter</filter-name>
<filter-class>org.springframework.mobile.device.DeviceResolverRequestFilter</filter-class>
</filter>
的applicationContext.xml
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
</mvc:argument-resolvers>
</mvc:annotation-driven>
類
public class AuthFailureHandler implements AuthenticationFailureHandler{
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException ae) throws IOException, ServletException {
Device device = DeviceUtils.getCurrentDevice(request);
if(device.isNormal()){
response.sendRedirect(response.encodeRedirectURL("./userNoAuth"));
} else {
response.sendRedirect(response.encodeRedirectURL("./rest/userNoAuth"));
}
}
}
錯誤
java.lang.NullPointerException at com.myapp.security.handler.AuthFailureHandler.onAuthenticationFailure(AuthFailureHandler.java:19)
UPDATE:
我改變.getCurrentDevice(HttpServletRequest的)方法來getRequiredCurrentDevice(HttpServletRequest的)。
現在我得到這個錯誤。
java.lang.IllegalStateException: No currenet device is set in this request and one is required - have you configured a DeviceResolvingHandlerInterceptor?
我的web.xml這個配置已經... – Dani