public void findLdapDnMemberOfList(LdapTemplate ldapTemplate, String ldapDn, List<String> resultDnList, List<String> dnIgnoreList){ if(dnIgnoreList.contains(ldapDn)){ return; } AndFilter filter = new AndFilter(); filter.and(new EqualsFilter(LdapUtil.getMemberKey(), ldapDn)); List<Object> groupList = ldapTemplate.search("", filter.toString(), new AbstractContextMapper<Object>() { @Override protected Object doMapFromContext(DirContextOperations ctx) { return ctx.getNameInNamespace(); } }); if(groupList.isEmpty()){ dnIgnoreList.add(ldapDn); return; } for(Object groupObj : groupList){ if(groupObj == null || !(groupObj instanceof String)){ continue; } String groupDn = (String)groupObj; if(resultDnList.contains(groupDn)){ continue; } resultDnList.add(groupDn); findLdapDnMemberOfList(ldapTemplate, groupDn, resultDnList, dnIgnoreList); } }
private void update(LdapTemplate ldapTemplate, LdapAccountRefVO ref){ String uid = ref.getLdapUid(); AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("uid", ref.getLdapUid())); List<Object> result = ldapTemplate.search("", filter.toString(), new AbstractContextMapper<Object>() { @Override protected Object doMapFromContext(DirContextOperations ctx) { return ctx.getNameInNamespace(); } }); if(result.size() == 0){ logger.error(String.format("Can not find ldapUid[%s] dn", uid)); return; } if(result.size() > 1){ logger.error(String.format("ldapUid[%s] More than one dn result", uid)); return; } String dn = result.get(0).toString(); ref.setLdapUid(dn); dbf.update(ref); logger.info(String.format("update ldapUid[%s] to ldapDn[%s] success", uid, dn)); }
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; }
@Override public BinaryLogicalFilter constructFilter() { return new AndFilter(); } }, OR {
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; } }
private void handle(APIGetCandidateLdapEntryForBindingMsg msg) { APIGetLdapEntryReply reply = new APIGetLdapEntryReply(); AndFilter andFilter = new AndFilter(); andFilter.and(new HardcodedFilter(msg.getLdapFilter())); List<String> boundLdapEntryList = Q.New(LdapAccountRefVO.class) .select(LdapAccountRefVO_.ldapUid) .listValues(); List<Object> result = this.searchLdapEntry(andFilter.toString(), msg.getLimit(), new ResultFilter() { @Override boolean needSelect(String dn) { return !boundLdapEntryList.contains(dn); } }); reply.setInventories(result); bus.reply(msg, reply); }
@Override public GroupOrg findByDepartment(final String department) { final AndFilter filter = new AndFilter().and(new EqualsFilter("objectclass", GROUP_OF_UNIQUE_NAMES)) .and(new EqualsFilter(DEPARTMENT_ATTRIBUTE, department)); return template.search(groupsBaseDn, filter.encode(), (Object ctx) -> (DirContextAdapter) ctx).stream() .findFirst().map(c -> c.getStringAttribute("cn")).map(Normalizer::normalize).map(this::findById) .orElse(null); } }
@Override public Filter filterFor(Class<?> clazz, Filter baseFilter) { Filter ocFilter = getEntityData(clazz).ocFilter; if(baseFilter == null) { return ocFilter; } AndFilter andFilter = new AndFilter(); return andFilter.append(ocFilter).append(baseFilter); }
@Override public Filter filterFor(Class<?> clazz, Filter baseFilter) { Filter ocFilter = getEntityData(clazz).ocFilter; if(baseFilter == null) { return ocFilter; } AndFilter andFilter = new AndFilter(); return andFilter.append(ocFilter).append(baseFilter); }
public List<Organisation> findOrganisationsMultiCriteres(String rne, String nom){ AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", classObjet)); if(!rne.trim().isEmpty()){ filter.and(new LikeFilter(id, rne+"*")); } if(!nom.trim().isEmpty()){ filter.and(new LikeFilter(displayName, "*"+nom+"*")); } OrganisationAttributMapper orgAttributMapper = new OrganisationAttributMapper(); return ldapTemplateLecture.search("", filter.encode(),SearchControls.SUBTREE_SCOPE ,orgAttributMapper); }
@SuppressWarnings("unchecked") public List<GroupesApplications> findGroupesNoeud(String dnNoeud) { String dnNoeudRelatif = dnNoeud.replace(","+BASE_DN,""); AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", classeObjet)); GroupesApplicationsAttributMapper groupesApplicationsAttributMapper = new GroupesApplicationsAttributMapper(); return ldapTemplateLecture.search(dnNoeudRelatif, filter.encode(), SearchControls.ONELEVEL_SCOPE , groupesApplicationsAttributMapper); }
public Filter groupnameFilter(String groupname) { String attributeKey = getGroupAttribute("name"); AndFilter filter = new AndFilter(); filter.and(getGroupFilter()); filter.and(new EqualsFilter(attributeKey, groupname)); return filter; }
public List<Person> getPersonByUid(String uid) { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", classObjet)); filter.and(new LikeFilter(id, uid+"*")); PersonAttributMapper personAttributMapper = new PersonAttributMapper(); @SuppressWarnings("unchecked") List<Person> liste = ldapTemplateLecture.search("", filter.encode(), personAttributMapper); return liste; }
public List<Person> getPersonByName(String name) { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", classObjet)); filter.and(new LikeFilter(nom, name+"*")); PersonAttributMapper personAttributMapper = new PersonAttributMapper(); @SuppressWarnings("unchecked") List<Person> liste = ldapTemplateLecture.search("", filter.encode(), personAttributMapper); return liste; }
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); }
@SuppressWarnings("unchecked") public List<Structure> findAllStructures() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", classObjetStructure)); filter.and(new LikeFilter(id, "*")); StructureAttributMapper strAttributMapper = new StructureAttributMapper(); return ldapTemplateLecture.search("ou="+categorieLDAP, filter.encode(),SearchControls.ONELEVEL_SCOPE ,strAttributMapper); }
@Test public void testThree() { AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b")).and( new EqualsFilter("c", "d")).and(new EqualsFilter("e", "f")); assertThat(aq.encode()).isEqualTo("(&(a=b)(c=d)(e=f))"); }
@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 @Category(NoAdTest.class) public void testAuthenticate() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3")); assertThat(ldapTemplate.authenticate("", filter.toString(), "password")).isTrue(); }
@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"); }