private ErrorCode testAddLdapServerConnection(LdapServerInventory inv) { Map<String, Object> properties = new HashMap<>(); String timeout = Integer.toString(LdapGlobalProperty.LDAP_ADD_SERVER_CONNECT_TIMEOUT); properties.put("com.sun.jndi.ldap.connect.timeout", timeout); LdapTemplateContextSource ldapTemplateContextSource = new LdapUtil().loadLdap(inv, properties); try { AndFilter filter = new AndFilter(); // Any search conditions filter.and(new EqualsFilter(LdapConstant.LDAP_UID_KEY, "")); ldapTemplateContextSource.getLdapTemplate().authenticate("", filter.toString(), ""); logger.info("LDAP connection was successful"); } catch (Exception e) { logger.debug("Cannot connect to LDAP server", e); return operr("Cannot connect to LDAP server, %s", e.toString()); } return null; }
public boolean isValid(String uid, String password) { LdapTemplateContextSource ldapTemplateContextSource = readLdapServerConfiguration(); String ldapUseAsLoginName = LdapUtil.getLdapUseAsLoginName(); try { boolean valid; String fullUserDn = getFullUserDn(ldapTemplateContextSource.getLdapTemplate(), ldapUseAsLoginName, uid); if (fullUserDn.equals("") || password.equals("")) { return false; } LdapServerVO ldapServerVO = getLdapServer(); LdapServerInventory ldapServerInventory = LdapServerInventory.valueOf(ldapServerVO); ldapServerInventory.setUsername(fullUserDn); ldapServerInventory.setPassword(password); LdapTemplateContextSource ldapTemplateContextSource2 = new LdapUtil().loadLdap(ldapServerInventory); AndFilter filter = new AndFilter(); filter.and(new EqualsFilter(ldapUseAsLoginName, uid)); valid = ldapTemplateContextSource2.getLdapTemplate(). authenticate("", filter.toString(), password); logger.info(String.format("isValid[%s:%s, dn:%s, valid:%s]", ldapUseAsLoginName, uid, fullUserDn, valid)); return valid; } catch (NamingException e) { logger.info("isValid fail userName:" + uid, e); return false; } catch (Exception e) { logger.info("isValid error userName:" + uid, e); return false; } }
/** * {@inheritDoc} */ @Override public boolean authenticate(String base, String filter, String password, final AuthenticatedLdapEntryContextCallback callback, final AuthenticationErrorCallback errorCallback) { return authenticate(LdapUtils.newLdapName(base), filter, password, callback, errorCallback); }
/** * {@inheritDoc} */ @Override public boolean authenticate(Name base, String filter, String password, final AuthenticatedLdapEntryContextCallback callback) { return authenticate(base, filter, password, callback, new NullAuthenticationErrorCallback()); }
/** * {@inheritDoc} */ @Override public boolean authenticate(Name base, String filter, String password, final AuthenticationErrorCallback errorCallback) { return authenticate(base, filter, password, new NullAuthenticatedLdapEntryContextCallback(), errorCallback); }
/** * {@inheritDoc} */ @Override public void authenticate(LdapQuery query, String password) { authenticate(query, password, new NullAuthenticatedLdapEntryContextCallback()); }
/** * {@inheritDoc} */ @Override public boolean authenticate(String base, String filter, String password, AuthenticationErrorCallback errorCallback) { return authenticate(LdapUtils.newLdapName(base), filter, password, new NullAuthenticatedLdapEntryContextCallback(), errorCallback); }
/** * {@inheritDoc} */ @Override public boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) { return authenticate(LdapUtils.newLdapName(base), filter, password, callback, new NullAuthenticationErrorCallback()); }
/** * {@inheritDoc} */ @Override public boolean authenticate(String base, String filter, String password, AuthenticationErrorCallback errorCallback) { return authenticate(LdapUtils.newLdapName(base), filter, password, new NullAuthenticatedLdapEntryContextCallback(), errorCallback); }
/** * {@inheritDoc} */ @Override public boolean authenticate(Name base, String filter, String password) { return authenticate(base, filter, password, new NullAuthenticatedLdapEntryContextCallback(), new NullAuthenticationErrorCallback()); }
/** * {@inheritDoc} */ @Override public boolean authenticate(Name base, String filter, String password) { return authenticate(base, filter, password, new NullAuthenticatedLdapEntryContextCallback(), new NullAuthenticationErrorCallback()); }
/** * {@inheritDoc} */ @Override public boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) { return authenticate(LdapUtils.newLdapName(base), filter, password, callback, new NullAuthenticationErrorCallback()); }
/** * {@inheritDoc} */ @Override public boolean authenticate(Name base, String filter, String password) { return authenticate(base, filter, password, new NullAuthenticatedLdapEntryContextCallback(), new NullAuthenticationErrorCallback()); }
/** * {@inheritDoc} */ @Override public boolean authenticate(String base, String filter, String password) { return authenticate(LdapUtils.newLdapName(base), filter, password, new NullAuthenticatedLdapEntryContextCallback(), new NullAuthenticationErrorCallback()); }
@SuppressWarnings("RedundantThrows") protected boolean authenticateInLdap(LoginPasswordCredentials credentials) throws LoginException { String login = credentials.getLogin(); String password = credentials.getPassword(); return ldapTemplate.authenticate(LdapUtils.emptyLdapName(), buildPersonFilter(login), password); }
@Override public void authenticate(String login, String password, Locale messagesLocale) throws LoginException { if (!ldapTemplate.authenticate(LdapUtils.emptyLdapName(), buildPersonFilter(login), password)) { throw new LoginException( messages.formatMessage(LdapAuthProvider.class, "LoginException.InvalidLoginOrPassword", messagesLocale, login) ); } }
@Test public void testAuthenticateWhenNoUserWasFoundShouldFail() throws Exception { when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock); noSearchResults(searchControlsRecursive()); boolean result = tested.authenticate(nameMock, "(ou=somevalue)", "password", entryContextCallbackMock); verify(dirContextMock).close(); assertThat(result).isFalse(); }
public boolean authenticate(String uid, String mdpNonCode){ AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", classObjet)); filter.and(new EqualsFilter(id, uid)); return this.getLdapTemplateLectureNonPoolee().authenticate("", filter.toString(), mdpNonCode); }
@Test @Category(NoAdTest.class) public void testAuthenticateWithFilterThatDoesNotMatchAnything() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")).and( new EqualsFilter("uid", "some.person.that.isnt.there")); assertThat(tested.authenticate("", filter.toString(), "password")).isFalse(); }
@Test(expected=IncorrectResultSizeDataAccessException.class) @Category(NoAdTest.class) public void testAuthenticateWithFilterThatMatchesSeveralEntries() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", "Some Person")); tested.authenticate("", filter.toString(), "password"); }