/** * @see org.projectforge.business.ldap.LdapLoginHandler#initialize() */ @Override public void initialize() { super.initialize(); if (StringUtils.isBlank(ldapConfig.getManagerUser()) == true) { mode = Mode.SIMPLE; } else if (StringUtils.isNotBlank(ldapConfig.getGroupBase()) == true) { mode = Mode.USERS;// Mode.USER_GROUPS; log.warn("Groups aren't yet supported by this LDAP handler."); } else { mode = Mode.USERS; } switch (mode) { case SIMPLE: log.info("LDAP slave login handler works in mode 'simple'."); break; case USERS: log.info("LDAP slave login handler works in mode 'users'."); break; case USER_GROUPS: log.info("LDAP slave login handler works in mode 'user_groups'."); break; } }
public LdapContext createContext() { init(); final Hashtable<String, String> env; final String authentication = ldapConfig.getAuthentication(); if ("none".equals(authentication) == false) { env = createEnv(ldapConfig.getManagerUser(), ldapConfig.getManagerPassword()); } else { env = createEnv(null, null); } try { final LdapContext ctx = new InitialLdapContext(env, null); return ctx; } catch (final NamingException ex) { log.error("While trying to connect LDAP initally: " + ex.getMessage(), ex); throw new RuntimeException(ex); } }
public LdapUser authenticate(final String username, final String userPassword, final String... organizationalUnits) { String dn; LdapUser user = null; final String searchBase = getSearchBase(organizationalUnits); if (StringUtils.isNotBlank(ldapConfig.getManagerUser()) == true && StringUtils.isNotBlank(ldapConfig.getManagerPassword()) == true) { user = findByUsername(username, searchBase); if (user == null || StringUtils.equals(username, user.getId()) == false) { log.info("User with id '" + username + "' not found."); return null; } dn = user.getDn() + "," + ldapConnector.getBase(); } else { dn = "uid=" + username + "," + searchBase + "," + ldapConnector.getBase(); } try { ldapConnector.createContext(dn, userPassword); log.info("User '" + username + "' (" + dn + ") successfully authenticated."); return user; } catch (final Exception ex) { log.error("User '" + username + "' (" + dn + ") with invalid credentials."); return null; } }