public String getFullUserDn(LdapTemplate ldapTemplate, String key, String val) { EqualsFilter f = new EqualsFilter(key, val); return getFullUserDn(ldapTemplate, f.toString()); }
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 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); }
protected String buildPersonFilter(String login) { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")) .and(new EqualsFilter(ldapUserLoginField, login)); return filter.encode(); }
public void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }
@Override public BinaryLogicalFilter constructFilter() { return new OrFilter(); } };
HardcodedFilter hardcodedFilter = new HardcodedFilter(filter); if(validateDnExist(ldapTemplateContextSource, ldapDn, hardcodedFilter)){ accountUuidList.add(ldapAccRefVO.getAccountUuid());
@Override public int hashCode() { return filter != null ? filter.hashCode() : 0; } }
@Override public String toString() { return encode(); } }
/** * Add a query to the AND expression. * * @param query The expression to AND with the rest of the AND:ed * expressions. * @return This LdapAndQuery */ public AndFilter and(Filter query) { append(query); return this; } }
/** * Add a query to the OR expression * * @param query The query to or with the rest of the or:ed queries. * @return This LdapOrQuery */ public OrFilter or(Filter query) { append(query); return this; }
public CompareFilter(String attribute, String value) { this.attribute = attribute; this.value = value; this.encodedValue = encodeValue(value); }
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 void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }
@Override public BinaryLogicalFilter constructFilter() { return new OrFilter(); } };
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)); }
public void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }
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; } }
public void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }