Class JdbcSimpleUserDao
- java.lang.Object
-
- com.sun.identity.idm.plugins.database.JdbcSimpleUserDao
-
- All Implemented Interfaces:
DaoInterface
public class JdbcSimpleUserDao extends Object implements DaoInterface
This class encapsulates all the JDBC code used to access identity information in a database.
-
-
Constructor Summary
Constructors Constructor Description JdbcSimpleUserDao()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMembersToGroup(Set<String> members, String groupName, String membershipIdAttributeName)
void
createGroup(String groupName, String membershipIdAttributeName)
String
createUser(String userIDAttributeName, Map<String,Set<String>> attrMap)
void
deleteGroup(String groupName, String membershipIdAttributeName)
void
deleteMembersFromGroup(Set<String> members, String groupName, String membershipIdAttributeName)
void
deleteUser(String userID, String userIDAttributeName)
Map<String,Set<String>>
getAttributes(String userID, String userIDAttributeName, Set<String> attributesToFetch)
gets values for the user attributes specified in the atributesToFetch set.String
getDataSourceURL()
get the url of the current database.Map<String,Set<String>>
getGroupAttributes(String groupName, String membershipIdAttributeName, Set<String> attributesToFetch)
Set<String>
getMembers(String groupName, String membershipIdAttributeName)
Set<String>
getMemberships(String userName, String membershipIdAttributeName)
void
initialize(String jndiName, String userDataBaseTableName, String membershipDataBaseTableName, Debug idRepoDebugLog)
This class must be called before using the methods since the datasource must be set up.void
initialize(String jdbcDriver, String jdbcDriverUrl, String jdbcUser, String jdbcPassword, String userDataBaseTableName, String membershipDataBaseTableName, Debug idRepoDebugLog)
This class must be called before using the methods since the datasource must be set up.Map<String,Map<String,Set<String>>>
search(String userIDAttributeName, int limit, String idPattern, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs)
Fetch the set of users and including for each user all their attributes specified in attributesToFetch.Map<String,Map<String,Set<String>>>
search(String userIDAttributeName, int limit, org.forgerock.util.query.QueryFilter<org.forgerock.json.JsonPointer> queryFilter, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs)
Dealing with a query filter is not supported as yet and will give an empty map.Map<String,Map<String,Set<String>>>
searchForGroups(String membershipIdAttributeName, int limit, String idPattern, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs)
Map<String,Map<String,Set<String>>>
searchForGroups(String membershipIdAttributeName, int limit, org.forgerock.util.query.QueryFilter<org.forgerock.json.JsonPointer> queryFilter, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs)
void
updateUser(String userID, String userIDAttributeName, Map<String,Set<String>> attrMap)
-
-
-
Method Detail
-
initialize
public void initialize(String jndiName, String userDataBaseTableName, String membershipDataBaseTableName, Debug idRepoDebugLog) throws InstantiationException
This class must be called before using the methods since the datasource must be set up. This version of initialize is used when connections are retreived using a Java EE datasource resource which is configured through the application server. For example if you use your server's ability to configure and pool connections. This also requires a java:comp/env resource-ref in web.xml- Specified by:
initialize
in interfaceDaoInterface
- Throws:
InstantiationException
- when not able to instantiate this class, for example if parameters are bad or null or can not make a connection to datasource.
-
initialize
public void initialize(String jdbcDriver, String jdbcDriverUrl, String jdbcUser, String jdbcPassword, String userDataBaseTableName, String membershipDataBaseTableName, Debug idRepoDebugLog) throws InstantiationException
This class must be called before using the methods since the datasource must be set up. This version of initialize is used when connections are retreived using JDBC driver classes directly.- Specified by:
initialize
in interfaceDaoInterface
- Throws:
InstantiationException
- when not able to instantiate this class, for example if parameters are bad or null or can not make a connection to datasource.
-
updateUser
public void updateUser(String userID, String userIDAttributeName, Map<String,Set<String>> attrMap)
- Specified by:
updateUser
in interfaceDaoInterface
- Parameters:
userID
- is user idattrMap
- is a Map that contains attribute/column names as keys and values are Sets of values
-
deleteUser
public void deleteUser(String userID, String userIDAttributeName)
- Specified by:
deleteUser
in interfaceDaoInterface
-
createUser
public String createUser(String userIDAttributeName, Map<String,Set<String>> attrMap)
- Specified by:
createUser
in interfaceDaoInterface
-
getAttributes
public Map<String,Set<String>> getAttributes(String userID, String userIDAttributeName, Set<String> attributesToFetch)
gets values for the user attributes specified in the atributesToFetch set. Normalizes the types by converting all the individual values into Strings.- Specified by:
getAttributes
in interfaceDaoInterface
- Parameters:
userID
- is String of the users unique identifieruserIDAttributeName
- is the column name of the id field so is used for example in the where clause of SQL WHERE userIDAttributeName = userIDattributesToFetch
- is the set of column names for the attributes that should be fetched from the DB table.- Returns:
- user a map of Maps where each map is a user and their attributes
-
search
public Map<String,Map<String,Set<String>>> search(String userIDAttributeName, int limit, String idPattern, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs)
Fetch the set of users and including for each user all their attributes specified in attributesToFetch. If there is an attribute being asked for in attributesToFetch but that attribute is not present in the DB table then currently that attribute is not included in the returned Map of each user. For example, if the attributesToFetch includes "address" but there is no address column in the DB table and no "address" included in the result set for each row, then neither the attribute "address" of any value is put into the set of attributes for each user. Is this correct ????- Specified by:
search
in interfaceDaoInterface
- Parameters:
idPattern
- which is used in an SQL LIKE query on the id attribute usually contains some SQL search chars like % to broaden matches WHERE id_attribute LIKE 'the_pattern_value' If idPattern is empty or null then it means to get all users so do not need to use a LIKE clause on queryattributesToFetch
- is set of desired attributes to fetch for each user. If EMPTY or NULL, then will not do anything, return empty map. Callers should be sure to specify which attributes to fetch.limit
- is maximum number of results to return. This is added to the END of the WHERE clause using mysql LIMIT on a query. Default if no limit(if limit<0) is specified is LIMIT=1 Limit is ignored in this implementation since it is not portable SQLfilterOperand
- is a string of AND, or OR and is used to add extra attributes and values to the WHERE search clause, and it is applied between attribute = 'value' pairs in the parameter for avPairs.avPairs
- is a map of attribute names as the keys and the associated values are a SET for each attribute name, and would be added to the WHERE clause after the isPattern part of clause and before the LIMIT part of the where clause, for example WHERE id_attribute LIKE 'the_pattern_value' AND (attr_1='value1' ...filterOperand/AND/OR... attr_2='value2' ) LIMIT 2- Returns:
- a set of Maps where each map is a user and their attributes
-
search
public Map<String,Map<String,Set<String>>> search(String userIDAttributeName, int limit, org.forgerock.util.query.QueryFilter<org.forgerock.json.JsonPointer> queryFilter, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs) throws IdRepoUnsupportedOpException
Dealing with a query filter is not supported as yet and will give an empty map.- Specified by:
search
in interfaceDaoInterface
- Parameters:
userIDAttributeName
- the name of the attribute which uniquely identifies users, e.g. "uid".limit
- is maximum number of results to return. This is added to the END of the WHERE clause using mysql LIMIT on a query. Default if no limit(if limit<0) is specified is LIMIT=1 Limit is ignored in this implementation since it is not portable SQLqueryFilter
- the query filter sent, more or less directly, from a CREST endpoint _queryFilter value.attributesToFetch
- is set of desired attributes to fetch for each user. If EMPTY or NULL, then will not do anything, return empty map. Callers should be sure to specify which attributes to fetch.filterOperand
- is a string of AND, or OR and is used to add extra attributes and values to the WHERE search clause, and it is applied between attribute = 'value' pairs in the parameter for avPairs.avPairs
- is a map of attribute names as the keys and the associated values are a SET for each attribute name, and would be added to the WHERE clause after the isPattern part of clause and before the LIMIT part of the where clause, for example WHERE id_attribute LIKE 'the_pattern_value' AND (attr_1='value1' ...filterOperand/AND/OR... attr_2='value2' ) LIMIT 2- Returns:
- a set of Maps where each map is a user and their attributes
- Throws:
IdRepoUnsupportedOpException
-
getDataSourceURL
public String getDataSourceURL()
get the url of the current database.- Specified by:
getDataSourceURL
in interfaceDaoInterface
- Returns:
- a url of the current db connection, should be of the form jdbc:mysql://localhost:3306/seantestdb1 It is used by the IdRepo implementation to provide a fully qualified domain name for users, and this value serves as sort of the prefix.
-
getMembers
public Set<String> getMembers(String groupName, String membershipIdAttributeName)
- Specified by:
getMembers
in interfaceDaoInterface
-
getMemberships
public Set<String> getMemberships(String userName, String membershipIdAttributeName)
- Specified by:
getMemberships
in interfaceDaoInterface
-
deleteGroup
public void deleteGroup(String groupName, String membershipIdAttributeName)
- Specified by:
deleteGroup
in interfaceDaoInterface
-
createGroup
public void createGroup(String groupName, String membershipIdAttributeName)
- Specified by:
createGroup
in interfaceDaoInterface
-
deleteMembersFromGroup
public void deleteMembersFromGroup(Set<String> members, String groupName, String membershipIdAttributeName)
- Specified by:
deleteMembersFromGroup
in interfaceDaoInterface
-
addMembersToGroup
public void addMembersToGroup(Set<String> members, String groupName, String membershipIdAttributeName)
- Specified by:
addMembersToGroup
in interfaceDaoInterface
-
searchForGroups
public Map<String,Map<String,Set<String>>> searchForGroups(String membershipIdAttributeName, int limit, String idPattern, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs)
- Specified by:
searchForGroups
in interfaceDaoInterface
-
searchForGroups
public Map<String,Map<String,Set<String>>> searchForGroups(String membershipIdAttributeName, int limit, org.forgerock.util.query.QueryFilter<org.forgerock.json.JsonPointer> queryFilter, Set<String> attributesToFetch, String filterOperand, Map<String,Set<String>> avPairs)
- Specified by:
searchForGroups
in interfaceDaoInterface
-
getGroupAttributes
public Map<String,Set<String>> getGroupAttributes(String groupName, String membershipIdAttributeName, Set<String> attributesToFetch)
- Specified by:
getGroupAttributes
in interfaceDaoInterface
-
-