2014-03-24 76 views
0

我收到一個奇怪的錯誤。如果我將一個有效的用戶名/密碼傳遞給我的Shiro LDAP,那麼一切正常,但如果組合無效,則會引發異常並繼續通過Shiro領域代碼進行循環。在調試器中,它只停留在Shiro代碼中,除了我的一個覆蓋方法:通過Shiro LDAP域環境進行身份驗證失敗

public class MyJndiLdapRealm extends JndiLdapRealm { 


public MyJndiLdapRealm() { 
    super(); 
} 

@Override 
protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token, 
     LdapContextFactory ldapContextFactory) 
throws NamingException { 

Object principal = token.getPrincipal(); 
Object credentials = token.getCredentials(); 

principal = getLdapPrincipal(token); 

LdapContext ctx = null; 
try { 
    ctx = ldapContextFactory.getLdapContext(principal, credentials); 

    //context was opened successfully, which means their credentials were valid. Return the AuthenticationInfo: 
    return createAuthenticationInfo(token, principal, credentials, ctx); 
} finally { 
    LdapUtils.closeContext(ctx); 
} 

} 



      <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> 
    <property name="securityManager" ref="securityManager"/> 
    <property name="loginUrl" value="/ldapLogin"/> 
    <property name="unauthorizedUrl" value="/ldapLogin"/> 
    <property name="successUrl" value="/ldapLogin"/>  
    <property name="filterChainDefinitions"> 
     <value> 
      [urls] 
      /** = ssl[8443],authc, customAuthFilter 
      [main] 
      /logout = logout 
     </value> 
    </property> 
</bean> 

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> 
    <property name="realms"> 
     <list> 
      <ref bean="authenticateLdapRealm"/> 
      <ref bean="authenticateDbRolesRealm"/> 
      <ref bean="DbAuthorizingRealm"/> 
     </list> 
    </property> 
    <property name="authenticator.authenticationStrategy"> 
     <bean class="org.apache.shiro.authc.pam.AllSuccessfulStrategy"/> 
    </property> 
</bean> 

<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/> 

<bean id="authenticateLdapRealm" class="security.MyJndiLdapRealm"> 
    <property name="contextFactory" ref="contextFactory" /> 
    <property name="userDnTemplate" value="cn={0},ou=REMOTE,o=OFF" /> 
</bean> 

<bean id="contextFactory" class="org.apache.shiro.realm.ldap.JndiLdapContextFactory"> 
    <property name="url" value="ldap://172.25.3.91:389"/> 
</bean> 

<bean id="authenticateDbRolesRealm" class="security.DbRolesRealm"> 
</bean> 

<bean id="SwiDbAuthorizingRealm" class="security.DbAuthorizingRealm"> 
</bean> 

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/> 
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> 
    <property name="securityManager" ref="securityManager"/> 
</bean> 

回答

0

不知何故,我的自定義過濾器是問題。去了PassThruAuthenticationFilter並且問題解決了。