Package io.continual.iam.impl
Class MultiSourceDb<I extends Identity,G extends Group>
java.lang.Object
io.continual.iam.impl.MultiSourceDb<I,G>
- All Implemented Interfaces:
AccessDb<G>,AccessManager<G>,AclUpdateListener,IamDb<I,,G> IdentityDb<I>,IdentityManager<I>,TagManager,MetricsSupplier,Closeable,AutoCloseable
-
Field Summary
Fields inherited from interface io.continual.iam.access.AccessDb
kCreateOperation, kDeleteOperation, kReadOperation, kWriteOperation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a username/alias for this user.voidAdd a JWT validator to the identity manager.voidaddUserToGroup(String groupId, String userId) Add a user to a given groupAuthenticate with an API key and signatureAuthenticate with a JWT tokenAuthenticate with a username and passwordbooleanCan the given user perform the requested access?booleancompletePasswordReset(String tag, String newPassword) Complete a password reset by providing a tag and a new password.Create a new anonymous user in the identity manager.createGroup(String groupDesc) Create a groupcreateGroup(String groupId, String groupDesc) Create a group with a given group IDCreate a JWT token for the given identity.Create a tag for a given user id with a particular type and duration.createUser(String userId) Create a new user in the identity manager.voiddeleteUser(String userId) Delete a user from the identity manager.Find users with a user ID that starts with the given stringload an ACL for a resourcegetAliasesFor(String userId) Get the aliases for a userId.Get all group IDs in this db.Get all user IDs in this db.getUserIdForTag(String tag) Retrieves the userId associated with a tag.getUsersGroups(String userId) Find out which groups a user is a member of.getUsersInGroup(String groupId) Get the set of user IDs in a particular group.voidinvalidateJwtToken(String jwtToken) Invalidate the given JWT tokenLoad all users in this identity manager.loadApiKeyRecord(String apiKey) Load an API key record based on the API key ID.Get a group by its identifier.Load a user from the identity manager.loadUserOrAlias(String userIdOrAlias) Load a user from the identity manager.voidonAclUpdate(AccessControlList accessControlList) voidpopulateMetrics(MetricsCatalog metrics) voidremoveAlias(String alias) Remove a username/alias from the database.voidremoveMatchingTag(String userId, String appTagType) Remove any matching tag for the given user and type.voidremoveUserFromGroup(String groupId, String userId) Remove a user from a given groupvoidrestoreApiKey(ApiKey key) Restore an API key into the API key storevoidSweep any expired tags.booleanuserExists(String userId) Find out if a given user exists.booleanuserOrAliasExists(String userIdOrAlias) Find out if a given user or alias exists.
-
Constructor Details
-
MultiSourceDb
public MultiSourceDb(ServiceContainer sc, org.json.JSONObject rawConfig) throws Builder.BuildFailure - Throws:
Builder.BuildFailure
-
-
Method Details
-
userExists
Description copied from interface:IdentityDbFind out if a given user exists.- Specified by:
userExistsin interfaceIdentityDb<I extends Identity>- Parameters:
userId- a user ID- Returns:
- true if the user exists in the identity manager.
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
userOrAliasExists
Description copied from interface:IdentityDbFind out if a given user or alias exists.- Specified by:
userOrAliasExistsin interfaceIdentityDb<I extends Identity>- Parameters:
userIdOrAlias- the user ID or an alias- Returns:
- true if the user exists by userId or alias in the identity manager.
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
loadUser
Description copied from interface:IdentityDbLoad a user from the identity manager.- Specified by:
loadUserin interfaceIdentityDb<I extends Identity>- Parameters:
userId- a user ID- Returns:
- a user or null if the user doesn't exist
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
loadUserOrAlias
Description copied from interface:IdentityDbLoad a user from the identity manager.- Specified by:
loadUserOrAliasin interfaceIdentityDb<I extends Identity>- Parameters:
userIdOrAlias- the actual userId or an alias- Returns:
- a user or null if the user doesn't exist
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
findUsers
Description copied from interface:IdentityManagerFind users with a user ID that starts with the given string- Specified by:
findUsersin interfaceIdentityManager<I extends Identity>- Parameters:
startingWith- a prefix for users- Returns:
- a list of 0 or more matching user IDs
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
createUser
Description copied from interface:IdentityManagerCreate a new user in the identity manager. The username for this user defaults to the userId value provided here.- Specified by:
createUserin interfaceIdentityManager<I extends Identity>- Parameters:
userId- a user ID- Returns:
- the new user
- Throws:
IamIdentityExists- if the user existsIamSvcException- when the call cannot be completed due to a service error
-
createAnonymousUser
Description copied from interface:IdentityManagerCreate a new anonymous user in the identity manager.- Specified by:
createAnonymousUserin interfaceIdentityManager<I extends Identity>- Returns:
- a new anonymous user
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
deleteUser
Description copied from interface:IdentityManagerDelete a user from the identity manager.- Specified by:
deleteUserin interfaceIdentityManager<I extends Identity>- Parameters:
userId- a user ID- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
addAlias
Description copied from interface:IdentityManagerAdd a username/alias for this user. Identity DBs should normally support multiple aliases (username, email, mobile phone, etc.). Tracking them beyond being references to an identity record is done at the application level.- Specified by:
addAliasin interfaceIdentityManager<I extends Identity>- Parameters:
userId- a user IDalias- an alias- Throws:
IamSvcException- when the call cannot be completed due to a service errorIamBadRequestException- if the request is illegal
-
removeAlias
Description copied from interface:IdentityManagerRemove a username/alias from the database. A userId may not be removed (disable the user instead).- Specified by:
removeAliasin interfaceIdentityManager<I extends Identity>- Parameters:
alias- an alias- Throws:
IamBadRequestException- If a userId is provided.IamSvcException- when the call cannot be completed due to a service error
-
getAliasesFor
public Collection<String> getAliasesFor(String userId) throws IamSvcException, IamIdentityDoesNotExist Description copied from interface:IdentityManagerGet the aliases for a userId. The result must be non-null but may be empty. The userId is not included in the list.- Specified by:
getAliasesForin interfaceIdentityManager<I extends Identity>- Parameters:
userId- a user ID- Returns:
- a collection of 0 or more aliases for a userId
- Throws:
IamSvcException- when the call cannot be completed due to a service errorIamIdentityDoesNotExist- if the identity does not exist
-
completePasswordReset
Description copied from interface:IdentityManagerComplete a password reset by providing a tag and a new password. The update will fail if the tag is unknown or has expired. SeerequestPasswordResetfor details on creating a password reset tag.- Specified by:
completePasswordResetin interfaceIdentityManager<I extends Identity>- Parameters:
tag- a tagnewPassword- a new password- Returns:
- true if the password was updated successfully.
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
loadApiKeyRecord
Description copied from interface:IdentityManagerLoad an API key record based on the API key ID.- Specified by:
loadApiKeyRecordin interfaceIdentityManager<I extends Identity>- Parameters:
apiKey- an API key- Returns:
- an API key or null if it doesn't exist
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
restoreApiKey
public void restoreApiKey(ApiKey key) throws IamIdentityDoesNotExist, IamBadRequestException, IamSvcException Description copied from interface:IdentityManagerRestore an API key into the API key store- Specified by:
restoreApiKeyin interfaceIdentityManager<I extends Identity>- Parameters:
key-- Throws:
IamIdentityDoesNotExistIamBadRequestExceptionIamSvcException
-
addJwtValidator
Description copied from interface:IdentityManagerAdd a JWT validator to the identity manager.- Specified by:
addJwtValidatorin interfaceIdentityManager<I extends Identity>- Parameters:
v- a validator
-
getAllUsers
Description copied from interface:IdentityManagerGet all user IDs in this db. Clearly not suitable for systems beyond a few thousand users. For larger scale, this call may throw an IamSvcException signaling that the underlying database won't return a user list.- Specified by:
getAllUsersin interfaceIdentityManager<I extends Identity>- Returns:
- a collection of user Ids
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
loadAllUsers
Description copied from interface:IdentityManagerLoad all users in this identity manager. Clearly not suitable for systems beyond a few thousand users. For larger scale, this call may throw an IamSvcException signaling that the underlying database won't return a user list.- Specified by:
loadAllUsersin interfaceIdentityManager<I extends Identity>- Returns:
- a map of user ID to identity
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
authenticate
Description copied from interface:IdentityDbAuthenticate with a username and password- Specified by:
authenticatein interfaceIdentityDb<I extends Identity>- Parameters:
upc- the username/password credential- Returns:
- an authenticated identity or null
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
authenticate
Description copied from interface:IdentityDbAuthenticate with an API key and signature- Specified by:
authenticatein interfaceIdentityDb<I extends Identity>- Parameters:
akc- the API key credential- Returns:
- an authenticated identity or null
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
authenticate
Description copied from interface:IdentityDbAuthenticate with a JWT token- Specified by:
authenticatein interfaceIdentityDb<I extends Identity>- Parameters:
jwt- the JWT credential- Returns:
- an authenticated identity or null
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
createJwtToken
Description copied from interface:IdentityDbCreate a JWT token for the given identity.- Specified by:
createJwtTokenin interfaceIdentityDb<I extends Identity>- Parameters:
ii- an identity- Returns:
- a JWT token
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
invalidateJwtToken
Description copied from interface:IdentityDbInvalidate the given JWT token- Specified by:
invalidateJwtTokenin interfaceIdentityDb<I extends Identity>- Parameters:
jwtToken- a JWT token- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
createGroup
Description copied from interface:AccessManagerCreate a group- Specified by:
createGroupin interfaceAccessManager<I extends Identity>- Parameters:
groupDesc- the group description- Returns:
- a new group with the given description
- Throws:
IamGroupExists- if the group already existsIamSvcException- when the call cannot be completed due to a service error
-
createGroup
Description copied from interface:AccessManagerCreate a group with a given group ID- Specified by:
createGroupin interfaceAccessManager<I extends Identity>- Parameters:
groupId- a group IDgroupDesc- a group description- Returns:
- a new group with the given id and description
- Throws:
IamGroupExists- if the group already existsIamSvcException- when the call cannot be completed due to a service error
-
addUserToGroup
public void addUserToGroup(String groupId, String userId) throws IamSvcException, IamIdentityDoesNotExist, IamGroupDoesNotExist Description copied from interface:AccessManagerAdd a user to a given group- Specified by:
addUserToGroupin interfaceAccessManager<I extends Identity>- Parameters:
groupId- a group IDuserId- a user ID- Throws:
IamSvcException- when the call cannot be completed due to a service errorIamIdentityDoesNotExist- when the identity doesn't existIamGroupDoesNotExist- if the group does not exist
-
removeUserFromGroup
public void removeUserFromGroup(String groupId, String userId) throws IamSvcException, IamIdentityDoesNotExist, IamGroupDoesNotExist Description copied from interface:AccessManagerRemove a user from a given group- Specified by:
removeUserFromGroupin interfaceAccessManager<I extends Identity>- Parameters:
groupId- a group IDuserId- a user ID- Throws:
IamSvcException- when the call cannot be completed due to a service errorIamIdentityDoesNotExist- when the identity doesn't existIamGroupDoesNotExist- if the group does not exist
-
getUsersGroups
Description copied from interface:AccessManagerFind out which groups a user is a member of.- Specified by:
getUsersGroupsin interfaceAccessManager<I extends Identity>- Parameters:
userId- a user ID- Returns:
- a set of 0 or more group IDs
- Throws:
IamSvcException- when the call cannot be completed due to a service errorIamIdentityDoesNotExist- when the identity doesn't exist
-
getUsersInGroup
Description copied from interface:AccessManagerGet the set of user IDs in a particular group.- Specified by:
getUsersInGroupin interfaceAccessManager<I extends Identity>- Parameters:
groupId- a group ID- Returns:
- a set of 0 or more user IDs
- Throws:
IamSvcException- when the call cannot be completed due to a service errorIamGroupDoesNotExist- when the identity doesn't exist
-
getAllGroups
Description copied from interface:AccessManagerGet all group IDs in this db. Clearly not suitable for systems beyond a few thousand groups. For larger scale, this call may throw an IamSvcException signaling that the underlying database won't return a group list.- Specified by:
getAllGroupsin interfaceAccessManager<I extends Identity>- Returns:
- a collection of group Ids
- Throws:
IamSvcException- when the call cannot be completed due to a service error
-
loadGroup
Description copied from interface:AccessDbGet a group by its identifier.- Specified by:
loadGroupin interfaceAccessDb<I extends Identity>- Parameters:
id- the group's ID- Returns:
- a group, or null if it does not exist
- Throws:
IamSvcException- if there's a problem in the IAM service
-
getAclFor
Description copied from interface:AccessDbload an ACL for a resource- Specified by:
getAclForin interfaceAccessDb<I extends Identity>- Parameters:
resource- the resource for which you want the ACL- Returns:
- an ACL, or null if there is none
- Throws:
IamSvcException- if there's a problem in the IAM service
-
canUser
Description copied from interface:AccessDbCan the given user perform the requested access?- Specified by:
canUserin interfaceAccessDb<I extends Identity>- Parameters:
id- the identity/subject making the requestresource- the resource on which access is requestedoperation- the operation- Returns:
- true if the user is allowed to perform the operation, false otherwise
- Throws:
IamSvcException- if there's a problem in the IAM service
-
createTag
public String createTag(String userId, String appTagType, long duration, TimeUnit durationTimeUnit, String nonce) throws IamSvcException Description copied from interface:TagManagerCreate a tag for a given user id with a particular type and duration. If a tag for the same user with the same type exists, it's replaced with the new tag.- Specified by:
createTagin interfaceTagManager- Parameters:
userId- a user IDappTagType- a tag typeduration- the length of time the tag should existdurationTimeUnit- the time unit for the durationnonce- used to seed random number generator- Returns:
- a tag
- Throws:
IamSvcException- if there's a problem in the IAM service
-
getUserIdForTag
Description copied from interface:TagManagerRetrieves the userId associated with a tag. If the tag has expired, null is returned.- Specified by:
getUserIdForTagin interfaceTagManager- Parameters:
tag- a tag generated by createTag- Returns:
- a user ID or null if no entry exists (or an entry existed but expired)
- Throws:
IamSvcException- if there's a problem in the IAM service
-
removeMatchingTag
Description copied from interface:TagManagerRemove any matching tag for the given user and type.- Specified by:
removeMatchingTagin interfaceTagManager- Parameters:
userId- a user IDappTagType- a tag type- Throws:
IamSvcException- if there's a problem in the IAM service
-
sweepExpiredTags
Description copied from interface:TagManagerSweep any expired tags. The tag manager implementation may not actually require this operation. In that case, make it a no-op.- Specified by:
sweepExpiredTagsin interfaceTagManager- Throws:
IamSvcException- if there's a problem in the IAM service
-
onAclUpdate
- Specified by:
onAclUpdatein interfaceAclUpdateListener
-
populateMetrics
- Specified by:
populateMetricsin interfaceMetricsSupplier
-