Solución al problema de login con Spring
El problema tiene fácil solución, cargarse el patrón IOC (Inversión de Control) del que hace gala Spring.
Añadimos al applicationContext lo siguiente para las búsquedas:
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource" >
<property name="urls" value="ldap://172.19.133.153:389/" />
<property name="base" value="o=empleados,o=juntadeandalucia,c=es" />
<property name="dirObjectFactory" value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
<property name="ignorePartialResultException" value="true"/>
</bean>
<bean id="ILDAPSpring"
class="es.juntadeandalucia.servicedesk.model.connector.authorizations.LDAPSpring">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
Luego creamos el método login, donde realizamos una conexión sin pasar por el applicationContext.
public boolean login(String userid, String password, String strUserOrg) throws LDAPConnectionException, LDAPLoginException {
String user = "uid=" + userid + ",o=" + strUserOrg.trim() + "," + USERS_ROOT + "," + ROOT;
try {
LdapContextSource ctx = new LdapContextSource();
ctx.setUrl(URL);
ctx.setUserDn(user);
ctx.setPassword(password);
ctx.setCacheEnvironmentProperties(true);
ctx.setPooled(true);
ctx.setBase(ROOT);
ctx.afterPropertiesSet();
ctx.getReadWriteContext();
logger.info("User [" + user + "] ");
return true;
} catch (Exception e) {
logger.info("FAILED --- User [" + user + "] can not System.out.println");
return false;
}
}

Escribe un comentario