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()));
}
}
}
}
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);
}
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());
}
}
}
Aggregations