Search in sources :

Example 1 with EscapeStrategy

use of org.keycloak.storage.ldap.idm.query.EscapeStrategy in project keycloak by keycloak.

the class FullNameLDAPStorageMapper method beforeLDAPQuery.

@Override
public void beforeLDAPQuery(LDAPQuery query) {
    if (isWriteOnly()) {
        return;
    }
    String ldapFullNameAttrName = getLdapFullNameAttrName();
    query.addReturningLdapAttribute(ldapFullNameAttrName);
    // Change conditions and compute condition for fullName from the conditions for firstName and lastName. Right now just "equal" condition is supported
    EqualCondition firstNameCondition = null;
    EqualCondition lastNameCondition = null;
    Set<Condition> conditionsCopy = new HashSet<Condition>(query.getConditions());
    for (Condition condition : conditionsCopy) {
        String paramName = condition.getParameterName();
        if (paramName != null) {
            if (paramName.equals(UserModel.FIRST_NAME)) {
                firstNameCondition = (EqualCondition) condition;
                query.getConditions().remove(condition);
            } else if (paramName.equals(UserModel.LAST_NAME)) {
                lastNameCondition = (EqualCondition) condition;
                query.getConditions().remove(condition);
            } else if (paramName.equals(LDAPConstants.GIVENNAME)) {
                // Some previous mapper already converted it to LDAP name
                firstNameCondition = (EqualCondition) condition;
            } else if (paramName.equals(LDAPConstants.SN)) {
                // Some previous mapper already converted it to LDAP name
                lastNameCondition = (EqualCondition) condition;
            }
        }
    }
    String fullName = null;
    if (firstNameCondition != null && lastNameCondition != null) {
        fullName = firstNameCondition.getValue() + " " + lastNameCondition.getValue();
    } else if (firstNameCondition != null) {
        fullName = (String) firstNameCondition.getValue();
    } else if (lastNameCondition != null) {
        fullName = (String) lastNameCondition.getValue();
    } else {
        return;
    }
    EscapeStrategy escapeStrategy = firstNameCondition != null ? firstNameCondition.getEscapeStrategy() : lastNameCondition.getEscapeStrategy();
    EqualCondition fullNameCondition = new EqualCondition(ldapFullNameAttrName, fullName, escapeStrategy);
    query.addWhereCondition(fullNameCondition);
}
Also used : EqualCondition(org.keycloak.storage.ldap.idm.query.internal.EqualCondition) Condition(org.keycloak.storage.ldap.idm.query.Condition) EqualCondition(org.keycloak.storage.ldap.idm.query.internal.EqualCondition) EscapeStrategy(org.keycloak.storage.ldap.idm.query.EscapeStrategy) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Condition (org.keycloak.storage.ldap.idm.query.Condition)1 EscapeStrategy (org.keycloak.storage.ldap.idm.query.EscapeStrategy)1 EqualCondition (org.keycloak.storage.ldap.idm.query.internal.EqualCondition)1