Search in sources :

Example 16 with Condition

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

the class CertificateLDAPStorageMapper method beforeLDAPQuery.

@Override
public void beforeLDAPQuery(LDAPQuery query) {
    super.beforeLDAPQuery(query);
    String ldapAttrName = getLdapAttributeName();
    if (isDerFormatted()) {
        for (Condition condition : query.getConditions()) {
            if (condition instanceof EqualCondition && condition.getParameterName().equalsIgnoreCase(ldapAttrName)) {
                EqualCondition equalCondition = ((EqualCondition) condition);
                equalCondition.setValue(PemUtils.pemToDer(equalCondition.getValue().toString()));
            }
        }
    }
}
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)

Example 17 with Condition

use of org.keycloak.storage.ldap.idm.query.Condition 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)

Example 18 with Condition

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

the class UserAttributeLDAPStorageMapper method beforeLDAPQuery.

@Override
public void beforeLDAPQuery(LDAPQuery query) {
    String userModelAttrName = getUserModelAttribute();
    String ldapAttrName = getLdapAttributeName();
    // Add mapped attribute to returning ldap attributes
    query.addReturningLdapAttribute(ldapAttrName);
    if (isReadOnly()) {
        query.addReturningReadOnlyLdapAttribute(ldapAttrName);
    }
    // Change conditions and use ldapAttribute instead of userModel
    for (Condition condition : query.getConditions()) {
        condition.updateParameterName(userModelAttrName, ldapAttrName);
        String parameterName = condition.getParameterName();
        if (parameterName != null && (parameterName.equalsIgnoreCase(userModelAttrName) || parameterName.equalsIgnoreCase(ldapAttrName))) {
            condition.setBinary(isBinaryAttribute());
        }
    }
}
Also used : Condition(org.keycloak.storage.ldap.idm.query.Condition)

Aggregations

Condition (org.keycloak.storage.ldap.idm.query.Condition)18 LDAPQuery (org.keycloak.storage.ldap.idm.query.internal.LDAPQuery)12 LDAPQueryConditionsBuilder (org.keycloak.storage.ldap.idm.query.internal.LDAPQueryConditionsBuilder)12 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)4 EqualCondition (org.keycloak.storage.ldap.idm.query.internal.EqualCondition)4 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 AuthenticationException (javax.naming.AuthenticationException)1 NamingException (javax.naming.NamingException)1 AttributeInUseException (javax.naming.directory.AttributeInUseException)1 NoSuchAttributeException (javax.naming.directory.NoSuchAttributeException)1 SchemaViolationException (javax.naming.directory.SchemaViolationException)1 SearchResult (javax.naming.directory.SearchResult)1 ComponentModel (org.keycloak.component.ComponentModel)1 ModelException (org.keycloak.models.ModelException)1 UserModel (org.keycloak.models.UserModel)1 CachedUserModel (org.keycloak.models.cache.CachedUserModel)1 EscapeStrategy (org.keycloak.storage.ldap.idm.query.EscapeStrategy)1