Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEYCLOAK-1906 Customized LDAP filter. LDAP conditions improvements
- Loading branch information
Showing
27 changed files
with
312 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/QueryParameter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 17 additions & 14 deletions
31
.../ldap/src/main/java/org/keycloak/federation/ldap/idm/query/internal/BetweenCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,33 +1,36 @@ | |||
package org.keycloak.federation.ldap.idm.query.internal; | package org.keycloak.federation.ldap.idm.query.internal; | ||
|
|
||
import org.keycloak.federation.ldap.idm.query.Condition; | import java.util.Date; | ||
import org.keycloak.federation.ldap.idm.query.QueryParameter; |
|
||
import org.keycloak.federation.ldap.idm.store.ldap.LDAPUtil; | |||
|
|
||
/** | /** | ||
* @author Pedro Igor | * @author Pedro Igor | ||
*/ | */ | ||
public class BetweenCondition implements Condition { | class BetweenCondition extends NamedParameterCondition { | ||
|
|
||
private final Comparable x; | private final Comparable x; | ||
private final Comparable y; | private final Comparable y; | ||
private final QueryParameter parameter; | |||
|
|
||
public BetweenCondition(QueryParameter parameter, Comparable x, Comparable y) { | public BetweenCondition(String name, Comparable x, Comparable y) { | ||
this.parameter = parameter; | super(name); | ||
this.x = x; | this.x = x; | ||
this.y = y; | this.y = y; | ||
} | } | ||
|
|
||
@Override | @Override | ||
public QueryParameter getParameter() { | public void applyCondition(StringBuilder filter) { | ||
return this.parameter; | Comparable x = this.x; | ||
} | Comparable y = this.y; | ||
|
|
||
public Comparable getX() { | if (Date.class.isInstance(x)) { | ||
return this.x; | x = LDAPUtil.formatDate((Date) x); | ||
} | } | ||
|
|||
if (Date.class.isInstance(y)) { | |||
y = LDAPUtil.formatDate((Date) y); | |||
} | |||
|
|
||
public Comparable getY() { | filter.append("(").append(x).append("<=").append(getParameterName()).append("<=").append(y).append(")"); | ||
return this.y; | |||
} | } | ||
} | } |
29 changes: 29 additions & 0 deletions
29
.../ldap/src/main/java/org/keycloak/federation/ldap/idm/query/internal/CustomLDAPFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
package org.keycloak.federation.ldap.idm.query.internal; | |||
|
|||
import org.keycloak.federation.ldap.idm.query.Condition; | |||
|
|||
/** | |||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a> | |||
*/ | |||
class CustomLDAPFilter implements Condition { | |||
|
|||
private final String customFilter; | |||
|
|||
public CustomLDAPFilter(String customFilter) { | |||
this.customFilter = customFilter; | |||
} | |||
|
|||
@Override | |||
public String getParameterName() { | |||
return null; | |||
} | |||
|
|||
@Override | |||
public void setParameterName(String parameterName) { | |||
} | |||
|
|||
@Override | |||
public void applyCondition(StringBuilder filter) { | |||
filter.append(customFilter); | |||
} | |||
} |
30 changes: 18 additions & 12 deletions
30
...on/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/internal/EqualCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 18 additions & 15 deletions
33
...p/src/main/java/org/keycloak/federation/ldap/idm/query/internal/GreaterThanCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,34 +1,37 @@ | |||
package org.keycloak.federation.ldap.idm.query.internal; | package org.keycloak.federation.ldap.idm.query.internal; | ||
|
|
||
import java.util.Date; | |||
|
|||
import org.keycloak.federation.ldap.idm.query.Condition; | import org.keycloak.federation.ldap.idm.query.Condition; | ||
import org.keycloak.federation.ldap.idm.query.QueryParameter; | import org.keycloak.federation.ldap.idm.store.ldap.LDAPUtil; | ||
|
|
||
/** | /** | ||
* @author Pedro Igor | * @author Pedro Igor | ||
*/ | */ | ||
public class GreaterThanCondition implements Condition { | class GreaterThanCondition extends NamedParameterCondition { | ||
|
|
||
private final boolean orEqual; | private final boolean orEqual; | ||
|
|
||
private final QueryParameter parameter; | |||
private final Comparable value; | private final Comparable value; | ||
|
|
||
public GreaterThanCondition(QueryParameter parameter, Comparable value, boolean orEqual) { | public GreaterThanCondition(String name, Comparable value, boolean orEqual) { | ||
this.parameter = parameter; | super(name); | ||
this.value = value; | this.value = value; | ||
this.orEqual = orEqual; | this.orEqual = orEqual; | ||
} | } | ||
|
|
||
@Override | @Override | ||
public QueryParameter getParameter() { | public void applyCondition(StringBuilder filter) { | ||
return this.parameter; | Comparable parameterValue = value; | ||
} |
|
||
|
if (Date.class.isInstance(parameterValue)) { | ||
public Comparable getValue() { | parameterValue = LDAPUtil.formatDate((Date) parameterValue); | ||
return this.value; | } | ||
} |
|
||
|
if (orEqual) { | ||
public boolean isOrEqual() { | filter.append("(").append(getParameterName()).append(">=").append(parameterValue).append(")"); | ||
return this.orEqual; | } else { | ||
filter.append("(").append(getParameterName()).append(">").append(parameterValue).append(")"); | |||
} | |||
} | } | ||
} | } |
Oops, something went wrong.