Managed properties are stored as ad-hoc attributes and mapped from and to a specific property of a type.
+ * + * @return + */ + boolean managed() default false; + +} diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/model/AttributedType.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/model/AttributedType.java new file mode 100644 index 0000000000..5c374278c2 --- /dev/null +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/model/AttributedType.java @@ -0,0 +1,75 @@ +package org.keycloak.federation.ldap.idm.model; + +import java.io.Serializable; +import java.util.Collection; + +import org.keycloak.federation.ldap.idm.query.AttributeParameter; +import org.keycloak.federation.ldap.idm.query.QueryParameter; + +/** + * + * @author Shane Bryzak + * + */ +public interface AttributedType extends Serializable { + + /** + * A query parameter used to set the id value. + */ + QueryParameter ID = new AttributeParameter("id"); + + /** + * Returns the unique identifier for this instance + * @return + */ + String getId(); + + /** + * Sets the unique identifier for this instance + * @return + */ + void setId(String id); + + /** + * Set the specified attribute. This operation will overwrite any previous value. + * + * @param attribute to be set + */ + void setAttribute(Attribute extends Serializable> attribute); + + /** + * Remove the attribute with given name + * + * @param name of attribute + */ + void removeAttribute(String name); + + + // LDAP specific stuff + void setEntryDN(String entryDN); + String getEntryDN(); + + + /** + * Return the attribute value with the specified name + * + * @param name of attribute + * @return attribute value or null if attribute with given name doesn't exist. If given attribute has many values method + * will return first one + */ +Sets the current enabled status of this {@link IdentityType}.
+ * + * @param enabled + */ + void setEnabled(boolean enabled); + + /** + * Returns the date that this IdentityType instance was created. + * + * @return Date value representing the creation date + */ + Date getCreatedDate(); + + /** + *Sets the date that this {@link IdentityType} was created.
+ * + * @param createdDate + */ + void setCreatedDate(Date createdDate); + + /** + * Returns the date that this IdentityType expires, or null if there is no expiry date. + * + * @return + */ + Date getExpirationDate(); + + /** + *Sets the date that this {@link IdentityType} expires.
+ * + * @param expirationDate + */ + void setExpirationDate(Date expirationDate); + +} + diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/model/LDAPUser.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/model/LDAPUser.java new file mode 100644 index 0000000000..4ce7ef9516 --- /dev/null +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/model/LDAPUser.java @@ -0,0 +1,85 @@ +package org.keycloak.federation.ldap.idm.model; + + +import org.keycloak.federation.ldap.idm.query.QueryParameter; + +/** + * This class represents a User; a human agent that may authenticate with the application + * + * @author Shane Bryzak + */ +public class LDAPUser extends AbstractIdentityType { + + private static final long serialVersionUID = 4117586097100398485L; + + public static final QueryParameter LOGIN_NAME = AttributedType.QUERY_ATTRIBUTE.byName("loginName"); + + /** + * A query parameter used to set the firstName value. + */ + public static final QueryParameter FIRST_NAME = QUERY_ATTRIBUTE.byName("firstName"); + + /** + * A query parameter used to set the lastName value. + */ + public static final QueryParameter LAST_NAME = QUERY_ATTRIBUTE.byName("lastName"); + + /** + * A query parameter used to set the email value. + */ + public static final QueryParameter EMAIL = QUERY_ATTRIBUTE.byName("email"); + + @AttributeProperty + private String loginName; + + @AttributeProperty + private String firstName; + + @AttributeProperty + private String lastName; + + @AttributeProperty + private String email; + + public LDAPUser() { + + } + + public LDAPUser(String loginName) { + this.loginName = loginName; + } + + public String getLoginName() { + return loginName; + } + + public void setLoginName(String loginName) { + this.loginName = loginName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return this.email; + } + + public void setEmail(String email) { + this.email = email; + } + +} + diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/AttributeParameter.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/AttributeParameter.java new file mode 100644 index 0000000000..c5feea9319 --- /dev/null +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/AttributeParameter.java @@ -0,0 +1,21 @@ +package org.keycloak.federation.ldap.idm.query; + +/** + *This class can be used to define a query parameter for properties annotated with + * {@link org.keycloak.federation.ldap.idm.model.AttributeProperty}. + *
+ * + * @author pedroigor + */ +public class AttributeParameter implements QueryParameter { + + private final String name; + + public AttributeParameter(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } +} diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/Condition.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/Condition.java new file mode 100644 index 0000000000..85d81d8915 --- /dev/null +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/Condition.java @@ -0,0 +1,18 @@ +package org.keycloak.federation.ldap.idm.query; + +/** + *A {@link Condition} is used to specify how a specific {@link QueryParameter} + * is defined in order to filter query results.
+ * + * @author Pedro Igor + */ +public interface Condition { + + /** + *The {@link QueryParameter} restricted by this condition.
+ * + * @return + */ + QueryParameter getParameter(); + +} \ No newline at end of file diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/IdentityQuery.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/IdentityQuery.java new file mode 100644 index 0000000000..1a77727fa8 --- /dev/null +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/query/IdentityQuery.java @@ -0,0 +1,225 @@ +package org.keycloak.federation.ldap.idm.query; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.keycloak.federation.ldap.idm.model.IdentityType; + +/** + *An {@link IdentityQuery} is responsible for querying the underlying identity stores for instances of + * a given {@link IdentityType}.
+ * + *Instances of this class are obtained using the {@link IdentityQueryBuilder#createIdentityQuery(Class)} + * method.
+ * + *+ * IdentityManager identityManager = getIdentityManager(); + * + * // here we get the query builder + * IdentityQueryBuilder builder = identityManager.getQueryBuilder(); + * + * // create a condition + * Condition condition = builder.equal(User.LOGIN_NAME, "john"); + * + * // create a query for a specific identity type using the previously created condition + * IdentityQuery query = builder.createIdentityQuery(User.class).where(condition); + * + * // execute the query + * List+ * + *result = query.getResultList(); + *
When preparing a query you may want to create conditions to filter its results and configure how they must be retrieved. + * For that, you can use the {@link IdentityQueryBuilder}, which provides useful methods for creating + * different expressions and conditions.
+ * + * @author Shane Bryzak + * @author Pedro Igor + */ +public interface IdentityQuerySet a query parameter to this query in order to filter the results.
+ * + *This method always create an equality condition. For more conditions options take a look at {@link + * IdentityQueryBuilder} and use the {@link IdentityQuery#where(Condition...)} + * instead.
+ * + * @param param The query parameter. + * @param value The value to match for equality. + * + * @return + * + * @deprecated Use {@link IdentityQuery#where(Condition...)} to specify query conditions. + */ + @Deprecated + IdentityQueryAdd to this query the conditions that will be used to filter results.
+ * + *Any condition previously added to this query will be preserved and the new conditions added. If you want to clear the + * conditions you must create a new query instance.
+ * + * @param condition One or more conditions created from {@link IdentityQueryBuilder}. + * + * @return + */ + IdentityQueryAdd to this query the sorting conditions to be applied to the results.
+ * + * @param sorts The ordering conditions. + * + * @return + */ + IdentityQueryThe type used to create this query.
+ * + * @return + */ + ClassReturns a map with all the parameter set for this query.
+ * + * @return + * + * @deprecated Use {@link IdentityQuery#getConditions()} instead. Will be removed. + */ + @Deprecated + MapReturns a set containing all conditions used by this query to filter its results.
+ * + * @return + */ + SetReturns a set containing all sorting conditions used to filter the results.
+ * + * @return + */ + SetReturns the value used to restrict the given query parameter.
+ * + * @param queryParameter + * + * @return + */ + @Deprecated + Object[] getParameter(QueryParameter queryParameter); + + @Deprecated + MapSet the position of the first result to retrieve.
+ * + * @param offset + * + * @return + */ + IdentityQueryReturns the number of instances to retrieve.
+ * + * @return + */ + int getLimit(); + + /** + *Set the maximum number of results to retrieve.
+ * + * @param limit the number of instances to retrieve. + * + * @return + */ + IdentityQueryExecute the query against the underlying identity stores and returns a list containing all instances of + * the type (defined when creating this query instance) that match the conditions previously specified.
+ * + * @return + */ + ListThe {@link IdentityQueryBuilder} is responsible for creating {@link IdentityQuery} instances and also + * provide methods to create conditions, orderings, sorting, etc.
+ * + * @author Pedro Igor + */ +public interface IdentityQueryBuilder { + + /** + *Create a condition for testing the whether the query parameter satisfies the given pattern..
+ * + * @param parameter The query parameter. + * @param pattern The pattern to match. + * + * @return + */ + Condition like(QueryParameter parameter, String pattern); + + /** + *Create a condition for testing the arguments for equality.
+ * + * @param parameter The query parameter. + * @param value The value to compare. + * + * @return + */ + Condition equal(QueryParameter parameter, Object value); + + /** + *Create a condition for testing whether the query parameter is grater than the given value..
+ * + * @param parameter The query parameter. + * @param x The value to compare. + * + * @return + */ + Condition greaterThan(QueryParameter parameter, Object x); + + /** + *Create a condition for testing whether the query parameter is grater than or equal to the given value..
+ * + * @param parameter The query parameter. + * @param x The value to compare. + * + * @return + */ + Condition greaterThanOrEqualTo(QueryParameter parameter, Object x); + + /** + *Create a condition for testing whether the query parameter is less than the given value..
+ * + * @param parameter The query parameter. + * @param x The value to compare. + * + * @return + */ + Condition lessThan(QueryParameter parameter, Object x); + + /** + *Create a condition for testing whether the query parameter is less than or equal to the given value..
+ * + * @param parameter The query parameter. + * @param x The value to compare. + * + * @return + */ + Condition lessThanOrEqualTo(QueryParameter parameter, Object x); + + /** + *Create a condition for testing whether the query parameter is between the given values.
+ * + * @param parameter The query parameter. + * @param x The first value. + * @param x The second value. + * + * @return + */ + Condition between(QueryParameter parameter, Object x, Object y); + + /** + *Create a condition for testing whether the query parameter is contained in a list of values.
+ * + * @param parameter The query parameter. + * @param values A list of values. + * + * @return + */ + Condition in(QueryParameter parameter, Object... values); + + /** + *Create an ascending order for the given parameter
. Once created, you can use it to sort the results of a
+ * query.
Create an descending order for the given parameter
. Once created, you can use it to sort the results of a
+ * query.
Create an {@link IdentityQuery} that can be used to query for {@link
+ * IdentityType} instances of a the given identityType
.