Search in sources :

Example 1 with LdapDirContextAdapter

use of com.evolveum.midpoint.authentication.impl.ldap.LdapDirContextAdapter in project midpoint by Evolveum.

the class MidPointLdapAuthenticationProvider method doAuthentication.

protected DirContextOperations doAuthentication(DirContextOperations originalDirContextOperations) {
    if (originalDirContextOperations instanceof DirContextAdapter) {
        Authentication actualAuthentication = SecurityContextHolder.getContext().getAuthentication();
        if (actualAuthentication instanceof MidpointAuthentication) {
            MidpointAuthentication mpAuthentication = (MidpointAuthentication) actualAuthentication;
            ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) getProcessingModule(mpAuthentication);
            if (moduleAuthentication instanceof LdapModuleAuthentication) {
                // HACK because of NP in DirContextAdapter(DirContextAdapter master)
                if (!originalDirContextOperations.isUpdateMode()) {
                    ((DirContextAdapter) originalDirContextOperations).setUpdateMode(true);
                    ((DirContextAdapter) originalDirContextOperations).setUpdateMode(false);
                }
                LdapDirContextAdapter mpDirContextAdapter = new LdapDirContextAdapter((DirContextAdapter) originalDirContextOperations);
                mpDirContextAdapter.setNamingAttr(((LdapModuleAuthentication) moduleAuthentication).getNamingAttribute());
                if (moduleAuthentication.getFocusType() != null) {
                    Class<FocusType> focusType = PrismContext.get().getSchemaRegistry().determineCompileTimeClass(moduleAuthentication.getFocusType());
                    mpDirContextAdapter.setFocusType(focusType);
                }
                return mpDirContextAdapter;
            }
        }
    }
    return originalDirContextOperations;
}
Also used : LdapDirContextAdapter(com.evolveum.midpoint.authentication.impl.ldap.LdapDirContextAdapter) ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) LdapModuleAuthentication(com.evolveum.midpoint.authentication.impl.module.authentication.LdapModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) LdapDirContextAdapter(com.evolveum.midpoint.authentication.impl.ldap.LdapDirContextAdapter) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) LdapModuleAuthentication(com.evolveum.midpoint.authentication.impl.module.authentication.LdapModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Aggregations

MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)1 LdapDirContextAdapter (com.evolveum.midpoint.authentication.impl.ldap.LdapDirContextAdapter)1 LdapModuleAuthentication (com.evolveum.midpoint.authentication.impl.module.authentication.LdapModuleAuthentication)1 ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl)1 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)1 Authentication (org.springframework.security.core.Authentication)1