Tag Archives: Spring

Spring LdapTemplate 连接 LDAP 服务器缓慢的问题

同时有两个windows AD, 配置相同,代码相同,一个速度超快,一个慢的要死,差不多要10秒

还好spring ldap 是开源的,看源码查看其实运行速度很快,只有其中遍历的时候比较慢。 于是就想到可能是没有设置base

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="url" value="ldap://192.168.1.1:389/dc=go,dc=local"/>
        <property name="userDn" value="cn=root"/>
        <property name="password" value="password"/>
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
        <property name="contextSource" ref="contextSource"/>
</bean>

修改后如下

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="url" value="ldap://192.168.1.1:389/dc=go,dc=local"/>
        <property name="userDn" value="cn=root"/>
        <property name="base" value="OU=User,dc=go,dc=local" />
        <property name="password" value="password"/>
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
        <property name="contextSource" ref="contextSource"/>
</bean>

 

红色部分根据自己的情况来定,你可以用ADExplorer 来查看这部分内容

在filter 中使用spring

filter是容器在启动的时候就创建的,Spring 好像有点力不从心。

还好可以手动在filter的init方法中添加, 如下:
[java]

/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
ApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
this.ldapUserDao = (LdapUserDAO) context.getBean(“LdapUserDAO”);
this.tempAclDAO = (TempAclDAO) context.getBean(“tempAclDAO”);
}
[/java]

Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition

Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition

让人蛋疼的错误,找了好久不知道是什么原因,最后看源码,原来spring自动帮我加我flushmode = 手动。 明明在web.xml里面已经配置过了的,最后发现原来是有我自己的安全方法,哎。。。。

 

如下[java]












[/java]

加上你的方法表达式就可以了

Spring Security virtual URLs

Spring Security virtual URLs

下述为Spring Security的虚路由,它与应用程序无关,默认映射在应用的根路径上:
/j_spring_security_check 

— checked by UsernamePasswordAuthenticationFilter for username/password form
authentication.
/j_spring_openid_security_check

— checked by OpenIDAuthenticationFilter for OpenID returning authentication
(from the OpenID provider).
/j_spring_cas_security_check

—used by CAS authentication upon return from CAS SSO login.
/spring_security_login

—the URL used by the DefaultLoginPageGeneratingFilter when configured to auto-generate
a login page.
/j_spring_security_logout

—used by LogoutFilter to detect a log out action.
/saml/SSO

—used by the Spring Security SAML SSO extension SAMLProcessingFilter to process a SAML SSO sign-on request.
/saml/logout

—used by the Spring Security SAML SSO extension SAMLLogoutFilter to process a SAML SSO sign-out request.
/j_spring_security_switch_user

—used by the SwitchUserFilter to switch users to another user.
/j_spring_security_exit_user

—used to exit the switch user functionality.