从Spring Security捕获“CommunicationException”

时间:2015-09-10 12:25:06

标签: java spring spring-security

下午好,

我目前正在制作一个网络应用程序,对于可以在网络上和网络外的用户都必须可以访问。但在这两种情况下都需要身份验证。

问题是当我尝试通过网络进行身份验证时,我不知道如何捕获Spring安全性抛出的以下异常:

(适用javax.naming.CommunicationException)

   public ActionResult Contact()
    {
        ViewBag.Message = "Your contact page.";

        return View();
    }
    public ActionResult Contact(string str)
    {
        ViewBag.Message = "Your contact page by overloaded method";

        return View();
    }

这是我的“GlobalAuthenticationConfigurerAdapter”适配器:

org.springframework.security.authentication.InternalAuthenticationServiceException: companyname.com:636; nested exception is javax.naming.CommunicationException: companyname.com:636 [Root exception is java.net.UnknownHostException: com.companyname]
at org.springframework.security.ldap.authentication.LdapAuthenticationProvider.doAuthentication(LdapAuthenticationProvider.java:191)
at org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider.authenticate(AbstractLdapAuthenticationProvider.java:80)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:177)
at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:92)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:211)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)

我的目标只是在ldap服务器不可用时实现“后备模式”。

您是否了解如何捕获异常甚至阻止它?

提前致谢。

0 个答案:

没有答案